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

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

Issue 2102023002: Add ContentSuggestionsService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add explicit cast from ContentSuggestionsCategory to int Created 4 years, 5 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_service_factory.cc
diff --git a/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc b/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6e16f96b0f7445ceb0ba854d009f72c761aa8c4b
--- /dev/null
+++ b/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc
@@ -0,0 +1,56 @@
+// 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_service_factory.h"
+
+#include "base/feature_list.h"
+#include "base/memory/singleton.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/pref_names.h"
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#include "components/ntp_snippets/content_suggestions_service.h"
+#include "components/prefs/pref_service.h"
+#include "content/public/browser/browser_context.h"
+
+#if defined(OS_ANDROID)
+#include "chrome/browser/android/chrome_feature_list.h"
+#endif // OS_ANDROID
+
+// static
+ContentSuggestionsServiceFactory*
+ContentSuggestionsServiceFactory::GetInstance() {
+ return base::Singleton<ContentSuggestionsServiceFactory>::get();
+}
+
+// static
+ntp_snippets::ContentSuggestionsService*
+ContentSuggestionsServiceFactory::GetForProfile(Profile* profile) {
+ DCHECK(!profile->IsOffTheRecord());
+ return static_cast<ntp_snippets::ContentSuggestionsService*>(
+ GetInstance()->GetServiceForBrowserContext(profile, true));
+}
+
+ContentSuggestionsServiceFactory::ContentSuggestionsServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "ContentSuggestionsService",
+ BrowserContextDependencyManager::GetInstance()) {}
+
+ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() {}
+
+KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor(
+ content::BrowserContext* context) const {
+ using State = ntp_snippets::ContentSuggestionsService::State;
+
+ // TODO(mvanouwerkerk): Move the enable logic into the service once we start
+ // observing pref changes.
+ State enabled = State::DISABLED;
+#if defined(OS_ANDROID)
+ // TODO(pke): Split that feature into suggestions overall and article
+ // suggestions in particular.
+ if (base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature))
+ enabled = State::ENABLED;
+#endif // OS_ANDROID
+
+ return new ntp_snippets::ContentSuggestionsService(enabled);
+}
« no previous file with comments | « chrome/browser/ntp_snippets/content_suggestions_service_factory.h ('k') | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698