| 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/push_messaging/push_messaging_service_impl.h" | 5 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
| 10 #include "base/base64url.h" | 10 #include "base/base64url.h" |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 app_identifier.PersistToPrefs(profile_); | 625 app_identifier.PersistToPrefs(profile_); |
| 626 | 626 |
| 627 IncreasePushSubscriptionCount(1, false /* is_pending */); | 627 IncreasePushSubscriptionCount(1, false /* is_pending */); |
| 628 | 628 |
| 629 SubscribeEnd(callback, subscription_id, | 629 SubscribeEnd(callback, subscription_id, |
| 630 std::vector<uint8_t>(p256dh.begin(), p256dh.end()), | 630 std::vector<uint8_t>(p256dh.begin(), p256dh.end()), |
| 631 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()), | 631 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()), |
| 632 content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE); | 632 content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE); |
| 633 } | 633 } |
| 634 | 634 |
| 635 // GetEncryptionInfo methods --------------------------------------------------- | 635 // GetSubscriptionInfo methods ------------------------------------------------- |
| 636 | 636 |
| 637 void PushMessagingServiceImpl::GetEncryptionInfo( | 637 void PushMessagingServiceImpl::GetSubscriptionInfo( |
| 638 const GURL& origin, | 638 const GURL& origin, |
| 639 int64_t service_worker_registration_id, | 639 int64_t service_worker_registration_id, |
| 640 const std::string& sender_id, | 640 const std::string& sender_id, |
| 641 const PushMessagingService::EncryptionInfoCallback& callback) { | 641 const std::string& subscription_id, |
| 642 const SubscriptionInfoCallback& callback) { |
| 642 PushMessagingAppIdentifier app_identifier = | 643 PushMessagingAppIdentifier app_identifier = |
| 643 PushMessagingAppIdentifier::FindByServiceWorker( | 644 PushMessagingAppIdentifier::FindByServiceWorker( |
| 644 profile_, origin, service_worker_registration_id); | 645 profile_, origin, service_worker_registration_id); |
| 645 | 646 |
| 646 DCHECK(!app_identifier.is_null()); | 647 if (app_identifier.is_null()) { |
| 648 callback.Run(false /* is_valid */, std::vector<uint8_t>() /* p256dh */, |
| 649 std::vector<uint8_t>() /* auth */); |
| 650 return; |
| 651 } |
| 652 |
| 653 const std::string& app_id = app_identifier.app_id(); |
| 654 base::Callback<void(bool)> validate_cb = |
| 655 base::Bind(&PushMessagingServiceImpl::DidValidateSubscription, |
| 656 weak_factory_.GetWeakPtr(), app_id, sender_id, callback); |
| 657 |
| 658 if (PushMessagingAppIdentifier::UseInstanceID(app_id)) { |
| 659 GetInstanceIDDriver()->GetInstanceID(app_id)->ValidateToken( |
| 660 NormalizeSenderInfo(sender_id), kGCMScope, subscription_id, |
| 661 validate_cb); |
| 662 } else { |
| 663 GetGCMDriver()->ValidateRegistration( |
| 664 app_id, {NormalizeSenderInfo(sender_id)}, subscription_id, validate_cb); |
| 665 } |
| 666 } |
| 667 |
| 668 void PushMessagingServiceImpl::DidValidateSubscription( |
| 669 const std::string& app_id, |
| 670 const std::string& sender_id, |
| 671 const SubscriptionInfoCallback& callback, |
| 672 bool is_valid) { |
| 673 if (!is_valid) { |
| 674 callback.Run(false /* is_valid */, std::vector<uint8_t>() /* p256dh */, |
| 675 std::vector<uint8_t>() /* auth */); |
| 676 return; |
| 677 } |
| 647 | 678 |
| 648 GetEncryptionInfoForAppId( | 679 GetEncryptionInfoForAppId( |
| 649 app_identifier.app_id(), sender_id, | 680 app_id, sender_id, |
| 650 base::Bind(&PushMessagingServiceImpl::DidGetEncryptionInfo, | 681 base::Bind(&PushMessagingServiceImpl::DidGetEncryptionInfo, |
| 651 weak_factory_.GetWeakPtr(), callback)); | 682 weak_factory_.GetWeakPtr(), callback)); |
| 652 } | 683 } |
| 653 | 684 |
| 654 void PushMessagingServiceImpl::DidGetEncryptionInfo( | 685 void PushMessagingServiceImpl::DidGetEncryptionInfo( |
| 655 const PushMessagingService::EncryptionInfoCallback& callback, | 686 const SubscriptionInfoCallback& callback, |
| 656 const std::string& p256dh, | 687 const std::string& p256dh, |
| 657 const std::string& auth_secret) const { | 688 const std::string& auth_secret) const { |
| 658 // I/O errors might prevent the GCM Driver from retrieving a key-pair. | 689 // I/O errors might prevent the GCM Driver from retrieving a key-pair. |
| 659 const bool success = !p256dh.empty(); | 690 bool is_valid = !p256dh.empty(); |
| 660 | 691 callback.Run(is_valid, std::vector<uint8_t>(p256dh.begin(), p256dh.end()), |
| 661 callback.Run(success, std::vector<uint8_t>(p256dh.begin(), p256dh.end()), | |
| 662 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end())); | 692 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end())); |
| 663 } | 693 } |
| 664 | 694 |
| 665 // Unsubscribe methods --------------------------------------------------------- | 695 // Unsubscribe methods --------------------------------------------------------- |
| 666 | 696 |
| 667 void PushMessagingServiceImpl::Unsubscribe( | 697 void PushMessagingServiceImpl::Unsubscribe( |
| 698 content::PushUnregistrationReason reason, |
| 668 const GURL& requesting_origin, | 699 const GURL& requesting_origin, |
| 669 int64_t service_worker_registration_id, | 700 int64_t service_worker_registration_id, |
| 670 const std::string& sender_id, | 701 const std::string& sender_id, |
| 671 const UnregisterCallback& callback) { | 702 const UnregisterCallback& callback) { |
| 672 PushMessagingAppIdentifier app_identifier = | 703 PushMessagingAppIdentifier app_identifier = |
| 673 PushMessagingAppIdentifier::FindByServiceWorker( | 704 PushMessagingAppIdentifier::FindByServiceWorker( |
| 674 profile_, requesting_origin, service_worker_registration_id); | 705 profile_, requesting_origin, service_worker_registration_id); |
| 675 | 706 |
| 676 UnsubscribeInternal( | 707 UnsubscribeInternal( |
| 677 content::PUSH_UNREGISTRATION_REASON_JAVASCRIPT_API, requesting_origin, | 708 reason, requesting_origin, service_worker_registration_id, |
| 678 service_worker_registration_id, | |
| 679 app_identifier.is_null() ? std::string() : app_identifier.app_id(), | 709 app_identifier.is_null() ? std::string() : app_identifier.app_id(), |
| 680 sender_id, callback); | 710 sender_id, callback); |
| 681 } | 711 } |
| 682 | 712 |
| 683 void PushMessagingServiceImpl::UnsubscribeInternal( | 713 void PushMessagingServiceImpl::UnsubscribeInternal( |
| 684 content::PushUnregistrationReason reason, | 714 content::PushUnregistrationReason reason, |
| 685 const GURL& origin, | 715 const GURL& origin, |
| 686 int64_t service_worker_registration_id, | 716 int64_t service_worker_registration_id, |
| 687 const std::string& app_id, | 717 const std::string& app_id, |
| 688 const std::string& sender_id, | 718 const std::string& sender_id, |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 } | 1019 } |
| 990 | 1020 |
| 991 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() | 1021 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() |
| 992 const { | 1022 const { |
| 993 instance_id::InstanceIDProfileService* instance_id_profile_service = | 1023 instance_id::InstanceIDProfileService* instance_id_profile_service = |
| 994 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); | 1024 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); |
| 995 CHECK(instance_id_profile_service); | 1025 CHECK(instance_id_profile_service); |
| 996 CHECK(instance_id_profile_service->driver()); | 1026 CHECK(instance_id_profile_service->driver()); |
| 997 return instance_id_profile_service->driver(); | 1027 return instance_id_profile_service->driver(); |
| 998 } | 1028 } |
| OLD | NEW |