OLD | NEW |
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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 case content::PUSH_DELIVERY_STATUS_SUCCESS: | 255 case content::PUSH_DELIVERY_STATUS_SUCCESS: |
256 case content::PUSH_DELIVERY_STATUS_EVENT_WAITUNTIL_REJECTED: | 256 case content::PUSH_DELIVERY_STATUS_EVENT_WAITUNTIL_REJECTED: |
257 RequireUserVisibleUX(requesting_origin, service_worker_registration_id); | 257 RequireUserVisibleUX(requesting_origin, service_worker_registration_id); |
258 break; | 258 break; |
259 case content::PUSH_DELIVERY_STATUS_INVALID_MESSAGE: | 259 case content::PUSH_DELIVERY_STATUS_INVALID_MESSAGE: |
260 case content::PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR: | 260 case content::PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR: |
261 break; | 261 break; |
262 case content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID: | 262 case content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID: |
263 case content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED: | 263 case content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED: |
264 case content::PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER: | 264 case content::PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER: |
265 Unregister(app_id_guid, true /*retry_on_failure*/, UnregisterCallback()); | 265 Unregister(app_id_guid, message.sender_id, true /* retry_on_failure */, |
| 266 UnregisterCallback()); |
266 break; | 267 break; |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 void PushMessagingServiceImpl::RequireUserVisibleUX( | 271 void PushMessagingServiceImpl::RequireUserVisibleUX( |
271 const GURL& requesting_origin, int64 service_worker_registration_id) { | 272 const GURL& requesting_origin, int64 service_worker_registration_id) { |
272 #if defined(ENABLE_NOTIFICATIONS) | 273 #if defined(ENABLE_NOTIFICATIONS) |
273 // TODO(johnme): Relax this heuristic slightly. | 274 // TODO(johnme): Relax this heuristic slightly. |
274 PlatformNotificationServiceImpl* notification_service = | 275 PlatformNotificationServiceImpl* notification_service = |
275 PlatformNotificationServiceImpl::GetInstance(); | 276 PlatformNotificationServiceImpl::GetInstance(); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 application_id.app_id_guid, | 611 application_id.app_id_guid, |
611 sender_ids, | 612 sender_ids, |
612 base::Bind(&PushMessagingServiceImpl::DidRegister, | 613 base::Bind(&PushMessagingServiceImpl::DidRegister, |
613 weak_factory_.GetWeakPtr(), | 614 weak_factory_.GetWeakPtr(), |
614 application_id, register_callback)); | 615 application_id, register_callback)); |
615 } | 616 } |
616 | 617 |
617 void PushMessagingServiceImpl::Unregister( | 618 void PushMessagingServiceImpl::Unregister( |
618 const GURL& requesting_origin, | 619 const GURL& requesting_origin, |
619 int64 service_worker_registration_id, | 620 int64 service_worker_registration_id, |
| 621 const std::string& sender_id, |
620 bool retry_on_failure, | 622 bool retry_on_failure, |
621 const content::PushMessagingService::UnregisterCallback& callback) { | 623 const content::PushMessagingService::UnregisterCallback& callback) { |
622 DCHECK(gcm_profile_service_->driver()); | 624 DCHECK(gcm_profile_service_->driver()); |
623 | 625 |
624 PushMessagingApplicationId application_id = PushMessagingApplicationId::Get( | 626 PushMessagingApplicationId application_id = PushMessagingApplicationId::Get( |
625 profile_, requesting_origin, service_worker_registration_id); | 627 profile_, requesting_origin, service_worker_registration_id); |
626 if (!application_id.IsValid()) { | 628 if (!application_id.IsValid()) { |
627 callback.Run( | 629 callback.Run( |
628 content::PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED); | 630 content::PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED); |
629 return; | 631 return; |
630 } | 632 } |
631 | 633 |
632 Unregister(application_id.app_id_guid, retry_on_failure, callback); | 634 Unregister(application_id.app_id_guid, sender_id, retry_on_failure, callback); |
633 } | 635 } |
634 | 636 |
635 void PushMessagingServiceImpl::Unregister( | 637 void PushMessagingServiceImpl::Unregister( |
636 const std::string& app_id_guid, | 638 const std::string& app_id_guid, |
| 639 const std::string& sender_id, |
637 bool retry_on_failure, | 640 bool retry_on_failure, |
638 const content::PushMessagingService::UnregisterCallback& callback) { | 641 const content::PushMessagingService::UnregisterCallback& callback) { |
639 DCHECK(gcm_profile_service_->driver()); | 642 DCHECK(gcm_profile_service_->driver()); |
640 | 643 |
641 if (retry_on_failure) { | 644 if (retry_on_failure) { |
642 // Delete the mapping for this app id, to guarantee that no messages get | 645 // Delete the mapping for this app id, to guarantee that no messages get |
643 // delivered in future (even if unregistration fails). | 646 // delivered in future (even if unregistration fails). |
644 // TODO(johnme): Instead of deleting these app ids, store them elsewhere, | 647 // TODO(johnme): Instead of deleting these app ids, store them elsewhere, |
645 // and retry unregistration if it fails due to network errors. | 648 // and retry unregistration if it fails due to network errors. |
646 PushMessagingApplicationId application_id = | 649 PushMessagingApplicationId application_id = |
647 PushMessagingApplicationId::Get(profile_, app_id_guid); | 650 PushMessagingApplicationId::Get(profile_, app_id_guid); |
648 if (application_id.IsValid()) | 651 if (application_id.IsValid()) |
649 application_id.DeleteFromDisk(profile_); | 652 application_id.DeleteFromDisk(profile_); |
650 } | 653 } |
651 | 654 |
652 gcm_profile_service_->driver()->Unregister( | 655 gcm_profile_service_->driver()->UnregisterWithSenderId( |
653 app_id_guid, | 656 app_id_guid, sender_id, |
654 base::Bind(&PushMessagingServiceImpl::DidUnregister, | 657 base::Bind(&PushMessagingServiceImpl::DidUnregister, |
655 weak_factory_.GetWeakPtr(), | 658 weak_factory_.GetWeakPtr(), |
656 app_id_guid, retry_on_failure, callback)); | 659 app_id_guid, retry_on_failure, callback)); |
657 } | 660 } |
658 | 661 |
659 void PushMessagingServiceImpl::DidUnregister( | 662 void PushMessagingServiceImpl::DidUnregister( |
660 const std::string& app_id_guid, | 663 const std::string& app_id_guid, |
661 bool retry_on_failure, | 664 bool retry_on_failure, |
662 const content::PushMessagingService::UnregisterCallback& callback, | 665 const content::PushMessagingService::UnregisterCallback& callback, |
663 GCMClient::Result result) { | 666 GCMClient::Result result) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { | 704 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { |
702 gcm::PushMessagingPermissionContext* permission_context = | 705 gcm::PushMessagingPermissionContext* permission_context = |
703 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); | 706 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); |
704 DCHECK(permission_context); | 707 DCHECK(permission_context); |
705 | 708 |
706 return permission_context->GetPermissionStatus(origin, origin) == | 709 return permission_context->GetPermissionStatus(origin, origin) == |
707 CONTENT_SETTING_ALLOW; | 710 CONTENT_SETTING_ALLOW; |
708 } | 711 } |
709 | 712 |
710 } // namespace gcm | 713 } // namespace gcm |
OLD | NEW |