| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 g_push_provider_tls.Pointer()->Set(this); | 44 g_push_provider_tls.Pointer()->Set(this); |
| 45 } | 45 } |
| 46 | 46 |
| 47 PushProvider::~PushProvider() { | 47 PushProvider::~PushProvider() { |
| 48 STLDeleteContainerPairSecondPointers(registration_callbacks_.begin(), | 48 STLDeleteContainerPairSecondPointers(registration_callbacks_.begin(), |
| 49 registration_callbacks_.end()); | 49 registration_callbacks_.end()); |
| 50 registration_callbacks_.clear(); | 50 registration_callbacks_.clear(); |
| 51 STLDeleteContainerPairSecondPointers(permission_status_callbacks_.begin(), | 51 STLDeleteContainerPairSecondPointers(permission_status_callbacks_.begin(), |
| 52 permission_status_callbacks_.end()); | 52 permission_status_callbacks_.end()); |
| 53 permission_status_callbacks_.clear(); | 53 permission_status_callbacks_.clear(); |
| 54 STLDeleteContainerPairSecondPointers(unregister_callbacks_.begin(), |
| 55 unregister_callbacks_.end()); |
| 56 unregister_callbacks_.clear(); |
| 54 g_push_provider_tls.Pointer()->Set(nullptr); | 57 g_push_provider_tls.Pointer()->Set(nullptr); |
| 55 } | 58 } |
| 56 | 59 |
| 57 PushProvider* PushProvider::ThreadSpecificInstance( | 60 PushProvider* PushProvider::ThreadSpecificInstance( |
| 58 ThreadSafeSender* thread_safe_sender, | 61 ThreadSafeSender* thread_safe_sender, |
| 59 PushDispatcher* push_dispatcher) { | 62 PushDispatcher* push_dispatcher) { |
| 60 if (g_push_provider_tls.Pointer()->Get()) | 63 if (g_push_provider_tls.Pointer()->Get()) |
| 61 return g_push_provider_tls.Pointer()->Get(); | 64 return g_push_provider_tls.Pointer()->Get(); |
| 62 | 65 |
| 63 PushProvider* provider = | 66 PushProvider* provider = |
| (...skipping 26 matching lines...) Expand all Loading... |
| 90 DCHECK(service_worker_registration); | 93 DCHECK(service_worker_registration); |
| 91 DCHECK(callbacks); | 94 DCHECK(callbacks); |
| 92 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); | 95 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); |
| 93 permission_status_callbacks_[request_id] = callbacks; | 96 permission_status_callbacks_[request_id] = callbacks; |
| 94 int64 service_worker_registration_id = | 97 int64 service_worker_registration_id = |
| 95 GetServiceWorkerRegistrationId(service_worker_registration); | 98 GetServiceWorkerRegistrationId(service_worker_registration); |
| 96 thread_safe_sender_->Send(new PushMessagingHostMsg_GetPermissionStatus( | 99 thread_safe_sender_->Send(new PushMessagingHostMsg_GetPermissionStatus( |
| 97 request_id, service_worker_registration_id)); | 100 request_id, service_worker_registration_id)); |
| 98 } | 101 } |
| 99 | 102 |
| 103 void PushProvider::unregister( |
| 104 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 105 blink::WebPushUnregisterCallbacks* callback) { |
| 106 DCHECK(service_worker_registration); |
| 107 DCHECK(callback); |
| 108 |
| 109 int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId()); |
| 110 unregister_callbacks_[request_id] = callback; |
| 111 |
| 112 int64 service_worker_registration_id = |
| 113 GetServiceWorkerRegistrationId(service_worker_registration); |
| 114 thread_safe_sender_->Send(new PushMessagingHostMsg_Unregister( |
| 115 request_id, service_worker_registration_id)); |
| 116 } |
| 117 |
| 100 bool PushProvider::OnMessageReceived(const IPC::Message& message) { | 118 bool PushProvider::OnMessageReceived(const IPC::Message& message) { |
| 101 bool handled = true; | 119 bool handled = true; |
| 102 IPC_BEGIN_MESSAGE_MAP(PushProvider, message) | 120 IPC_BEGIN_MESSAGE_MAP(PushProvider, message) |
| 103 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromWorkerSuccess, | 121 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromWorkerSuccess, |
| 104 OnRegisterFromWorkerSuccess); | 122 OnRegisterFromWorkerSuccess); |
| 105 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromWorkerError, | 123 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromWorkerError, |
| 106 OnRegisterFromWorkerError); | 124 OnRegisterFromWorkerError); |
| 107 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusSuccess, | 125 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusSuccess, |
| 108 OnGetPermissionStatusSuccess); | 126 OnGetPermissionStatusSuccess); |
| 109 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusError, | 127 IPC_MESSAGE_HANDLER(PushMessagingMsg_GetPermissionStatusError, |
| 110 OnGetPermissionStatusError); | 128 OnGetPermissionStatusError); |
| 129 IPC_MESSAGE_HANDLER(PushMessagingMsg_UnregisterResponse, |
| 130 OnUnregisterResponse); |
| 111 IPC_MESSAGE_UNHANDLED(handled = false) | 131 IPC_MESSAGE_UNHANDLED(handled = false) |
| 112 IPC_END_MESSAGE_MAP() | 132 IPC_END_MESSAGE_MAP() |
| 113 | 133 |
| 114 return handled; | 134 return handled; |
| 115 } | 135 } |
| 116 | 136 |
| 117 void PushProvider::OnRegisterFromWorkerSuccess( | 137 void PushProvider::OnRegisterFromWorkerSuccess( |
| 118 int request_id, | 138 int request_id, |
| 119 const GURL& endpoint, | 139 const GURL& endpoint, |
| 120 const std::string& registration_id) { | 140 const std::string& registration_id) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 const auto& it = permission_status_callbacks_.find(request_id); | 184 const auto& it = permission_status_callbacks_.find(request_id); |
| 165 if (it == permission_status_callbacks_.end()) | 185 if (it == permission_status_callbacks_.end()) |
| 166 return; | 186 return; |
| 167 | 187 |
| 168 scoped_ptr<blink::WebPushPermissionStatusCallbacks> callbacks(it->second); | 188 scoped_ptr<blink::WebPushPermissionStatusCallbacks> callbacks(it->second); |
| 169 permission_status_callbacks_.erase(it); | 189 permission_status_callbacks_.erase(it); |
| 170 | 190 |
| 171 callbacks->onError(); | 191 callbacks->onError(); |
| 172 } | 192 } |
| 173 | 193 |
| 194 void PushProvider::OnUnregisterResponse(int request_id, bool unregistered) { |
| 195 const auto& it = unregister_callbacks_.find(request_id); |
| 196 if (it == unregister_callbacks_.end()) |
| 197 return; |
| 198 |
| 199 scoped_ptr<blink::WebPushUnregisterCallbacks> callback(it->second); |
| 200 unregister_callbacks_.erase(it); |
| 201 |
| 202 callback->onSuccess(&unregistered); |
| 203 } |
| 204 |
| 174 } // namespace content | 205 } // namespace content |
| OLD | NEW |