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

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

Issue 2606753002: Post notification after fetching articles (Closed)
Patch Set: Address comments 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 bool ContentSuggestionsNotifierServiceFactory::
22 ServiceIsCreatedWithBrowserContext() const {
23 return true;
24 }
25
26 ContentSuggestionsNotifierServiceFactory*
27 ContentSuggestionsNotifierServiceFactory::GetInstance() {
28 return base::Singleton<ContentSuggestionsNotifierServiceFactory>::get();
29 }
30
31 ContentSuggestionsNotifierService*
32 ContentSuggestionsNotifierServiceFactory::GetForProfile(Profile* profile) {
33 #if defined(OS_ANDROID)
34 return static_cast<ContentSuggestionsNotifierService*>(
35 GetInstance()->GetServiceForBrowserContext(profile, true));
36 #else
37 return nullptr;
38 #endif
39 }
40
41 ContentSuggestionsNotifierService*
42 ContentSuggestionsNotifierServiceFactory::GetForProfileIfExists(
43 Profile* profile) {
44 #if defined(OS_ANDROID)
45 return static_cast<ContentSuggestionsNotifierService*>(
46 GetInstance()->GetServiceForBrowserContext(profile, false));
47 #else
48 return nullptr;
49 #endif
50 }
51
52 ContentSuggestionsNotifierServiceFactory::
53 ContentSuggestionsNotifierServiceFactory()
54 : BrowserContextKeyedServiceFactory(
55 "ContentSuggestionsNotifierService",
56 BrowserContextDependencyManager::GetInstance()) {
57 DependsOn(ContentSuggestionsServiceFactory::GetInstance());
58 }
59
60 ContentSuggestionsNotifierServiceFactory::
61 ~ContentSuggestionsNotifierServiceFactory() = default;
62
63 // BrowserContextKeyedServiceFactory implementation.
64 KeyedService* ContentSuggestionsNotifierServiceFactory::BuildServiceInstanceFor(
65 content::BrowserContext* context) const {
66 #if defined(OS_ANDROID)
67 if (base::FeatureList::IsEnabled(kContentSuggestionsNotificationsFeature)) {
68 Profile* profile = Profile::FromBrowserContext(context);
69 ntp_snippets::ContentSuggestionsService* suggestions =
70 ContentSuggestionsServiceFactory::GetForProfile(profile);
71 return new ContentSuggestionsNotifierService(profile, suggestions,
72 profile->GetPrefs());
73 }
74 #endif
75 return nullptr;
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698