Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 #include "components/ntp_snippets/ntp_snippets_constants.h" | 40 #include "components/ntp_snippets/ntp_snippets_constants.h" |
| 41 #include "components/ntp_snippets/remote/persistent_scheduler.h" | 41 #include "components/ntp_snippets/remote/persistent_scheduler.h" |
| 42 #include "components/ntp_snippets/remote/remote_suggestions_database.h" | 42 #include "components/ntp_snippets/remote/remote_suggestions_database.h" |
| 43 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" | 43 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" |
| 44 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" | 44 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
| 45 #include "components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h" | 45 #include "components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h" |
| 46 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" | 46 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" |
| 47 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider .h" | 47 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider .h" |
| 48 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" | 48 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" |
| 49 #include "components/ntp_snippets/user_classifier.h" | 49 #include "components/ntp_snippets/user_classifier.h" |
| 50 #include "components/offline_pages/features/features.h" | |
| 50 #include "components/prefs/pref_service.h" | 51 #include "components/prefs/pref_service.h" |
| 51 #include "components/safe_json/safe_json_parser.h" | 52 #include "components/safe_json/safe_json_parser.h" |
| 52 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 53 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 53 #include "components/signin/core/browser/signin_manager.h" | 54 #include "components/signin/core/browser/signin_manager.h" |
| 54 #include "components/translate/core/browser/language_model.h" | 55 #include "components/translate/core/browser/language_model.h" |
| 55 #include "components/version_info/version_info.h" | 56 #include "components/version_info/version_info.h" |
| 56 #include "content/public/browser/browser_context.h" | 57 #include "content/public/browser/browser_context.h" |
| 57 #include "content/public/browser/browser_thread.h" | 58 #include "content/public/browser/browser_thread.h" |
| 58 #include "content/public/browser/storage_partition.h" | 59 #include "content/public/browser/storage_partition.h" |
| 59 #include "google_apis/google_api_keys.h" | 60 #include "google_apis/google_api_keys.h" |
| 60 #include "net/url_request/url_request_context_getter.h" | 61 #include "net/url_request/url_request_context_getter.h" |
| 61 | 62 |
| 62 #if defined(OS_ANDROID) | 63 #if defined(OS_ANDROID) |
| 63 #include "chrome/browser/android/chrome_feature_list.h" | 64 #include "chrome/browser/android/chrome_feature_list.h" |
| 64 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" | 65 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" |
| 65 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | |
| 66 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" | |
| 67 #include "chrome/browser/download/download_core_service.h" | 66 #include "chrome/browser/download/download_core_service.h" |
| 68 #include "chrome/browser/download/download_core_service_factory.h" | 67 #include "chrome/browser/download/download_core_service_factory.h" |
| 69 #include "chrome/browser/download/download_history.h" | 68 #include "chrome/browser/download/download_history.h" |
| 70 #include "chrome/browser/ntp_snippets/download_suggestions_provider.h" | 69 #include "chrome/browser/ntp_snippets/download_suggestions_provider.h" |
| 71 #include "components/ntp_snippets/offline_pages/recent_tab_suggestions_provider. h" | |
| 72 #include "components/ntp_snippets/physical_web_pages/physical_web_page_suggestio ns_provider.h" | 70 #include "components/ntp_snippets/physical_web_pages/physical_web_page_suggestio ns_provider.h" |
| 73 #include "components/offline_pages/content/suggested_articles_observer.h" | |
| 74 #include "components/offline_pages/core/background/request_coordinator.h" | |
| 75 #include "components/offline_pages/core/offline_page_feature.h" | |
| 76 #include "components/offline_pages/core/offline_page_model.h" | |
| 77 #include "components/offline_pages/core/recent_tabs/recent_tabs_ui_adapter_deleg ate.h" | |
| 78 #include "components/physical_web/data_source/physical_web_data_source.h" | 71 #include "components/physical_web/data_source/physical_web_data_source.h" |
| 79 | 72 |
| 80 using content::DownloadManager; | 73 using content::DownloadManager; |
| 81 using ntp_snippets::PhysicalWebPageSuggestionsProvider; | 74 using ntp_snippets::PhysicalWebPageSuggestionsProvider; |
| 75 using physical_web::PhysicalWebDataSource; | |
| 76 #endif // OS_ANDROID | |
| 77 | |
| 78 #if BUILDFLAG(ENABLE_OFFLINE_PAGES) | |
|
Bernhard Bauer
2017/05/18 19:11:31
Nit: If you're touching this code anyway, I would
dewittj
2017/05/22 22:00:08
Done.
| |
| 79 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | |
| 80 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" | |
| 81 #include "chrome/browser/offline_pages/prefetch/prefetch_service_factory.h" | |
| 82 #include "components/ntp_snippets/offline_pages/recent_tab_suggestions_provider. h" | |
| 83 #include "components/offline_pages/core/background/request_coordinator.h" | |
| 84 #include "components/offline_pages/core/offline_page_feature.h" | |
| 85 #include "components/offline_pages/core/offline_page_model.h" | |
| 86 #include "components/offline_pages/core/prefetch/suggested_articles_observer.h" | |
| 87 #include "components/offline_pages/core/recent_tabs/recent_tabs_ui_adapter_deleg ate.h" | |
| 88 | |
| 82 using ntp_snippets::RecentTabSuggestionsProvider; | 89 using ntp_snippets::RecentTabSuggestionsProvider; |
| 83 using offline_pages::OfflinePageModel; | 90 using offline_pages::OfflinePageModel; |
| 84 using offline_pages::RequestCoordinator; | 91 using offline_pages::RequestCoordinator; |
| 85 using offline_pages::OfflinePageModelFactory; | 92 using offline_pages::OfflinePageModelFactory; |
| 86 using offline_pages::RequestCoordinatorFactory; | 93 using offline_pages::RequestCoordinatorFactory; |
| 87 using physical_web::PhysicalWebDataSource; | 94 #endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 88 #endif // OS_ANDROID | |
| 89 | 95 |
| 90 using bookmarks::BookmarkModel; | 96 using bookmarks::BookmarkModel; |
| 91 using content::BrowserThread; | 97 using content::BrowserThread; |
| 92 using history::HistoryService; | 98 using history::HistoryService; |
| 93 using image_fetcher::ImageFetcherImpl; | 99 using image_fetcher::ImageFetcherImpl; |
| 94 using ntp_snippets::BookmarkSuggestionsProvider; | 100 using ntp_snippets::BookmarkSuggestionsProvider; |
| 95 using ntp_snippets::CategoryRanker; | 101 using ntp_snippets::CategoryRanker; |
| 96 using ntp_snippets::ContentSuggestionsService; | 102 using ntp_snippets::ContentSuggestionsService; |
| 97 using ntp_snippets::ForeignSessionsSuggestionsProvider; | 103 using ntp_snippets::ForeignSessionsSuggestionsProvider; |
| 98 using ntp_snippets::GetFetchEndpoint; | 104 using ntp_snippets::GetFetchEndpoint; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 123 namespace { | 129 namespace { |
| 124 | 130 |
| 125 bool IsChromeHomeEnabled() { | 131 bool IsChromeHomeEnabled() { |
| 126 #if defined(OS_ANDROID) | 132 #if defined(OS_ANDROID) |
| 127 return base::FeatureList::IsEnabled(chrome::android::kChromeHomeFeature); | 133 return base::FeatureList::IsEnabled(chrome::android::kChromeHomeFeature); |
| 128 #else | 134 #else |
| 129 return false; | 135 return false; |
| 130 #endif | 136 #endif |
| 131 } | 137 } |
| 132 | 138 |
| 133 #if defined(OS_ANDROID) | 139 #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 134 | 140 |
| 135 bool IsRecentTabProviderEnabled() { | 141 bool IsRecentTabProviderEnabled() { |
| 136 return base::FeatureList::IsEnabled( | 142 return base::FeatureList::IsEnabled( |
| 137 ntp_snippets::kRecentOfflineTabSuggestionsFeature) && | 143 ntp_snippets::kRecentOfflineTabSuggestionsFeature) && |
| 138 base::FeatureList::IsEnabled( | 144 base::FeatureList::IsEnabled( |
| 139 offline_pages::kOffliningRecentPagesFeature); | 145 offline_pages::kOffliningRecentPagesFeature); |
| 140 } | 146 } |
| 141 | 147 |
| 142 void RegisterRecentTabProvider(OfflinePageModel* offline_page_model, | 148 void RegisterRecentTabProvider(OfflinePageModel* offline_page_model, |
| 143 RequestCoordinator* request_coordinator, | 149 RequestCoordinator* request_coordinator, |
| 144 ContentSuggestionsService* service, | 150 ContentSuggestionsService* service, |
| 145 PrefService* pref_service) { | 151 PrefService* pref_service) { |
| 146 offline_pages::DownloadUIAdapter* ui_adapter = offline_pages:: | 152 offline_pages::DownloadUIAdapter* ui_adapter = offline_pages:: |
| 147 RecentTabsUIAdapterDelegate::GetOrCreateRecentTabsUIAdapter( | 153 RecentTabsUIAdapterDelegate::GetOrCreateRecentTabsUIAdapter( |
| 148 offline_page_model, request_coordinator); | 154 offline_page_model, request_coordinator); |
| 149 auto provider = base::MakeUnique<RecentTabSuggestionsProvider>( | 155 auto provider = base::MakeUnique<RecentTabSuggestionsProvider>( |
| 150 service, ui_adapter, pref_service); | 156 service, ui_adapter, pref_service); |
| 151 service->RegisterProvider(std::move(provider)); | 157 service->RegisterProvider(std::move(provider)); |
| 152 } | 158 } |
| 153 | 159 |
| 160 #endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) | |
| 161 | |
| 162 #if defined(OS_ANDROID) | |
| 163 | |
| 154 void RegisterDownloadsProvider(OfflinePageModel* offline_page_model, | 164 void RegisterDownloadsProvider(OfflinePageModel* offline_page_model, |
| 155 DownloadManager* download_manager, | 165 DownloadManager* download_manager, |
| 156 DownloadHistory* download_history, | 166 DownloadHistory* download_history, |
| 157 ContentSuggestionsService* service, | 167 ContentSuggestionsService* service, |
| 158 PrefService* pref_service) { | 168 PrefService* pref_service) { |
| 159 auto provider = base::MakeUnique<DownloadSuggestionsProvider>( | 169 auto provider = base::MakeUnique<DownloadSuggestionsProvider>( |
| 160 service, offline_page_model, download_manager, download_history, | 170 service, offline_page_model, download_manager, download_history, |
| 161 pref_service, base::MakeUnique<base::DefaultClock>()); | 171 pref_service, base::MakeUnique<base::DefaultClock>()); |
| 162 service->RegisterProvider(std::move(provider)); | 172 service->RegisterProvider(std::move(provider)); |
| 163 } | 173 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 GetInstance()->GetServiceForBrowserContext(profile, false)); | 289 GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 280 } | 290 } |
| 281 | 291 |
| 282 ContentSuggestionsServiceFactory::ContentSuggestionsServiceFactory() | 292 ContentSuggestionsServiceFactory::ContentSuggestionsServiceFactory() |
| 283 : BrowserContextKeyedServiceFactory( | 293 : BrowserContextKeyedServiceFactory( |
| 284 "ContentSuggestionsService", | 294 "ContentSuggestionsService", |
| 285 BrowserContextDependencyManager::GetInstance()) { | 295 BrowserContextDependencyManager::GetInstance()) { |
| 286 DependsOn(BookmarkModelFactory::GetInstance()); | 296 DependsOn(BookmarkModelFactory::GetInstance()); |
| 287 DependsOn(HistoryServiceFactory::GetInstance()); | 297 DependsOn(HistoryServiceFactory::GetInstance()); |
| 288 DependsOn(LargeIconServiceFactory::GetInstance()); | 298 DependsOn(LargeIconServiceFactory::GetInstance()); |
| 289 #if defined(OS_ANDROID) | 299 #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 290 DependsOn(OfflinePageModelFactory::GetInstance()); | 300 DependsOn(OfflinePageModelFactory::GetInstance()); |
| 291 #endif // OS_ANDROID | 301 DependsOn(offline_pages::PrefetchServiceFactory::GetInstance()); |
| 302 #endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) | |
| 292 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 303 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
| 293 DependsOn(ProfileSyncServiceFactory::GetInstance()); | 304 DependsOn(ProfileSyncServiceFactory::GetInstance()); |
| 294 DependsOn(SigninManagerFactory::GetInstance()); | 305 DependsOn(SigninManagerFactory::GetInstance()); |
| 295 } | 306 } |
| 296 | 307 |
| 297 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() = default; | 308 ContentSuggestionsServiceFactory::~ContentSuggestionsServiceFactory() = default; |
| 298 | 309 |
| 299 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor( | 310 KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor( |
| 300 content::BrowserContext* context) const { | 311 content::BrowserContext* context) const { |
| 301 #if CONTENT_SUGGESTIONS_ENABLED | 312 #if CONTENT_SUGGESTIONS_ENABLED |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 326 favicon::LargeIconService* large_icon_service = | 337 favicon::LargeIconService* large_icon_service = |
| 327 LargeIconServiceFactory::GetForBrowserContext(profile); | 338 LargeIconServiceFactory::GetForBrowserContext(profile); |
| 328 std::unique_ptr<CategoryRanker> category_ranker = | 339 std::unique_ptr<CategoryRanker> category_ranker = |
| 329 ntp_snippets::BuildSelectedCategoryRanker( | 340 ntp_snippets::BuildSelectedCategoryRanker( |
| 330 pref_service, base::MakeUnique<base::DefaultClock>()); | 341 pref_service, base::MakeUnique<base::DefaultClock>()); |
| 331 auto* service = new ContentSuggestionsService( | 342 auto* service = new ContentSuggestionsService( |
| 332 State::ENABLED, signin_manager, history_service, large_icon_service, | 343 State::ENABLED, signin_manager, history_service, large_icon_service, |
| 333 pref_service, std::move(category_ranker), std::move(user_classifier), | 344 pref_service, std::move(category_ranker), std::move(user_classifier), |
| 334 std::move(scheduler)); | 345 std::move(scheduler)); |
| 335 | 346 |
| 336 #if defined(OS_ANDROID) | 347 #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 337 OfflinePageModel* offline_page_model = | 348 OfflinePageModel* offline_page_model = |
| 338 OfflinePageModelFactory::GetForBrowserContext(profile); | 349 OfflinePageModelFactory::GetForBrowserContext(profile); |
| 339 if (IsRecentTabProviderEnabled()) { | 350 if (IsRecentTabProviderEnabled()) { |
| 340 RequestCoordinator* request_coordinator = | 351 RequestCoordinator* request_coordinator = |
| 341 RequestCoordinatorFactory::GetForBrowserContext(profile); | 352 RequestCoordinatorFactory::GetForBrowserContext(profile); |
| 342 RegisterRecentTabProvider(offline_page_model, request_coordinator, service, | 353 RegisterRecentTabProvider(offline_page_model, request_coordinator, service, |
| 343 pref_service); | 354 pref_service); |
| 344 } | 355 } |
| 345 | 356 |
| 357 offline_pages::PrefetchService* prefetch_service = | |
| 358 offline_pages::PrefetchServiceFactory::GetForBrowserContext(profile); | |
| 359 prefetch_service->ObserveContentSuggestionsService(service); | |
| 360 #endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) | |
| 361 | |
| 362 #if defined(OS_ANDROID) | |
| 346 bool show_asset_downloads = | 363 bool show_asset_downloads = |
| 347 !IsChromeHomeEnabled() && | 364 !IsChromeHomeEnabled() && |
| 348 base::FeatureList::IsEnabled(features::kAssetDownloadSuggestionsFeature); | 365 base::FeatureList::IsEnabled(features::kAssetDownloadSuggestionsFeature); |
| 349 bool show_offline_page_downloads = | 366 bool show_offline_page_downloads = |
| 350 !IsChromeHomeEnabled() && | 367 !IsChromeHomeEnabled() && |
| 351 base::FeatureList::IsEnabled( | 368 base::FeatureList::IsEnabled( |
| 352 features::kOfflinePageDownloadSuggestionsFeature); | 369 features::kOfflinePageDownloadSuggestionsFeature); |
| 353 if (show_asset_downloads || show_offline_page_downloads) { | 370 if (show_asset_downloads || show_offline_page_downloads) { |
| 354 DownloadManager* download_manager = | 371 DownloadManager* download_manager = |
| 355 content::BrowserContext::GetDownloadManager(profile); | 372 content::BrowserContext::GetDownloadManager(profile); |
| 356 DownloadCoreService* download_core_service = | 373 DownloadCoreService* download_core_service = |
| 357 DownloadCoreServiceFactory::GetForBrowserContext(profile); | 374 DownloadCoreServiceFactory::GetForBrowserContext(profile); |
| 358 DownloadHistory* download_history = | 375 DownloadHistory* download_history = |
| 359 download_core_service->GetDownloadHistory(); | 376 download_core_service->GetDownloadHistory(); |
| 360 RegisterDownloadsProvider( | 377 RegisterDownloadsProvider( |
| 361 show_offline_page_downloads ? offline_page_model : nullptr, | 378 show_offline_page_downloads ? offline_page_model : nullptr, |
| 362 show_asset_downloads ? download_manager : nullptr, download_history, | 379 show_asset_downloads ? download_manager : nullptr, download_history, |
| 363 service, pref_service); | 380 service, pref_service); |
| 364 } | 381 } |
| 365 | |
| 366 offline_pages::SuggestedArticlesObserver::ObserveContentSuggestionsService( | |
| 367 profile, service); | |
| 368 #endif // OS_ANDROID | 382 #endif // OS_ANDROID |
| 369 | 383 |
| 370 // |bookmark_model| can be null in tests. | 384 // |bookmark_model| can be null in tests. |
| 371 BookmarkModel* bookmark_model = | 385 BookmarkModel* bookmark_model = |
| 372 BookmarkModelFactory::GetForBrowserContext(profile); | 386 BookmarkModelFactory::GetForBrowserContext(profile); |
| 373 if (base::FeatureList::IsEnabled(ntp_snippets::kBookmarkSuggestionsFeature) && | 387 if (base::FeatureList::IsEnabled(ntp_snippets::kBookmarkSuggestionsFeature) && |
| 374 bookmark_model && !IsChromeHomeEnabled()) { | 388 bookmark_model && !IsChromeHomeEnabled()) { |
| 375 RegisterBookmarkProvider(bookmark_model, service, pref_service); | 389 RegisterBookmarkProvider(bookmark_model, service, pref_service); |
| 376 } | 390 } |
| 377 | 391 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 400 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile); | 414 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile); |
| 401 RegisterForeignSessionsProvider(sync_service, service, pref_service); | 415 RegisterForeignSessionsProvider(sync_service, service, pref_service); |
| 402 } | 416 } |
| 403 | 417 |
| 404 return service; | 418 return service; |
| 405 | 419 |
| 406 #else | 420 #else |
| 407 return nullptr; | 421 return nullptr; |
| 408 #endif // CONTENT_SUGGESTIONS_ENABLED | 422 #endif // CONTENT_SUGGESTIONS_ENABLED |
| 409 } | 423 } |
| OLD | NEW |