DescriptionPush API: Refactor and fix unsubscribe API
Before this patch, 4 high-level codepaths for unsubscribe had evolved:
a) JS-initiated unsubscribe where PushMessagingMessageFilter's
UnsubscribeHavingGottenIds would skip talking to the
PushMessagingServiceImpl because it could not find the subscription
in the Service Worker database.
b) JS-initiated unsubscribe where PushMessagingMessageFilter did talk to
the PushMessagingServiceImpl, then directly removed the subscription
from the Service Worker database in PushMessagingMessageFilter's
Core::DidUnregisterFromService.
c) Automatic unsubscribe after revoked permission where
PushMessagingServiceImpl::UnsubscribeBecausePermissionRevoked would
call PushMessagingService::ClearPushSubscriptionID to ask the content
layer to remove the subscription from the Service Worker database.
d) Automatic unsubscribe after bad incoming messages where
PushMessagingServiceImpl would never remove the subscription from the
Service Worker database.
This patch unifies them, such that all unsubscription requests go via
PushMessagingServiceImpl::UnsubscribeInternal, and this method is now
responsible for calling PushMessagingService::ClearPushSubscriptionID
in all cases to remove the subscription from the Service Worker
database.
- Eliminating (d) fixes the PUSH_DELIVERY_STATUS_PERMISSION_DENIED case,
where previously we would automatically unsubscribe but never remove
the corresponding subscription from the Service Worker database (this
situation occurs for users that had been hit by crbug.com/633310).
- Eliminating (a) makes us more robust against any cases where a
subscription had been removed from the Service Worker database but not
from the PushMessagingAppIdentifier map (e.g. due to race conditions
where processes are killed partway through writing state to disk).
- This adds UMA logging for the reason that caused unsubscription. This
will be useful in tracking down https://crbug.com/642139
- This adds tests for each of the reasons that can trigger automatic
unsubscription. Previously many of these had no coverage.
- This fixes PushMessagingBrowserTest.UnsubscribeSuccess and
LegacyUnsubscribeSuccess which were failing to test what they intended
to test (instead of calling unsubscribe on old references to
unsubscribed PushSubscriptions and PushSubscriptions from unregistered
Service Workers, they were trying and failing to get a fresh
reference, and considering that failure to mean that unsubscribe had
succeeded); and I added a test where the Service Worker is replaced,
since unregistering a Service Worker isn't actually enough to stop it
controlling the current page.
- This merges the DidUnsubscribeInstanceID and DidUnsubscribe methods in
PushMessagingServiceImpl to avoid duplication of logic.
BUG=646426, 642139, 633310
NOTRY=true
(remaining trybot failures are flake)
Committed: https://crrev.com/92ef94f69eb941d144e31f6cac45c6e3ce8a8720
Cr-Commit-Position: refs/heads/master@{#422330}
Patch Set 1 #
Total comments: 24
Patch Set 2 : Address peter's review comments #
Total comments: 4
Patch Set 3 : Added enum reuse comments #Messages
Total messages: 32 (19 generated)
|