| OLD | NEW |
| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 push_messaging_manager_->Unsubscribe( | 177 push_messaging_manager_->Unsubscribe( |
| 178 service_worker_registration_id, | 178 service_worker_registration_id, |
| 179 // Safe to use base::Unretained because |push_messaging_manager_ |is owned | 179 // Safe to use base::Unretained because |push_messaging_manager_ |is owned |
| 180 // by |this|. | 180 // by |this|. |
| 181 base::Bind(&PushProvider::DidUnsubscribe, base::Unretained(this), | 181 base::Bind(&PushProvider::DidUnsubscribe, base::Unretained(this), |
| 182 base::Passed(&callbacks))); | 182 base::Passed(&callbacks))); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void PushProvider::DidUnsubscribe( | 185 void PushProvider::DidUnsubscribe( |
| 186 std::unique_ptr<blink::WebPushUnsubscribeCallbacks> callbacks, | 186 std::unique_ptr<blink::WebPushUnsubscribeCallbacks> callbacks, |
| 187 bool is_success, | 187 blink::WebPushError::ErrorType error_type, |
| 188 bool did_unsubscribe, | 188 bool did_unsubscribe, |
| 189 blink::WebPushError::ErrorType error_type, | |
| 190 const base::Optional<std::string>& error_message) { | 189 const base::Optional<std::string>& error_message) { |
| 191 DCHECK(callbacks); | 190 DCHECK(callbacks); |
| 192 | 191 |
| 193 if (is_success) { | 192 // ErrorTypeNone indicates success. |
| 193 if (error_type == blink::WebPushError::ErrorTypeNone) { |
| 194 callbacks->onSuccess(did_unsubscribe); | 194 callbacks->onSuccess(did_unsubscribe); |
| 195 } else { | 195 } else { |
| 196 callbacks->onError(blink::WebPushError( | 196 callbacks->onError(blink::WebPushError( |
| 197 error_type, blink::WebString::fromUTF8(error_message->c_str()))); | 197 error_type, blink::WebString::fromUTF8(error_message->c_str()))); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 void PushProvider::getSubscription( | 201 void PushProvider::getSubscription( |
| 202 blink::WebServiceWorkerRegistration* service_worker_registration, | 202 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 203 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) { | 203 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 push_messaging_manager_->GetPermissionStatus( | 253 push_messaging_manager_->GetPermissionStatus( |
| 254 service_worker_registration_id, options.userVisibleOnly, | 254 service_worker_registration_id, options.userVisibleOnly, |
| 255 // Safe to use base::Unretained because |push_messaging_manager_ |is owned | 255 // Safe to use base::Unretained because |push_messaging_manager_ |is owned |
| 256 // by |this|. | 256 // by |this|. |
| 257 base::Bind(&PushProvider::DidGetPermissionStatus, base::Unretained(this), | 257 base::Bind(&PushProvider::DidGetPermissionStatus, base::Unretained(this), |
| 258 base::Passed(&callbacks))); | 258 base::Passed(&callbacks))); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void PushProvider::DidGetPermissionStatus( | 261 void PushProvider::DidGetPermissionStatus( |
| 262 std::unique_ptr<blink::WebPushPermissionStatusCallbacks> callbacks, | 262 std::unique_ptr<blink::WebPushPermissionStatusCallbacks> callbacks, |
| 263 bool is_success, | 263 blink::WebPushError::ErrorType error_type, |
| 264 blink::WebPushPermissionStatus status, | 264 blink::WebPushPermissionStatus status) { |
| 265 blink::WebPushError::ErrorType error) { | |
| 266 DCHECK(callbacks); | 265 DCHECK(callbacks); |
| 267 | 266 // ErrorTypeNone indicates success. |
| 268 if (is_success) { | 267 if (error_type == blink::WebPushError::ErrorTypeNone) { |
| 269 callbacks->onSuccess(status); | 268 callbacks->onSuccess(status); |
| 270 } else { | 269 } else { |
| 271 std::string error_message; | 270 std::string error_message; |
| 272 if (error == blink::WebPushError::ErrorTypeNotSupported) { | 271 if (error_type == blink::WebPushError::ErrorTypeNotSupported) { |
| 273 error_message = | 272 error_message = |
| 274 "Push subscriptions that don't enable userVisibleOnly are not " | 273 "Push subscriptions that don't enable userVisibleOnly are not " |
| 275 "supported."; | 274 "supported."; |
| 276 } | 275 } |
| 277 callbacks->onError( | 276 callbacks->onError(blink::WebPushError( |
| 278 blink::WebPushError(error, blink::WebString::fromUTF8(error_message))); | 277 error_type, blink::WebString::fromUTF8(error_message))); |
| 279 } | 278 } |
| 280 } | 279 } |
| 281 | 280 |
| 282 } // namespace content | 281 } // namespace content |
| OLD | NEW |