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

Unified Diff: content/child/push_messaging/push_provider.cc

Issue 793403002: Implement WebPushProvider.unregister() in Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mvan_2
Patch Set: browsertests and override fix 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/child/push_messaging/push_provider.cc
diff --git a/content/child/push_messaging/push_provider.cc b/content/child/push_messaging/push_provider.cc
index 6829d3869071f5e368e7405a45fdd5bc71e13c8b..9c8d5323ea5c11bc61388baea7a9d5143e137221 100644
--- a/content/child/push_messaging/push_provider.cc
+++ b/content/child/push_messaging/push_provider.cc
@@ -97,6 +97,21 @@ void PushProvider::getPermissionStatus(
request_id, service_worker_registration_id));
}
+void PushProvider::unregister(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushUnregisterCallbacks* callback) {
Michael van Ouwerkerk 2014/12/12 13:55:41 Please rename callback to callbacks for consistenc
mlamouri (slow - plz ping) 2014/12/15 11:29:36 I prefer not. See below.
+ DCHECK(service_worker_registration);
+ DCHECK(callback);
+
+ int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId());
+ unregister_callbacks_[request_id] = callback;
+
+ int64 service_worker_registration_id =
+ GetServiceWorkerRegistrationId(service_worker_registration);
+ thread_safe_sender_->Send(new PushMessagingHostMsg_Unregister(
+ request_id, service_worker_registration_id));
+}
+
bool PushProvider::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PushProvider, message)
@@ -108,6 +123,8 @@ bool PushProvider::OnMessageReceived(const IPC::Message& message) {
OnGetPermissionStatusSuccess);
IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusError,
OnGetPermissionStatusError);
+ IPC_MESSAGE_HANDLER(PushMessagingMsg_UnregisterResponse,
+ OnUnregisterResponse);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -171,4 +188,15 @@ void PushProvider::OnGetPermissionStatusError(int request_id) {
callbacks->onError();
}
+void PushProvider::OnUnregisterResponse(int request_id, bool response) {
+ const auto& it = unregister_callbacks_.find(request_id);
+ if (it == unregister_callbacks_.end())
+ return;
+
+ scoped_ptr<blink::WebPushUnregisterCallbacks> callback(it->second);
Michael van Ouwerkerk 2014/12/12 13:55:41 s/callback/callbacks/
mlamouri (slow - plz ping) 2014/12/15 11:29:37 As much as we need to keep the silly class name be
+ unregister_callbacks_.erase(it);
+
+ callback->onSuccess(&response);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698