OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/ntp_snippets/content_suggestions_service_factory.h" |
| 6 |
| 7 #include "base/feature_list.h" |
| 8 #include "base/memory/singleton.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 #include "components/ntp_snippets/content_suggestions_service.h" |
| 13 #include "components/prefs/pref_service.h" |
| 14 #include "content/public/browser/browser_context.h" |
| 15 |
| 16 #if defined(OS_ANDROID) |
| 17 #include "chrome/browser/android/chrome_feature_list.h" |
| 18 #endif // OS_ANDROID |
| 19 |
| 20 // static |
| 21 ContentSuggestionsServiceFactory* |
| 22 ContentSuggestionsServiceFactory::GetInstance() { |
| 23 return base::Singleton<ContentSuggestionsServiceFactory>::get(); |
| 24 } |
| 25 |
| 26 // static |
| 27 ntp_snippets::ContentSuggestionsService* |
| 28 ContentSuggestionsServiceFactory::GetForProfile(Profile* profile) { |
| 29 DCHECK(!profile->IsOffTheRecord()); |
| 30 return static_cast<ntp_snippets::ContentSuggestionsService*>( |
| 31 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 32 } |
| 33 |
| 34 ContentSuggestionsServiceFactory::ContentSuggestionsServiceFactory() |
| 35 : BrowserContextKeyedServiceFactory( |
| 36 "ContentSuggestionsService", |
| 37 BrowserContextDependencyManager::GetInstance()) {} |
| 38 |
| 39 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() {} |
| 40 |
| 41 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor( |
| 42 content::BrowserContext* context) const { |
| 43 // TODO(mvanouwerkerk): Move the enable logic into the service once we start |
| 44 // observing pref changes. |
| 45 bool enabled = true; |
| 46 #if defined(OS_ANDROID) |
| 47 enabled = enabled && |
| 48 base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature); |
| 49 #endif // OS_ANDROID |
| 50 |
| 51 return new ntp_snippets::ContentSuggestionsService(enabled); |
| 52 } |
OLD | NEW |