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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 #include "content/public/browser/browser_context.h" | 47 #include "content/public/browser/browser_context.h" |
| 48 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
| 49 #include "content/public/browser/storage_partition.h" | 49 #include "content/public/browser/storage_partition.h" |
| 50 #include "google_apis/google_api_keys.h" | 50 #include "google_apis/google_api_keys.h" |
| 51 #include "net/url_request/url_request_context_getter.h" | 51 #include "net/url_request/url_request_context_getter.h" |
| 52 | 52 |
| 53 #if defined(OS_ANDROID) | 53 #if defined(OS_ANDROID) |
| 54 #include "chrome/browser/android/chrome_feature_list.h" | 54 #include "chrome/browser/android/chrome_feature_list.h" |
| 55 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" | 55 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" |
| 56 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 56 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| 57 #include "components/ntp_snippets/downloads/download_suggestions_provider.h" | |
| 57 #include "components/ntp_snippets/offline_pages/offline_page_proxy.h" | 58 #include "components/ntp_snippets/offline_pages/offline_page_proxy.h" |
| 58 #include "components/ntp_snippets/physical_web_pages/physical_web_page_suggestio ns_provider.h" | 59 #include "components/ntp_snippets/physical_web_pages/physical_web_page_suggestio ns_provider.h" |
| 59 #include "components/ntp_snippets/recent_tabs/recent_tab_suggestions_provider.h" | 60 #include "components/ntp_snippets/recent_tabs/recent_tab_suggestions_provider.h" |
| 60 #include "components/offline_pages/offline_page_model.h" | 61 #include "components/offline_pages/offline_page_model.h" |
| 61 | 62 |
| 62 using ntp_snippets::OfflinePageProxy; | 63 using ntp_snippets::OfflinePageProxy; |
| 63 using ntp_snippets::PhysicalWebPageSuggestionsProvider; | 64 using ntp_snippets::PhysicalWebPageSuggestionsProvider; |
| 64 using ntp_snippets::RecentTabSuggestionsProvider; | 65 using ntp_snippets::RecentTabSuggestionsProvider; |
| 65 using offline_pages::OfflinePageModel; | 66 using offline_pages::OfflinePageModel; |
| 66 using offline_pages::OfflinePageModelFactory; | 67 using offline_pages::OfflinePageModelFactory; |
| 68 using content::DownloadManager; | |
| 67 #endif // OS_ANDROID | 69 #endif // OS_ANDROID |
| 68 | 70 |
| 69 using bookmarks::BookmarkModel; | 71 using bookmarks::BookmarkModel; |
| 70 using content::BrowserThread; | 72 using content::BrowserThread; |
| 71 using history::HistoryService; | 73 using history::HistoryService; |
| 72 using image_fetcher::ImageFetcherImpl; | 74 using image_fetcher::ImageFetcherImpl; |
| 73 using ntp_snippets::BookmarkSuggestionsProvider; | 75 using ntp_snippets::BookmarkSuggestionsProvider; |
| 74 using ntp_snippets::CategoryFactory; | 76 using ntp_snippets::CategoryFactory; |
| 75 using ntp_snippets::ContentSuggestionsService; | 77 using ntp_snippets::ContentSuggestionsService; |
| 78 using ntp_snippets::DownloadSuggestionsProvider; | |
|
Marc Treib
2016/09/22 13:45:52
I think this should also go into the OS_ANDROID se
vitaliii
2016/10/11 08:15:56
Done.
| |
| 76 using ntp_snippets::NTPSnippetsDatabase; | 79 using ntp_snippets::NTPSnippetsDatabase; |
| 77 using ntp_snippets::NTPSnippetsFetcher; | 80 using ntp_snippets::NTPSnippetsFetcher; |
| 78 using ntp_snippets::NTPSnippetsService; | 81 using ntp_snippets::NTPSnippetsService; |
| 79 using ntp_snippets::NTPSnippetsScheduler; | 82 using ntp_snippets::NTPSnippetsScheduler; |
| 80 using ntp_snippets::NTPSnippetsStatusService; | 83 using ntp_snippets::NTPSnippetsStatusService; |
| 81 using ntp_snippets::ForeignSessionsSuggestionsProvider; | 84 using ntp_snippets::ForeignSessionsSuggestionsProvider; |
| 82 using ntp_snippets::TabDelegateSyncAdapter; | 85 using ntp_snippets::TabDelegateSyncAdapter; |
| 83 using suggestions::ImageDecoderImpl; | 86 using suggestions::ImageDecoderImpl; |
| 84 using suggestions::SuggestionsService; | 87 using suggestions::SuggestionsService; |
| 85 using suggestions::SuggestionsServiceFactory; | 88 using suggestions::SuggestionsServiceFactory; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 97 #if defined(OS_ANDROID) | 100 #if defined(OS_ANDROID) |
| 98 void RegisterRecentTabProvider( | 101 void RegisterRecentTabProvider( |
| 99 const scoped_refptr<OfflinePageProxy>& offline_page_proxy, | 102 const scoped_refptr<OfflinePageProxy>& offline_page_proxy, |
| 100 ContentSuggestionsService* service, | 103 ContentSuggestionsService* service, |
| 101 CategoryFactory* category_factory, | 104 CategoryFactory* category_factory, |
| 102 PrefService* pref_service) { | 105 PrefService* pref_service) { |
| 103 auto provider = base::MakeUnique<RecentTabSuggestionsProvider>( | 106 auto provider = base::MakeUnique<RecentTabSuggestionsProvider>( |
| 104 service, category_factory, offline_page_proxy, pref_service); | 107 service, category_factory, offline_page_proxy, pref_service); |
| 105 service->RegisterProvider(std::move(provider)); | 108 service->RegisterProvider(std::move(provider)); |
| 106 } | 109 } |
| 110 | |
| 111 void RegisterDownloadsProvider( | |
| 112 const scoped_refptr<OfflinePageProxy>& offline_page_proxy, | |
| 113 DownloadManager* download_manager, | |
| 114 ContentSuggestionsService* service, | |
| 115 CategoryFactory* category_factory, | |
| 116 PrefService* pref_service) { | |
| 117 bool download_manager_ui_enabled = | |
|
Marc Treib
2016/09/22 13:45:52
Instead of the explicit download_manager_ui_enable
vitaliii
2016/10/11 08:15:56
This variable has nothing to do with the DownloadM
| |
| 118 base::FeatureList::IsEnabled(chrome::android::kDownloadsUiFeature); | |
| 119 auto provider = base::MakeUnique<DownloadSuggestionsProvider>( | |
| 120 service, category_factory, offline_page_proxy, download_manager, | |
| 121 pref_service, download_manager_ui_enabled); | |
| 122 service->RegisterProvider(std::move(provider)); | |
| 123 } | |
| 107 #endif // OS_ANDROID | 124 #endif // OS_ANDROID |
| 108 | 125 |
| 109 void RegisterBookmarkProvider(BookmarkModel* bookmark_model, | 126 void RegisterBookmarkProvider(BookmarkModel* bookmark_model, |
| 110 ContentSuggestionsService* service, | 127 ContentSuggestionsService* service, |
| 111 CategoryFactory* category_factory, | 128 CategoryFactory* category_factory, |
| 112 PrefService* pref_service) { | 129 PrefService* pref_service) { |
| 113 auto provider = base::MakeUnique<BookmarkSuggestionsProvider>( | 130 auto provider = base::MakeUnique<BookmarkSuggestionsProvider>( |
| 114 service, category_factory, bookmark_model, pref_service); | 131 service, category_factory, bookmark_model, pref_service); |
| 115 service->RegisterProvider(std::move(provider)); | 132 service->RegisterProvider(std::move(provider)); |
| 116 } | 133 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 ClearScheduledTasks(); | 254 ClearScheduledTasks(); |
| 238 return service; | 255 return service; |
| 239 } | 256 } |
| 240 | 257 |
| 241 CategoryFactory* category_factory = service->category_factory(); | 258 CategoryFactory* category_factory = service->category_factory(); |
| 242 #if defined(OS_ANDROID) | 259 #if defined(OS_ANDROID) |
| 243 OfflinePageModel* offline_page_model = | 260 OfflinePageModel* offline_page_model = |
| 244 OfflinePageModelFactory::GetForBrowserContext(profile); | 261 OfflinePageModelFactory::GetForBrowserContext(profile); |
| 245 scoped_refptr<OfflinePageProxy> offline_page_proxy( | 262 scoped_refptr<OfflinePageProxy> offline_page_proxy( |
| 246 new OfflinePageProxy(offline_page_model)); | 263 new OfflinePageProxy(offline_page_model)); |
| 264 DownloadManager* download_manager = | |
| 265 content::BrowserContext::GetDownloadManager(profile); | |
| 247 #endif // OS_ANDROID | 266 #endif // OS_ANDROID |
| 248 BookmarkModel* bookmark_model = | 267 BookmarkModel* bookmark_model = |
| 249 BookmarkModelFactory::GetForBrowserContext(profile); | 268 BookmarkModelFactory::GetForBrowserContext(profile); |
| 250 SigninManagerBase* signin_manager = | 269 SigninManagerBase* signin_manager = |
| 251 SigninManagerFactory::GetForProfile(profile); | 270 SigninManagerFactory::GetForProfile(profile); |
| 252 OAuth2TokenService* token_service = | 271 OAuth2TokenService* token_service = |
| 253 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 272 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 254 SuggestionsService* suggestions_service = | 273 SuggestionsService* suggestions_service = |
| 255 SuggestionsServiceFactory::GetForProfile(profile); | 274 SuggestionsServiceFactory::GetForProfile(profile); |
| 256 SyncService* sync_service = | 275 SyncService* sync_service = |
| 257 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile); | 276 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile); |
| 258 | 277 |
| 259 #if defined(OS_ANDROID) | 278 #if defined(OS_ANDROID) |
| 260 if (base::FeatureList::IsEnabled( | 279 if (base::FeatureList::IsEnabled( |
| 261 ntp_snippets::kRecentOfflineTabSuggestionsFeature)) { | 280 ntp_snippets::kRecentOfflineTabSuggestionsFeature)) { |
| 262 RegisterRecentTabProvider(offline_page_proxy, service, category_factory, | 281 RegisterRecentTabProvider(offline_page_proxy, service, category_factory, |
| 263 pref_service); | 282 pref_service); |
| 264 } | 283 } |
| 284 | |
| 285 if (base::FeatureList::IsEnabled(ntp_snippets::kDownloadSuggestionsFeature)) { | |
| 286 RegisterDownloadsProvider(offline_page_proxy, download_manager, service, | |
| 287 category_factory, pref_service); | |
| 288 } | |
| 265 #endif // OS_ANDROID | 289 #endif // OS_ANDROID |
| 266 | 290 |
| 267 // |bookmark_model| can be null in tests. | 291 // |bookmark_model| can be null in tests. |
| 268 if (base::FeatureList::IsEnabled(ntp_snippets::kBookmarkSuggestionsFeature) && | 292 if (base::FeatureList::IsEnabled(ntp_snippets::kBookmarkSuggestionsFeature) && |
| 269 bookmark_model) { | 293 bookmark_model) { |
| 270 RegisterBookmarkProvider(bookmark_model, service, category_factory, | 294 RegisterBookmarkProvider(bookmark_model, service, category_factory, |
| 271 pref_service); | 295 pref_service); |
| 272 } | 296 } |
| 273 | 297 |
| 274 #if defined(OS_ANDROID) | 298 #if defined(OS_ANDROID) |
| 275 if (base::FeatureList::IsEnabled( | 299 if (base::FeatureList::IsEnabled( |
| 276 ntp_snippets::kPhysicalWebPageSuggestionsFeature)) { | 300 ntp_snippets::kPhysicalWebPageSuggestionsFeature)) { |
| 277 RegisterPhysicalWebPageProvider(service, category_factory); | 301 RegisterPhysicalWebPageProvider(service, category_factory); |
| 278 } | 302 } |
| 279 #endif // OS_ANDROID | 303 #endif // OS_ANDROID |
| 280 | 304 |
| 281 if (base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)) { | 305 if (base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)) { |
| 282 RegisterArticleProvider(signin_manager, token_service, suggestions_service, | 306 RegisterArticleProvider(signin_manager, token_service, suggestions_service, |
| 283 service, category_factory, pref_service, profile); | 307 service, category_factory, pref_service, profile); |
| 284 } | 308 } |
| 285 | 309 |
| 286 if (base::FeatureList::IsEnabled( | 310 if (base::FeatureList::IsEnabled( |
| 287 ntp_snippets::kForeignSessionsSuggestionsFeature)) { | 311 ntp_snippets::kForeignSessionsSuggestionsFeature)) { |
| 288 RegisterForeignSessionsProvider(sync_service, service, category_factory, | 312 RegisterForeignSessionsProvider(sync_service, service, category_factory, |
| 289 pref_service); | 313 pref_service); |
| 290 } | 314 } |
| 291 | 315 |
| 292 return service; | 316 return service; |
| 293 } | 317 } |
| OLD | NEW |