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

Unified Diff: chrome/browser/ntp_snippets/content_suggestions_notifier_service_factory.cc

Issue 2606753002: Post notification after fetching articles (Closed)
Patch Set: Add TODO. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ntp_snippets/content_suggestions_notifier_service_factory.cc
diff --git a/chrome/browser/ntp_snippets/content_suggestions_notifier_service_factory.cc b/chrome/browser/ntp_snippets/content_suggestions_notifier_service_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bce7105c7097894a76eeb358565c275e33d3da65
--- /dev/null
+++ b/chrome/browser/ntp_snippets/content_suggestions_notifier_service_factory.cc
@@ -0,0 +1,69 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ntp_snippets/content_suggestions_notifier_service_factory.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/memory/singleton.h"
+#include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
+#include "chrome/browser/ntp_snippets/ntp_snippets_features.h"
+#include "chrome/browser/profiles/profile.h"
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#include "components/variations/variations_associated_data.h"
+
+#if defined(OS_ANDROID)
+#include "chrome/browser/android/ntp/content_suggestions_notifier_service.h"
+#endif
+
+ContentSuggestionsNotifierServiceFactory*
+ContentSuggestionsNotifierServiceFactory::GetInstance() {
+ return base::Singleton<ContentSuggestionsNotifierServiceFactory>::get();
+}
+
+ContentSuggestionsNotifierService*
+ContentSuggestionsNotifierServiceFactory::GetForProfile(Profile* profile) {
+#if defined(OS_ANDROID)
+ return static_cast<ContentSuggestionsNotifierService*>(
+ GetInstance()->GetServiceForBrowserContext(profile, true));
+#else
+ return nullptr;
+#endif
+}
+
+ContentSuggestionsNotifierService*
+ContentSuggestionsNotifierServiceFactory::GetForProfileIfExists(
+ Profile* profile) {
+#if defined(OS_ANDROID)
+ return static_cast<ContentSuggestionsNotifierService*>(
+ GetInstance()->GetServiceForBrowserContext(profile, false));
+#else
+ return nullptr;
+#endif
+}
+
+ContentSuggestionsNotifierServiceFactory::
+ ContentSuggestionsNotifierServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "ContentSuggestionsNotifierService",
+ BrowserContextDependencyManager::GetInstance()) {
+ DependsOn(ContentSuggestionsServiceFactory::GetInstance());
+}
+
+ContentSuggestionsNotifierServiceFactory::
+ ~ContentSuggestionsNotifierServiceFactory() = default;
+
+// BrowserContextKeyedServiceFactory implementation.
+KeyedService* ContentSuggestionsNotifierServiceFactory::BuildServiceInstanceFor(
+ content::BrowserContext* context) const {
+#if defined(OS_ANDROID)
+ if (base::FeatureList::IsEnabled(kContentSuggestionsNotificationsFeature)) {
+ Profile* profile = Profile::FromBrowserContext(context);
+ ntp_snippets::ContentSuggestionsService* suggestions =
+ ContentSuggestionsServiceFactory::GetForProfile(profile);
+ return new ContentSuggestionsNotifierService(profile, suggestions,
+ profile->GetPrefs());
+ }
+#endif
+ return nullptr;
+}

Powered by Google App Engine
This is Rietveld 408576698