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

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

Issue 793403002: Implement WebPushProvider.unregister() in Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mvan_2
Patch Set: review comments Created 6 years 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 77abfad023fdff0d4f44d4050033ed6c1638b96f..ef255db7e64af60ba7319bb3a9d38c408a5d0ee5 100644
--- a/content/browser/push_messaging/push_messaging_message_filter.cc
+++ b/content/browser/push_messaging/push_messaging_message_filter.cc
@@ -75,6 +75,8 @@ bool PushMessagingMessageFilter::OnMessageReceived(
OnPermissionStatusRequest)
IPC_MESSAGE_HANDLER(PushMessagingHostMsg_GetPermissionStatus,
OnGetPermissionStatus)
+ IPC_MESSAGE_HANDLER(PushMessagingHostMsg_Unregister,
+ OnUnregister)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -385,6 +387,65 @@ void PushMessagingMessageFilter::SendRegisterSuccessOnUI(
SendRegisterSuccess(data, status, push_endpoint, push_registration_id);
}
+void PushMessagingMessageFilter::OnUnregister(
+ int request_id, int64 service_worker_registration_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ ServiceWorkerRegistration* service_worker_registration =
+ service_worker_context_->context()->GetLiveRegistration(
+ service_worker_registration_id);
+ DCHECK(service_worker_registration);
+ if (!service_worker_registration)
+ return;
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&PushMessagingMessageFilter::UnregisterOnUI,
+ this,
+ request_id,
+ service_worker_registration_id,
+ service_worker_registration->pattern().GetOrigin()));
+}
+
+void PushMessagingMessageFilter::UnregisterOnUI(
+ int request_id,
+ int64 service_worker_registration_id,
+ const GURL& requesting_origin) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ if (!service()) {
+ DidUnregister(request_id, PUSH_UNREGISTRATION_UNKNOWN_ERROR);
+ return;
+ }
+
+ service()->Unregister(requesting_origin, service_worker_registration_id,
+ base::Bind(&PushMessagingMessageFilter::DidUnregister,
+ weak_factory_ui_to_ui_.GetWeakPtr(), request_id));
+}
+
+void PushMessagingMessageFilter::DidUnregister(
+ int request_id,
+ PushUnregistrationStatus unregistration_status) {
+ switch (unregistration_status) {
+ case PUSH_UNREGISTRATION_SUCCESS_UNREGISTER:
+ Send(new PushMessagingMsg_UnregisterSuccess(request_id, true));
+ return;
+ case PUSH_UNREGISTRATION_SUCCESS_WAS_UNREGISTERED:
+ Send(new PushMessagingMsg_UnregisterSuccess(request_id, false));
+ return;
+ case PUSH_UNREGISTRATION_NETWORK_ERROR:
+ Send(new PushMessagingMsg_UnregisterError(
+ request_id,
+ blink::WebPushError::ErrorTypeNetwork,
+ "Failed to connect to the push server."));
+ return;
+ case PUSH_UNREGISTRATION_UNKNOWN_ERROR:
+ Send(new PushMessagingMsg_UnregisterError(
+ request_id,
+ blink::WebPushError::ErrorTypeUnknown,
+ "Unexpected error while trying to unregister from the push server."));
+ return;
+ }
+}
+
void PushMessagingMessageFilter::OnGetRegistration(
int request_id,
int64 service_worker_registration_id) {

Powered by Google App Engine
This is Rietveld 408576698