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

Unified Diff: chrome/browser/ntp_snippets/content_suggestions_service_factory.cc

Issue 2925053003: [NTP::Push] Adding BreakingNewsSuggestionsProvider (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ntp_snippets/content_suggestions_service_factory.cc
diff --git a/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc b/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc
index f9a9371616a26ece8a5c4d277ee4eb4489e9d349..9723c89734e670879e842ee11d504085b5174b08 100644
--- a/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc
+++ b/chrome/browser/ntp_snippets/content_suggestions_service_factory.cc
@@ -16,6 +16,9 @@
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/favicon/large_icon_service_factory.h"
+#include "chrome/browser/gcm/gcm_profile_service_factory.h"
+#include "chrome/browser/gcm/instance_id/instance_id_profile_service.h"
+#include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/suggestions/image_decoder_impl.h"
@@ -28,12 +31,16 @@
#include "chrome/common/pref_names.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/browser_sync/profile_sync_service.h"
+#include "components/gcm_driver/gcm_profile_service.h"
#include "components/image_fetcher/core/image_decoder.h"
#include "components/image_fetcher/core/image_fetcher.h"
#include "components/image_fetcher/core/image_fetcher_impl.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h"
+#include "components/ntp_snippets/breaking_news/breaking_news_suggestions_provider.h"
+#include "components/ntp_snippets/breaking_news/content_suggestions_gcm_app_handler.h"
+#include "components/ntp_snippets/breaking_news/subscription_manager.h"
#include "components/ntp_snippets/category_rankers/category_ranker.h"
#include "components/ntp_snippets/content_suggestions_service.h"
#include "components/ntp_snippets/features.h"
@@ -88,16 +95,20 @@ using content::BrowserThread;
using history::HistoryService;
using image_fetcher::ImageFetcherImpl;
using ntp_snippets::BookmarkSuggestionsProvider;
+using ntp_snippets::BreakingNewsSuggestionsProvider;
using ntp_snippets::CategoryRanker;
+using ntp_snippets::ContentSuggestionsGCMAppHandler;
using ntp_snippets::ContentSuggestionsService;
using ntp_snippets::ForeignSessionsSuggestionsProvider;
using ntp_snippets::GetFetchEndpoint;
+using ntp_snippets::GetPushUpdatesSubscriptionEndpoint;
using ntp_snippets::PersistentScheduler;
using ntp_snippets::RemoteSuggestionsDatabase;
using ntp_snippets::RemoteSuggestionsFetcher;
using ntp_snippets::RemoteSuggestionsProviderImpl;
using ntp_snippets::RemoteSuggestionsSchedulerImpl;
using ntp_snippets::RemoteSuggestionsStatusService;
+using ntp_snippets::SubscriptionManager;
using ntp_snippets::TabDelegateSyncAdapter;
using ntp_snippets::UserClassifier;
using suggestions::ImageDecoderImpl;
@@ -268,6 +279,36 @@ void RegisterForeignSessionsProvider(SyncService* sync_service,
service->RegisterProvider(std::move(provider));
}
+void SubscribeForGCMPushUpdates(PrefService* pref_service,
+ ContentSuggestionsService* service,
+ Profile* profile) {
+ gcm::GCMDriver* gcm_driver =
+ gcm::GCMProfileServiceFactory::GetForProfile(profile)->driver();
+
+ scoped_refptr<net::URLRequestContextGetter> request_context =
+ content::BrowserContext::GetDefaultStoragePartition(profile)
+ ->GetURLRequestContext();
+
+ auto subscription_manager = base::MakeUnique<SubscriptionManager>(
+ request_context, pref_service,
+ GetPushUpdatesSubscriptionEndpoint(chrome::GetChannel()));
+
+ instance_id::InstanceIDProfileService* instance_id_profile_service =
+ instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile);
+ CHECK(instance_id_profile_service);
+ CHECK(instance_id_profile_service->driver());
+
+ auto handler = base::MakeUnique<ContentSuggestionsGCMAppHandler>(
+ gcm_driver, instance_id_profile_service->driver(), pref_service,
+ std::move(subscription_manager));
+
+ handler->StartListening();
+
+ auto provider = base::MakeUnique<BreakingNewsSuggestionsProvider>(
+ 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
+ service->RegisterProvider(std::move(provider));
+}
+
} // namespace
#endif // CONTENT_SUGGESTIONS_ENABLED
@@ -418,6 +459,10 @@ KeyedService* ContentSuggestionsServiceFactory::BuildServiceInstanceFor(
RegisterForeignSessionsProvider(sync_service, service, pref_service);
}
+ if (base::FeatureList::IsEnabled(
+ ntp_snippets::kContentSuggestionsPushFeature)) {
+ SubscribeForGCMPushUpdates(pref_service, service, profile);
+ }
return service;
#else

Powered by Google App Engine
This is Rietveld 408576698