| 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/history/shortcuts_backend_factory.h" | 5 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/history/shortcuts_backend.h" | 8 #include "chrome/browser/autocomplete/shortcuts_backend.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 11 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 12 | 12 |
| 13 using history::ShortcutsBackend; | |
| 14 | |
| 15 // static | 13 // static |
| 16 scoped_refptr<ShortcutsBackend> ShortcutsBackendFactory::GetForProfile( | 14 scoped_refptr<ShortcutsBackend> ShortcutsBackendFactory::GetForProfile( |
| 17 Profile* profile) { | 15 Profile* profile) { |
| 18 return static_cast<ShortcutsBackend*>( | 16 return static_cast<ShortcutsBackend*>( |
| 19 GetInstance()->GetServiceForBrowserContext(profile, true).get()); | 17 GetInstance()->GetServiceForBrowserContext(profile, true).get()); |
| 20 } | 18 } |
| 21 | 19 |
| 22 // static | 20 // static |
| 23 scoped_refptr<ShortcutsBackend> ShortcutsBackendFactory::GetForProfileIfExists( | 21 scoped_refptr<ShortcutsBackend> ShortcutsBackendFactory::GetForProfileIfExists( |
| 24 Profile* profile) { | 22 Profile* profile) { |
| 25 return static_cast<ShortcutsBackend*>( | 23 return static_cast<ShortcutsBackend*>( |
| 26 GetInstance()->GetServiceForBrowserContext(profile, false).get()); | 24 GetInstance()->GetServiceForBrowserContext(profile, false).get()); |
| 27 } | 25 } |
| 28 | 26 |
| 29 // static | 27 // static |
| 30 ShortcutsBackendFactory* ShortcutsBackendFactory::GetInstance() { | 28 ShortcutsBackendFactory* ShortcutsBackendFactory::GetInstance() { |
| 31 return Singleton<ShortcutsBackendFactory>::get(); | 29 return Singleton<ShortcutsBackendFactory>::get(); |
| 32 } | 30 } |
| 33 | 31 |
| 34 // static | 32 // static |
| 35 scoped_refptr<RefcountedBrowserContextKeyedService> | 33 scoped_refptr<RefcountedBrowserContextKeyedService> |
| 36 ShortcutsBackendFactory::BuildProfileForTesting( | 34 ShortcutsBackendFactory::BuildProfileForTesting( |
| 37 content::BrowserContext* profile) { | 35 content::BrowserContext* profile) { |
| 38 scoped_refptr<history::ShortcutsBackend> backend( | 36 scoped_refptr<ShortcutsBackend> backend( |
| 39 new ShortcutsBackend(static_cast<Profile*>(profile), false)); | 37 new ShortcutsBackend(static_cast<Profile*>(profile), false)); |
| 40 if (backend->Init()) | 38 if (backend->Init()) |
| 41 return backend; | 39 return backend; |
| 42 return NULL; | 40 return NULL; |
| 43 } | 41 } |
| 44 | 42 |
| 45 // static | 43 // static |
| 46 scoped_refptr<RefcountedBrowserContextKeyedService> | 44 scoped_refptr<RefcountedBrowserContextKeyedService> |
| 47 ShortcutsBackendFactory::BuildProfileNoDatabaseForTesting( | 45 ShortcutsBackendFactory::BuildProfileNoDatabaseForTesting( |
| 48 content::BrowserContext* profile) { | 46 content::BrowserContext* profile) { |
| 49 scoped_refptr<history::ShortcutsBackend> backend( | 47 scoped_refptr<ShortcutsBackend> backend( |
| 50 new ShortcutsBackend(static_cast<Profile*>(profile), true)); | 48 new ShortcutsBackend(static_cast<Profile*>(profile), true)); |
| 51 if (backend->Init()) | 49 if (backend->Init()) |
| 52 return backend; | 50 return backend; |
| 53 return NULL; | 51 return NULL; |
| 54 } | 52 } |
| 55 | 53 |
| 56 ShortcutsBackendFactory::ShortcutsBackendFactory() | 54 ShortcutsBackendFactory::ShortcutsBackendFactory() |
| 57 : RefcountedBrowserContextKeyedServiceFactory( | 55 : RefcountedBrowserContextKeyedServiceFactory( |
| 58 "ShortcutsBackend", | 56 "ShortcutsBackend", |
| 59 BrowserContextDependencyManager::GetInstance()) { | 57 BrowserContextDependencyManager::GetInstance()) { |
| 60 } | 58 } |
| 61 | 59 |
| 62 ShortcutsBackendFactory::~ShortcutsBackendFactory() {} | 60 ShortcutsBackendFactory::~ShortcutsBackendFactory() {} |
| 63 | 61 |
| 64 scoped_refptr<RefcountedBrowserContextKeyedService> | 62 scoped_refptr<RefcountedBrowserContextKeyedService> |
| 65 ShortcutsBackendFactory::BuildServiceInstanceFor( | 63 ShortcutsBackendFactory::BuildServiceInstanceFor( |
| 66 content::BrowserContext* profile) const { | 64 content::BrowserContext* profile) const { |
| 67 scoped_refptr<history::ShortcutsBackend> backend( | 65 scoped_refptr<ShortcutsBackend> backend( |
| 68 new ShortcutsBackend(static_cast<Profile*>(profile), false)); | 66 new ShortcutsBackend(static_cast<Profile*>(profile), false)); |
| 69 if (backend->Init()) | 67 if (backend->Init()) |
| 70 return backend; | 68 return backend; |
| 71 return NULL; | 69 return NULL; |
| 72 } | 70 } |
| 73 | 71 |
| 74 bool ShortcutsBackendFactory::ServiceIsNULLWhileTesting() const { | 72 bool ShortcutsBackendFactory::ServiceIsNULLWhileTesting() const { |
| 75 return true; | 73 return true; |
| 76 } | 74 } |
| OLD | NEW |