| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" | 5 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 12 #include "chrome/browser/signin/signin_manager_factory.h" |
| 11 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 13 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 14 #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
| 12 #include "components/ntp_snippets/ntp_snippets_service.h" | 15 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 16 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 17 #include "components/signin/core/browser/signin_manager.h" |
| 13 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "net/url_request/url_request_context_getter.h" |
| 21 |
| 22 using content::BrowserThread; |
| 14 | 23 |
| 15 // static | 24 // static |
| 16 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() { | 25 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() { |
| 17 return base::Singleton<NTPSnippetsServiceFactory>::get(); | 26 return base::Singleton<NTPSnippetsServiceFactory>::get(); |
| 18 } | 27 } |
| 19 | 28 |
| 20 // static | 29 // static |
| 21 ntp_snippets::NTPSnippetsService* NTPSnippetsServiceFactory::GetForProfile( | 30 ntp_snippets::NTPSnippetsService* NTPSnippetsServiceFactory::GetForProfile( |
| 22 Profile* profile) { | 31 Profile* profile) { |
| 23 DCHECK(!profile->IsOffTheRecord()); | 32 DCHECK(!profile->IsOffTheRecord()); |
| 24 return static_cast<ntp_snippets::NTPSnippetsService*>( | 33 return static_cast<ntp_snippets::NTPSnippetsService*>( |
| 25 GetInstance()->GetServiceForBrowserContext(profile, true)); | 34 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 26 } | 35 } |
| 27 | 36 |
| 28 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory() | 37 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory() |
| 29 : BrowserContextKeyedServiceFactory( | 38 : BrowserContextKeyedServiceFactory( |
| 30 "NTPSnippetsService", | 39 "NTPSnippetsService", |
| 31 BrowserContextDependencyManager::GetInstance()) {} | 40 BrowserContextDependencyManager::GetInstance()) {} |
| 32 | 41 |
| 33 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} | 42 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} |
| 34 | 43 |
| 35 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( | 44 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( |
| 36 content::BrowserContext* context) const { | 45 content::BrowserContext* context) const { |
| 46 Profile* profile = Profile::FromBrowserContext(context); |
| 47 SigninManagerBase* signin_manager = |
| 48 SigninManagerFactory::GetForProfile(profile); |
| 49 OAuth2TokenService* token_service = |
| 50 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 51 scoped_refptr<net::URLRequestContextGetter> request_context = |
| 52 context->GetRequestContext(); |
| 53 |
| 54 scoped_refptr<base::SequencedTaskRunner> task_runner = |
| 55 BrowserThread::GetBlockingPool() |
| 56 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 57 base::SequencedWorkerPool::GetSequenceToken(), |
| 58 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 59 |
| 37 return new ntp_snippets::NTPSnippetsService( | 60 return new ntp_snippets::NTPSnippetsService( |
| 38 g_browser_process->GetApplicationLocale()); | 61 task_runner, g_browser_process->GetApplicationLocale(), |
| 62 make_scoped_ptr(new ntp_snippets::NTPSnippetsFetcher( |
| 63 task_runner, signin_manager, token_service, request_context, |
| 64 profile->GetPath()))); |
| 39 } | 65 } |
| OLD | NEW |