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

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

Issue 914693002: Push API: Fix unsubscribing from GCM on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment nits I missed earlier Created 5 years, 10 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 <bitset> 7 #include <bitset>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 191
192 // Drop messages whose application is is invalid. 192 // Drop messages whose application is is invalid.
193 if (!application_id.IsValid()) { 193 if (!application_id.IsValid()) {
194 DeliverMessageCallback(application_id, message, 194 DeliverMessageCallback(application_id, message,
195 content::PUSH_DELIVERY_STATUS_INVALID_MESSAGE); 195 content::PUSH_DELIVERY_STATUS_INVALID_MESSAGE);
196 return; 196 return;
197 } 197 }
198 198
199 // |origin| may have lost push permission. Unregister and drop this message. 199 // |origin| may have lost push permission. Unregister and drop this message.
200 if (!HasPermission(application_id.origin)) { 200 if (!HasPermission(application_id.origin)) {
201 Unregister(application_id, UnregisterCallback()); 201 Unregister(application_id, message.sender_id, UnregisterCallback());
202 return; 202 return;
203 } 203 }
204 204
205 std::string data; 205 std::string data;
206 206
207 // TODO(peter): Message payloads are disabled pending mandatory encryption. 207 // TODO(peter): Message payloads are disabled pending mandatory encryption.
208 // https://crbug.com/449184 208 // https://crbug.com/449184
209 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 209 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
210 switches::kEnablePushMessagePayload)) { 210 switches::kEnablePushMessagePayload)) {
211 GCMClient::MessageData::const_iterator it = message.data.find("data"); 211 GCMClient::MessageData::const_iterator it = message.data.find("data");
(...skipping 29 matching lines...) Expand all
241 // Worker JS, even if the website's event handler failed (to prevent sites 241 // Worker JS, even if the website's event handler failed (to prevent sites
242 // deliberately failing in order to avoid having to show notifications). 242 // deliberately failing in order to avoid having to show notifications).
243 case content::PUSH_DELIVERY_STATUS_SUCCESS: 243 case content::PUSH_DELIVERY_STATUS_SUCCESS:
244 case content::PUSH_DELIVERY_STATUS_EVENT_WAITUNTIL_REJECTED: 244 case content::PUSH_DELIVERY_STATUS_EVENT_WAITUNTIL_REJECTED:
245 RequireUserVisibleUX(application_id); 245 RequireUserVisibleUX(application_id);
246 break; 246 break;
247 case content::PUSH_DELIVERY_STATUS_INVALID_MESSAGE: 247 case content::PUSH_DELIVERY_STATUS_INVALID_MESSAGE:
248 case content::PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR: 248 case content::PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR:
249 break; 249 break;
250 case content::PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER: 250 case content::PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER:
251 Unregister(application_id, UnregisterCallback()); 251 Unregister(application_id, message.sender_id, UnregisterCallback());
252 break; 252 break;
253 } 253 }
254 } 254 }
255 255
256 void PushMessagingServiceImpl::RequireUserVisibleUX( 256 void PushMessagingServiceImpl::RequireUserVisibleUX(
257 const PushMessagingApplicationId& application_id) { 257 const PushMessagingApplicationId& application_id) {
258 #if defined(ENABLE_NOTIFICATIONS) 258 #if defined(ENABLE_NOTIFICATIONS)
259 // TODO(johnme): Relax this heuristic slightly. 259 // TODO(johnme): Relax this heuristic slightly.
260 PlatformNotificationServiceImpl* notification_service = 260 PlatformNotificationServiceImpl* notification_service =
261 PlatformNotificationServiceImpl::GetInstance(); 261 PlatformNotificationServiceImpl::GetInstance();
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 application_id.ToString(), 574 application_id.ToString(),
575 sender_ids, 575 sender_ids,
576 base::Bind(&PushMessagingServiceImpl::DidRegister, 576 base::Bind(&PushMessagingServiceImpl::DidRegister,
577 weak_factory_.GetWeakPtr(), 577 weak_factory_.GetWeakPtr(),
578 register_callback)); 578 register_callback));
579 } 579 }
580 580
581 void PushMessagingServiceImpl::Unregister( 581 void PushMessagingServiceImpl::Unregister(
582 const GURL& requesting_origin, 582 const GURL& requesting_origin,
583 int64 service_worker_registration_id, 583 int64 service_worker_registration_id,
584 const std::string& sender_id,
584 const content::PushMessagingService::UnregisterCallback& callback) { 585 const content::PushMessagingService::UnregisterCallback& callback) {
585 DCHECK(gcm_profile_service_->driver()); 586 DCHECK(gcm_profile_service_->driver());
586 587
587 PushMessagingApplicationId application_id = PushMessagingApplicationId( 588 PushMessagingApplicationId application_id = PushMessagingApplicationId(
588 requesting_origin, service_worker_registration_id); 589 requesting_origin, service_worker_registration_id);
589 DCHECK(application_id.IsValid()); 590 DCHECK(application_id.IsValid());
590 591
591 Unregister(application_id, callback); 592 Unregister(application_id, sender_id, callback);
592 } 593 }
593 594
594 void PushMessagingServiceImpl::Unregister( 595 void PushMessagingServiceImpl::Unregister(
595 const PushMessagingApplicationId& application_id, 596 const PushMessagingApplicationId& application_id,
597 const std::string& sender_id,
596 const content::PushMessagingService::UnregisterCallback& callback) { 598 const content::PushMessagingService::UnregisterCallback& callback) {
597 DCHECK(gcm_profile_service_->driver()); 599 DCHECK(gcm_profile_service_->driver());
598 600
599 gcm_profile_service_->driver()->Unregister( 601 gcm_profile_service_->driver()->Unregister(
600 application_id.ToString(), 602 application_id.ToString(),
603 std::vector<std::string>(1, sender_id),
601 base::Bind(&PushMessagingServiceImpl::DidUnregister, 604 base::Bind(&PushMessagingServiceImpl::DidUnregister,
602 weak_factory_.GetWeakPtr(), callback)); 605 weak_factory_.GetWeakPtr(), callback));
603 } 606 }
604 607
605 void PushMessagingServiceImpl::DidUnregister( 608 void PushMessagingServiceImpl::DidUnregister(
606 const content::PushMessagingService::UnregisterCallback& callback, 609 const content::PushMessagingService::UnregisterCallback& callback,
607 GCMClient::Result result) { 610 GCMClient::Result result) {
608 // Internal calls pass a null callback. 611 // Internal calls pass a null callback.
609 if (!callback.is_null()) { 612 if (!callback.is_null()) {
610 switch (result) { 613 switch (result) {
(...skipping 25 matching lines...) Expand all
636 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { 639 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) {
637 gcm::PushMessagingPermissionContext* permission_context = 640 gcm::PushMessagingPermissionContext* permission_context =
638 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); 641 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_);
639 DCHECK(permission_context); 642 DCHECK(permission_context);
640 643
641 return permission_context->GetPermissionStatus(origin, origin) == 644 return permission_context->GetPermissionStatus(origin, origin) ==
642 CONTENT_SETTING_ALLOW; 645 CONTENT_SETTING_ALLOW;
643 } 646 }
644 647
645 } // namespace gcm 648 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698