| 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, |
| 635 callback); |
| 633 } | 636 } |
| 634 | 637 |
| 635 void PushMessagingServiceImpl::Unregister( | 638 void PushMessagingServiceImpl::Unregister( |
| 636 const std::string& app_id_guid, | 639 const std::string& app_id_guid, |
| 640 const std::string& sender_id, |
| 637 bool retry_on_failure, | 641 bool retry_on_failure, |
| 638 const content::PushMessagingService::UnregisterCallback& callback) { | 642 const content::PushMessagingService::UnregisterCallback& callback) { |
| 639 DCHECK(gcm_profile_service_->driver()); | 643 DCHECK(gcm_profile_service_->driver()); |
| 640 | 644 |
| 641 if (retry_on_failure) { | 645 if (retry_on_failure) { |
| 642 // Delete the mapping for this app id, to guarantee that no messages get | 646 // Delete the mapping for this app id, to guarantee that no messages get |
| 643 // delivered in future (even if unregistration fails). | 647 // delivered in future (even if unregistration fails). |
| 644 // TODO(johnme): Instead of deleting these app ids, store them elsewhere, | 648 // TODO(johnme): Instead of deleting these app ids, store them elsewhere, |
| 645 // and retry unregistration if it fails due to network errors. | 649 // and retry unregistration if it fails due to network errors. |
| 646 PushMessagingApplicationId application_id = | 650 PushMessagingApplicationId application_id = |
| 647 PushMessagingApplicationId::Get(profile_, app_id_guid); | 651 PushMessagingApplicationId::Get(profile_, app_id_guid); |
| 648 if (application_id.IsValid()) | 652 if (application_id.IsValid()) |
| 649 application_id.DeleteFromDisk(profile_); | 653 application_id.DeleteFromDisk(profile_); |
| 650 } | 654 } |
| 651 | 655 |
| 652 gcm_profile_service_->driver()->Unregister( | 656 const auto& unregister_callback = |
| 653 app_id_guid, | |
| 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); |
| 660 #if defined(OS_ANDROID) |
| 661 // On Android the backend is different, and requires the original sender_id. |
| 662 gcm_profile_service_->driver()->UnregisterWithSenderId(app_id_guid, sender_id, |
| 663 unregister_callback); |
| 664 #else |
| 665 gcm_profile_service_->driver()->Unregister(app_id_guid, unregister_callback); |
| 666 #endif |
| 657 } | 667 } |
| 658 | 668 |
| 659 void PushMessagingServiceImpl::DidUnregister( | 669 void PushMessagingServiceImpl::DidUnregister( |
| 660 const std::string& app_id_guid, | 670 const std::string& app_id_guid, |
| 661 bool retry_on_failure, | 671 bool retry_on_failure, |
| 662 const content::PushMessagingService::UnregisterCallback& callback, | 672 const content::PushMessagingService::UnregisterCallback& callback, |
| 663 GCMClient::Result result) { | 673 GCMClient::Result result) { |
| 664 if (result == GCMClient::SUCCESS) { | 674 if (result == GCMClient::SUCCESS) { |
| 665 PushMessagingApplicationId application_id = | 675 PushMessagingApplicationId application_id = |
| 666 PushMessagingApplicationId::Get(profile_, app_id_guid); | 676 PushMessagingApplicationId::Get(profile_, app_id_guid); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { | 711 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { |
| 702 gcm::PushMessagingPermissionContext* permission_context = | 712 gcm::PushMessagingPermissionContext* permission_context = |
| 703 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); | 713 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); |
| 704 DCHECK(permission_context); | 714 DCHECK(permission_context); |
| 705 | 715 |
| 706 return permission_context->GetPermissionStatus(origin, origin) == | 716 return permission_context->GetPermissionStatus(origin, origin) == |
| 707 CONTENT_SETTING_ALLOW; | 717 CONTENT_SETTING_ALLOW; |
| 708 } | 718 } |
| 709 | 719 |
| 710 } // namespace gcm | 720 } // namespace gcm |
| OLD | NEW |