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

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

Issue 2712693002: Implement some follow-ups after mojofiction of Push-messaging. (Closed)
Patch Set: code rebase Created 3 years, 10 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
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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 // Just treat the server key as a string of bytes and pass it to the push 130 // Just treat the server key as a string of bytes and pass it to the push
131 // service. 131 // service.
132 content_options.sender_info = options.applicationServerKey.latin1(); 132 content_options.sender_info = options.applicationServerKey.latin1();
133 133
134 push_messaging_manager_->Subscribe( 134 push_messaging_manager_->Subscribe(
135 ChildProcessHost::kInvalidUniqueID, service_worker_registration_id, 135 ChildProcessHost::kInvalidUniqueID, service_worker_registration_id,
136 content_options, 136 content_options,
137 // Safe to use base::Unretained because |push_messaging_manager_ |is owned 137 // Safe to use base::Unretained because |push_messaging_manager_ |is owned
138 // by |this|. 138 // by |this|.
139 base::Bind(&PushProvider::SubscribeCallback, base::Unretained(this), 139 base::Bind(&PushProvider::DidSubscribe, base::Unretained(this),
140 base::Passed(&callbacks))); 140 base::Passed(&callbacks)));
141 } 141 }
142 142
143 void PushProvider::SubscribeCallback( 143 void PushProvider::DidSubscribe(
144 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks, 144 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks,
145 content::PushRegistrationStatus status, 145 content::PushRegistrationStatus status,
146 const base::Optional<GURL>& endpoint, 146 const base::Optional<GURL>& endpoint,
147 const base::Optional<content::PushSubscriptionOptions>& options, 147 const base::Optional<content::PushSubscriptionOptions>& options,
148 const base::Optional<std::vector<uint8_t>>& p256dh, 148 const base::Optional<std::vector<uint8_t>>& p256dh,
149 const base::Optional<std::vector<uint8_t>>& auth) { 149 const base::Optional<std::vector<uint8_t>>& auth) {
150 if (!callbacks) { 150 DCHECK(callbacks);
151 return;
152 }
153 151
154 if (status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE || 152 if (status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE ||
155 status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_CACHE) { 153 status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_CACHE) {
156 DCHECK(endpoint); 154 DCHECK(endpoint);
157 DCHECK(options); 155 DCHECK(options);
158 DCHECK(p256dh); 156 DCHECK(p256dh);
159 DCHECK(auth); 157 DCHECK(auth);
160 158
161 callbacks->onSuccess(base::MakeUnique<blink::WebPushSubscription>( 159 callbacks->onSuccess(base::MakeUnique<blink::WebPushSubscription>(
162 endpoint.value(), options.value().user_visible_only, 160 endpoint.value(), options.value().user_visible_only,
(...skipping 10 matching lines...) Expand all
173 DCHECK(service_worker_registration); 171 DCHECK(service_worker_registration);
174 DCHECK(callbacks); 172 DCHECK(callbacks);
175 173
176 int64_t service_worker_registration_id = 174 int64_t service_worker_registration_id =
177 GetServiceWorkerRegistrationId(service_worker_registration); 175 GetServiceWorkerRegistrationId(service_worker_registration);
178 176
179 push_messaging_manager_->Unsubscribe( 177 push_messaging_manager_->Unsubscribe(
180 service_worker_registration_id, 178 service_worker_registration_id,
181 // Safe to use base::Unretained because |push_messaging_manager_ |is owned 179 // Safe to use base::Unretained because |push_messaging_manager_ |is owned
182 // by |this|. 180 // by |this|.
183 base::Bind(&PushProvider::UnsubscribeCallback, base::Unretained(this), 181 base::Bind(&PushProvider::DidUnsubscribe, base::Unretained(this),
184 base::Passed(&callbacks))); 182 base::Passed(&callbacks)));
185 } 183 }
186 184
187 void PushProvider::UnsubscribeCallback( 185 void PushProvider::DidUnsubscribe(
188 std::unique_ptr<blink::WebPushUnsubscribeCallbacks> callbacks, 186 std::unique_ptr<blink::WebPushUnsubscribeCallbacks> callbacks,
189 bool is_success, 187 bool is_success,
190 bool did_unsubscribe, 188 bool did_unsubscribe,
191 blink::WebPushError::ErrorType error_type, 189 blink::WebPushError::ErrorType error_type,
192 const base::Optional<std::string>& error_message) { 190 const base::Optional<std::string>& error_message) {
193 if (!callbacks) { 191 DCHECK(callbacks);
194 return;
195 }
196 192
197 if (is_success) { 193 if (is_success) {
198 callbacks->onSuccess(did_unsubscribe); 194 callbacks->onSuccess(did_unsubscribe);
199 } else { 195 } else {
200 callbacks->onError(blink::WebPushError( 196 callbacks->onError(blink::WebPushError(
201 error_type, blink::WebString::fromUTF8(error_message->c_str()))); 197 error_type, blink::WebString::fromUTF8(error_message->c_str())));
202 } 198 }
203 } 199 }
204 200
205 void PushProvider::getSubscription( 201 void PushProvider::getSubscription(
206 blink::WebServiceWorkerRegistration* service_worker_registration, 202 blink::WebServiceWorkerRegistration* service_worker_registration,
207 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) { 203 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) {
208 DCHECK(service_worker_registration); 204 DCHECK(service_worker_registration);
209 DCHECK(callbacks); 205 DCHECK(callbacks);
210 206
211 int64_t service_worker_registration_id = 207 int64_t service_worker_registration_id =
212 GetServiceWorkerRegistrationId(service_worker_registration); 208 GetServiceWorkerRegistrationId(service_worker_registration);
213 209
214 push_messaging_manager_->GetSubscription( 210 push_messaging_manager_->GetSubscription(
215 service_worker_registration_id, 211 service_worker_registration_id,
216 // Safe to use base::Unretained because |push_messaging_manager_ |is owned 212 // Safe to use base::Unretained because |push_messaging_manager_ |is owned
217 // by |this|. 213 // by |this|.
218 base::Bind(&PushProvider::GetSubscriptionCallback, base::Unretained(this), 214 base::Bind(&PushProvider::DidGetSubscription, base::Unretained(this),
219 base::Passed(&callbacks))); 215 base::Passed(&callbacks)));
220 } 216 }
221 217
222 void PushProvider::GetSubscriptionCallback( 218 void PushProvider::DidGetSubscription(
223 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks, 219 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks,
224 content::PushGetRegistrationStatus status, 220 content::PushGetRegistrationStatus status,
225 const base::Optional<GURL>& endpoint, 221 const base::Optional<GURL>& endpoint,
226 const base::Optional<content::PushSubscriptionOptions>& options, 222 const base::Optional<content::PushSubscriptionOptions>& options,
227 const base::Optional<std::vector<uint8_t>>& p256dh, 223 const base::Optional<std::vector<uint8_t>>& p256dh,
228 const base::Optional<std::vector<uint8_t>>& auth) { 224 const base::Optional<std::vector<uint8_t>>& auth) {
229 if (!callbacks) 225 DCHECK(callbacks);
230 return;
231 226
232 if (status == PUSH_GETREGISTRATION_STATUS_SUCCESS) { 227 if (status == PUSH_GETREGISTRATION_STATUS_SUCCESS) {
233 DCHECK(endpoint); 228 DCHECK(endpoint);
234 DCHECK(options); 229 DCHECK(options);
235 DCHECK(p256dh); 230 DCHECK(p256dh);
236 DCHECK(auth); 231 DCHECK(auth);
237 232
238 callbacks->onSuccess(base::MakeUnique<blink::WebPushSubscription>( 233 callbacks->onSuccess(base::MakeUnique<blink::WebPushSubscription>(
239 endpoint.value(), options.value().user_visible_only, 234 endpoint.value(), options.value().user_visible_only,
240 blink::WebString::fromLatin1(options.value().sender_info), 235 blink::WebString::fromLatin1(options.value().sender_info),
(...skipping 11 matching lines...) Expand all
252 DCHECK(service_worker_registration); 247 DCHECK(service_worker_registration);
253 DCHECK(callbacks); 248 DCHECK(callbacks);
254 249
255 int64_t service_worker_registration_id = 250 int64_t service_worker_registration_id =
256 GetServiceWorkerRegistrationId(service_worker_registration); 251 GetServiceWorkerRegistrationId(service_worker_registration);
257 252
258 push_messaging_manager_->GetPermissionStatus( 253 push_messaging_manager_->GetPermissionStatus(
259 service_worker_registration_id, options.userVisibleOnly, 254 service_worker_registration_id, options.userVisibleOnly,
260 // Safe to use base::Unretained because |push_messaging_manager_ |is owned 255 // Safe to use base::Unretained because |push_messaging_manager_ |is owned
261 // by |this|. 256 // by |this|.
262 base::Bind(&PushProvider::GetPermissionStatusCallback, 257 base::Bind(&PushProvider::DidGetPermissionStatus, base::Unretained(this),
263 base::Unretained(this), base::Passed(&callbacks))); 258 base::Passed(&callbacks)));
264 } 259 }
265 260
266 void PushProvider::GetPermissionStatusCallback( 261 void PushProvider::DidGetPermissionStatus(
267 std::unique_ptr<blink::WebPushPermissionStatusCallbacks> callbacks, 262 std::unique_ptr<blink::WebPushPermissionStatusCallbacks> callbacks,
268 bool is_success, 263 bool is_success,
269 blink::WebPushPermissionStatus status, 264 blink::WebPushPermissionStatus status,
270 blink::WebPushError::ErrorType error) { 265 blink::WebPushError::ErrorType error) {
271 if (!callbacks) 266 DCHECK(callbacks);
272 return;
273 267
274 if (is_success) { 268 if (is_success) {
275 callbacks->onSuccess(status); 269 callbacks->onSuccess(status);
276 } else { 270 } else {
277 std::string error_message; 271 std::string error_message;
278 if (error == blink::WebPushError::ErrorTypeNotSupported) { 272 if (error == blink::WebPushError::ErrorTypeNotSupported) {
279 error_message = 273 error_message =
280 "Push subscriptions that don't enable userVisibleOnly are not " 274 "Push subscriptions that don't enable userVisibleOnly are not "
281 "supported."; 275 "supported.";
282 } 276 }
283 callbacks->onError( 277 callbacks->onError(
284 blink::WebPushError(error, blink::WebString::fromUTF8(error_message))); 278 blink::WebPushError(error, blink::WebString::fromUTF8(error_message)));
285 } 279 }
286 } 280 }
287 281
288 } // namespace content 282 } // namespace content
OLDNEW
« no previous file with comments | « content/child/push_messaging/push_provider.h ('k') | content/renderer/push_messaging/push_messaging_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698