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

Unified Diff: content/browser/push_messaging/push_messaging_message_filter.cc

Issue 1851423003: Make Web Push use InstanceID tokens instead of GCM registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid4default
Patch Set: Rebase (main conflics in browsertest and PMMF) Created 4 years, 7 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: content/browser/push_messaging/push_messaging_message_filter.cc
diff --git a/content/browser/push_messaging/push_messaging_message_filter.cc b/content/browser/push_messaging/push_messaging_message_filter.cc
index 31ddbb504e839f9b911b5aa2fe063e6634937216..cb40cb08c9e341f0dc21e835e4063ac1e3e07104 100644
--- a/content/browser/push_messaging/push_messaging_message_filter.cc
+++ b/content/browser/push_messaging/push_messaging_message_filter.cc
@@ -36,8 +36,9 @@
namespace content {
// Service Worker database keys. If a registration ID is stored, the stored
-// sender ID must be the one used to subscribe. Unfortunately, this isn't always
-// true of subscriptions previously stored in the database.
+// sender ID must be the one used to register. Unfortunately, this isn't always
+// true of pre-InstanceID registrations previously stored in the database, but
+// fortunately it's less important for their sender ID to be accurate.
const char kPushSenderIdServiceWorkerKey[] = "push_sender_id";
const char kPushRegistrationIdServiceWorkerKey[] = "push_registration_id";
@@ -136,6 +137,7 @@ class PushMessagingMessageFilter::Core {
void GetEncryptionInfoOnUI(
const GURL& origin,
int64_t service_worker_registration_id,
+ const std::string& sender_id,
const PushMessagingService::EncryptionInfoCallback& io_thread_callback);
// Called (directly) from both the UI and IO threads.
@@ -304,7 +306,8 @@ void PushMessagingMessageFilter::DidCheckForExistingRegistration(
BrowserThread::UI, FROM_HERE,
base::Bind(&Core::GetEncryptionInfoOnUI,
base::Unretained(ui_core_.get()), data.requesting_origin,
- data.service_worker_registration_id, callback));
+ data.service_worker_registration_id,
+ data.options.sender_info, callback));
return;
}
// TODO(johnme): The spec allows the register algorithm to reject with an
@@ -365,6 +368,8 @@ void PushMessagingMessageFilter::Core::RegisterOnUI(
PushMessagingService* push_service = service();
if (!push_service) {
if (!is_incognito()) {
+ // This might happen if InstanceIDProfileService::IsInstanceIDEnabled
+ // returns false because the Instance ID kill switch was enabled.
// TODO(johnme): Might be better not to expose the API in this case.
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
@@ -724,45 +729,25 @@ void PushMessagingMessageFilter::OnGetSubscription(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(johnme): Validate arguments?
service_worker_context_->GetRegistrationUserData(
- service_worker_registration_id, {kPushSenderIdServiceWorkerKey},
- base::Bind(&PushMessagingMessageFilter::DidGetSenderInfo,
- weak_factory_io_to_io_.GetWeakPtr(), request_id,
- service_worker_registration_id));
-}
-
-void PushMessagingMessageFilter::DidGetSenderInfo(
- int request_id,
- int64_t service_worker_registration_id,
- const std::vector<std::string>& sender_info,
- ServiceWorkerStatusCode status) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (status != SERVICE_WORKER_OK || sender_info.size() != 1) {
- DidGetSubscription(request_id, service_worker_registration_id,
- false /* uses_standard_protocol */,
- std::vector<std::string>() /* push_subscription_id */,
- status);
- return;
- }
-
- const bool uses_standard_protocol = IsApplicationServerKey(sender_info[0]);
- service_worker_context_->GetRegistrationUserData(
- service_worker_registration_id, {kPushRegistrationIdServiceWorkerKey},
+ service_worker_registration_id,
+ {kPushRegistrationIdServiceWorkerKey, kPushSenderIdServiceWorkerKey},
base::Bind(&PushMessagingMessageFilter::DidGetSubscription,
weak_factory_io_to_io_.GetWeakPtr(), request_id,
- service_worker_registration_id, uses_standard_protocol));
+ service_worker_registration_id));
}
void PushMessagingMessageFilter::DidGetSubscription(
int request_id,
int64_t service_worker_registration_id,
- bool uses_standard_protocol,
- const std::vector<std::string>& push_subscription_id,
+ const std::vector<std::string>& push_subscription_id_and_sender_info,
Peter Beverloo 2016/06/02 15:53:18 nit: subscription_info?
johnme 2016/06/07 14:16:43 I like that you can tell exactly what e.g. push_su
ServiceWorkerStatusCode service_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
PushGetRegistrationStatus get_status =
PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR;
switch (service_worker_status) {
case SERVICE_WORKER_OK: {
+ DCHECK_EQ(2u, push_subscription_id_and_sender_info.size());
+
if (!service_available_) {
// Return not found in incognito mode, so websites can't detect it.
get_status =
@@ -775,11 +760,12 @@ void PushMessagingMessageFilter::DidGetSubscription(
ServiceWorkerRegistration* registration =
service_worker_context_->GetLiveRegistration(
service_worker_registration_id);
-
const GURL origin = registration->pattern().GetOrigin();
- DCHECK_EQ(1u, push_subscription_id.size());
- const GURL endpoint =
- CreateEndpoint(uses_standard_protocol, push_subscription_id[0]);
+
+ const bool uses_standard_protocol =
+ IsApplicationServerKey(push_subscription_id_and_sender_info[1]);
+ const GURL endpoint = CreateEndpoint(
+ uses_standard_protocol, push_subscription_id_and_sender_info[0]);
auto callback =
base::Bind(&PushMessagingMessageFilter::DidGetSubscriptionKeys,
@@ -789,7 +775,8 @@ void PushMessagingMessageFilter::DidGetSubscription(
BrowserThread::UI, FROM_HERE,
base::Bind(&Core::GetEncryptionInfoOnUI,
base::Unretained(ui_core_.get()), origin,
- service_worker_registration_id, callback));
+ service_worker_registration_id,
+ push_subscription_id_and_sender_info[1], callback));
return;
}
@@ -909,12 +896,13 @@ void PushMessagingMessageFilter::Core::GetPermissionStatusOnUI(
void PushMessagingMessageFilter::Core::GetEncryptionInfoOnUI(
const GURL& origin,
int64_t service_worker_registration_id,
+ const std::string& sender_id,
const PushMessagingService::EncryptionInfoCallback& io_thread_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
PushMessagingService* push_service = service();
if (push_service) {
push_service->GetEncryptionInfo(
- origin, service_worker_registration_id,
+ origin, service_worker_registration_id, sender_id,
base::Bind(&ForwardEncryptionInfoToIOThreadProxy, io_thread_callback));
return;
}

Powered by Google App Engine
This is Rietveld 408576698