| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" | 5 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "chrome/browser/autocomplete/shortcuts_extensions_manager.h" | 10 #include "chrome/browser/autocomplete/shortcuts_extensions_manager.h" |
| 11 #include "chrome/browser/history/history_service_factory.h" | 11 #include "chrome/browser/history/history_service_factory.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/search_engines/template_url_service_factory.h" | 13 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 14 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 14 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
| 15 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 15 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 16 #include "components/omnibox/browser/shortcuts_backend.h" | 16 #include "components/omnibox/browser/shortcuts_backend.h" |
| 17 #include "components/omnibox/browser/shortcuts_constants.h" | 17 #include "components/omnibox/browser/shortcuts_constants.h" |
| 18 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "extensions/features/features.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 #if defined(ENABLE_EXTENSIONS) | 23 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 23 const char kShortcutsExtensionsManagerKey[] = "ShortcutsExtensionsManager"; | 24 const char kShortcutsExtensionsManagerKey[] = "ShortcutsExtensionsManager"; |
| 24 #endif | 25 #endif |
| 25 } | 26 } |
| 26 | 27 |
| 27 // static | 28 // static |
| 28 scoped_refptr<ShortcutsBackend> ShortcutsBackendFactory::GetForProfile( | 29 scoped_refptr<ShortcutsBackend> ShortcutsBackendFactory::GetForProfile( |
| 29 Profile* profile) { | 30 Profile* profile) { |
| 30 return static_cast<ShortcutsBackend*>( | 31 return static_cast<ShortcutsBackend*>( |
| 31 GetInstance()->GetServiceForBrowserContext(profile, true).get()); | 32 GetInstance()->GetServiceForBrowserContext(profile, true).get()); |
| 32 } | 33 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 content::BrowserContext* profile) const { | 73 content::BrowserContext* profile) const { |
| 73 return CreateShortcutsBackend(Profile::FromBrowserContext(profile), false); | 74 return CreateShortcutsBackend(Profile::FromBrowserContext(profile), false); |
| 74 } | 75 } |
| 75 | 76 |
| 76 bool ShortcutsBackendFactory::ServiceIsNULLWhileTesting() const { | 77 bool ShortcutsBackendFactory::ServiceIsNULLWhileTesting() const { |
| 77 return true; | 78 return true; |
| 78 } | 79 } |
| 79 | 80 |
| 80 void ShortcutsBackendFactory::BrowserContextShutdown( | 81 void ShortcutsBackendFactory::BrowserContextShutdown( |
| 81 content::BrowserContext* context) { | 82 content::BrowserContext* context) { |
| 82 #if defined(ENABLE_EXTENSIONS) | 83 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 83 context->RemoveUserData(kShortcutsExtensionsManagerKey); | 84 context->RemoveUserData(kShortcutsExtensionsManagerKey); |
| 84 #endif | 85 #endif |
| 85 | 86 |
| 86 RefcountedBrowserContextKeyedServiceFactory::BrowserContextShutdown(context); | 87 RefcountedBrowserContextKeyedServiceFactory::BrowserContextShutdown(context); |
| 87 } | 88 } |
| 88 | 89 |
| 89 // static | 90 // static |
| 90 scoped_refptr<ShortcutsBackend> ShortcutsBackendFactory::CreateShortcutsBackend( | 91 scoped_refptr<ShortcutsBackend> ShortcutsBackendFactory::CreateShortcutsBackend( |
| 91 Profile* profile, | 92 Profile* profile, |
| 92 bool suppress_db) { | 93 bool suppress_db) { |
| 93 scoped_refptr<ShortcutsBackend> backend(new ShortcutsBackend( | 94 scoped_refptr<ShortcutsBackend> backend(new ShortcutsBackend( |
| 94 TemplateURLServiceFactory::GetForProfile(profile), | 95 TemplateURLServiceFactory::GetForProfile(profile), |
| 95 base::MakeUnique<UIThreadSearchTermsData>(profile), | 96 base::MakeUnique<UIThreadSearchTermsData>(profile), |
| 96 HistoryServiceFactory::GetForProfile(profile, | 97 HistoryServiceFactory::GetForProfile(profile, |
| 97 ServiceAccessType::EXPLICIT_ACCESS), | 98 ServiceAccessType::EXPLICIT_ACCESS), |
| 98 content::BrowserThread::GetTaskRunnerForThread( | 99 content::BrowserThread::GetTaskRunnerForThread( |
| 99 content::BrowserThread::DB), | 100 content::BrowserThread::DB), |
| 100 profile->GetPath().Append(kShortcutsDatabaseName), suppress_db)); | 101 profile->GetPath().Append(kShortcutsDatabaseName), suppress_db)); |
| 101 #if defined(ENABLE_EXTENSIONS) | 102 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 102 ShortcutsExtensionsManager* extensions_manager = | 103 ShortcutsExtensionsManager* extensions_manager = |
| 103 new ShortcutsExtensionsManager(profile); | 104 new ShortcutsExtensionsManager(profile); |
| 104 profile->SetUserData(kShortcutsExtensionsManagerKey, extensions_manager); | 105 profile->SetUserData(kShortcutsExtensionsManagerKey, extensions_manager); |
| 105 #endif | 106 #endif |
| 106 return backend->Init() ? backend : nullptr; | 107 return backend->Init() ? backend : nullptr; |
| 107 } | 108 } |
| OLD | NEW |