| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/content_suggestions_service_factory.h" | 5 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "components/image_fetcher/image_fetcher.h" | 27 #include "components/image_fetcher/image_fetcher.h" |
| 28 #include "components/image_fetcher/image_fetcher_impl.h" | 28 #include "components/image_fetcher/image_fetcher_impl.h" |
| 29 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 29 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 30 #include "components/keyed_service/core/service_access_type.h" | 30 #include "components/keyed_service/core/service_access_type.h" |
| 31 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" | 31 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" |
| 32 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" | 32 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" |
| 33 #include "components/ntp_snippets/content_suggestions_service.h" | 33 #include "components/ntp_snippets/content_suggestions_service.h" |
| 34 #include "components/ntp_snippets/features.h" | 34 #include "components/ntp_snippets/features.h" |
| 35 #include "components/ntp_snippets/ntp_snippets_constants.h" | 35 #include "components/ntp_snippets/ntp_snippets_constants.h" |
| 36 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" | 36 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" |
| 37 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h" | 37 #include "components/ntp_snippets/remote/persistent_scheduler.h" |
| 38 #include "components/ntp_snippets/remote/remote_suggestions_database.h" | 38 #include "components/ntp_snippets/remote/remote_suggestions_database.h" |
| 39 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" | 39 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
| 40 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" | 40 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" |
| 41 #include "components/ntp_snippets/remote/scheduling_remote_suggestions_provider.
h" |
| 41 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider
.h" | 42 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider
.h" |
| 42 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" | 43 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" |
| 43 #include "components/prefs/pref_service.h" | 44 #include "components/prefs/pref_service.h" |
| 44 #include "components/safe_json/safe_json_parser.h" | 45 #include "components/safe_json/safe_json_parser.h" |
| 45 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 46 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 46 #include "components/signin/core/browser/signin_manager.h" | 47 #include "components/signin/core/browser/signin_manager.h" |
| 47 #include "components/translate/core/browser/language_model.h" | 48 #include "components/translate/core/browser/language_model.h" |
| 48 #include "components/version_info/version_info.h" | 49 #include "components/version_info/version_info.h" |
| 49 #include "content/public/browser/browser_context.h" | 50 #include "content/public/browser/browser_context.h" |
| 50 #include "content/public/browser/browser_thread.h" | 51 #include "content/public/browser/browser_thread.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 71 #endif // OS_ANDROID | 72 #endif // OS_ANDROID |
| 72 | 73 |
| 73 using bookmarks::BookmarkModel; | 74 using bookmarks::BookmarkModel; |
| 74 using content::BrowserThread; | 75 using content::BrowserThread; |
| 75 using history::HistoryService; | 76 using history::HistoryService; |
| 76 using image_fetcher::ImageFetcherImpl; | 77 using image_fetcher::ImageFetcherImpl; |
| 77 using ntp_snippets::BookmarkSuggestionsProvider; | 78 using ntp_snippets::BookmarkSuggestionsProvider; |
| 78 using ntp_snippets::ContentSuggestionsService; | 79 using ntp_snippets::ContentSuggestionsService; |
| 79 using ntp_snippets::ForeignSessionsSuggestionsProvider; | 80 using ntp_snippets::ForeignSessionsSuggestionsProvider; |
| 80 using ntp_snippets::NTPSnippetsFetcher; | 81 using ntp_snippets::NTPSnippetsFetcher; |
| 81 using ntp_snippets::NTPSnippetsScheduler; | 82 using ntp_snippets::PersistentScheduler; |
| 82 using ntp_snippets::RemoteSuggestionsDatabase; | 83 using ntp_snippets::RemoteSuggestionsDatabase; |
| 83 using ntp_snippets::RemoteSuggestionsProvider; | 84 using ntp_snippets::RemoteSuggestionsProviderImpl; |
| 84 using ntp_snippets::RemoteSuggestionsStatusService; | 85 using ntp_snippets::RemoteSuggestionsStatusService; |
| 86 using ntp_snippets::SchedulingRemoteSuggestionsProvider; |
| 85 using ntp_snippets::TabDelegateSyncAdapter; | 87 using ntp_snippets::TabDelegateSyncAdapter; |
| 86 using suggestions::ImageDecoderImpl; | 88 using suggestions::ImageDecoderImpl; |
| 87 using syncer::SyncService; | 89 using syncer::SyncService; |
| 88 using translate::LanguageModel; | 90 using translate::LanguageModel; |
| 89 | 91 |
| 90 namespace { | 92 namespace { |
| 91 | 93 |
| 92 // Clear the tasks that can be scheduled by running services. | 94 // Clear the tasks that can be scheduled by running services. |
| 93 void ClearScheduledTasks() { | 95 void ClearScheduledTasks() { |
| 94 #if defined(OS_ANDROID) | 96 #if defined(OS_ANDROID) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 void RegisterArticleProvider(SigninManagerBase* signin_manager, | 142 void RegisterArticleProvider(SigninManagerBase* signin_manager, |
| 141 OAuth2TokenService* token_service, | 143 OAuth2TokenService* token_service, |
| 142 ContentSuggestionsService* service, | 144 ContentSuggestionsService* service, |
| 143 LanguageModel* language_model, | 145 LanguageModel* language_model, |
| 144 PrefService* pref_service, | 146 PrefService* pref_service, |
| 145 Profile* profile) { | 147 Profile* profile) { |
| 146 scoped_refptr<net::URLRequestContextGetter> request_context = | 148 scoped_refptr<net::URLRequestContextGetter> request_context = |
| 147 content::BrowserContext::GetDefaultStoragePartition(profile) | 149 content::BrowserContext::GetDefaultStoragePartition(profile) |
| 148 ->GetURLRequestContext(); | 150 ->GetURLRequestContext(); |
| 149 | 151 |
| 150 NTPSnippetsScheduler* scheduler = nullptr; | |
| 151 #if defined(OS_ANDROID) | |
| 152 scheduler = NTPSnippetsLauncher::Get(); | |
| 153 #endif // OS_ANDROID | |
| 154 base::FilePath database_dir( | 152 base::FilePath database_dir( |
| 155 profile->GetPath().Append(ntp_snippets::kDatabaseFolder)); | 153 profile->GetPath().Append(ntp_snippets::kDatabaseFolder)); |
| 156 scoped_refptr<base::SequencedTaskRunner> task_runner = | 154 scoped_refptr<base::SequencedTaskRunner> task_runner = |
| 157 BrowserThread::GetBlockingPool() | 155 BrowserThread::GetBlockingPool() |
| 158 ->GetSequencedTaskRunnerWithShutdownBehavior( | 156 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 159 base::SequencedWorkerPool::GetSequenceToken(), | 157 base::SequencedWorkerPool::GetSequenceToken(), |
| 160 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 158 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 161 bool is_stable_channel = | 159 bool is_stable_channel = |
| 162 chrome::GetChannel() == version_info::Channel::STABLE; | 160 chrome::GetChannel() == version_info::Channel::STABLE; |
| 163 auto provider = base::MakeUnique<RemoteSuggestionsProvider>( | 161 auto provider = base::MakeUnique<RemoteSuggestionsProviderImpl>( |
| 164 service, pref_service, g_browser_process->GetApplicationLocale(), | 162 service, pref_service, g_browser_process->GetApplicationLocale(), |
| 165 service->category_ranker(), service->user_classifier(), scheduler, | 163 service->category_ranker(), |
| 166 base::MakeUnique<NTPSnippetsFetcher>( | 164 base::MakeUnique<NTPSnippetsFetcher>( |
| 167 signin_manager, token_service, request_context, pref_service, | 165 signin_manager, token_service, request_context, pref_service, |
| 168 language_model, base::Bind(&safe_json::SafeJsonParser::Parse), | 166 language_model, base::Bind(&safe_json::SafeJsonParser::Parse), |
| 169 is_stable_channel ? google_apis::GetAPIKey() | 167 is_stable_channel ? google_apis::GetAPIKey() |
| 170 : google_apis::GetNonStableAPIKey(), | 168 : google_apis::GetNonStableAPIKey(), |
| 171 service->user_classifier()), | 169 service->user_classifier()), |
| 172 base::MakeUnique<ImageFetcherImpl>(base::MakeUnique<ImageDecoderImpl>(), | 170 base::MakeUnique<ImageFetcherImpl>(base::MakeUnique<ImageDecoderImpl>(), |
| 173 request_context.get()), | 171 request_context.get()), |
| 174 base::MakeUnique<ImageDecoderImpl>(), | 172 base::MakeUnique<ImageDecoderImpl>(), |
| 175 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner), | 173 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir, task_runner), |
| 176 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager, | 174 base::MakeUnique<RemoteSuggestionsStatusService>(signin_manager, |
| 177 pref_service)); | 175 pref_service)); |
| 178 service->set_ntp_snippets_service(provider.get()); | 176 |
| 179 service->RegisterProvider(std::move(provider)); | 177 PersistentScheduler* scheduler = nullptr; |
| 178 #if defined(OS_ANDROID) |
| 179 scheduler = NTPSnippetsLauncher::Get(); |
| 180 #endif // OS_ANDROID |
| 181 |
| 182 auto scheduling_provider = |
| 183 base::MakeUnique<SchedulingRemoteSuggestionsProvider>( |
| 184 service, std::move(provider), scheduler, service->user_classifier(), |
| 185 pref_service); |
| 186 service->set_remote_suggestions_provider(scheduling_provider.get()); |
| 187 service->set_remote_suggestions_scheduler(scheduling_provider.get()); |
| 188 service->RegisterProvider(std::move(scheduling_provider)); |
| 180 } | 189 } |
| 181 | 190 |
| 182 void RegisterForeignSessionsProvider(SyncService* sync_service, | 191 void RegisterForeignSessionsProvider(SyncService* sync_service, |
| 183 ContentSuggestionsService* service, | 192 ContentSuggestionsService* service, |
| 184 PrefService* pref_service) { | 193 PrefService* pref_service) { |
| 185 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = | 194 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = |
| 186 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); | 195 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); |
| 187 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( | 196 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( |
| 188 service, std::move(sync_adapter), pref_service); | 197 service, std::move(sync_adapter), pref_service); |
| 189 service->RegisterProvider(std::move(provider)); | 198 service->RegisterProvider(std::move(provider)); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 language_model, pref_service, profile); | 318 language_model, pref_service, profile); |
| 310 } | 319 } |
| 311 | 320 |
| 312 if (base::FeatureList::IsEnabled( | 321 if (base::FeatureList::IsEnabled( |
| 313 ntp_snippets::kForeignSessionsSuggestionsFeature)) { | 322 ntp_snippets::kForeignSessionsSuggestionsFeature)) { |
| 314 RegisterForeignSessionsProvider(sync_service, service, pref_service); | 323 RegisterForeignSessionsProvider(sync_service, service, pref_service); |
| 315 } | 324 } |
| 316 | 325 |
| 317 return service; | 326 return service; |
| 318 } | 327 } |
| OLD | NEW |