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

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: Now compiles and passes tests (and uses CHECK_EQ) 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 application_id.ToString(), 573 application_id.ToString(),
574 sender_ids, 574 sender_ids,
575 base::Bind(&PushMessagingServiceImpl::DidRegister, 575 base::Bind(&PushMessagingServiceImpl::DidRegister,
576 weak_factory_.GetWeakPtr(), 576 weak_factory_.GetWeakPtr(),
577 register_callback)); 577 register_callback));
578 } 578 }
579 579
580 void PushMessagingServiceImpl::Unregister( 580 void PushMessagingServiceImpl::Unregister(
581 const GURL& requesting_origin, 581 const GURL& requesting_origin,
582 int64 service_worker_registration_id, 582 int64 service_worker_registration_id,
583 const std::string& sender_id,
583 const content::PushMessagingService::UnregisterCallback& callback) { 584 const content::PushMessagingService::UnregisterCallback& callback) {
584 DCHECK(gcm_profile_service_->driver()); 585 DCHECK(gcm_profile_service_->driver());
585 586
586 PushMessagingApplicationId application_id = PushMessagingApplicationId( 587 PushMessagingApplicationId application_id = PushMessagingApplicationId(
587 requesting_origin, service_worker_registration_id); 588 requesting_origin, service_worker_registration_id);
588 DCHECK(application_id.IsValid()); 589 DCHECK(application_id.IsValid());
589 590
590 Unregister(application_id, callback); 591 Unregister(application_id, sender_id, callback);
591 } 592 }
592 593
593 void PushMessagingServiceImpl::Unregister( 594 void PushMessagingServiceImpl::Unregister(
594 const PushMessagingApplicationId& application_id, 595 const PushMessagingApplicationId& application_id,
596 const std::string& sender_id,
595 const content::PushMessagingService::UnregisterCallback& callback) { 597 const content::PushMessagingService::UnregisterCallback& callback) {
596 DCHECK(gcm_profile_service_->driver()); 598 DCHECK(gcm_profile_service_->driver());
597 599
598 gcm_profile_service_->driver()->Unregister( 600 gcm_profile_service_->driver()->Unregister(
599 application_id.ToString(), 601 application_id.ToString(),
602 std::vector<std::string>(1, sender_id),
600 base::Bind(&PushMessagingServiceImpl::DidUnregister, 603 base::Bind(&PushMessagingServiceImpl::DidUnregister,
601 weak_factory_.GetWeakPtr(), callback)); 604 weak_factory_.GetWeakPtr(), callback));
602 } 605 }
603 606
604 void PushMessagingServiceImpl::DidUnregister( 607 void PushMessagingServiceImpl::DidUnregister(
605 const content::PushMessagingService::UnregisterCallback& callback, 608 const content::PushMessagingService::UnregisterCallback& callback,
606 GCMClient::Result result) { 609 GCMClient::Result result) {
607 // Internal calls pass a null callback. 610 // Internal calls pass a null callback.
608 if (!callback.is_null()) { 611 if (!callback.is_null()) {
609 switch (result) { 612 switch (result) {
(...skipping 25 matching lines...) Expand all
635 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { 638 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) {
636 gcm::PushMessagingPermissionContext* permission_context = 639 gcm::PushMessagingPermissionContext* permission_context =
637 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); 640 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_);
638 DCHECK(permission_context); 641 DCHECK(permission_context);
639 642
640 return permission_context->GetPermissionStatus(origin, origin) == 643 return permission_context->GetPermissionStatus(origin, origin) ==
641 CONTENT_SETTING_ALLOW; 644 CONTENT_SETTING_ALLOW;
642 } 645 }
643 646
644 } // namespace gcm 647 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698