| Index: chrome/browser/push_messaging/push_messaging_service_impl.cc
|
| diff --git a/chrome/browser/push_messaging/push_messaging_service_impl.cc b/chrome/browser/push_messaging/push_messaging_service_impl.cc
|
| index 9144cd5376fb74d6b36dcc1dd70379aff5c01690..b6e881f9c06bf665f3f9fa0ef5496c2100d95f7f 100644
|
| --- a/chrome/browser/push_messaging/push_messaging_service_impl.cc
|
| +++ b/chrome/browser/push_messaging/push_messaging_service_impl.cc
|
| @@ -632,39 +632,70 @@ void PushMessagingServiceImpl::DidSubscribeWithEncryptionInfo(
|
| content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE);
|
| }
|
|
|
| -// GetEncryptionInfo methods ---------------------------------------------------
|
| +// GetSubscriptionInfo methods -------------------------------------------------
|
|
|
| -void PushMessagingServiceImpl::GetEncryptionInfo(
|
| +void PushMessagingServiceImpl::GetSubscriptionInfo(
|
| const GURL& origin,
|
| int64_t service_worker_registration_id,
|
| const std::string& sender_id,
|
| - const PushMessagingService::EncryptionInfoCallback& callback) {
|
| + const std::string& subscription_id,
|
| + const SubscriptionInfoCallback& callback) {
|
| PushMessagingAppIdentifier app_identifier =
|
| PushMessagingAppIdentifier::FindByServiceWorker(
|
| profile_, origin, service_worker_registration_id);
|
|
|
| - DCHECK(!app_identifier.is_null());
|
| + if (app_identifier.is_null()) {
|
| + callback.Run(false /* is_valid */, std::vector<uint8_t>() /* p256dh */,
|
| + std::vector<uint8_t>() /* auth */);
|
| + return;
|
| + }
|
| +
|
| + const std::string& app_id = app_identifier.app_id();
|
| + base::Callback<void(bool)> validate_cb =
|
| + base::Bind(&PushMessagingServiceImpl::DidValidateSubscription,
|
| + weak_factory_.GetWeakPtr(), app_id, sender_id, callback);
|
| +
|
| + if (PushMessagingAppIdentifier::UseInstanceID(app_id)) {
|
| + GetInstanceIDDriver()->GetInstanceID(app_id)->ValidateToken(
|
| + NormalizeSenderInfo(sender_id), kGCMScope, subscription_id,
|
| + validate_cb);
|
| + } else {
|
| + GetGCMDriver()->ValidateRegistration(
|
| + app_id, {NormalizeSenderInfo(sender_id)}, subscription_id, validate_cb);
|
| + }
|
| +}
|
| +
|
| +void PushMessagingServiceImpl::DidValidateSubscription(
|
| + const std::string& app_id,
|
| + const std::string& sender_id,
|
| + const SubscriptionInfoCallback& callback,
|
| + bool is_valid) {
|
| + if (!is_valid) {
|
| + callback.Run(false /* is_valid */, std::vector<uint8_t>() /* p256dh */,
|
| + std::vector<uint8_t>() /* auth */);
|
| + return;
|
| + }
|
|
|
| GetEncryptionInfoForAppId(
|
| - app_identifier.app_id(), sender_id,
|
| + app_id, sender_id,
|
| base::Bind(&PushMessagingServiceImpl::DidGetEncryptionInfo,
|
| weak_factory_.GetWeakPtr(), callback));
|
| }
|
|
|
| void PushMessagingServiceImpl::DidGetEncryptionInfo(
|
| - const PushMessagingService::EncryptionInfoCallback& callback,
|
| + const SubscriptionInfoCallback& callback,
|
| const std::string& p256dh,
|
| const std::string& auth_secret) const {
|
| // I/O errors might prevent the GCM Driver from retrieving a key-pair.
|
| - const bool success = !p256dh.empty();
|
| -
|
| - callback.Run(success, std::vector<uint8_t>(p256dh.begin(), p256dh.end()),
|
| + bool is_valid = !p256dh.empty();
|
| + callback.Run(is_valid, std::vector<uint8_t>(p256dh.begin(), p256dh.end()),
|
| std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()));
|
| }
|
|
|
| // Unsubscribe methods ---------------------------------------------------------
|
|
|
| void PushMessagingServiceImpl::Unsubscribe(
|
| + content::PushUnregistrationReason reason,
|
| const GURL& requesting_origin,
|
| int64_t service_worker_registration_id,
|
| const std::string& sender_id,
|
| @@ -674,8 +705,7 @@ void PushMessagingServiceImpl::Unsubscribe(
|
| profile_, requesting_origin, service_worker_registration_id);
|
|
|
| UnsubscribeInternal(
|
| - content::PUSH_UNREGISTRATION_REASON_JAVASCRIPT_API, requesting_origin,
|
| - service_worker_registration_id,
|
| + reason, requesting_origin, service_worker_registration_id,
|
| app_identifier.is_null() ? std::string() : app_identifier.app_id(),
|
| sender_id, callback);
|
| }
|
|
|