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" | |
13 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
18 #include "content/public/browser/browser_thread.h" | |
19 #include "net/url_request/url_request_context_getter.h" | |
20 | |
21 using content::BrowserThread; | |
14 | 22 |
15 // static | 23 // static |
16 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() { | 24 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() { |
17 return base::Singleton<NTPSnippetsServiceFactory>::get(); | 25 return base::Singleton<NTPSnippetsServiceFactory>::get(); |
18 } | 26 } |
19 | 27 |
20 // static | 28 // static |
21 ntp_snippets::NTPSnippetsService* NTPSnippetsServiceFactory::GetForProfile( | 29 ntp_snippets::NTPSnippetsService* NTPSnippetsServiceFactory::GetForProfile( |
22 Profile* profile) { | 30 Profile* profile) { |
23 DCHECK(!profile->IsOffTheRecord()); | 31 DCHECK(!profile->IsOffTheRecord()); |
24 return static_cast<ntp_snippets::NTPSnippetsService*>( | 32 return static_cast<ntp_snippets::NTPSnippetsService*>( |
25 GetInstance()->GetServiceForBrowserContext(profile, true)); | 33 GetInstance()->GetServiceForBrowserContext(profile, true)); |
26 } | 34 } |
27 | 35 |
28 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory() | 36 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory() |
29 : BrowserContextKeyedServiceFactory( | 37 : BrowserContextKeyedServiceFactory( |
30 "NTPSnippetsService", | 38 "NTPSnippetsService", |
31 BrowserContextDependencyManager::GetInstance()) {} | 39 BrowserContextDependencyManager::GetInstance()) {} |
32 | 40 |
33 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} | 41 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} |
34 | 42 |
35 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( | 43 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( |
36 content::BrowserContext* context) const { | 44 content::BrowserContext* context) const { |
45 Profile* profile = Profile::FromBrowserContext(context); | |
46 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile); | |
47 OAuth2TokenService* token_service = | |
48 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | |
49 scoped_refptr<net::URLRequestContextGetter> request_context = | |
50 context->GetRequestContext(); | |
51 | |
52 scoped_refptr<base::SequencedTaskRunner> task_runner = | |
53 BrowserThread::GetBlockingPool() | |
54 ->GetSequencedTaskRunnerWithShutdownBehavior( | |
55 base::SequencedWorkerPool::GetSequenceToken(), | |
56 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | |
37 return new ntp_snippets::NTPSnippetsService( | 57 return new ntp_snippets::NTPSnippetsService( |
38 g_browser_process->GetApplicationLocale()); | 58 task_runner, g_browser_process->GetApplicationLocale(), |
59 scoped_ptr<ntp_snippets::NTPSnippetsFetcher>( | |
Marc Treib
2016/02/11 09:23:21
You could use make_scoped_ptr here, then the type
May
2016/02/11 15:25:24
TIL! Done.
| |
60 new ntp_snippets::NTPSnippetsFetcher(task_runner, signin_manager, | |
61 token_service, | |
62 request_context.get()))); | |
39 } | 63 } |
OLD | NEW |