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

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

Issue 2925053003: [NTP::Push] Adding BreakingNewsSuggestionsProvider (Closed)
Patch Set: Fixing the build. 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
« no previous file with comments | « no previous file | components/ntp_snippets/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 13 matching lines...) Expand all
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 #include "components/offline_pages/core/prefetch/prefetch_service.h" 89 #include "components/offline_pages/core/prefetch/prefetch_service.h"
86 #include "components/offline_pages/core/prefetch/suggested_articles_observer.h" 90 #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" 91 #include "components/offline_pages/core/recent_tabs/recent_tabs_ui_adapter_deleg ate.h"
88 #endif 92 #endif
89 93
90 using bookmarks::BookmarkModel; 94 using bookmarks::BookmarkModel;
91 using content::BrowserThread; 95 using content::BrowserThread;
92 using history::HistoryService; 96 using history::HistoryService;
93 using image_fetcher::ImageFetcherImpl; 97 using image_fetcher::ImageFetcherImpl;
94 using ntp_snippets::BookmarkSuggestionsProvider; 98 using ntp_snippets::BookmarkSuggestionsProvider;
99 using ntp_snippets::BreakingNewsSuggestionsProvider;
95 using ntp_snippets::CategoryRanker; 100 using ntp_snippets::CategoryRanker;
101 using ntp_snippets::ContentSuggestionsGCMAppHandler;
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;
105 using ntp_snippets::GetPushUpdatesSubscriptionEndpoint;
106 using ntp_snippets::GetPushUpdatesUnsubscriptionEndpoint;
99 using ntp_snippets::PersistentScheduler; 107 using ntp_snippets::PersistentScheduler;
100 using ntp_snippets::RemoteSuggestionsDatabase; 108 using ntp_snippets::RemoteSuggestionsDatabase;
101 using ntp_snippets::RemoteSuggestionsFetcher; 109 using ntp_snippets::RemoteSuggestionsFetcher;
102 using ntp_snippets::RemoteSuggestionsProviderImpl; 110 using ntp_snippets::RemoteSuggestionsProviderImpl;
103 using ntp_snippets::RemoteSuggestionsSchedulerImpl; 111 using ntp_snippets::RemoteSuggestionsSchedulerImpl;
104 using ntp_snippets::RemoteSuggestionsStatusService; 112 using ntp_snippets::RemoteSuggestionsStatusService;
113 using ntp_snippets::SubscriptionManager;
105 using ntp_snippets::TabDelegateSyncAdapter; 114 using ntp_snippets::TabDelegateSyncAdapter;
106 using ntp_snippets::UserClassifier; 115 using ntp_snippets::UserClassifier;
107 using suggestions::ImageDecoderImpl; 116 using suggestions::ImageDecoderImpl;
108 using syncer::SyncService; 117 using syncer::SyncService;
109 using translate::LanguageModel; 118 using translate::LanguageModel;
110 119
111 #if defined(OS_ANDROID) 120 #if defined(OS_ANDROID)
112 using content::DownloadManager; 121 using content::DownloadManager;
113 using ntp_snippets::PhysicalWebPageSuggestionsProvider; 122 using ntp_snippets::PhysicalWebPageSuggestionsProvider;
114 using physical_web::PhysicalWebDataSource; 123 using physical_web::PhysicalWebDataSource;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 361
353 SyncService* sync_service = 362 SyncService* sync_service =
354 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile); 363 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile);
355 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter = 364 std::unique_ptr<TabDelegateSyncAdapter> sync_adapter =
356 base::MakeUnique<TabDelegateSyncAdapter>(sync_service); 365 base::MakeUnique<TabDelegateSyncAdapter>(sync_service);
357 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>( 366 auto provider = base::MakeUnique<ForeignSessionsSuggestionsProvider>(
358 service, std::move(sync_adapter), profile->GetPrefs()); 367 service, std::move(sync_adapter), profile->GetPrefs());
359 service->RegisterProvider(std::move(provider)); 368 service->RegisterProvider(std::move(provider));
360 } 369 }
361 370
371 void SubscribeForGCMPushUpdates(PrefService* pref_service,
372 ContentSuggestionsService* service,
373 Profile* profile) {
374 gcm::GCMDriver* gcm_driver =
375 gcm::GCMProfileServiceFactory::GetForProfile(profile)->driver();
376
377 scoped_refptr<net::URLRequestContextGetter> request_context =
378 content::BrowserContext::GetDefaultStoragePartition(profile)
379 ->GetURLRequestContext();
380
381 auto subscription_manager = base::MakeUnique<SubscriptionManager>(
382 request_context, pref_service,
383 GetPushUpdatesSubscriptionEndpoint(chrome::GetChannel()),
384 GetPushUpdatesUnsubscriptionEndpoint(chrome::GetChannel()));
385
386 instance_id::InstanceIDProfileService* instance_id_profile_service =
387 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile);
388 DCHECK(instance_id_profile_service);
389 DCHECK(instance_id_profile_service->driver());
390
391 auto handler = base::MakeUnique<ContentSuggestionsGCMAppHandler>(
392 gcm_driver, instance_id_profile_service->driver(), pref_service,
393 std::move(subscription_manager));
394
395 auto provider = base::MakeUnique<BreakingNewsSuggestionsProvider>(
396 service, std::move(handler));
397 provider->Start();
398 service->RegisterProvider(std::move(provider));
399 }
400
362 } // namespace 401 } // namespace
363 402
364 #endif // CONTENT_SUGGESTIONS_ENABLED 403 #endif // CONTENT_SUGGESTIONS_ENABLED
365 404
366 // static 405 // static
367 ContentSuggestionsServiceFactory* 406 ContentSuggestionsServiceFactory*
368 ContentSuggestionsServiceFactory::GetInstance() { 407 ContentSuggestionsServiceFactory::GetInstance() {
369 return base::Singleton<ContentSuggestionsServiceFactory>::get(); 408 return base::Singleton<ContentSuggestionsServiceFactory>::get();
370 } 409 }
371 410
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 RegisterRecentTabProviderIfEnabled(service, profile, offline_page_model); 502 RegisterRecentTabProviderIfEnabled(service, profile, offline_page_model);
464 503
465 if (offline_pages::IsPrefetchingOfflinePagesEnabled()) { 504 if (offline_pages::IsPrefetchingOfflinePagesEnabled()) {
466 offline_pages::SuggestedArticlesObserver* observer = 505 offline_pages::SuggestedArticlesObserver* observer =
467 offline_pages::PrefetchServiceFactory::GetForBrowserContext(profile) 506 offline_pages::PrefetchServiceFactory::GetForBrowserContext(profile)
468 ->GetSuggestedArticlesObserver(); 507 ->GetSuggestedArticlesObserver();
469 observer->SetContentSuggestionsServiceAndObserve(service); 508 observer->SetContentSuggestionsServiceAndObserve(service);
470 } 509 }
471 #endif 510 #endif
472 511
512 if (base::FeatureList::IsEnabled(
513 ntp_snippets::kContentSuggestionsPushFeature)) {
514 SubscribeForGCMPushUpdates(pref_service, service, profile);
515 }
473 return service; 516 return service;
474 517
475 #else 518 #else
476 return nullptr; 519 return nullptr;
477 #endif // CONTENT_SUGGESTIONS_ENABLED 520 #endif // CONTENT_SUGGESTIONS_ENABLED
478 } 521 }
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698