| 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/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.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/search/suggestions/suggestions_service_factory.h" | 11 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" |
| 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 13 #include "chrome/browser/signin/signin_manager_factory.h" |
| 12 #include "chrome/common/channel_info.h" | 14 #include "chrome/common/channel_info.h" |
| 13 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 15 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 14 #include "components/ntp_snippets/ntp_snippets_fetcher.h" | 16 #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
| 15 #include "components/ntp_snippets/ntp_snippets_scheduler.h" | 17 #include "components/ntp_snippets/ntp_snippets_scheduler.h" |
| 16 #include "components/ntp_snippets/ntp_snippets_service.h" | 18 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 17 #include "components/safe_json/safe_json_parser.h" | 19 #include "components/safe_json/safe_json_parser.h" |
| 20 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 21 #include "components/signin/core/browser/signin_manager.h" |
| 18 #include "components/version_info/version_info.h" | 22 #include "components/version_info/version_info.h" |
| 19 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/storage_partition.h" | 25 #include "content/public/browser/storage_partition.h" |
| 22 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
| 23 | 27 |
| 24 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
| 25 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" | 29 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" |
| 26 #endif // OS_ANDROID | 30 #endif // OS_ANDROID |
| 27 | 31 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 39 Profile* profile) { | 43 Profile* profile) { |
| 40 DCHECK(!profile->IsOffTheRecord()); | 44 DCHECK(!profile->IsOffTheRecord()); |
| 41 return static_cast<ntp_snippets::NTPSnippetsService*>( | 45 return static_cast<ntp_snippets::NTPSnippetsService*>( |
| 42 GetInstance()->GetServiceForBrowserContext(profile, true)); | 46 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 43 } | 47 } |
| 44 | 48 |
| 45 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory() | 49 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory() |
| 46 : BrowserContextKeyedServiceFactory( | 50 : BrowserContextKeyedServiceFactory( |
| 47 "NTPSnippetsService", | 51 "NTPSnippetsService", |
| 48 BrowserContextDependencyManager::GetInstance()) { | 52 BrowserContextDependencyManager::GetInstance()) { |
| 53 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
| 54 DependsOn(SigninManagerFactory::GetInstance()); |
| 49 DependsOn(SuggestionsServiceFactory::GetInstance()); | 55 DependsOn(SuggestionsServiceFactory::GetInstance()); |
| 50 } | 56 } |
| 51 | 57 |
| 52 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} | 58 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} |
| 53 | 59 |
| 54 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( | 60 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( |
| 55 content::BrowserContext* context) const { | 61 content::BrowserContext* context) const { |
| 56 Profile* profile = Profile::FromBrowserContext(context); | 62 Profile* profile = Profile::FromBrowserContext(context); |
| 63 SigninManagerBase* signin_manager = |
| 64 SigninManagerFactory::GetForProfile(profile); |
| 65 OAuth2TokenService* token_service = |
| 66 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 57 scoped_refptr<net::URLRequestContextGetter> request_context = | 67 scoped_refptr<net::URLRequestContextGetter> request_context = |
| 58 content::BrowserContext::GetDefaultStoragePartition(context)-> | 68 content::BrowserContext::GetDefaultStoragePartition(context)-> |
| 59 GetURLRequestContext(); | 69 GetURLRequestContext(); |
| 60 SuggestionsService* suggestions_service = | 70 SuggestionsService* suggestions_service = |
| 61 SuggestionsServiceFactory::GetForProfile(profile); | 71 SuggestionsServiceFactory::GetForProfile(profile); |
| 62 | 72 |
| 63 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr; | 73 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr; |
| 64 #if defined(OS_ANDROID) | 74 #if defined(OS_ANDROID) |
| 65 scheduler = NTPSnippetsLauncher::Get(); | 75 scheduler = NTPSnippetsLauncher::Get(); |
| 66 #endif // OS_ANDROID | 76 #endif // OS_ANDROID |
| 67 | 77 |
| 68 scoped_refptr<base::SequencedTaskRunner> task_runner = | 78 scoped_refptr<base::SequencedTaskRunner> task_runner = |
| 69 BrowserThread::GetBlockingPool() | 79 BrowserThread::GetBlockingPool() |
| 70 ->GetSequencedTaskRunnerWithShutdownBehavior( | 80 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 71 base::SequencedWorkerPool::GetSequenceToken(), | 81 base::SequencedWorkerPool::GetSequenceToken(), |
| 72 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 82 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 73 | 83 |
| 74 return new ntp_snippets::NTPSnippetsService( | 84 return new ntp_snippets::NTPSnippetsService( |
| 75 profile->GetPrefs(), suggestions_service, task_runner, | 85 profile->GetPrefs(), suggestions_service, task_runner, |
| 76 g_browser_process->GetApplicationLocale(), scheduler, | 86 g_browser_process->GetApplicationLocale(), scheduler, |
| 77 base::WrapUnique(new ntp_snippets::NTPSnippetsFetcher( | 87 base::WrapUnique(new ntp_snippets::NTPSnippetsFetcher( |
| 78 request_context, | 88 signin_manager, token_service, request_context, |
| 79 chrome::GetChannel() == version_info::Channel::STABLE)), | 89 chrome::GetChannel() == version_info::Channel::STABLE)), |
| 80 base::Bind(&safe_json::SafeJsonParser::Parse)); | 90 base::Bind(&safe_json::SafeJsonParser::Parse)); |
| 81 } | 91 } |
| OLD | NEW |