Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / autocomplete / shortcuts_backend_factory.cc
blobadf93dbed3797e73c67a85ff956294d41a27587b
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
3 // found in the LICENSE file.
5 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/autocomplete/shortcuts_backend.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "components/keyed_service/content/browser_context_dependency_manager.h"
12 // static
13 scoped_refptr<ShortcutsBackend> ShortcutsBackendFactory::GetForProfile(
14 Profile* profile) {
15 return static_cast<ShortcutsBackend*>(
16 GetInstance()->GetServiceForBrowserContext(profile, true).get());
19 // static
20 scoped_refptr<ShortcutsBackend> ShortcutsBackendFactory::GetForProfileIfExists(
21 Profile* profile) {
22 return static_cast<ShortcutsBackend*>(
23 GetInstance()->GetServiceForBrowserContext(profile, false).get());
26 // static
27 ShortcutsBackendFactory* ShortcutsBackendFactory::GetInstance() {
28 return Singleton<ShortcutsBackendFactory>::get();
31 // static
32 scoped_refptr<RefcountedKeyedService>
33 ShortcutsBackendFactory::BuildProfileForTesting(
34 content::BrowserContext* profile) {
35 scoped_refptr<ShortcutsBackend> backend(
36 new ShortcutsBackend(static_cast<Profile*>(profile), false));
37 if (backend->Init())
38 return backend;
39 return NULL;
42 // static
43 scoped_refptr<RefcountedKeyedService>
44 ShortcutsBackendFactory::BuildProfileNoDatabaseForTesting(
45 content::BrowserContext* profile) {
46 scoped_refptr<ShortcutsBackend> backend(
47 new ShortcutsBackend(static_cast<Profile*>(profile), true));
48 if (backend->Init())
49 return backend;
50 return NULL;
53 ShortcutsBackendFactory::ShortcutsBackendFactory()
54 : RefcountedBrowserContextKeyedServiceFactory(
55 "ShortcutsBackend",
56 BrowserContextDependencyManager::GetInstance()) {
59 ShortcutsBackendFactory::~ShortcutsBackendFactory() {}
61 scoped_refptr<RefcountedKeyedService>
62 ShortcutsBackendFactory::BuildServiceInstanceFor(
63 content::BrowserContext* profile) const {
64 scoped_refptr<ShortcutsBackend> backend(
65 new ShortcutsBackend(static_cast<Profile*>(profile), false));
66 if (backend->Init())
67 return backend;
68 return NULL;
71 bool ShortcutsBackendFactory::ServiceIsNULLWhileTesting() const {
72 return true;