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