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" |
13 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
17 #include "content/public/browser/browser_thread.h" | |
18 #include "net/url_request/url_request_context_getter.h" | |
19 | |
20 using content::BrowserThread; | |
14 | 21 |
15 // static | 22 // static |
16 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() { | 23 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() { |
17 return base::Singleton<NTPSnippetsServiceFactory>::get(); | 24 return base::Singleton<NTPSnippetsServiceFactory>::get(); |
18 } | 25 } |
19 | 26 |
20 // static | 27 // static |
21 ntp_snippets::NTPSnippetsService* NTPSnippetsServiceFactory::GetForProfile( | 28 ntp_snippets::NTPSnippetsService* NTPSnippetsServiceFactory::GetForProfile( |
22 Profile* profile) { | 29 Profile* profile) { |
23 DCHECK(!profile->IsOffTheRecord()); | 30 DCHECK(!profile->IsOffTheRecord()); |
24 return static_cast<ntp_snippets::NTPSnippetsService*>( | 31 return static_cast<ntp_snippets::NTPSnippetsService*>( |
25 GetInstance()->GetServiceForBrowserContext(profile, true)); | 32 GetInstance()->GetServiceForBrowserContext(profile, true)); |
26 } | 33 } |
27 | 34 |
28 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory() | 35 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory() |
29 : BrowserContextKeyedServiceFactory( | 36 : BrowserContextKeyedServiceFactory( |
30 "NTPSnippetsService", | 37 "NTPSnippetsService", |
31 BrowserContextDependencyManager::GetInstance()) {} | 38 BrowserContextDependencyManager::GetInstance()) {} |
32 | 39 |
33 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} | 40 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} |
34 | 41 |
35 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( | 42 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( |
36 content::BrowserContext* context) const { | 43 content::BrowserContext* context) const { |
44 Profile* profile = Profile::FromBrowserContext(context); | |
45 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile); | |
46 OAuth2TokenService* token_service = | |
47 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | |
48 scoped_refptr<net::URLRequestContextGetter> request_context = | |
49 context->GetRequestContext(); | |
50 | |
37 return new ntp_snippets::NTPSnippetsService( | 51 return new ntp_snippets::NTPSnippetsService( |
38 g_browser_process->GetApplicationLocale()); | 52 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
Bernhard Bauer
2016/02/08 18:19:26
Use BrowserThread::GetBlockingPool() for this (but
May
2016/02/09 17:38:53
Done.
| |
53 g_browser_process->GetApplicationLocale(), | |
54 new ntp_snippets::NTPSnippetsFetcher( | |
55 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | |
56 signin_manager, token_service, request_context.get())); | |
39 } | 57 } |
OLD | NEW |