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