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.
5 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
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"
15 namespace suggestions {
18 SuggestionsService* SuggestionsServiceFactory::GetForProfile(Profile* profile) {
19 if (!SuggestionsService::IsEnabled())
22 return static_cast<SuggestionsService*>(
23 GetInstance()->GetServiceForBrowserContext(profile, true));
27 SuggestionsServiceFactory* SuggestionsServiceFactory::GetInstance() {
28 return Singleton<SuggestionsServiceFactory>::get();
31 SuggestionsServiceFactory::SuggestionsServiceFactory()
32 : BrowserContextKeyedServiceFactory(
34 BrowserContextDependencyManager::GetInstance()) {
38 SuggestionsServiceFactory::~SuggestionsServiceFactory() {
41 content::BrowserContext* SuggestionsServiceFactory::GetBrowserContextToUse(
42 content::BrowserContext* context) const {
43 return chrome::GetBrowserContextRedirectedInIncognito(context);
46 BrowserContextKeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor(
47 content::BrowserContext* profile) const {
48 return new SuggestionsService(static_cast<Profile*>(profile));
51 } // namespace suggestions