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; |
+} |