Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / search / suggestions / suggestions_service_factory.cc
1 // Copyright 2014 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/search/suggestions/suggestions_service_factory.h"
6
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/incognito_helpers.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search/suggestions/suggestions_service.h"
11 #include "chrome/common/pref_names.h"
12 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
13 #include "components/user_prefs/pref_registry_syncable.h"
14
15 namespace suggestions {
16
17 // static
18 SuggestionsService* SuggestionsServiceFactory::GetForProfile(Profile* profile) {
19   if (!SuggestionsService::IsEnabled())
20     return NULL;
21
22   return static_cast<SuggestionsService*>(
23       GetInstance()->GetServiceForBrowserContext(profile, true));
24 }
25
26 // static
27 SuggestionsServiceFactory* SuggestionsServiceFactory::GetInstance() {
28   return Singleton<SuggestionsServiceFactory>::get();
29 }
30
31 SuggestionsServiceFactory::SuggestionsServiceFactory()
32     : BrowserContextKeyedServiceFactory(
33         "SuggestionsService",
34         BrowserContextDependencyManager::GetInstance()) {
35   // No dependencies.
36 }
37
38 SuggestionsServiceFactory::~SuggestionsServiceFactory() {
39 }
40
41 content::BrowserContext* SuggestionsServiceFactory::GetBrowserContextToUse(
42     content::BrowserContext* context) const {
43   return chrome::GetBrowserContextRedirectedInIncognito(context);
44 }
45
46 BrowserContextKeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor(
47     content::BrowserContext* profile) const {
48   return new SuggestionsService(static_cast<Profile*>(profile));
49 }
50
51 }  // namespace suggestions