| 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 "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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::OnSubscribeFromWorkerSuccess( | 149 void PushProvider::OnSubscribeFromWorkerSuccess( |
| 150 int request_id, | 150 int request_id, |
| 151 const GURL& endpoint, | 151 const GURL& endpoint) { |
| 152 const std::string& subscription_id) { | |
| 153 blink::WebPushSubscriptionCallbacks* callbacks = | 152 blink::WebPushSubscriptionCallbacks* callbacks = |
| 154 subscription_callbacks_.Lookup(request_id); | 153 subscription_callbacks_.Lookup(request_id); |
| 155 if (!callbacks) | 154 if (!callbacks) |
| 156 return; | 155 return; |
| 157 | 156 |
| 158 scoped_ptr<blink::WebPushSubscription> subscription( | 157 scoped_ptr<blink::WebPushSubscription> subscription( |
| 159 new blink::WebPushSubscription( | 158 new blink::WebPushSubscription(endpoint)); |
| 160 blink::WebString::fromUTF8(endpoint.spec()), | |
| 161 blink::WebString::fromUTF8(subscription_id))); | |
| 162 callbacks->onSuccess(subscription.release()); | 159 callbacks->onSuccess(subscription.release()); |
| 163 | 160 |
| 164 subscription_callbacks_.Remove(request_id); | 161 subscription_callbacks_.Remove(request_id); |
| 165 } | 162 } |
| 166 | 163 |
| 167 void PushProvider::OnSubscribeFromWorkerError(int request_id, | 164 void PushProvider::OnSubscribeFromWorkerError(int request_id, |
| 168 PushRegistrationStatus status) { | 165 PushRegistrationStatus status) { |
| 169 blink::WebPushSubscriptionCallbacks* callbacks = | 166 blink::WebPushSubscriptionCallbacks* callbacks = |
| 170 subscription_callbacks_.Lookup(request_id); | 167 subscription_callbacks_.Lookup(request_id); |
| 171 if (!callbacks) | 168 if (!callbacks) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 201 | 198 |
| 202 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( | 199 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( |
| 203 error_type, blink::WebString::fromUTF8(error_message))); | 200 error_type, blink::WebString::fromUTF8(error_message))); |
| 204 callbacks->onError(error.release()); | 201 callbacks->onError(error.release()); |
| 205 | 202 |
| 206 unsubscribe_callbacks_.Remove(request_id); | 203 unsubscribe_callbacks_.Remove(request_id); |
| 207 } | 204 } |
| 208 | 205 |
| 209 void PushProvider::OnGetRegistrationSuccess( | 206 void PushProvider::OnGetRegistrationSuccess( |
| 210 int request_id, | 207 int request_id, |
| 211 const GURL& endpoint, | 208 const GURL& endpoint) { |
| 212 const std::string& registration_id) { | |
| 213 blink::WebPushSubscriptionCallbacks* callbacks = | 209 blink::WebPushSubscriptionCallbacks* callbacks = |
| 214 subscription_callbacks_.Lookup(request_id); | 210 subscription_callbacks_.Lookup(request_id); |
| 215 if (!callbacks) | 211 if (!callbacks) |
| 216 return; | 212 return; |
| 217 | 213 |
| 218 scoped_ptr<blink::WebPushSubscription> subscription( | 214 scoped_ptr<blink::WebPushSubscription> subscription( |
| 219 new blink::WebPushSubscription( | 215 new blink::WebPushSubscription(endpoint)); |
| 220 blink::WebString::fromUTF8(endpoint.spec()), | |
| 221 blink::WebString::fromUTF8(registration_id))); | |
| 222 callbacks->onSuccess(subscription.release()); | 216 callbacks->onSuccess(subscription.release()); |
| 223 | 217 |
| 224 subscription_callbacks_.Remove(request_id); | 218 subscription_callbacks_.Remove(request_id); |
| 225 } | 219 } |
| 226 | 220 |
| 227 void PushProvider::OnGetRegistrationError( | 221 void PushProvider::OnGetRegistrationError( |
| 228 int request_id, | 222 int request_id, |
| 229 PushGetRegistrationStatus status) { | 223 PushGetRegistrationStatus status) { |
| 230 blink::WebPushSubscriptionCallbacks* callbacks = | 224 blink::WebPushSubscriptionCallbacks* callbacks = |
| 231 subscription_callbacks_.Lookup(request_id); | 225 subscription_callbacks_.Lookup(request_id); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 262 |
| 269 scoped_ptr<blink::WebPushError> web_error(new blink::WebPushError( | 263 scoped_ptr<blink::WebPushError> web_error(new blink::WebPushError( |
| 270 error, blink::WebString::fromUTF8(error_message))); | 264 error, blink::WebString::fromUTF8(error_message))); |
| 271 | 265 |
| 272 callbacks->onError(web_error.release()); | 266 callbacks->onError(web_error.release()); |
| 273 | 267 |
| 274 permission_status_callbacks_.Remove(request_id); | 268 permission_status_callbacks_.Remove(request_id); |
| 275 } | 269 } |
| 276 | 270 |
| 277 } // namespace content | 271 } // namespace content |
| OLD | NEW |