Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/service_worker/service_worker_dispatcher.h" | 5 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
| 10 #include "content/child/child_thread.h" | 10 #include "content/child/child_thread.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { | 50 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 51 bool handled = true; | 51 bool handled = true; |
| 52 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) | 52 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) |
| 53 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) | 53 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) |
| 54 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, | 54 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, |
| 55 OnUnregistered) | 55 OnUnregistered) |
| 56 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, | 56 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, |
| 57 OnRegistrationError) | 57 OnRegistrationError) |
| 58 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, | 58 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, |
| 59 OnServiceWorkerStateChanged) | 59 OnServiceWorkerStateChanged) |
| 60 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetWaitingServiceWorker, | |
| 61 OnSetWaitingServiceWorker) | |
| 60 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetCurrentServiceWorker, | 62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetCurrentServiceWorker, |
| 61 OnSetCurrentServiceWorker) | 63 OnSetCurrentServiceWorker) |
| 62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, | 64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, |
| 63 OnPostMessage) | 65 OnPostMessage) |
| 64 IPC_MESSAGE_UNHANDLED(handled = false) | 66 IPC_MESSAGE_UNHANDLED(handled = false) |
| 65 IPC_END_MESSAGE_MAP() | 67 IPC_END_MESSAGE_MAP() |
| 66 DCHECK(handled) << "Unhandled message:" << msg.type(); | 68 DCHECK(handled) << "Unhandled message:" << msg.type(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { | 71 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 97 int provider_id = provider_context->provider_id(); | 99 int provider_id = provider_context->provider_id(); |
| 98 DCHECK(!ContainsKey(provider_contexts_, provider_id)); | 100 DCHECK(!ContainsKey(provider_contexts_, provider_id)); |
| 99 provider_contexts_[provider_id] = provider_context; | 101 provider_contexts_[provider_id] = provider_context; |
| 100 } | 102 } |
| 101 | 103 |
| 102 void ServiceWorkerDispatcher::RemoveProviderContext( | 104 void ServiceWorkerDispatcher::RemoveProviderContext( |
| 103 ServiceWorkerProviderContext* provider_context) { | 105 ServiceWorkerProviderContext* provider_context) { |
| 104 DCHECK(provider_context); | 106 DCHECK(provider_context); |
| 105 DCHECK(ContainsKey(provider_contexts_, provider_context->provider_id())); | 107 DCHECK(ContainsKey(provider_contexts_, provider_context->provider_id())); |
| 106 provider_contexts_.erase(provider_context->provider_id()); | 108 provider_contexts_.erase(provider_context->provider_id()); |
| 109 worker_to_provider_.erase(provider_context->waiting_handle_id()); | |
| 107 worker_to_provider_.erase(provider_context->current_handle_id()); | 110 worker_to_provider_.erase(provider_context->current_handle_id()); |
| 108 } | 111 } |
| 109 | 112 |
| 110 void ServiceWorkerDispatcher::AddScriptClient( | 113 void ServiceWorkerDispatcher::AddScriptClient( |
| 111 int provider_id, | 114 int provider_id, |
| 112 blink::WebServiceWorkerProviderClient* client) { | 115 blink::WebServiceWorkerProviderClient* client) { |
| 113 DCHECK(client); | 116 DCHECK(client); |
| 114 DCHECK(!ContainsKey(script_clients_, provider_id)); | 117 DCHECK(!ContainsKey(script_clients_, provider_id)); |
| 115 script_clients_[provider_id] = client; | 118 script_clients_[provider_id] = client; |
| 116 } | 119 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 144 return g_dispatcher_tls.Pointer()->Get(); | 147 return g_dispatcher_tls.Pointer()->Get(); |
| 145 } | 148 } |
| 146 | 149 |
| 147 void ServiceWorkerDispatcher::OnWorkerRunLoopStopped() { | 150 void ServiceWorkerDispatcher::OnWorkerRunLoopStopped() { |
| 148 delete this; | 151 delete this; |
| 149 } | 152 } |
| 150 | 153 |
| 151 WebServiceWorkerImpl* ServiceWorkerDispatcher::GetServiceWorker( | 154 WebServiceWorkerImpl* ServiceWorkerDispatcher::GetServiceWorker( |
| 152 const ServiceWorkerObjectInfo& info, | 155 const ServiceWorkerObjectInfo& info, |
| 153 bool adopt_handle) { | 156 bool adopt_handle) { |
| 157 if (info.handle_id == kInvalidServiceWorkerHandleId) | |
| 158 return NULL; | |
| 159 | |
| 154 WorkerObjectMap::iterator existing_worker = | 160 WorkerObjectMap::iterator existing_worker = |
| 155 service_workers_.find(info.handle_id); | 161 service_workers_.find(info.handle_id); |
| 156 | 162 |
| 157 if (existing_worker != service_workers_.end()) { | 163 if (existing_worker != service_workers_.end()) { |
| 158 if (adopt_handle) { | 164 if (adopt_handle) { |
| 159 // We are instructed to adopt a handle but we already have one, so | 165 // We are instructed to adopt a handle but we already have one, so |
| 160 // adopt and destroy a handle ref. | 166 // adopt and destroy a handle ref. |
| 161 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); | 167 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); |
| 162 } | 168 } |
| 163 return existing_worker->second; | 169 return existing_worker->second; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 blink::WebServiceWorkerState state) { | 227 blink::WebServiceWorkerState state) { |
| 222 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); | 228 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); |
| 223 if (worker != service_workers_.end()) | 229 if (worker != service_workers_.end()) |
| 224 worker->second->OnStateChanged(state); | 230 worker->second->OnStateChanged(state); |
| 225 | 231 |
| 226 WorkerToProviderMap::iterator provider = worker_to_provider_.find(handle_id); | 232 WorkerToProviderMap::iterator provider = worker_to_provider_.find(handle_id); |
| 227 if (provider != worker_to_provider_.end()) | 233 if (provider != worker_to_provider_.end()) |
| 228 provider->second->OnServiceWorkerStateChanged(handle_id, state); | 234 provider->second->OnServiceWorkerStateChanged(handle_id, state); |
| 229 } | 235 } |
| 230 | 236 |
| 237 void ServiceWorkerDispatcher::OnSetWaitingServiceWorker( | |
| 238 int thread_id, | |
| 239 int provider_id, | |
| 240 const ServiceWorkerObjectInfo& info) { | |
| 241 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | |
| 242 if (provider != provider_contexts_.end()) { | |
| 243 int existing_waiting_id = provider->second->waiting_handle_id(); | |
| 244 if (existing_waiting_id != info.handle_id && | |
| 245 existing_waiting_id != kInvalidServiceWorkerHandleId) { | |
| 246 WorkerToProviderMap::iterator associated_provider = | |
| 247 worker_to_provider_.find(existing_waiting_id); | |
| 248 DCHECK(associated_provider != worker_to_provider_.end()); | |
| 249 DCHECK(associated_provider->second->provider_id() == provider_id); | |
| 250 worker_to_provider_.erase(associated_provider); | |
| 251 } | |
| 252 provider->second->OnSetWaitingServiceWorker(provider_id, info); | |
| 253 if (info.handle_id != kInvalidServiceWorkerHandleId) | |
| 254 worker_to_provider_[info.handle_id] = provider->second; | |
| 255 } | |
| 256 | |
| 257 ScriptClientMap::iterator found = script_clients_.find(provider_id); | |
| 258 if (found != script_clients_.end()) { | |
| 259 // Populate the .waiting field with the new worker object. | |
| 260 found->second->setWaiting(GetServiceWorker(info, false)); | |
| 261 } | |
| 262 } | |
| 263 | |
| 231 void ServiceWorkerDispatcher::OnSetCurrentServiceWorker( | 264 void ServiceWorkerDispatcher::OnSetCurrentServiceWorker( |
| 232 int thread_id, | 265 int thread_id, |
| 233 int provider_id, | 266 int provider_id, |
| 234 const ServiceWorkerObjectInfo& info) { | 267 const ServiceWorkerObjectInfo& info) { |
| 235 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 268 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 236 if (provider != provider_contexts_.end()) { | 269 if (provider != provider_contexts_.end()) { |
| 237 provider->second->OnSetCurrentServiceWorker(provider_id, info); | 270 provider->second->OnSetCurrentServiceWorker(provider_id, info); |
| 238 worker_to_provider_[info.handle_id] = provider->second; | 271 worker_to_provider_[info.handle_id] = provider->second; |
| 239 } | 272 } |
| 240 | 273 |
| 241 ScriptClientMap::iterator found = script_clients_.find(provider_id); | 274 ScriptClientMap::iterator found = script_clients_.find(provider_id); |
| 242 if (found != script_clients_.end()) { | 275 if (found != script_clients_.end()) { |
| 243 // Populate the .current field with the new worker object. | 276 // Populate the .current field with the new worker object. |
|
falken
2014/06/10 20:34:28
can you update the comment to say .controller also
| |
| 244 found->second->setCurrentServiceWorker(GetServiceWorker(info, false)); | 277 found->second->setController(GetServiceWorker(info, false)); |
| 245 } | 278 } |
| 246 } | 279 } |
| 247 | 280 |
| 248 void ServiceWorkerDispatcher::OnPostMessage( | 281 void ServiceWorkerDispatcher::OnPostMessage( |
| 249 int thread_id, | 282 int thread_id, |
| 250 int provider_id, | 283 int provider_id, |
| 251 const base::string16& message, | 284 const base::string16& message, |
| 252 const std::vector<int>& sent_message_port_ids, | 285 const std::vector<int>& sent_message_port_ids, |
| 253 const std::vector<int>& new_routing_ids) { | 286 const std::vector<int>& new_routing_ids) { |
| 254 // Make sure we're on the main document thread. (That must be the only | 287 // Make sure we're on the main document thread. (That must be the only |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 280 DCHECK(!ContainsKey(service_workers_, handle_id)); | 313 DCHECK(!ContainsKey(service_workers_, handle_id)); |
| 281 service_workers_[handle_id] = worker; | 314 service_workers_[handle_id] = worker; |
| 282 } | 315 } |
| 283 | 316 |
| 284 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { | 317 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { |
| 285 DCHECK(ContainsKey(service_workers_, handle_id)); | 318 DCHECK(ContainsKey(service_workers_, handle_id)); |
| 286 service_workers_.erase(handle_id); | 319 service_workers_.erase(handle_id); |
| 287 } | 320 } |
| 288 | 321 |
| 289 } // namespace content | 322 } // namespace content |
| OLD | NEW |