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

Side by Side Diff: chrome/browser/services/gcm/push_messaging_service_impl.cc

Issue 658783002: Split PushMessagingStatus enum according to use case (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comment Created 6 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/services/gcm/push_messaging_service_impl.h" 5 #include "chrome/browser/services/gcm/push_messaging_service_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // TODO(mvanouwerkerk): Show a warning in the developer console of the 125 // TODO(mvanouwerkerk): Show a warning in the developer console of the
126 // Service Worker corresponding to app_id. 126 // Service Worker corresponding to app_id.
127 // TODO(johnme): Add diagnostic observers (e.g. UMA and an internals page) 127 // TODO(johnme): Add diagnostic observers (e.g. UMA and an internals page)
128 // to know when bad things happen. 128 // to know when bad things happen.
129 } 129 }
130 } 130 }
131 131
132 void PushMessagingServiceImpl::DeliverMessageCallback( 132 void PushMessagingServiceImpl::DeliverMessageCallback(
133 const PushMessagingApplicationId& application_id, 133 const PushMessagingApplicationId& application_id,
134 const GCMClient::IncomingMessage& message, 134 const GCMClient::IncomingMessage& message,
135 content::PushMessagingStatus status) { 135 content::PushDeliveryStatus status) {
136 // TODO(mvanouwerkerk): UMA logging. 136 // TODO(mvanouwerkerk): UMA logging.
137 // TODO(mvanouwerkerk): Is there a way to recover from failure? 137 // TODO(mvanouwerkerk): Is there a way to recover from failure?
138 } 138 }
139 139
140 void PushMessagingServiceImpl::OnMessagesDeleted(const std::string& app_id) { 140 void PushMessagingServiceImpl::OnMessagesDeleted(const std::string& app_id) {
141 // TODO(mvanouwerkerk): Fire push error event on the Service Worker 141 // TODO(mvanouwerkerk): Fire push error event on the Service Worker
142 // corresponding to app_id. 142 // corresponding to app_id.
143 } 143 }
144 144
145 void PushMessagingServiceImpl::OnSendError( 145 void PushMessagingServiceImpl::OnSendError(
(...skipping 19 matching lines...) Expand all
165 if (!gcm_profile_service_->driver()) { 165 if (!gcm_profile_service_->driver()) {
166 NOTREACHED() << "There is no GCMDriver. Has GCMProfileService shut down?"; 166 NOTREACHED() << "There is no GCMDriver. Has GCMProfileService shut down?";
167 } 167 }
168 168
169 PushMessagingApplicationId application_id = 169 PushMessagingApplicationId application_id =
170 PushMessagingApplicationId(origin, service_worker_registration_id); 170 PushMessagingApplicationId(origin, service_worker_registration_id);
171 DCHECK(application_id.IsValid()); 171 DCHECK(application_id.IsValid());
172 172
173 if (profile_->GetPrefs()->GetInteger( 173 if (profile_->GetPrefs()->GetInteger(
174 prefs::kPushMessagingRegistrationCount) >= kMaxRegistrations) { 174 prefs::kPushMessagingRegistrationCount) >= kMaxRegistrations) {
175 RegisterEnd( 175 RegisterEnd(callback,
176 callback, 176 std::string(),
177 std::string(), 177 content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED);
178 content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_LIMIT_REACHED);
179 return; 178 return;
180 } 179 }
181 180
182 // If this is registering for the first time then the driver does not have 181 // If this is registering for the first time then the driver does not have
183 // this as an app handler and registration would fail. 182 // this as an app handler and registration would fail.
184 if (gcm_profile_service_->driver()->GetAppHandler( 183 if (gcm_profile_service_->driver()->GetAppHandler(
185 kPushMessagingApplicationIdPrefix) != this) 184 kPushMessagingApplicationIdPrefix) != this)
186 gcm_profile_service_->driver()->AddAppHandler( 185 gcm_profile_service_->driver()->AddAppHandler(
187 kPushMessagingApplicationIdPrefix, this); 186 kPushMessagingApplicationIdPrefix, this);
188 187
(...skipping 16 matching lines...) Expand all
205 int bridge_id = -1; 204 int bridge_id = -1;
206 205
207 const PermissionRequestID id( 206 const PermissionRequestID id(
208 renderer_id, web_contents->GetRoutingID(), bridge_id, GURL()); 207 renderer_id, web_contents->GetRoutingID(), bridge_id, GURL());
209 208
210 GURL embedder = web_contents->GetLastCommittedURL(); 209 GURL embedder = web_contents->GetLastCommittedURL();
211 gcm::PushMessagingPermissionContext* permission_context = 210 gcm::PushMessagingPermissionContext* permission_context =
212 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); 211 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_);
213 212
214 if (permission_context == NULL) { 213 if (permission_context == NULL) {
215 RegisterEnd( 214 RegisterEnd(callback,
216 callback, 215 std::string(),
217 std::string(), 216 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED);
218 content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_PERMISSION_DENIED);
219 return; 217 return;
220 } 218 }
221 219
222 permission_context->RequestPermission( 220 permission_context->RequestPermission(
223 web_contents, 221 web_contents,
224 id, 222 id,
225 embedder, 223 embedder,
226 user_gesture, 224 user_gesture,
227 base::Bind(&PushMessagingServiceImpl::DidRequestPermission, 225 base::Bind(&PushMessagingServiceImpl::DidRequestPermission,
228 weak_factory_.GetWeakPtr(), 226 weak_factory_.GetWeakPtr(),
229 application_id, 227 application_id,
230 sender_id, 228 sender_id,
231 callback)); 229 callback));
232 } 230 }
233 231
234 void PushMessagingServiceImpl::RegisterEnd( 232 void PushMessagingServiceImpl::RegisterEnd(
235 const content::PushMessagingService::RegisterCallback& callback, 233 const content::PushMessagingService::RegisterCallback& callback,
236 const std::string& registration_id, 234 const std::string& registration_id,
237 content::PushMessagingStatus status) { 235 content::PushRegistrationStatus status) {
238 GURL endpoint = GURL("https://android.googleapis.com/gcm/send"); 236 GURL endpoint = GURL("https://android.googleapis.com/gcm/send");
239 callback.Run(endpoint, registration_id, status); 237 callback.Run(endpoint, registration_id, status);
240 if (status == content::PUSH_MESSAGING_STATUS_OK) { 238 if (status == content::PUSH_REGISTRATION_STATUS_SUCCESS) {
241 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes. 239 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes.
242 int registration_count = profile_->GetPrefs()->GetInteger( 240 int registration_count = profile_->GetPrefs()->GetInteger(
243 prefs::kPushMessagingRegistrationCount); 241 prefs::kPushMessagingRegistrationCount);
244 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, 242 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount,
245 registration_count + 1); 243 registration_count + 1);
246 } 244 }
247 } 245 }
248 246
249 void PushMessagingServiceImpl::DidRegister( 247 void PushMessagingServiceImpl::DidRegister(
250 const content::PushMessagingService::RegisterCallback& callback, 248 const content::PushMessagingService::RegisterCallback& callback,
251 const std::string& registration_id, 249 const std::string& registration_id,
252 GCMClient::Result result) { 250 GCMClient::Result result) {
253 content::PushMessagingStatus status = 251 content::PushRegistrationStatus status =
254 result == GCMClient::SUCCESS 252 result == GCMClient::SUCCESS
255 ? content::PUSH_MESSAGING_STATUS_OK 253 ? content::PUSH_REGISTRATION_STATUS_SUCCESS
256 : content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_SERVICE_ERROR; 254 : content::PUSH_REGISTRATION_STATUS_SERVICE_ERROR;
257 RegisterEnd(callback, registration_id, status); 255 RegisterEnd(callback, registration_id, status);
258 } 256 }
259 257
260 void PushMessagingServiceImpl::DidRequestPermission( 258 void PushMessagingServiceImpl::DidRequestPermission(
261 const PushMessagingApplicationId& application_id, 259 const PushMessagingApplicationId& application_id,
262 const std::string& sender_id, 260 const std::string& sender_id,
263 const content::PushMessagingService::RegisterCallback& register_callback, 261 const content::PushMessagingService::RegisterCallback& register_callback,
264 bool allow) { 262 bool allow) {
265 if (!allow) { 263 if (!allow) {
266 RegisterEnd( 264 RegisterEnd(register_callback,
267 register_callback, 265 std::string(),
268 std::string(), 266 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED);
269 content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_PERMISSION_DENIED);
270 return; 267 return;
271 } 268 }
272 269
273 // The GCMDriver could be NULL if GCMProfileService has been shut down. 270 // The GCMDriver could be NULL if GCMProfileService has been shut down.
274 if (!gcm_profile_service_->driver()) 271 if (!gcm_profile_service_->driver())
275 return; 272 return;
276 273
277 std::vector<std::string> sender_ids(1, sender_id); 274 std::vector<std::string> sender_ids(1, sender_id);
278 275
279 gcm_profile_service_->driver()->Register( 276 gcm_profile_service_->driver()->Register(
280 application_id.ToString(), 277 application_id.ToString(),
281 sender_ids, 278 sender_ids,
282 base::Bind(&PushMessagingServiceImpl::DidRegister, 279 base::Bind(&PushMessagingServiceImpl::DidRegister,
283 weak_factory_.GetWeakPtr(), 280 weak_factory_.GetWeakPtr(),
284 register_callback)); 281 register_callback));
285 } 282 }
286 283
287 // TODO(johnme): Unregister should decrement the pref, and call 284 // TODO(johnme): Unregister should decrement the pref, and call
288 // RemoveAppHandler if the count drops to zero. 285 // RemoveAppHandler if the count drops to zero.
289 286
290 } // namespace gcm 287 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/push_messaging_service_impl.h ('k') | content/browser/browser_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698