Chromium Code Reviews| 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.
|
| +} |