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 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
13 #include "content/child/push_messaging/push_dispatcher.h" | 13 #include "content/child/push_messaging/push_dispatcher.h" |
14 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 14 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
15 #include "content/child/thread_safe_sender.h" | 15 #include "content/child/thread_safe_sender.h" |
16 #include "content/common/push_messaging_messages.h" | 16 #include "content/common/push_messaging_messages.h" |
| 17 #include "content/public/common/child_process_host.h" |
17 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
18 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc
ription.h" | 19 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc
ription.h" |
19 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc
riptionOptions.h" | 20 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc
riptionOptions.h" |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 namespace { | 23 namespace { |
23 | 24 |
24 int CurrentWorkerId() { | 25 int CurrentWorkerId() { |
25 return WorkerThread::GetCurrentId(); | 26 return WorkerThread::GetCurrentId(); |
26 } | 27 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); | 77 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); |
77 subscription_callbacks_.AddWithID(callbacks, request_id); | 78 subscription_callbacks_.AddWithID(callbacks, request_id); |
78 int64_t service_worker_registration_id = | 79 int64_t service_worker_registration_id = |
79 GetServiceWorkerRegistrationId(service_worker_registration); | 80 GetServiceWorkerRegistrationId(service_worker_registration); |
80 PushSubscriptionOptions content_options; | 81 PushSubscriptionOptions content_options; |
81 content_options.user_visible_only = options.userVisibleOnly; | 82 content_options.user_visible_only = options.userVisibleOnly; |
82 | 83 |
83 // Just treat the server key as a string of bytes and pass it to the push | 84 // Just treat the server key as a string of bytes and pass it to the push |
84 // service. | 85 // service. |
85 content_options.sender_info = options.applicationServerKey.latin1(); | 86 content_options.sender_info = options.applicationServerKey.latin1(); |
86 thread_safe_sender_->Send(new PushMessagingHostMsg_SubscribeFromWorker( | 87 thread_safe_sender_->Send(new PushMessagingHostMsg_Subscribe( |
87 request_id, service_worker_registration_id, content_options)); | 88 ChildProcessHost::kInvalidUniqueID, request_id, |
| 89 service_worker_registration_id, content_options)); |
88 } | 90 } |
89 | 91 |
90 void PushProvider::unsubscribe( | 92 void PushProvider::unsubscribe( |
91 blink::WebServiceWorkerRegistration* service_worker_registration, | 93 blink::WebServiceWorkerRegistration* service_worker_registration, |
92 blink::WebPushUnsubscribeCallbacks* callbacks) { | 94 blink::WebPushUnsubscribeCallbacks* callbacks) { |
93 DCHECK(service_worker_registration); | 95 DCHECK(service_worker_registration); |
94 DCHECK(callbacks); | 96 DCHECK(callbacks); |
95 | 97 |
96 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); | 98 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); |
97 unsubscribe_callbacks_.AddWithID(callbacks, request_id); | 99 unsubscribe_callbacks_.AddWithID(callbacks, request_id); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 "supported."; | 272 "supported."; |
271 } | 273 } |
272 | 274 |
273 callbacks->onError( | 275 callbacks->onError( |
274 blink::WebPushError(error, blink::WebString::fromUTF8(error_message))); | 276 blink::WebPushError(error, blink::WebString::fromUTF8(error_message))); |
275 | 277 |
276 permission_status_callbacks_.Remove(request_id); | 278 permission_status_callbacks_.Remove(request_id); |
277 } | 279 } |
278 | 280 |
279 } // namespace content | 281 } // namespace content |
OLD | NEW |