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

Unified Diff: chrome/browser/push_messaging/push_messaging_service_impl.cc

Issue 2697793004: Push API: Validate storage before returning cached subscriptions (Closed)
Patch Set: Comment out PUSH_GETREGISTRATION_STATUS_PUBLIC_KEY_UNAVAILABLE Created 3 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 side-by-side diff with in-line comments
Download patch
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 fbc0c0e932ff2eed5caf85631cf94baaf31b131f..ea433fb0c2c496fbe20b6b8bc218d5b60726976a 100644
--- a/chrome/browser/push_messaging/push_messaging_service_impl.cc
+++ b/chrome/browser/push_messaging/push_messaging_service_impl.cc
@@ -628,39 +628,71 @@ void PushMessagingServiceImpl::DidSubscribeWithEncryptionInfo(
content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE);
}
-// GetEncryptionInfo methods ---------------------------------------------------
+// GetSubscriptionInfo methods
+// ---------------------------------------------------
Peter Beverloo 2017/03/20 23:50:13 nit: dito
johnme 2017/03/30 18:36:38 Done.
-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,
@@ -670,8 +702,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);
}

Powered by Google App Engine
This is Rietveld 408576698