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 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/search/suggestions/image_decoder_impl.h" | 24 #include "chrome/browser/search/suggestions/image_decoder_impl.h" |
25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
26 #include "chrome/browser/signin/signin_manager_factory.h" | 26 #include "chrome/browser/signin/signin_manager_factory.h" |
27 #include "chrome/browser/sync/profile_sync_service_factory.h" | 27 #include "chrome/browser/sync/profile_sync_service_factory.h" |
28 #include "chrome/browser/translate/language_model_factory.h" | 28 #include "chrome/browser/translate/language_model_factory.h" |
29 #include "chrome/common/channel_info.h" | 29 #include "chrome/common/channel_info.h" |
30 #include "chrome/common/chrome_features.h" | 30 #include "chrome/common/chrome_features.h" |
31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
32 #include "components/bookmarks/browser/bookmark_model.h" | 32 #include "components/bookmarks/browser/bookmark_model.h" |
33 #include "components/browser_sync/profile_sync_service.h" | 33 #include "components/browser_sync/profile_sync_service.h" |
| 34 #include "components/gcm_driver/gcm_profile_service.h" |
34 #include "components/image_fetcher/core/image_decoder.h" | 35 #include "components/image_fetcher/core/image_decoder.h" |
35 #include "components/image_fetcher/core/image_fetcher.h" | 36 #include "components/image_fetcher/core/image_fetcher.h" |
36 #include "components/image_fetcher/core/image_fetcher_impl.h" | 37 #include "components/image_fetcher/core/image_fetcher_impl.h" |
37 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 38 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
38 #include "components/keyed_service/core/service_access_type.h" | 39 #include "components/keyed_service/core/service_access_type.h" |
39 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" | 40 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h" |
| 41 #include "components/ntp_snippets/breaking_news/breaking_news_suggestions_provid
er.h" |
| 42 #include "components/ntp_snippets/breaking_news/content_suggestions_gcm_app_hand
ler.h" |
| 43 #include "components/ntp_snippets/breaking_news/subscription_manager.h" |
40 #include "components/ntp_snippets/category_rankers/category_ranker.h" | 44 #include "components/ntp_snippets/category_rankers/category_ranker.h" |
41 #include "components/ntp_snippets/content_suggestions_service.h" | 45 #include "components/ntp_snippets/content_suggestions_service.h" |
42 #include "components/ntp_snippets/features.h" | 46 #include "components/ntp_snippets/features.h" |
43 #include "components/ntp_snippets/ntp_snippets_constants.h" | 47 #include "components/ntp_snippets/ntp_snippets_constants.h" |
44 #include "components/ntp_snippets/remote/persistent_scheduler.h" | 48 #include "components/ntp_snippets/remote/persistent_scheduler.h" |
45 #include "components/ntp_snippets/remote/remote_suggestions_database.h" | 49 #include "components/ntp_snippets/remote/remote_suggestions_database.h" |
46 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" | 50 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" |
47 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" | 51 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
48 #include "components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h" | 52 #include "components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h" |
49 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" | 53 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 #include "components/offline_pages/core/offline_page_model.h" | 88 #include "components/offline_pages/core/offline_page_model.h" |
85 #include "components/offline_pages/core/prefetch/suggested_articles_observer.h" | 89 #include "components/offline_pages/core/prefetch/suggested_articles_observer.h" |
86 #include "components/offline_pages/core/recent_tabs/recent_tabs_ui_adapter_deleg
ate.h" | 90 #include "components/offline_pages/core/recent_tabs/recent_tabs_ui_adapter_deleg
ate.h" |
87 #endif | 91 #endif |
88 | 92 |
89 using bookmarks::BookmarkModel; | 93 using bookmarks::BookmarkModel; |
90 using content::BrowserThread; | 94 using content::BrowserThread; |
91 using history::HistoryService; | 95 using history::HistoryService; |
92 using image_fetcher::ImageFetcherImpl; | 96 using image_fetcher::ImageFetcherImpl; |
93 using ntp_snippets::BookmarkSuggestionsProvider; | 97 using ntp_snippets::BookmarkSuggestionsProvider; |
| 98 using ntp_snippets::BreakingNewsSuggestionsProvider; |
94 using ntp_snippets::CategoryRanker; | 99 using ntp_snippets::CategoryRanker; |
| 100 using ntp_snippets::ContentSuggestionsGCMAppHandler; |
95 using ntp_snippets::ContentSuggestionsService; | 101 using ntp_snippets::ContentSuggestionsService; |
96 using ntp_snippets::ForeignSessionsSuggestionsProvider; | 102 using ntp_snippets::ForeignSessionsSuggestionsProvider; |
97 using ntp_snippets::GetFetchEndpoint; | 103 using ntp_snippets::GetFetchEndpoint; |
| 104 using ntp_snippets::GetPushUpdatesSubscriptionEndpoint; |
| 105 using ntp_snippets::GetPushUpdatesUnsubscriptionEndpoint; |
98 using ntp_snippets::PersistentScheduler; | 106 using ntp_snippets::PersistentScheduler; |
99 using ntp_snippets::RemoteSuggestionsDatabase; | 107 using ntp_snippets::RemoteSuggestionsDatabase; |
100 using ntp_snippets::RemoteSuggestionsFetcher; | 108 using ntp_snippets::RemoteSuggestionsFetcher; |
101 using ntp_snippets::RemoteSuggestionsProviderImpl; | 109 using ntp_snippets::RemoteSuggestionsProviderImpl; |
102 using ntp_snippets::RemoteSuggestionsSchedulerImpl; | 110 using ntp_snippets::RemoteSuggestionsSchedulerImpl; |
103 using ntp_snippets::RemoteSuggestionsStatusService; | 111 using ntp_snippets::RemoteSuggestionsStatusService; |
| 112 using ntp_snippets::SubscriptionManager; |
104 using ntp_snippets::TabDelegateSyncAdapter; | 113 using ntp_snippets::TabDelegateSyncAdapter; |
105 using ntp_snippets::UserClassifier; | 114 using ntp_snippets::UserClassifier; |
106 using suggestions::ImageDecoderImpl; | 115 using suggestions::ImageDecoderImpl; |
107 using syncer::SyncService; | 116 using syncer::SyncService; |
108 using translate::LanguageModel; | 117 using translate::LanguageModel; |
109 | 118 |
110 #if defined(OS_ANDROID) | 119 #if defined(OS_ANDROID) |
111 using content::DownloadManager; | 120 using content::DownloadManager; |
112 using ntp_snippets::PhysicalWebPageSuggestionsProvider; | 121 using ntp_snippets::PhysicalWebPageSuggestionsProvider; |
113 using physical_web::PhysicalWebDataSource; | 122 using physical_web::PhysicalWebDataSource; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 void RegisterForeignSessionsProvider(SyncService* sync_service, | 273 void RegisterForeignSessionsProvider(SyncService* sync_service, |
265 ContentSuggestionsService* service, | 274 ContentSuggestionsService* service, |
266 PrefService* pref_service) { | 275 PrefService* pref_service) { |
267 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = | 276 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = |
268 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); | 277 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); |
269 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( | 278 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( |
270 service, std::move(sync_adapter), pref_service); | 279 service, std::move(sync_adapter), pref_service); |
271 service->RegisterProvider(std::move(provider)); | 280 service->RegisterProvider(std::move(provider)); |
272 } | 281 } |
273 | 282 |
| 283 void SubscribeForGCMPushUpdates(PrefService* pref_service, |
| 284 ContentSuggestionsService* service, |
| 285 Profile* profile) { |
| 286 gcm::GCMDriver* gcm_driver = |
| 287 gcm::GCMProfileServiceFactory::GetForProfile(profile)->driver(); |
| 288 |
| 289 scoped_refptr<net::URLRequestContextGetter> request_context = |
| 290 content::BrowserContext::GetDefaultStoragePartition(profile) |
| 291 ->GetURLRequestContext(); |
| 292 |
| 293 auto subscription_manager = base::MakeUnique<SubscriptionManager>( |
| 294 request_context, pref_service, |
| 295 GetPushUpdatesSubscriptionEndpoint(chrome::GetChannel()), |
| 296 GetPushUpdatesUnsubscriptionEndpoint(chrome::GetChannel())); |
| 297 |
| 298 instance_id::InstanceIDProfileService* instance_id_profile_service = |
| 299 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile); |
| 300 DCHECK(instance_id_profile_service); |
| 301 DCHECK(instance_id_profile_service->driver()); |
| 302 |
| 303 auto handler = base::MakeUnique<ContentSuggestionsGCMAppHandler>( |
| 304 gcm_driver, instance_id_profile_service->driver(), pref_service, |
| 305 std::move(subscription_manager)); |
| 306 |
| 307 auto provider = base::MakeUnique<BreakingNewsSuggestionsProvider>( |
| 308 service, std::move(handler)); |
| 309 provider->Start(); |
| 310 service->RegisterProvider(std::move(provider)); |
| 311 } |
| 312 |
274 } // namespace | 313 } // namespace |
275 | 314 |
276 #endif // CONTENT_SUGGESTIONS_ENABLED | 315 #endif // CONTENT_SUGGESTIONS_ENABLED |
277 | 316 |
278 // static | 317 // static |
279 ContentSuggestionsServiceFactory* | 318 ContentSuggestionsServiceFactory* |
280 ContentSuggestionsServiceFactory::GetInstance() { | 319 ContentSuggestionsServiceFactory::GetInstance() { |
281 return base::Singleton<ContentSuggestionsServiceFactory>::get(); | 320 return base::Singleton<ContentSuggestionsServiceFactory>::get(); |
282 } | 321 } |
283 | 322 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 profile); | 457 profile); |
419 } | 458 } |
420 | 459 |
421 if (base::FeatureList::IsEnabled( | 460 if (base::FeatureList::IsEnabled( |
422 ntp_snippets::kForeignSessionsSuggestionsFeature)) { | 461 ntp_snippets::kForeignSessionsSuggestionsFeature)) { |
423 SyncService* sync_service = | 462 SyncService* sync_service = |
424 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile); | 463 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile); |
425 RegisterForeignSessionsProvider(sync_service, service, pref_service); | 464 RegisterForeignSessionsProvider(sync_service, service, pref_service); |
426 } | 465 } |
427 | 466 |
| 467 if (base::FeatureList::IsEnabled( |
| 468 ntp_snippets::kContentSuggestionsPushFeature)) { |
| 469 SubscribeForGCMPushUpdates(pref_service, service, profile); |
| 470 } |
428 return service; | 471 return service; |
429 | 472 |
430 #else | 473 #else |
431 return nullptr; | 474 return nullptr; |
432 #endif // CONTENT_SUGGESTIONS_ENABLED | 475 #endif // CONTENT_SUGGESTIONS_ENABLED |
433 } | 476 } |
OLD | NEW |