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 | 9 |
9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
12 #include "base/threading/thread_local.h" | 13 #include "base/threading/thread_local.h" |
13 #include "content/child/push_messaging/push_dispatcher.h" | 14 #include "content/child/push_messaging/push_dispatcher.h" |
14 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 15 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
15 #include "content/child/thread_safe_sender.h" | 16 #include "content/child/thread_safe_sender.h" |
16 #include "content/common/push_messaging_messages.h" | 17 #include "content/common/push_messaging_messages.h" |
17 #include "content/public/common/child_process_host.h" | 18 #include "content/public/common/child_process_host.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return provider; | 97 return provider; |
97 } | 98 } |
98 | 99 |
99 void PushProvider::WillStopCurrentWorkerThread() { | 100 void PushProvider::WillStopCurrentWorkerThread() { |
100 delete this; | 101 delete this; |
101 } | 102 } |
102 | 103 |
103 void PushProvider::subscribe( | 104 void PushProvider::subscribe( |
104 blink::WebServiceWorkerRegistration* service_worker_registration, | 105 blink::WebServiceWorkerRegistration* service_worker_registration, |
105 const blink::WebPushSubscriptionOptions& options, | 106 const blink::WebPushSubscriptionOptions& options, |
106 blink::WebPushSubscriptionCallbacks* callbacks) { | 107 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) { |
107 DCHECK(service_worker_registration); | 108 DCHECK(service_worker_registration); |
108 DCHECK(callbacks); | 109 DCHECK(callbacks); |
109 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); | 110 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); |
110 subscription_callbacks_.AddWithID(callbacks, request_id); | 111 subscription_callbacks_.AddWithID(std::move(callbacks), request_id); |
111 int64_t service_worker_registration_id = | 112 int64_t service_worker_registration_id = |
112 GetServiceWorkerRegistrationId(service_worker_registration); | 113 GetServiceWorkerRegistrationId(service_worker_registration); |
113 PushSubscriptionOptions content_options; | 114 PushSubscriptionOptions content_options; |
114 content_options.user_visible_only = options.userVisibleOnly; | 115 content_options.user_visible_only = options.userVisibleOnly; |
115 | 116 |
116 // Just treat the server key as a string of bytes and pass it to the push | 117 // Just treat the server key as a string of bytes and pass it to the push |
117 // service. | 118 // service. |
118 content_options.sender_info = options.applicationServerKey.latin1(); | 119 content_options.sender_info = options.applicationServerKey.latin1(); |
119 thread_safe_sender_->Send(new PushMessagingHostMsg_Subscribe( | 120 thread_safe_sender_->Send(new PushMessagingHostMsg_Subscribe( |
120 ChildProcessHost::kInvalidUniqueID, request_id, | 121 ChildProcessHost::kInvalidUniqueID, request_id, |
121 service_worker_registration_id, content_options)); | 122 service_worker_registration_id, content_options)); |
122 } | 123 } |
123 | 124 |
124 void PushProvider::unsubscribe( | 125 void PushProvider::unsubscribe( |
125 blink::WebServiceWorkerRegistration* service_worker_registration, | 126 blink::WebServiceWorkerRegistration* service_worker_registration, |
126 blink::WebPushUnsubscribeCallbacks* callbacks) { | 127 std::unique_ptr<blink::WebPushUnsubscribeCallbacks> callbacks) { |
127 DCHECK(service_worker_registration); | 128 DCHECK(service_worker_registration); |
128 DCHECK(callbacks); | 129 DCHECK(callbacks); |
129 | 130 |
130 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); | 131 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); |
131 unsubscribe_callbacks_.AddWithID(callbacks, request_id); | 132 unsubscribe_callbacks_.AddWithID(std::move(callbacks), request_id); |
132 | |
133 int64_t service_worker_registration_id = | 133 int64_t service_worker_registration_id = |
134 GetServiceWorkerRegistrationId(service_worker_registration); | 134 GetServiceWorkerRegistrationId(service_worker_registration); |
135 thread_safe_sender_->Send(new PushMessagingHostMsg_Unsubscribe( | 135 thread_safe_sender_->Send(new PushMessagingHostMsg_Unsubscribe( |
136 request_id, service_worker_registration_id)); | 136 request_id, service_worker_registration_id)); |
137 } | 137 } |
138 | 138 |
139 void PushProvider::getSubscription( | 139 void PushProvider::getSubscription( |
140 blink::WebServiceWorkerRegistration* service_worker_registration, | 140 blink::WebServiceWorkerRegistration* service_worker_registration, |
141 blink::WebPushSubscriptionCallbacks* callbacks) { | 141 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) { |
142 DCHECK(service_worker_registration); | 142 DCHECK(service_worker_registration); |
143 DCHECK(callbacks); | 143 DCHECK(callbacks); |
144 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); | 144 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); |
145 subscription_callbacks_.AddWithID(callbacks, request_id); | 145 subscription_callbacks_.AddWithID(std::move(callbacks), request_id); |
146 int64_t service_worker_registration_id = | 146 int64_t service_worker_registration_id = |
147 GetServiceWorkerRegistrationId(service_worker_registration); | 147 GetServiceWorkerRegistrationId(service_worker_registration); |
148 thread_safe_sender_->Send(new PushMessagingHostMsg_GetSubscription( | 148 thread_safe_sender_->Send(new PushMessagingHostMsg_GetSubscription( |
149 request_id, service_worker_registration_id)); | 149 request_id, service_worker_registration_id)); |
150 } | 150 } |
151 | 151 |
152 void PushProvider::getPermissionStatus( | 152 void PushProvider::getPermissionStatus( |
153 blink::WebServiceWorkerRegistration* service_worker_registration, | 153 blink::WebServiceWorkerRegistration* service_worker_registration, |
154 const blink::WebPushSubscriptionOptions& options, | 154 const blink::WebPushSubscriptionOptions& options, |
155 blink::WebPushPermissionStatusCallbacks* callbacks) { | 155 std::unique_ptr<blink::WebPushPermissionStatusCallbacks> callbacks) { |
156 DCHECK(service_worker_registration); | 156 DCHECK(service_worker_registration); |
157 DCHECK(callbacks); | 157 DCHECK(callbacks); |
158 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); | 158 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); |
159 permission_status_callbacks_.AddWithID(callbacks, request_id); | 159 permission_status_callbacks_.AddWithID(std::move(callbacks), request_id); |
160 int64_t service_worker_registration_id = | 160 int64_t service_worker_registration_id = |
161 GetServiceWorkerRegistrationId(service_worker_registration); | 161 GetServiceWorkerRegistrationId(service_worker_registration); |
162 thread_safe_sender_->Send(new PushMessagingHostMsg_GetPermissionStatus( | 162 thread_safe_sender_->Send(new PushMessagingHostMsg_GetPermissionStatus( |
163 request_id, service_worker_registration_id, options.userVisibleOnly)); | 163 request_id, service_worker_registration_id, options.userVisibleOnly)); |
164 } | 164 } |
165 | 165 |
166 bool PushProvider::OnMessageReceived(const IPC::Message& message) { | 166 bool PushProvider::OnMessageReceived(const IPC::Message& message) { |
167 bool handled = true; | 167 bool handled = true; |
168 IPC_BEGIN_MESSAGE_MAP(PushProvider, message) | 168 IPC_BEGIN_MESSAGE_MAP(PushProvider, message) |
169 IPC_MESSAGE_HANDLER(PushMessagingMsg_SubscribeFromWorkerSuccess, | 169 IPC_MESSAGE_HANDLER(PushMessagingMsg_SubscribeFromWorkerSuccess, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 "supported."; | 301 "supported."; |
302 } | 302 } |
303 | 303 |
304 callbacks->onError( | 304 callbacks->onError( |
305 blink::WebPushError(error, blink::WebString::fromUTF8(error_message))); | 305 blink::WebPushError(error, blink::WebString::fromUTF8(error_message))); |
306 | 306 |
307 permission_status_callbacks_.Remove(request_id); | 307 permission_status_callbacks_.Remove(request_id); |
308 } | 308 } |
309 | 309 |
310 } // namespace content | 310 } // namespace content |
OLD | NEW |