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 using State = ntp_snippets::ContentSuggestionsService::State; | |
44 | |
45 // TODO(mvanouwerkerk): Move the enable logic into the service once we start | |
46 // observing pref changes. | |
47 State enabled = State::ENABLED; | |
Bernhard Bauer
2016/07/07 10:02:19
Wait, on non-Android platforms this is always enab
Philipp Keck
2016/07/07 12:22:29
Should be the same as NTPSnippetsServiceFactory.
O
Marc Treib
2016/07/07 12:32:16
Yup, IMO we should change this. The change for NTP
Philipp Keck
2016/07/07 12:44:06
Done. Should I prepare a separate CL for NTPSnippe
Marc Treib
2016/07/07 12:48:18
Yup, please do :)
Philipp Keck
2016/07/08 09:28:57
@bauerb Please take a look again at the factory, a
| |
48 #if defined(OS_ANDROID) | |
49 // TODO(pke) Split that feature into suggestions overall and article | |
50 // suggestions in particular. | |
51 if (!base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature)) { | |
Bernhard Bauer
2016/07/07 10:02:19
Nit: No braces for single-line bodies.
Philipp Keck
2016/07/07 12:22:29
A very debatable style rule ... makes it harder to
| |
52 enabled = State::DISABLED; | |
53 } | |
54 #endif // OS_ANDROID | |
55 | |
56 return new ntp_snippets::ContentSuggestionsService(enabled); | |
57 } | |
OLD | NEW |