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

Side by Side Diff: components/ntp_snippets/breaking_news/content_suggestions_gcm_app_handler.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/ntp_snippets/breaking_news/content_suggestions_gcm_app_hand ler.h" 5 #include "components/ntp_snippets/breaking_news/content_suggestions_gcm_app_hand ler.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "components/gcm_driver/gcm_driver.h" 8 #include "components/gcm_driver/gcm_driver.h"
9 #include "components/gcm_driver/gcm_profile_service.h" 9 #include "components/gcm_driver/gcm_profile_service.h"
10 #include "components/gcm_driver/instance_id/instance_id.h" 10 #include "components/gcm_driver/instance_id/instance_id.h"
(...skipping 29 matching lines...) Expand all
40 // DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); 40 // DependsOn(gcm::GCMProfileServiceFactory::GetInstance());
41 // DependsOn(instance_id::InstanceIDProfileServiceFactory::GetInstance()); 41 // DependsOn(instance_id::InstanceIDProfileServiceFactory::GetInstance());
42 // #endif 42 // #endif
43 } 43 }
44 ContentSuggestionsGCMAppHandler::~ContentSuggestionsGCMAppHandler() { 44 ContentSuggestionsGCMAppHandler::~ContentSuggestionsGCMAppHandler() {
45 if (gcm_driver_->GetAppHandler(kContentSuggestionsGCMAppID) == this) { 45 if (gcm_driver_->GetAppHandler(kContentSuggestionsGCMAppID) == this) {
46 StopListening(); 46 StopListening();
47 } 47 }
48 } 48 }
49 49
50 void ContentSuggestionsGCMAppHandler::StartListening() { 50 void ContentSuggestionsGCMAppHandler::StartListening(
51 OnNewContentCallback on_new_content_callback) {
51 #if !defined(OS_ANDROID) 52 #if !defined(OS_ANDROID)
52 NOTREACHED() 53 NOTREACHED()
53 << "The ContentSuggestionsGCMAppHandler should only be used on Android."; 54 << "The ContentSuggestionsGCMAppHandler should only be used on Android.";
54 #endif 55 #endif
55 Subscribe(); 56 Subscribe();
57 on_new_content_callback_ = std::move(on_new_content_callback);
56 gcm_driver_->AddAppHandler(kContentSuggestionsGCMAppID, this); 58 gcm_driver_->AddAppHandler(kContentSuggestionsGCMAppID, this);
57 } 59 }
58 60
59 void ContentSuggestionsGCMAppHandler::StopListening() { 61 void ContentSuggestionsGCMAppHandler::StopListening() {
60 DCHECK_EQ(gcm_driver_->GetAppHandler(kContentSuggestionsGCMAppID), this); 62 DCHECK_EQ(gcm_driver_->GetAppHandler(kContentSuggestionsGCMAppID), this);
61 gcm_driver_->RemoveAppHandler(kContentSuggestionsGCMAppID); 63 gcm_driver_->RemoveAppHandler(kContentSuggestionsGCMAppID);
62 std::string token = pref_service_->GetString( 64 std::string token = pref_service_->GetString(
63 ntp_snippets::prefs::kContentSuggestionsGCMSubscriptionTokenCache); 65 ntp_snippets::prefs::kContentSuggestionsGCMSubscriptionTokenCache);
64 subscription_manager_->Unsubscribe(token); 66 subscription_manager_->Unsubscribe(token);
65 } 67 }
sfiera 2017/06/08 13:37:15 Clear on_new_content_callback_?
mamir 2017/06/08 15:20:06 Done.
66 68
67 void ContentSuggestionsGCMAppHandler::Subscribe() { 69 void ContentSuggestionsGCMAppHandler::Subscribe() {
68 std::string token = pref_service_->GetString( 70 std::string token = pref_service_->GetString(
69 ntp_snippets::prefs::kContentSuggestionsGCMSubscriptionTokenCache); 71 ntp_snippets::prefs::kContentSuggestionsGCMSubscriptionTokenCache);
70 if (!token.empty()) { 72 if (!token.empty()) {
71 return; 73 return;
72 } 74 }
73 75
74 instance_id_driver_->GetInstanceID(kContentSuggestionsGCMAppID) 76 instance_id_driver_->GetInstanceID(kContentSuggestionsGCMAppID)
75 ->GetToken(kContentSuggestionsGCMSenderId, kGCMScope, 77 ->GetToken(kContentSuggestionsGCMSenderId, kGCMScope,
(...skipping 29 matching lines...) Expand all
105 void ContentSuggestionsGCMAppHandler::ShutdownHandler() {} 107 void ContentSuggestionsGCMAppHandler::ShutdownHandler() {}
106 108
107 void ContentSuggestionsGCMAppHandler::OnStoreReset() { 109 void ContentSuggestionsGCMAppHandler::OnStoreReset() {
108 pref_service_->ClearPref( 110 pref_service_->ClearPref(
109 ntp_snippets::prefs::kContentSuggestionsGCMSubscriptionTokenCache); 111 ntp_snippets::prefs::kContentSuggestionsGCMSubscriptionTokenCache);
110 } 112 }
111 113
112 void ContentSuggestionsGCMAppHandler::OnMessage( 114 void ContentSuggestionsGCMAppHandler::OnMessage(
113 const std::string& app_id, 115 const std::string& app_id,
114 const gcm::IncomingMessage& message) { 116 const gcm::IncomingMessage& message) {
115 // TODO(mamir): Implement Show notification and update the feed. 117 // TODO(mamir): Build the message.
118 on_new_content_callback_.Run(std::string());
116 } 119 }
117 120
118 void ContentSuggestionsGCMAppHandler::OnMessagesDeleted( 121 void ContentSuggestionsGCMAppHandler::OnMessagesDeleted(
119 const std::string& app_id) { 122 const std::string& app_id) {
120 // Messages don't get deleted. 123 // Messages don't get deleted.
121 NOTREACHED() << "ContentSuggestionsGCMAppHandler messages don't get deleted."; 124 NOTREACHED() << "ContentSuggestionsGCMAppHandler messages don't get deleted.";
122 } 125 }
123 126
124 void ContentSuggestionsGCMAppHandler::OnSendError( 127 void ContentSuggestionsGCMAppHandler::OnSendError(
125 const std::string& app_id, 128 const std::string& app_id,
(...skipping 11 matching lines...) Expand all
137 NOTREACHED() << "ContentSuggestionsGCMAppHandler doesn't send GCM messages."; 140 NOTREACHED() << "ContentSuggestionsGCMAppHandler doesn't send GCM messages.";
138 } 141 }
139 142
140 void ContentSuggestionsGCMAppHandler::RegisterProfilePrefs( 143 void ContentSuggestionsGCMAppHandler::RegisterProfilePrefs(
141 PrefRegistrySimple* registry) { 144 PrefRegistrySimple* registry) {
142 registry->RegisterStringPref( 145 registry->RegisterStringPref(
143 prefs::kContentSuggestionsGCMSubscriptionTokenCache, std::string()); 146 prefs::kContentSuggestionsGCMSubscriptionTokenCache, std::string());
144 } 147 }
145 148
146 } // namespace ntp_snippets 149 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698