Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(833)

Side by Side Diff: chrome/browser/ntp_snippets/content_suggestions_service_factory.cc

Issue 2925053003: [NTP::Push] Adding BreakingNewsSuggestionsProvider (Closed)
Patch Set: sfiera@ comments. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
105 using ntp_snippets::GetPushUpdatesUnsubscriptionEndpoint;
95 using ntp_snippets::PersistentScheduler; 106 using ntp_snippets::PersistentScheduler;
96 using ntp_snippets::RemoteSuggestionsDatabase; 107 using ntp_snippets::RemoteSuggestionsDatabase;
97 using ntp_snippets::RemoteSuggestionsFetcher; 108 using ntp_snippets::RemoteSuggestionsFetcher;
98 using ntp_snippets::RemoteSuggestionsProviderImpl; 109 using ntp_snippets::RemoteSuggestionsProviderImpl;
99 using ntp_snippets::RemoteSuggestionsSchedulerImpl; 110 using ntp_snippets::RemoteSuggestionsSchedulerImpl;
100 using ntp_snippets::RemoteSuggestionsStatusService; 111 using ntp_snippets::RemoteSuggestionsStatusService;
112 using ntp_snippets::SubscriptionManager;
101 using ntp_snippets::TabDelegateSyncAdapter; 113 using ntp_snippets::TabDelegateSyncAdapter;
102 using ntp_snippets::UserClassifier; 114 using ntp_snippets::UserClassifier;
103 using suggestions::ImageDecoderImpl; 115 using suggestions::ImageDecoderImpl;
104 using syncer::SyncService; 116 using syncer::SyncService;
105 using translate::LanguageModel; 117 using translate::LanguageModel;
106 118
107 #if defined(OS_ANDROID) 119 #if defined(OS_ANDROID)
108 using content::DownloadManager; 120 using content::DownloadManager;
109 using ntp_snippets::PhysicalWebPageSuggestionsProvider; 121 using ntp_snippets::PhysicalWebPageSuggestionsProvider;
110 using physical_web::PhysicalWebDataSource; 122 using physical_web::PhysicalWebDataSource;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 void RegisterForeignSessionsProvider(SyncService* sync_service, 273 void RegisterForeignSessionsProvider(SyncService* sync_service,
262 ContentSuggestionsService* service, 274 ContentSuggestionsService* service,
263 PrefService* pref_service) { 275 PrefService* pref_service) {
264 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = 276 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter =
265 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); 277 base::MakeUnique<TabDelegateSyncAdapter>(sync_service);
266 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( 278 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>(
267 service, std::move(sync_adapter), pref_service); 279 service, std::move(sync_adapter), pref_service);
268 service->RegisterProvider(std::move(provider)); 280 service->RegisterProvider(std::move(provider));
269 } 281 }
270 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 CHECK(instance_id_profile_service);
301 CHECK(instance_id_profile_service->driver());
sfiera 2017/06/08 13:37:15 These should probably be DCHECKs
mamir 2017/06/08 15:20:06 Done.
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
271 } // namespace 313 } // namespace
272 314
273 #endif // CONTENT_SUGGESTIONS_ENABLED 315 #endif // CONTENT_SUGGESTIONS_ENABLED
274 316
275 // static 317 // static
276 ContentSuggestionsServiceFactory* 318 ContentSuggestionsServiceFactory*
277 ContentSuggestionsServiceFactory::GetInstance() { 319 ContentSuggestionsServiceFactory::GetInstance() {
278 return base::Singleton<ContentSuggestionsServiceFactory>::get(); 320 return base::Singleton<ContentSuggestionsServiceFactory>::get();
279 } 321 }
280 322
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 profile); 453 profile);
412 } 454 }
413 455
414 if (base::FeatureList::IsEnabled( 456 if (base::FeatureList::IsEnabled(
415 ntp_snippets::kForeignSessionsSuggestionsFeature)) { 457 ntp_snippets::kForeignSessionsSuggestionsFeature)) {
416 SyncService* sync_service = 458 SyncService* sync_service =
417 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile); 459 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile);
418 RegisterForeignSessionsProvider(sync_service, service, pref_service); 460 RegisterForeignSessionsProvider(sync_service, service, pref_service);
419 } 461 }
420 462
463 if (base::FeatureList::IsEnabled(
464 ntp_snippets::kContentSuggestionsPushFeature)) {
465 SubscribeForGCMPushUpdates(pref_service, service, profile);
466 }
421 return service; 467 return service;
422 468
423 #else 469 #else
424 return nullptr; 470 return nullptr;
425 #endif // CONTENT_SUGGESTIONS_ENABLED 471 #endif // CONTENT_SUGGESTIONS_ENABLED
426 } 472 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698