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

Unified Diff: chrome/browser/ntp_suggestions/ntp_suggestions_service_factory.cc

Issue 1438043008: Creating the NTP snippet service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 1 month 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_suggestions/ntp_suggestions_service_factory.cc
diff --git a/chrome/browser/ntp_suggestions/ntp_suggestions_service_factory.cc b/chrome/browser/ntp_suggestions/ntp_suggestions_service_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b7534f9bae952579a575edf7abe61a3da376a9ba
--- /dev/null
+++ b/chrome/browser/ntp_suggestions/ntp_suggestions_service_factory.cc
@@ -0,0 +1,46 @@
+// Copyright 2015 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_suggestions/ntp_suggestions_service_factory.h"
+
+#include "base/logging.h"
+#include "base/memory/singleton.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/incognito_helpers.h"
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#include "components/ntp_suggestions/ntp_suggestions_service.h"
+#include "content/public/browser/browser_context.h"
+
+// static
+NTPSuggestionsServiceFactory* NTPSuggestionsServiceFactory::GetInstance() {
+ return base::Singleton<NTPSuggestionsServiceFactory>::get();
+}
+
+// static
+ntp_suggestions::NTPSuggestionsService*
+NTPSuggestionsServiceFactory::GetForBrowserContext(
+ content::BrowserContext* context) {
+ DCHECK(!context->IsOffTheRecord());
sdefresne 2015/11/17 13:57:29 nit: The default implementation of BrowserContextK
noyau (Ping after 24h) 2015/11/17 17:00:33 I prefer a crash rather than a null that needs to
+ return static_cast<ntp_suggestions::NTPSuggestionsService*>(
+ GetInstance()->GetServiceForBrowserContext(context, true));
+}
+
+NTPSuggestionsServiceFactory::NTPSuggestionsServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "NTPSuggestionsService",
+ BrowserContextDependencyManager::GetInstance()) {}
+
+NTPSuggestionsServiceFactory::~NTPSuggestionsServiceFactory() {}
+
+KeyedService* NTPSuggestionsServiceFactory::BuildServiceInstanceFor(
+ content::BrowserContext* context) const {
+ DCHECK(!context->IsOffTheRecord());
sdefresne 2015/11/17 13:57:29 Remove this DCHECK, it is useless.
noyau (Ping after 24h) 2015/11/17 17:00:33 Done.
+ return new ntp_suggestions::NTPSuggestionsService(
+ g_browser_process->GetApplicationLocale());
+}
+
+content::BrowserContext* NTPSuggestionsServiceFactory::GetBrowserContextToUse(
+ content::BrowserContext* context) const {
+ return chrome::GetBrowserContextRedirectedInIncognito(context);
sdefresne 2015/11/17 13:57:29 By default BrowserContextKeyedServiceFactory will
noyau (Ping after 24h) 2015/11/17 17:00:33 Done.
+}

Powered by Google App Engine
This is Rietveld 408576698