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" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
14 #include "base/task_scheduler/post_task.h" | 14 #include "base/task_scheduler/post_task.h" |
15 #include "base/time/default_clock.h" | 15 #include "base/time/default_clock.h" |
16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/favicon/large_icon_service_factory.h" | 18 #include "chrome/browser/favicon/large_icon_service_factory.h" |
19 #include "chrome/browser/gcm/gcm_profile_service_factory.h" | |
20 #include "chrome/browser/gcm/instance_id/instance_id_profile_service.h" | |
21 #include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h" | |
19 #include "chrome/browser/history/history_service_factory.h" | 22 #include "chrome/browser/history/history_service_factory.h" |
20 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/search/suggestions/image_decoder_impl.h" | 24 #include "chrome/browser/search/suggestions/image_decoder_impl.h" |
22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
23 #include "chrome/browser/signin/signin_manager_factory.h" | 26 #include "chrome/browser/signin/signin_manager_factory.h" |
24 #include "chrome/browser/sync/profile_sync_service_factory.h" | 27 #include "chrome/browser/sync/profile_sync_service_factory.h" |
25 #include "chrome/browser/translate/language_model_factory.h" | 28 #include "chrome/browser/translate/language_model_factory.h" |
26 #include "chrome/common/channel_info.h" | 29 #include "chrome/common/channel_info.h" |
27 #include "chrome/common/chrome_features.h" | 30 #include "chrome/common/chrome_features.h" |
28 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
29 #include "components/bookmarks/browser/bookmark_model.h" | 32 #include "components/bookmarks/browser/bookmark_model.h" |
30 #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" | |
31 #include "components/image_fetcher/core/image_decoder.h" | 35 #include "components/image_fetcher/core/image_decoder.h" |
32 #include "components/image_fetcher/core/image_fetcher.h" | 36 #include "components/image_fetcher/core/image_fetcher.h" |
33 #include "components/image_fetcher/core/image_fetcher_impl.h" | 37 #include "components/image_fetcher/core/image_fetcher_impl.h" |
34 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 38 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
35 #include "components/keyed_service/core/service_access_type.h" | 39 #include "components/keyed_service/core/service_access_type.h" |
36 #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" | |
37 #include "components/ntp_snippets/category_rankers/category_ranker.h" | 44 #include "components/ntp_snippets/category_rankers/category_ranker.h" |
38 #include "components/ntp_snippets/content_suggestions_service.h" | 45 #include "components/ntp_snippets/content_suggestions_service.h" |
39 #include "components/ntp_snippets/features.h" | 46 #include "components/ntp_snippets/features.h" |
40 #include "components/ntp_snippets/ntp_snippets_constants.h" | 47 #include "components/ntp_snippets/ntp_snippets_constants.h" |
41 #include "components/ntp_snippets/remote/persistent_scheduler.h" | 48 #include "components/ntp_snippets/remote/persistent_scheduler.h" |
42 #include "components/ntp_snippets/remote/remote_suggestions_database.h" | 49 #include "components/ntp_snippets/remote/remote_suggestions_database.h" |
43 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" | 50 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" |
44 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" | 51 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
45 #include "components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h" | 52 #include "components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h" |
46 #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... | |
81 #include "components/offline_pages/core/offline_page_model.h" | 88 #include "components/offline_pages/core/offline_page_model.h" |
82 #include "components/offline_pages/core/prefetch/suggested_articles_observer.h" | 89 #include "components/offline_pages/core/prefetch/suggested_articles_observer.h" |
83 #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" |
84 #endif | 91 #endif |
85 | 92 |
86 using bookmarks::BookmarkModel; | 93 using bookmarks::BookmarkModel; |
87 using content::BrowserThread; | 94 using content::BrowserThread; |
88 using history::HistoryService; | 95 using history::HistoryService; |
89 using image_fetcher::ImageFetcherImpl; | 96 using image_fetcher::ImageFetcherImpl; |
90 using ntp_snippets::BookmarkSuggestionsProvider; | 97 using ntp_snippets::BookmarkSuggestionsProvider; |
98 using ntp_snippets::BreakingNewsSuggestionsProvider; | |
91 using ntp_snippets::CategoryRanker; | 99 using ntp_snippets::CategoryRanker; |
100 using ntp_snippets::ContentSuggestionsGCMAppHandler; | |
92 using ntp_snippets::ContentSuggestionsService; | 101 using ntp_snippets::ContentSuggestionsService; |
93 using ntp_snippets::ForeignSessionsSuggestionsProvider; | 102 using ntp_snippets::ForeignSessionsSuggestionsProvider; |
94 using ntp_snippets::GetFetchEndpoint; | 103 using ntp_snippets::GetFetchEndpoint; |
104 using ntp_snippets::GetPushUpdatesSubscriptionEndpoint; | |
95 using ntp_snippets::PersistentScheduler; | 105 using ntp_snippets::PersistentScheduler; |
96 using ntp_snippets::RemoteSuggestionsDatabase; | 106 using ntp_snippets::RemoteSuggestionsDatabase; |
97 using ntp_snippets::RemoteSuggestionsFetcher; | 107 using ntp_snippets::RemoteSuggestionsFetcher; |
98 using ntp_snippets::RemoteSuggestionsProviderImpl; | 108 using ntp_snippets::RemoteSuggestionsProviderImpl; |
99 using ntp_snippets::RemoteSuggestionsSchedulerImpl; | 109 using ntp_snippets::RemoteSuggestionsSchedulerImpl; |
100 using ntp_snippets::RemoteSuggestionsStatusService; | 110 using ntp_snippets::RemoteSuggestionsStatusService; |
111 using ntp_snippets::SubscriptionManager; | |
101 using ntp_snippets::TabDelegateSyncAdapter; | 112 using ntp_snippets::TabDelegateSyncAdapter; |
102 using ntp_snippets::UserClassifier; | 113 using ntp_snippets::UserClassifier; |
103 using suggestions::ImageDecoderImpl; | 114 using suggestions::ImageDecoderImpl; |
104 using syncer::SyncService; | 115 using syncer::SyncService; |
105 using translate::LanguageModel; | 116 using translate::LanguageModel; |
106 | 117 |
107 #if defined(OS_ANDROID) | 118 #if defined(OS_ANDROID) |
108 using content::DownloadManager; | 119 using content::DownloadManager; |
109 using ntp_snippets::PhysicalWebPageSuggestionsProvider; | 120 using ntp_snippets::PhysicalWebPageSuggestionsProvider; |
110 using physical_web::PhysicalWebDataSource; | 121 using physical_web::PhysicalWebDataSource; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 void RegisterForeignSessionsProvider(SyncService* sync_service, | 272 void RegisterForeignSessionsProvider(SyncService* sync_service, |
262 ContentSuggestionsService* service, | 273 ContentSuggestionsService* service, |
263 PrefService* pref_service) { | 274 PrefService* pref_service) { |
264 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = | 275 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = |
265 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); | 276 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); |
266 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( | 277 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( |
267 service, std::move(sync_adapter), pref_service); | 278 service, std::move(sync_adapter), pref_service); |
268 service->RegisterProvider(std::move(provider)); | 279 service->RegisterProvider(std::move(provider)); |
269 } | 280 } |
270 | 281 |
282 void SubscribeForGCMPushUpdates(PrefService* pref_service, | |
283 ContentSuggestionsService* service, | |
284 Profile* profile) { | |
285 gcm::GCMDriver* gcm_driver = | |
286 gcm::GCMProfileServiceFactory::GetForProfile(profile)->driver(); | |
287 | |
288 scoped_refptr<net::URLRequestContextGetter> request_context = | |
289 content::BrowserContext::GetDefaultStoragePartition(profile) | |
290 ->GetURLRequestContext(); | |
291 | |
292 auto subscription_manager = base::MakeUnique<SubscriptionManager>( | |
293 request_context, pref_service, | |
294 GetPushUpdatesSubscriptionEndpoint(chrome::GetChannel())); | |
295 | |
296 instance_id::InstanceIDProfileService* instance_id_profile_service = | |
297 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile); | |
298 CHECK(instance_id_profile_service); | |
299 CHECK(instance_id_profile_service->driver()); | |
300 | |
301 auto handler = base::MakeUnique<ContentSuggestionsGCMAppHandler>( | |
302 gcm_driver, instance_id_profile_service->driver(), pref_service, | |
303 std::move(subscription_manager)); | |
304 | |
305 handler->StartListening(); | |
306 | |
307 auto provider = base::MakeUnique<BreakingNewsSuggestionsProvider>( | |
308 service, std::move(handler)); | |
sfiera
2017/06/07 13:58:14
So far you've punted on the question of how sugges
mamir
2017/06/08 09:58:28
Thank you very much for the suggestion which I lik
| |
309 service->RegisterProvider(std::move(provider)); | |
310 } | |
311 | |
271 } // namespace | 312 } // namespace |
272 | 313 |
273 #endif // CONTENT_SUGGESTIONS_ENABLED | 314 #endif // CONTENT_SUGGESTIONS_ENABLED |
274 | 315 |
275 // static | 316 // static |
276 ContentSuggestionsServiceFactory* | 317 ContentSuggestionsServiceFactory* |
277 ContentSuggestionsServiceFactory::GetInstance() { | 318 ContentSuggestionsServiceFactory::GetInstance() { |
278 return base::Singleton<ContentSuggestionsServiceFactory>::get(); | 319 return base::Singleton<ContentSuggestionsServiceFactory>::get(); |
279 } | 320 } |
280 | 321 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 profile); | 452 profile); |
412 } | 453 } |
413 | 454 |
414 if (base::FeatureList::IsEnabled( | 455 if (base::FeatureList::IsEnabled( |
415 ntp_snippets::kForeignSessionsSuggestionsFeature)) { | 456 ntp_snippets::kForeignSessionsSuggestionsFeature)) { |
416 SyncService* sync_service = | 457 SyncService* sync_service = |
417 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile); | 458 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile); |
418 RegisterForeignSessionsProvider(sync_service, service, pref_service); | 459 RegisterForeignSessionsProvider(sync_service, service, pref_service); |
419 } | 460 } |
420 | 461 |
462 if (base::FeatureList::IsEnabled( | |
463 ntp_snippets::kContentSuggestionsPushFeature)) { | |
464 SubscribeForGCMPushUpdates(pref_service, service, profile); | |
465 } | |
421 return service; | 466 return service; |
422 | 467 |
423 #else | 468 #else |
424 return nullptr; | 469 return nullptr; |
425 #endif // CONTENT_SUGGESTIONS_ENABLED | 470 #endif // CONTENT_SUGGESTIONS_ENABLED |
426 } | 471 } |
OLD | NEW |