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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/push_messaging/push_provider.h" 5 #include "content/child/push_messaging/push_provider.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 DCHECK(service_worker_registration); 90 DCHECK(service_worker_registration);
91 DCHECK(callbacks); 91 DCHECK(callbacks);
92 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); 92 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId());
93 permission_status_callbacks_[request_id] = callbacks; 93 permission_status_callbacks_[request_id] = callbacks;
94 int64 service_worker_registration_id = 94 int64 service_worker_registration_id =
95 GetServiceWorkerRegistrationId(service_worker_registration); 95 GetServiceWorkerRegistrationId(service_worker_registration);
96 thread_safe_sender_->Send(new PushMessagingHostMsg_GetPermissionStatus( 96 thread_safe_sender_->Send(new PushMessagingHostMsg_GetPermissionStatus(
97 request_id, service_worker_registration_id)); 97 request_id, service_worker_registration_id));
98 } 98 }
99 99
100 void PushProvider::unregister(
101 blink::WebServiceWorkerRegistration* service_worker_registration,
102 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.
103 DCHECK(service_worker_registration);
104 DCHECK(callback);
105
106 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId());
107 unregister_callbacks_[request_id] = callback;
108
109 int64 service_worker_registration_id =
110 GetServiceWorkerRegistrationId(service_worker_registration);
111 thread_safe_sender_->Send(new PushMessagingHostMsg_Unregister(
112 request_id, service_worker_registration_id));
113 }
114
100 bool PushProvider::OnMessageReceived(const IPC::Message& message) { 115 bool PushProvider::OnMessageReceived(const IPC::Message& message) {
101 bool handled = true; 116 bool handled = true;
102 IPC_BEGIN_MESSAGE_MAP(PushProvider, message) 117 IPC_BEGIN_MESSAGE_MAP(PushProvider, message)
103 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromWorkerSuccess, 118 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromWorkerSuccess,
104 OnRegisterFromWorkerSuccess); 119 OnRegisterFromWorkerSuccess);
105 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromWorkerError, 120 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromWorkerError,
106 OnRegisterFromWorkerError); 121 OnRegisterFromWorkerError);
107 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusSuccess, 122 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusSuccess,
108 OnGetPermissionStatusSuccess); 123 OnGetPermissionStatusSuccess);
109 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusError, 124 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusError,
110 OnGetPermissionStatusError); 125 OnGetPermissionStatusError);
126 IPC_MESSAGE_HANDLER(PushMessagingMsg_UnregisterResponse,
127 OnUnregisterResponse);
111 IPC_MESSAGE_UNHANDLED(handled = false) 128 IPC_MESSAGE_UNHANDLED(handled = false)
112 IPC_END_MESSAGE_MAP() 129 IPC_END_MESSAGE_MAP()
113 130
114 return handled; 131 return handled;
115 } 132 }
116 133
117 void PushProvider::OnRegisterFromWorkerSuccess( 134 void PushProvider::OnRegisterFromWorkerSuccess(
118 int request_id, 135 int request_id,
119 const GURL& endpoint, 136 const GURL& endpoint,
120 const std::string& registration_id) { 137 const std::string& registration_id) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 const auto& it = permission_status_callbacks_.find(request_id); 181 const auto& it = permission_status_callbacks_.find(request_id);
165 if (it == permission_status_callbacks_.end()) 182 if (it == permission_status_callbacks_.end())
166 return; 183 return;
167 184
168 scoped_ptr<blink::WebPushPermissionStatusCallbacks> callbacks(it->second); 185 scoped_ptr<blink::WebPushPermissionStatusCallbacks> callbacks(it->second);
169 permission_status_callbacks_.erase(it); 186 permission_status_callbacks_.erase(it);
170 187
171 callbacks->onError(); 188 callbacks->onError();
172 } 189 }
173 190
191 void PushProvider::OnUnregisterResponse(int request_id, bool response) {
192 const auto& it = unregister_callbacks_.find(request_id);
193 if (it == unregister_callbacks_.end())
194 return;
195
196 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
197 unregister_callbacks_.erase(it);
198
199 callback->onSuccess(&response);
200 }
201
174 } // namespace content 202 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698