Chromium Code Reviews| 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/feature_list.h" | |
| 7 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 8 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/search/suggestions/image_fetcher_impl.h" | 12 #include "chrome/browser/search/suggestions/image_fetcher_impl.h" |
| 12 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" | 13 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" |
| 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 14 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
| 15 #include "chrome/common/channel_info.h" | 16 #include "chrome/common/channel_info.h" |
| 17 #include "chrome/common/pref_names.h" | |
| 16 #include "components/image_fetcher/image_fetcher.h" | 18 #include "components/image_fetcher/image_fetcher.h" |
| 17 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 19 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 18 #include "components/ntp_snippets/ntp_snippets_fetcher.h" | 20 #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
| 19 #include "components/ntp_snippets/ntp_snippets_scheduler.h" | 21 #include "components/ntp_snippets/ntp_snippets_scheduler.h" |
| 20 #include "components/ntp_snippets/ntp_snippets_service.h" | 22 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 23 #include "components/prefs/pref_service.h" | |
| 21 #include "components/safe_json/safe_json_parser.h" | 24 #include "components/safe_json/safe_json_parser.h" |
| 22 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 25 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 23 #include "components/signin/core/browser/signin_manager.h" | 26 #include "components/signin/core/browser/signin_manager.h" |
| 24 #include "components/version_info/version_info.h" | 27 #include "components/version_info/version_info.h" |
| 25 #include "content/public/browser/browser_context.h" | 28 #include "content/public/browser/browser_context.h" |
| 26 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/storage_partition.h" | 30 #include "content/public/browser/storage_partition.h" |
| 28 #include "net/url_request/url_request_context_getter.h" | 31 #include "net/url_request/url_request_context_getter.h" |
| 29 | 32 |
| 30 #if defined(OS_ANDROID) | 33 #if defined(OS_ANDROID) |
| 34 #include "chrome/browser/android/chrome_feature_list.h" | |
| 31 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" | 35 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" |
| 32 #endif // OS_ANDROID | 36 #endif // OS_ANDROID |
| 33 | 37 |
| 34 using content::BrowserThread; | 38 using content::BrowserThread; |
| 35 using suggestions::ImageFetcherImpl; | 39 using suggestions::ImageFetcherImpl; |
| 36 using suggestions::SuggestionsService; | 40 using suggestions::SuggestionsService; |
| 37 using suggestions::SuggestionsServiceFactory; | 41 using suggestions::SuggestionsServiceFactory; |
| 38 | 42 |
| 39 // static | 43 // static |
| 40 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() { | 44 NTPSnippetsServiceFactory* NTPSnippetsServiceFactory::GetInstance() { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 56 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 60 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
| 57 DependsOn(SigninManagerFactory::GetInstance()); | 61 DependsOn(SigninManagerFactory::GetInstance()); |
| 58 DependsOn(SuggestionsServiceFactory::GetInstance()); | 62 DependsOn(SuggestionsServiceFactory::GetInstance()); |
| 59 } | 63 } |
| 60 | 64 |
| 61 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} | 65 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} |
| 62 | 66 |
| 63 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( | 67 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( |
| 64 content::BrowserContext* context) const { | 68 content::BrowserContext* context) const { |
| 65 Profile* profile = Profile::FromBrowserContext(context); | 69 Profile* profile = Profile::FromBrowserContext(context); |
| 70 | |
| 71 bool enabled = profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled); | |
| 72 #if defined(OS_ANDROID) | |
| 73 enabled = enabled && | |
| 74 base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature); | |
|
Bernhard Bauer
2016/05/20 10:43:24
Hm... both of these things use APIs that are avail
Michael van Ouwerkerk
2016/05/20 11:25:58
Agreed. I've added a TODO along those lines.
| |
| 75 #endif // OS_ANDROID | |
| 76 | |
| 66 SigninManagerBase* signin_manager = | 77 SigninManagerBase* signin_manager = |
| 67 SigninManagerFactory::GetForProfile(profile); | 78 SigninManagerFactory::GetForProfile(profile); |
| 68 OAuth2TokenService* token_service = | 79 OAuth2TokenService* token_service = |
| 69 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 80 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 70 scoped_refptr<net::URLRequestContextGetter> request_context = | 81 scoped_refptr<net::URLRequestContextGetter> request_context = |
| 71 content::BrowserContext::GetDefaultStoragePartition(context)-> | 82 content::BrowserContext::GetDefaultStoragePartition(context)-> |
| 72 GetURLRequestContext(); | 83 GetURLRequestContext(); |
| 73 SuggestionsService* suggestions_service = | 84 SuggestionsService* suggestions_service = |
| 74 SuggestionsServiceFactory::GetForProfile(profile); | 85 SuggestionsServiceFactory::GetForProfile(profile); |
| 75 | 86 |
| 76 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr; | 87 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr; |
| 77 #if defined(OS_ANDROID) | 88 #if defined(OS_ANDROID) |
| 78 scheduler = NTPSnippetsLauncher::Get(); | 89 scheduler = NTPSnippetsLauncher::Get(); |
| 79 #endif // OS_ANDROID | 90 #endif // OS_ANDROID |
| 80 | 91 |
| 81 scoped_refptr<base::SequencedTaskRunner> task_runner = | 92 scoped_refptr<base::SequencedTaskRunner> task_runner = |
| 82 BrowserThread::GetBlockingPool() | 93 BrowserThread::GetBlockingPool() |
| 83 ->GetSequencedTaskRunnerWithShutdownBehavior( | 94 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 84 base::SequencedWorkerPool::GetSequenceToken(), | 95 base::SequencedWorkerPool::GetSequenceToken(), |
| 85 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 96 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 86 | 97 |
| 87 return new ntp_snippets::NTPSnippetsService( | 98 return new ntp_snippets::NTPSnippetsService( |
| 88 profile->GetPrefs(), suggestions_service, task_runner, | 99 enabled, profile->GetPrefs(), suggestions_service, task_runner, |
| 89 g_browser_process->GetApplicationLocale(), scheduler, | 100 g_browser_process->GetApplicationLocale(), scheduler, |
| 90 base::WrapUnique(new ntp_snippets::NTPSnippetsFetcher( | 101 base::WrapUnique(new ntp_snippets::NTPSnippetsFetcher( |
| 91 signin_manager, token_service, request_context, | 102 signin_manager, token_service, request_context, |
| 92 base::Bind(&safe_json::SafeJsonParser::Parse), | 103 base::Bind(&safe_json::SafeJsonParser::Parse), |
| 93 chrome::GetChannel() == version_info::Channel::STABLE)), | 104 chrome::GetChannel() == version_info::Channel::STABLE)), |
| 94 base::WrapUnique(new ImageFetcherImpl(request_context.get()))); | 105 base::WrapUnique(new ImageFetcherImpl(request_context.get()))); |
| 95 } | 106 } |
| OLD | NEW |