Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: chrome/browser/ntp_snippets/content_suggestions_notifier_service_factory.cc

Issue 2606753002: Post notification after fetching articles (Closed)
Patch Set: override Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_notifier_service_facto ry.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/memory/singleton.h"
9 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/keyed_service/content/browser_context_dependency_manager.h"
12 #include "components/variations/variations_associated_data.h"
13
14 #if defined(OS_ANDROID)
15 #include "chrome/browser/android/ntp//content_suggestions_notifier_service.h"
16
17 const base::Feature kContentSuggestionsNotificationsFeature = {
18 "ContentSuggestionsNotifications", base::FEATURE_DISABLED_BY_DEFAULT};
19 #endif
20
21 ContentSuggestionsNotifierServiceFactory*
22 ContentSuggestionsNotifierServiceFactory::GetInstance() {
23 return base::Singleton<ContentSuggestionsNotifierServiceFactory>::get();
24 }
25
26 ContentSuggestionsNotifierService*
27 ContentSuggestionsNotifierServiceFactory::GetForProfile(Profile* profile) {
28 #if defined(OS_ANDROID)
29 return static_cast<ContentSuggestionsNotifierService*>(
30 GetInstance()->GetServiceForBrowserContext(profile, true));
31 #else
32 return nullptr;
33 #endif
34 }
35
36 ContentSuggestionsNotifierService*
37 ContentSuggestionsNotifierServiceFactory::GetForProfileIfExists(
38 Profile* profile) {
39 #if defined(OS_ANDROID)
40 return static_cast<ContentSuggestionsNotifierService*>(
41 GetInstance()->GetServiceForBrowserContext(profile, false));
42 #else
43 return nullptr;
44 #endif
45 }
46
47 ContentSuggestionsNotifierServiceFactory::
48 ContentSuggestionsNotifierServiceFactory()
49 : BrowserContextKeyedServiceFactory(
50 "ContentSuggestionsNotifierService",
51 BrowserContextDependencyManager::GetInstance()) {
52 DependsOn(ContentSuggestionsServiceFactory::GetInstance());
53 }
54
55 ContentSuggestionsNotifierServiceFactory::
56 ~ContentSuggestionsNotifierServiceFactory() = default;
57
58 // BrowserContextKeyedServiceFactory implementation.
59 KeyedService* ContentSuggestionsNotifierServiceFactory::BuildServiceInstanceFor(
60 content::BrowserContext* context) const {
61 #if defined(OS_ANDROID)
62 if (base::FeatureList::IsEnabled(kContentSuggestionsNotificationsFeature)) {
63 Profile* profile = Profile::FromBrowserContext(context);
64 auto suggestions = ContentSuggestionsServiceFactory::GetForProfile(profile);
Bernhard Bauer 2017/01/03 17:38:59 Nit: The type of |suggestions| isn't totally obvio
sfiera 2017/01/03 23:13:55 Done.
65 return new ContentSuggestionsNotifierService(profile, suggestions,
66 profile->GetPrefs());
67 }
68 #endif
69 return nullptr;
70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698