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

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: Remove NTPSnippet::ToContentSuggestion and make ContentSuggestionsProvider::MakeUniqueID protected 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..fb9b9f5f9f58a88538147ee909069ac71794bcd2
--- /dev/null
+++ b/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc
@@ -0,0 +1,57 @@
+// 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::ENABLED;
Bernhard Bauer 2016/07/07 10:02:19 Wait, on non-Android platforms this is always enab
Philipp Keck 2016/07/07 12:22:29 Should be the same as NTPSnippetsServiceFactory. O
Marc Treib 2016/07/07 12:32:16 Yup, IMO we should change this. The change for NTP
Philipp Keck 2016/07/07 12:44:06 Done. Should I prepare a separate CL for NTPSnippe
Marc Treib 2016/07/07 12:48:18 Yup, please do :)
Philipp Keck 2016/07/08 09:28:57 @bauerb Please take a look again at the factory, a
+#if defined(OS_ANDROID)
+ // TODO(pke) Split that feature into suggestions overall and article
+ // suggestions in particular.
+ if (!base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature)) {
Bernhard Bauer 2016/07/07 10:02:19 Nit: No braces for single-line bodies.
Philipp Keck 2016/07/07 12:22:29 A very debatable style rule ... makes it harder to
+ enabled = State::DISABLED;
+ }
+#endif // OS_ANDROID
+
+ return new ntp_snippets::ContentSuggestionsService(enabled);
+}

Powered by Google App Engine
This is Rietveld 408576698