Chromium Code Reviews| Index: chrome/browser/autocomplete/contextual_suggestions_service_factory.cc |
| diff --git a/chrome/browser/autocomplete/contextual_suggestions_service_factory.cc b/chrome/browser/autocomplete/contextual_suggestions_service_factory.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bbc7c27349d1f07d74afe36a031b62739d280f35 |
| --- /dev/null |
| +++ b/chrome/browser/autocomplete/contextual_suggestions_service_factory.cc |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2017 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/autocomplete/contextual_suggestions_service_factory.h" |
| + |
| +#include "base/memory/singleton.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/search_engines/template_url_service_factory.h" |
| +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| +#include "chrome/browser/signin/signin_manager_factory.h" |
| +#include "components/keyed_service/content/browser_context_dependency_manager.h" |
| +#include "components/omnibox/browser/contextual_suggestions_service.h" |
| +#include "components/signin/core/browser/profile_oauth2_token_service.h" |
| +#include "components/signin/core/browser/signin_manager.h" |
| + |
| +using contextual_suggestions::ContextualSuggestionsService; |
| + |
| +// static |
| +ContextualSuggestionsService* |
| +ContextualSuggestionsServiceFactory::GetForProfile(Profile* profile) { |
| + return static_cast<ContextualSuggestionsService*>( |
| + GetInstance()->GetServiceForBrowserContext(profile, true)); |
| +} |
| + |
| +// static |
| +ContextualSuggestionsServiceFactory* |
| +ContextualSuggestionsServiceFactory::GetInstance() { |
| + return base::Singleton<ContextualSuggestionsServiceFactory>::get(); |
| +} |
| + |
| +KeyedService* ContextualSuggestionsServiceFactory::BuildServiceInstanceFor( |
| + content::BrowserContext* context) const { |
| + Profile* profile = static_cast<Profile*>(context); |
|
Mark P
2017/07/17 23:36:11
This should be Profile::FromBrowserContext() inste
|
| + SigninManagerBase* signin_manager = |
| + SigninManagerFactory::GetForProfile(profile); |
| + ProfileOAuth2TokenService* token_service = |
| + ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| + TemplateURLService* template_url_service = |
| + TemplateURLServiceFactory::GetForProfile(profile); |
| + return new ContextualSuggestionsService(signin_manager, token_service, |
| + template_url_service, |
| + profile->GetRequestContext()); |
| +} |
| + |
| +ContextualSuggestionsServiceFactory::ContextualSuggestionsServiceFactory() |
| + : BrowserContextKeyedServiceFactory( |
| + "ContextualSuggestionsService", |
| + BrowserContextDependencyManager::GetInstance()) { |
| + DependsOn(SigninManagerFactory::GetInstance()); |
| + DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
| + DependsOn(TemplateURLServiceFactory::GetInstance()); |
| +} |
| + |
| +ContextualSuggestionsServiceFactory::~ContextualSuggestionsServiceFactory() {} |