/chrome/browser/autocomplete/in_memory_url_index_factory.cc

https://gitlab.com/0072016/Facebook-SDK- · C++ · 66 lines · 51 code · 9 blank · 6 comment · 0 complexity · 62b976d755d47f968fced440168c9fc9 MD5 · raw file

  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "chrome/browser/autocomplete/in_memory_url_index_factory.h"
  5. #include "base/memory/singleton.h"
  6. #include "chrome/browser/bookmarks/bookmark_model_factory.h"
  7. #include "chrome/browser/history/history_service_factory.h"
  8. #include "chrome/browser/profiles/incognito_helpers.h"
  9. #include "chrome/browser/profiles/profile.h"
  10. #include "chrome/browser/search_engines/template_url_service_factory.h"
  11. #include "components/keyed_service/content/browser_context_dependency_manager.h"
  12. #include "components/keyed_service/core/service_access_type.h"
  13. #include "components/omnibox/browser/in_memory_url_index.h"
  14. #include "content/public/browser/browser_thread.h"
  15. #include "content/public/common/url_constants.h"
  16. // static
  17. InMemoryURLIndex* InMemoryURLIndexFactory::GetForProfile(Profile* profile) {
  18. return static_cast<InMemoryURLIndex*>(
  19. GetInstance()->GetServiceForBrowserContext(profile, true));
  20. }
  21. // static
  22. InMemoryURLIndexFactory* InMemoryURLIndexFactory::GetInstance() {
  23. return base::Singleton<InMemoryURLIndexFactory>::get();
  24. }
  25. InMemoryURLIndexFactory::InMemoryURLIndexFactory()
  26. : BrowserContextKeyedServiceFactory(
  27. "InMemoryURLIndex",
  28. BrowserContextDependencyManager::GetInstance()) {
  29. DependsOn(BookmarkModelFactory::GetInstance());
  30. DependsOn(HistoryServiceFactory::GetInstance());
  31. DependsOn(TemplateURLServiceFactory::GetInstance());
  32. }
  33. InMemoryURLIndexFactory::~InMemoryURLIndexFactory() {
  34. }
  35. KeyedService* InMemoryURLIndexFactory::BuildServiceInstanceFor(
  36. content::BrowserContext* context) const {
  37. // Do not force creation of the HistoryService if saving history is disabled.
  38. Profile* profile = Profile::FromBrowserContext(context);
  39. SchemeSet chrome_schemes_to_whitelist;
  40. chrome_schemes_to_whitelist.insert(content::kChromeUIScheme);
  41. InMemoryURLIndex* in_memory_url_index = new InMemoryURLIndex(
  42. BookmarkModelFactory::GetForProfile(profile),
  43. HistoryServiceFactory::GetForProfile(profile,
  44. ServiceAccessType::IMPLICIT_ACCESS),
  45. TemplateURLServiceFactory::GetForProfile(profile),
  46. content::BrowserThread::GetBlockingPool(), profile->GetPath(),
  47. chrome_schemes_to_whitelist);
  48. in_memory_url_index->Init();
  49. return in_memory_url_index;
  50. }
  51. content::BrowserContext* InMemoryURLIndexFactory::GetBrowserContextToUse(
  52. content::BrowserContext* context) const {
  53. return chrome::GetBrowserContextRedirectedInIncognito(context);
  54. }
  55. bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const {
  56. return true;
  57. }