| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 using ntp_snippets::RemoteSuggestionsProviderImpl; | 90 using ntp_snippets::RemoteSuggestionsProviderImpl; |
| 91 using ntp_snippets::RemoteSuggestionsStatusService; | 91 using ntp_snippets::RemoteSuggestionsStatusService; |
| 92 using ntp_snippets::SchedulingRemoteSuggestionsProvider; | 92 using ntp_snippets::SchedulingRemoteSuggestionsProvider; |
| 93 using ntp_snippets::TabDelegateSyncAdapter; | 93 using ntp_snippets::TabDelegateSyncAdapter; |
| 94 using suggestions::ImageDecoderImpl; | 94 using suggestions::ImageDecoderImpl; |
| 95 using syncer::SyncService; | 95 using syncer::SyncService; |
| 96 using translate::LanguageModel; | 96 using translate::LanguageModel; |
| 97 | 97 |
| 98 namespace { | 98 namespace { |
| 99 | 99 |
| 100 // Clear the tasks that can be scheduled by running services. | |
| 101 void ClearScheduledTasks() { | |
| 102 #if defined(OS_ANDROID) | |
| 103 NTPSnippetsLauncher::Get()->Unschedule(); | |
| 104 #endif // OS_ANDROID | |
| 105 } | |
| 106 | |
| 107 #if defined(OS_ANDROID) | 100 #if defined(OS_ANDROID) |
| 108 | 101 |
| 109 bool IsRecentTabProviderEnabled() { | 102 bool IsRecentTabProviderEnabled() { |
| 110 return base::FeatureList::IsEnabled( | 103 return base::FeatureList::IsEnabled( |
| 111 ntp_snippets::kRecentOfflineTabSuggestionsFeature) && | 104 ntp_snippets::kRecentOfflineTabSuggestionsFeature) && |
| 112 base::FeatureList::IsEnabled( | 105 base::FeatureList::IsEnabled( |
| 113 offline_pages::kOffliningRecentPagesFeature); | 106 offline_pages::kOffliningRecentPagesFeature); |
| 114 } | 107 } |
| 115 | 108 |
| 116 void RegisterRecentTabProvider(OfflinePageModel* offline_page_model, | 109 void RegisterRecentTabProvider(OfflinePageModel* offline_page_model, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 251 |
| 259 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() = default; | 252 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() = default; |
| 260 | 253 |
| 261 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor( | 254 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor( |
| 262 content::BrowserContext* context) const { | 255 content::BrowserContext* context) const { |
| 263 using State = ContentSuggestionsService::State; | 256 using State = ContentSuggestionsService::State; |
| 264 Profile* profile = Profile::FromBrowserContext(context); | 257 Profile* profile = Profile::FromBrowserContext(context); |
| 265 DCHECK(!profile->IsOffTheRecord()); | 258 DCHECK(!profile->IsOffTheRecord()); |
| 266 | 259 |
| 267 // Create the ContentSuggestionsService. | 260 // Create the ContentSuggestionsService. |
| 268 State state = | |
| 269 base::FeatureList::IsEnabled(ntp_snippets::kContentSuggestionsFeature) | |
| 270 ? State::ENABLED | |
| 271 : State::DISABLED; | |
| 272 SigninManagerBase* signin_manager = | 261 SigninManagerBase* signin_manager = |
| 273 SigninManagerFactory::GetForProfile(profile); | 262 SigninManagerFactory::GetForProfile(profile); |
| 274 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 263 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
| 275 profile, ServiceAccessType::EXPLICIT_ACCESS); | 264 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 276 PrefService* pref_service = profile->GetPrefs(); | 265 PrefService* pref_service = profile->GetPrefs(); |
| 277 std::unique_ptr<CategoryRanker> category_ranker = | 266 std::unique_ptr<CategoryRanker> category_ranker = |
| 278 ntp_snippets::BuildSelectedCategoryRanker( | 267 ntp_snippets::BuildSelectedCategoryRanker( |
| 279 pref_service, base::MakeUnique<base::DefaultClock>()); | 268 pref_service, base::MakeUnique<base::DefaultClock>()); |
| 280 auto* service = | 269 auto* service = |
| 281 new ContentSuggestionsService(state, signin_manager, history_service, | 270 new ContentSuggestionsService(State::ENABLED, signin_manager, |
| 282 pref_service, std::move(category_ranker)); | 271 history_service, pref_service, std::move(category_ranker)); |
| 283 if (state == State::DISABLED) { | |
| 284 // Since we won't initialise the services, they won't get a chance to | |
| 285 // unschedule their tasks. We do it explicitly here instead. | |
| 286 ClearScheduledTasks(); | |
| 287 return service; | |
| 288 } | |
| 289 | 272 |
| 290 #if defined(OS_ANDROID) | 273 #if defined(OS_ANDROID) |
| 291 OfflinePageModel* offline_page_model = | 274 OfflinePageModel* offline_page_model = |
| 292 OfflinePageModelFactory::GetForBrowserContext(profile); | 275 OfflinePageModelFactory::GetForBrowserContext(profile); |
| 293 DownloadManager* download_manager = | 276 DownloadManager* download_manager = |
| 294 content::BrowserContext::GetDownloadManager(profile); | 277 content::BrowserContext::GetDownloadManager(profile); |
| 295 DownloadService* download_service = | 278 DownloadService* download_service = |
| 296 DownloadServiceFactory::GetForBrowserContext(profile); | 279 DownloadServiceFactory::GetForBrowserContext(profile); |
| 297 DownloadHistory* download_history = download_service->GetDownloadHistory(); | 280 DownloadHistory* download_history = download_service->GetDownloadHistory(); |
| 298 PhysicalWebDataSource* physical_web_data_source = | 281 PhysicalWebDataSource* physical_web_data_source = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 language_model, pref_service, profile); | 325 language_model, pref_service, profile); |
| 343 } | 326 } |
| 344 | 327 |
| 345 if (base::FeatureList::IsEnabled( | 328 if (base::FeatureList::IsEnabled( |
| 346 ntp_snippets::kForeignSessionsSuggestionsFeature)) { | 329 ntp_snippets::kForeignSessionsSuggestionsFeature)) { |
| 347 RegisterForeignSessionsProvider(sync_service, service, pref_service); | 330 RegisterForeignSessionsProvider(sync_service, service, pref_service); |
| 348 } | 331 } |
| 349 | 332 |
| 350 return service; | 333 return service; |
| 351 } | 334 } |
| OLD | NEW |