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

Side by Side Diff: content/child/push_messaging/push_provider.cc

Issue 1134733006: Push API: use (un)subscription instead of (un)registration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed pre-submit warning Created 5 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 unified diff | Download patch
« no previous file with comments | « content/child/push_messaging/push_provider.h ('k') | content/common/push_messaging_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 void PushProvider::subscribe( 68 void PushProvider::subscribe(
69 blink::WebServiceWorkerRegistration* service_worker_registration, 69 blink::WebServiceWorkerRegistration* service_worker_registration,
70 const blink::WebPushSubscriptionOptions& options, 70 const blink::WebPushSubscriptionOptions& options,
71 blink::WebPushSubscriptionCallbacks* callbacks) { 71 blink::WebPushSubscriptionCallbacks* callbacks) {
72 DCHECK(service_worker_registration); 72 DCHECK(service_worker_registration);
73 DCHECK(callbacks); 73 DCHECK(callbacks);
74 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); 74 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId());
75 subscription_callbacks_.AddWithID(callbacks, request_id); 75 subscription_callbacks_.AddWithID(callbacks, request_id);
76 int64 service_worker_registration_id = 76 int64 service_worker_registration_id =
77 GetServiceWorkerRegistrationId(service_worker_registration); 77 GetServiceWorkerRegistrationId(service_worker_registration);
78 thread_safe_sender_->Send(new PushMessagingHostMsg_RegisterFromWorker( 78 thread_safe_sender_->Send(new PushMessagingHostMsg_SubscribeFromWorker(
79 request_id, service_worker_registration_id, options.userVisibleOnly)); 79 request_id, service_worker_registration_id, options.userVisibleOnly));
80 } 80 }
81 81
82 void PushProvider::unsubscribe( 82 void PushProvider::unsubscribe(
83 blink::WebServiceWorkerRegistration* service_worker_registration, 83 blink::WebServiceWorkerRegistration* service_worker_registration,
84 blink::WebPushUnsubscribeCallbacks* callbacks) { 84 blink::WebPushUnsubscribeCallbacks* callbacks) {
85 DCHECK(service_worker_registration); 85 DCHECK(service_worker_registration);
86 DCHECK(callbacks); 86 DCHECK(callbacks);
87 87
88 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); 88 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId());
89 unsubscribe_callbacks_.AddWithID(callbacks, request_id); 89 unsubscribe_callbacks_.AddWithID(callbacks, request_id);
90 90
91 int64 service_worker_registration_id = 91 int64 service_worker_registration_id =
92 GetServiceWorkerRegistrationId(service_worker_registration); 92 GetServiceWorkerRegistrationId(service_worker_registration);
93 thread_safe_sender_->Send(new PushMessagingHostMsg_Unregister( 93 thread_safe_sender_->Send(new PushMessagingHostMsg_Unsubscribe(
94 request_id, service_worker_registration_id)); 94 request_id, service_worker_registration_id));
95 } 95 }
96 96
97 void PushProvider::getSubscription( 97 void PushProvider::getSubscription(
98 blink::WebServiceWorkerRegistration* service_worker_registration, 98 blink::WebServiceWorkerRegistration* service_worker_registration,
99 blink::WebPushSubscriptionCallbacks* callbacks) { 99 blink::WebPushSubscriptionCallbacks* callbacks) {
100 DCHECK(service_worker_registration); 100 DCHECK(service_worker_registration);
101 DCHECK(callbacks); 101 DCHECK(callbacks);
102 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); 102 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId());
103 subscription_callbacks_.AddWithID(callbacks, request_id); 103 subscription_callbacks_.AddWithID(callbacks, request_id);
(...skipping 13 matching lines...) Expand all
117 permission_status_callbacks_.AddWithID(callbacks, request_id); 117 permission_status_callbacks_.AddWithID(callbacks, request_id);
118 int64 service_worker_registration_id = 118 int64 service_worker_registration_id =
119 GetServiceWorkerRegistrationId(service_worker_registration); 119 GetServiceWorkerRegistrationId(service_worker_registration);
120 thread_safe_sender_->Send(new PushMessagingHostMsg_GetPermissionStatus( 120 thread_safe_sender_->Send(new PushMessagingHostMsg_GetPermissionStatus(
121 request_id, service_worker_registration_id, options.userVisibleOnly)); 121 request_id, service_worker_registration_id, options.userVisibleOnly));
122 } 122 }
123 123
124 bool PushProvider::OnMessageReceived(const IPC::Message& message) { 124 bool PushProvider::OnMessageReceived(const IPC::Message& message) {
125 bool handled = true; 125 bool handled = true;
126 IPC_BEGIN_MESSAGE_MAP(PushProvider, message) 126 IPC_BEGIN_MESSAGE_MAP(PushProvider, message)
127 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromWorkerSuccess, 127 IPC_MESSAGE_HANDLER(PushMessagingMsg_SubscribeFromWorkerSuccess,
128 OnRegisterFromWorkerSuccess); 128 OnSubscribeFromWorkerSuccess);
129 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromWorkerError, 129 IPC_MESSAGE_HANDLER(PushMessagingMsg_SubscribeFromWorkerError,
130 OnRegisterFromWorkerError); 130 OnSubscribeFromWorkerError);
131 IPC_MESSAGE_HANDLER(PushMessagingMsg_UnregisterSuccess, 131 IPC_MESSAGE_HANDLER(PushMessagingMsg_UnsubscribeSuccess,
132 OnUnregisterSuccess); 132 OnUnsubscribeSuccess);
133 IPC_MESSAGE_HANDLER(PushMessagingMsg_UnregisterError, 133 IPC_MESSAGE_HANDLER(PushMessagingMsg_UnsubscribeError,
134 OnUnregisterError); 134 OnUnsubscribeError);
135 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetRegistrationSuccess, 135 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetRegistrationSuccess,
136 OnGetRegistrationSuccess); 136 OnGetRegistrationSuccess);
137 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetRegistrationError, 137 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetRegistrationError,
138 OnGetRegistrationError); 138 OnGetRegistrationError);
139 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusSuccess, 139 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusSuccess,
140 OnGetPermissionStatusSuccess); 140 OnGetPermissionStatusSuccess);
141 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusError, 141 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusError,
142 OnGetPermissionStatusError); 142 OnGetPermissionStatusError);
143 IPC_MESSAGE_UNHANDLED(handled = false) 143 IPC_MESSAGE_UNHANDLED(handled = false)
144 IPC_END_MESSAGE_MAP() 144 IPC_END_MESSAGE_MAP()
145 145
146 return handled; 146 return handled;
147 } 147 }
148 148
149 void PushProvider::OnRegisterFromWorkerSuccess( 149 void PushProvider::OnSubscribeFromWorkerSuccess(
150 int request_id, 150 int request_id,
151 const GURL& endpoint, 151 const GURL& endpoint,
152 const std::string& registration_id) { 152 const std::string& subscription_id) {
153 blink::WebPushSubscriptionCallbacks* callbacks = 153 blink::WebPushSubscriptionCallbacks* callbacks =
154 subscription_callbacks_.Lookup(request_id); 154 subscription_callbacks_.Lookup(request_id);
155 if (!callbacks) 155 if (!callbacks)
156 return; 156 return;
157 157
158 scoped_ptr<blink::WebPushSubscription> subscription( 158 scoped_ptr<blink::WebPushSubscription> subscription(
159 new blink::WebPushSubscription( 159 new blink::WebPushSubscription(
160 blink::WebString::fromUTF8(endpoint.spec()), 160 blink::WebString::fromUTF8(endpoint.spec()),
161 blink::WebString::fromUTF8(registration_id))); 161 blink::WebString::fromUTF8(subscription_id)));
162 callbacks->onSuccess(subscription.release()); 162 callbacks->onSuccess(subscription.release());
163 163
164 subscription_callbacks_.Remove(request_id); 164 subscription_callbacks_.Remove(request_id);
165 } 165 }
166 166
167 void PushProvider::OnRegisterFromWorkerError(int request_id, 167 void PushProvider::OnSubscribeFromWorkerError(int request_id,
168 PushRegistrationStatus status) { 168 PushRegistrationStatus status) {
169 blink::WebPushSubscriptionCallbacks* callbacks = 169 blink::WebPushSubscriptionCallbacks* callbacks =
170 subscription_callbacks_.Lookup(request_id); 170 subscription_callbacks_.Lookup(request_id);
171 if (!callbacks) 171 if (!callbacks)
172 return; 172 return;
173 173
174 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( 174 scoped_ptr<blink::WebPushError> error(new blink::WebPushError(
175 blink::WebPushError::ErrorTypeAbort, 175 blink::WebPushError::ErrorTypeAbort,
176 blink::WebString::fromUTF8(PushRegistrationStatusToString(status)))); 176 blink::WebString::fromUTF8(PushRegistrationStatusToString(status))));
177 callbacks->onError(error.release()); 177 callbacks->onError(error.release());
178 178
179 subscription_callbacks_.Remove(request_id); 179 subscription_callbacks_.Remove(request_id);
180 } 180 }
181 181
182 void PushProvider::OnUnregisterSuccess(int request_id, bool did_unregister) { 182 void PushProvider::OnUnsubscribeSuccess(int request_id, bool did_unsubscribe) {
183 blink::WebPushUnsubscribeCallbacks* callbacks = 183 blink::WebPushUnsubscribeCallbacks* callbacks =
184 unsubscribe_callbacks_.Lookup(request_id); 184 unsubscribe_callbacks_.Lookup(request_id);
185 if (!callbacks) 185 if (!callbacks)
186 return; 186 return;
187 187
188 callbacks->onSuccess(&did_unregister); 188 callbacks->onSuccess(&did_unsubscribe);
189 189
190 unsubscribe_callbacks_.Remove(request_id); 190 unsubscribe_callbacks_.Remove(request_id);
191 } 191 }
192 192
193 void PushProvider::OnUnregisterError( 193 void PushProvider::OnUnsubscribeError(
194 int request_id, 194 int request_id,
195 blink::WebPushError::ErrorType error_type, 195 blink::WebPushError::ErrorType error_type,
196 const std::string& error_message) { 196 const std::string& error_message) {
197 blink::WebPushUnsubscribeCallbacks* callbacks = 197 blink::WebPushUnsubscribeCallbacks* callbacks =
198 unsubscribe_callbacks_.Lookup(request_id); 198 unsubscribe_callbacks_.Lookup(request_id);
199 if (!callbacks) 199 if (!callbacks)
200 return; 200 return;
201 201
202 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( 202 scoped_ptr<blink::WebPushError> error(new blink::WebPushError(
203 error_type, blink::WebString::fromUTF8(error_message))); 203 error_type, blink::WebString::fromUTF8(error_message)));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 scoped_ptr<blink::WebPushError> web_error(new blink::WebPushError( 269 scoped_ptr<blink::WebPushError> web_error(new blink::WebPushError(
270 error, blink::WebString::fromUTF8(error_message))); 270 error, blink::WebString::fromUTF8(error_message)));
271 271
272 callbacks->onError(web_error.release()); 272 callbacks->onError(web_error.release());
273 273
274 permission_status_callbacks_.Remove(request_id); 274 permission_status_callbacks_.Remove(request_id);
275 } 275 }
276 276
277 } // namespace content 277 } // namespace content
OLDNEW
« no previous file with comments | « content/child/push_messaging/push_provider.h ('k') | content/common/push_messaging_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698