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/debug/trace_event.h" | |
7 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
8 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
9 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
10 #include "content/child/child_thread.h" | 11 #include "content/child/child_thread.h" |
11 #include "content/child/service_worker/service_worker_handle_reference.h" | 12 #include "content/child/service_worker/service_worker_handle_reference.h" |
12 #include "content/child/service_worker/service_worker_provider_context.h" | 13 #include "content/child/service_worker/service_worker_provider_context.h" |
13 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h" | 14 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h" |
14 #include "content/child/service_worker/web_service_worker_impl.h" | 15 #include "content/child/service_worker/web_service_worker_impl.h" |
15 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 16 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
16 #include "content/child/thread_safe_sender.h" | 17 #include "content/child/thread_safe_sender.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { | 91 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { |
91 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | 92 scoped_ptr<WebServiceWorkerRegistrationCallbacks> |
92 owned_callbacks(callbacks); | 93 owned_callbacks(callbacks); |
93 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( | 94 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( |
94 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | 95 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); |
95 callbacks->onError(error.release()); | 96 callbacks->onError(error.release()); |
96 return; | 97 return; |
97 } | 98 } |
98 | 99 |
99 int request_id = pending_registration_callbacks_.Add(callbacks); | 100 int request_id = pending_registration_callbacks_.Add(callbacks); |
101 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | |
102 "ServiceWorkerDispatcher::RegisterServiceWorker", | |
103 request_id, | |
104 "Pettern", pattern.spec(), | |
105 "Script URL", script_url.spec()); | |
100 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 106 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
101 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); | 107 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); |
102 } | 108 } |
103 | 109 |
104 void ServiceWorkerDispatcher::UnregisterServiceWorker( | 110 void ServiceWorkerDispatcher::UnregisterServiceWorker( |
105 int provider_id, | 111 int provider_id, |
106 const GURL& pattern, | 112 const GURL& pattern, |
107 WebServiceWorkerUnregistrationCallbacks* callbacks) { | 113 WebServiceWorkerUnregistrationCallbacks* callbacks) { |
108 DCHECK(callbacks); | 114 DCHECK(callbacks); |
109 | 115 |
110 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { | 116 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { |
111 scoped_ptr<WebServiceWorkerUnregistrationCallbacks> | 117 scoped_ptr<WebServiceWorkerUnregistrationCallbacks> |
112 owned_callbacks(callbacks); | 118 owned_callbacks(callbacks); |
113 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( | 119 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( |
114 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | 120 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); |
115 callbacks->onError(error.release()); | 121 callbacks->onError(error.release()); |
116 return; | 122 return; |
117 } | 123 } |
118 | 124 |
119 int request_id = pending_unregistration_callbacks_.Add(callbacks); | 125 int request_id = pending_unregistration_callbacks_.Add(callbacks); |
126 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | |
127 "ServiceWorkerDispatcher::UnregisterServiceWorker", | |
128 request_id, | |
129 "Pettern", pattern.spec()); | |
120 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 130 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
121 CurrentWorkerId(), request_id, provider_id, pattern)); | 131 CurrentWorkerId(), request_id, provider_id, pattern)); |
122 } | 132 } |
123 | 133 |
124 void ServiceWorkerDispatcher::AddProviderContext( | 134 void ServiceWorkerDispatcher::AddProviderContext( |
125 ServiceWorkerProviderContext* provider_context) { | 135 ServiceWorkerProviderContext* provider_context) { |
126 DCHECK(provider_context); | 136 DCHECK(provider_context); |
127 int provider_id = provider_context->provider_id(); | 137 int provider_id = provider_context->provider_id(); |
128 DCHECK(!ContainsKey(provider_contexts_, provider_id)); | 138 DCHECK(!ContainsKey(provider_contexts_, provider_id)); |
129 provider_contexts_[provider_id] = provider_context; | 139 provider_contexts_[provider_id] = provider_context; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 // WebServiceWorkerRegistrationImpl constructor calls | 247 // WebServiceWorkerRegistrationImpl constructor calls |
238 // AddServiceWorkerRegistration. | 248 // AddServiceWorkerRegistration. |
239 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); | 249 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); |
240 } | 250 } |
241 | 251 |
242 void ServiceWorkerDispatcher::OnRegistered( | 252 void ServiceWorkerDispatcher::OnRegistered( |
243 int thread_id, | 253 int thread_id, |
244 int request_id, | 254 int request_id, |
245 const ServiceWorkerRegistrationObjectInfo& info, | 255 const ServiceWorkerRegistrationObjectInfo& info, |
246 const ServiceWorkerVersionAttributes& attrs) { | 256 const ServiceWorkerVersionAttributes& attrs) { |
257 TRACE_EVENT0("ServiceWorker", | |
horo
2014/09/05 11:02:32
TRACE_EVENT_ASYNC_STEP is better.
shimazu
2014/09/08 07:04:46
Done.
| |
258 "ServiceWorkerDispatcher::OnRegistered"); | |
247 WebServiceWorkerRegistrationCallbacks* callbacks = | 259 WebServiceWorkerRegistrationCallbacks* callbacks = |
248 pending_registration_callbacks_.Lookup(request_id); | 260 pending_registration_callbacks_.Lookup(request_id); |
249 DCHECK(callbacks); | 261 DCHECK(callbacks); |
250 if (!callbacks) | 262 if (!callbacks) |
251 return; | 263 return; |
252 | 264 |
253 WebServiceWorkerRegistrationImpl* registration = | 265 WebServiceWorkerRegistrationImpl* registration = |
254 GetServiceWorkerRegistration(info, true); | 266 GetServiceWorkerRegistration(info, true); |
255 registration->SetInstalling(GetServiceWorker(attrs.installing, true)); | 267 registration->SetInstalling(GetServiceWorker(attrs.installing, true)); |
256 registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); | 268 registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); |
257 registration->SetActive(GetServiceWorker(attrs.active, true)); | 269 registration->SetActive(GetServiceWorker(attrs.active, true)); |
258 | 270 |
259 callbacks->onSuccess(registration); | 271 callbacks->onSuccess(registration); |
260 pending_registration_callbacks_.Remove(request_id); | 272 pending_registration_callbacks_.Remove(request_id); |
273 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
274 "ServiceWorkerDispatcher::RegisterServiceWorker", | |
275 request_id); | |
261 } | 276 } |
262 | 277 |
263 void ServiceWorkerDispatcher::OnUnregistered( | 278 void ServiceWorkerDispatcher::OnUnregistered( |
264 int thread_id, | 279 int thread_id, |
265 int request_id) { | 280 int request_id) { |
266 WebServiceWorkerUnregistrationCallbacks* callbacks = | 281 WebServiceWorkerUnregistrationCallbacks* callbacks = |
267 pending_unregistration_callbacks_.Lookup(request_id); | 282 pending_unregistration_callbacks_.Lookup(request_id); |
283 TRACE_EVENT0("ServiceWorker", | |
horo
2014/09/05 11:02:32
TRACE_EVENT_ASYNC_STEP is better.
shimazu
2014/09/08 07:04:46
Done.
| |
284 "ServiceWorkerDispatcher::OnUnregistered"); | |
268 DCHECK(callbacks); | 285 DCHECK(callbacks); |
269 if (!callbacks) | 286 if (!callbacks) |
270 return; | 287 return; |
271 bool is_success = true; | 288 bool is_success = true; |
272 callbacks->onSuccess(&is_success); | 289 callbacks->onSuccess(&is_success); |
273 pending_unregistration_callbacks_.Remove(request_id); | 290 pending_unregistration_callbacks_.Remove(request_id); |
291 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
292 "ServiceWorkerDispatcher::UnregisterServiceWorker", | |
293 request_id); | |
274 } | 294 } |
275 | 295 |
276 void ServiceWorkerDispatcher::OnRegistrationError( | 296 void ServiceWorkerDispatcher::OnRegistrationError( |
277 int thread_id, | 297 int thread_id, |
278 int request_id, | 298 int request_id, |
279 WebServiceWorkerError::ErrorType error_type, | 299 WebServiceWorkerError::ErrorType error_type, |
280 const base::string16& message) { | 300 const base::string16& message) { |
301 TRACE_EVENT0("ServiceWorker", | |
horo
2014/09/05 11:02:32
TRACE_EVENT_ASYNC_STEP
shimazu
2014/09/08 07:04:46
Done.
| |
302 "ServiceWorkerDispatcher::OnRegistrationError"); | |
281 WebServiceWorkerRegistrationCallbacks* callbacks = | 303 WebServiceWorkerRegistrationCallbacks* callbacks = |
282 pending_registration_callbacks_.Lookup(request_id); | 304 pending_registration_callbacks_.Lookup(request_id); |
283 DCHECK(callbacks); | 305 DCHECK(callbacks); |
284 if (!callbacks) | 306 if (!callbacks) |
285 return; | 307 return; |
286 | 308 |
287 scoped_ptr<WebServiceWorkerError> error( | 309 scoped_ptr<WebServiceWorkerError> error( |
288 new WebServiceWorkerError(error_type, message)); | 310 new WebServiceWorkerError(error_type, message)); |
289 callbacks->onError(error.release()); | 311 callbacks->onError(error.release()); |
290 pending_registration_callbacks_.Remove(request_id); | 312 pending_registration_callbacks_.Remove(request_id); |
291 } | 313 } |
horo
2014/09/05 11:02:32
TRACE_EVENT_ASYNC_END
shimazu
2014/09/08 07:04:46
Done.
| |
292 | 314 |
293 void ServiceWorkerDispatcher::OnUnregistrationError( | 315 void ServiceWorkerDispatcher::OnUnregistrationError( |
294 int thread_id, | 316 int thread_id, |
295 int request_id, | 317 int request_id, |
296 WebServiceWorkerError::ErrorType error_type, | 318 WebServiceWorkerError::ErrorType error_type, |
297 const base::string16& message) { | 319 const base::string16& message) { |
320 TRACE_EVENT0("ServiceWorker", | |
horo
2014/09/05 11:02:32
TRACE_EVENT_ASYNC_STEP
shimazu
2014/09/08 07:04:46
Done.
| |
321 "ServiceWorkerDispatcher::OnUnregistrationError"); | |
298 WebServiceWorkerUnregistrationCallbacks* callbacks = | 322 WebServiceWorkerUnregistrationCallbacks* callbacks = |
299 pending_unregistration_callbacks_.Lookup(request_id); | 323 pending_unregistration_callbacks_.Lookup(request_id); |
300 DCHECK(callbacks); | 324 DCHECK(callbacks); |
301 if (!callbacks) | 325 if (!callbacks) |
302 return; | 326 return; |
303 | 327 |
304 scoped_ptr<WebServiceWorkerError> error( | 328 scoped_ptr<WebServiceWorkerError> error( |
305 new WebServiceWorkerError(error_type, message)); | 329 new WebServiceWorkerError(error_type, message)); |
306 callbacks->onError(error.release()); | 330 callbacks->onError(error.release()); |
307 pending_unregistration_callbacks_.Remove(request_id); | 331 pending_unregistration_callbacks_.Remove(request_id); |
308 } | 332 } |
horo
2014/09/05 11:02:32
TRACE_EVENT_ASYNC_END
shimazu
2014/09/08 07:04:46
Done.
| |
309 | 333 |
310 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( | 334 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( |
311 int thread_id, | 335 int thread_id, |
312 int handle_id, | 336 int handle_id, |
313 blink::WebServiceWorkerState state) { | 337 blink::WebServiceWorkerState state) { |
338 TRACE_EVENT2("ServiceWorker", | |
339 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", | |
340 "Thread ID", thread_id, | |
341 "State", state); | |
314 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); | 342 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); |
315 if (worker != service_workers_.end()) | 343 if (worker != service_workers_.end()) |
316 worker->second->OnStateChanged(state); | 344 worker->second->OnStateChanged(state); |
317 | 345 |
318 WorkerToProviderMap::iterator provider = worker_to_provider_.find(handle_id); | 346 WorkerToProviderMap::iterator provider = worker_to_provider_.find(handle_id); |
319 if (provider != worker_to_provider_.end()) | 347 if (provider != worker_to_provider_.end()) |
320 provider->second->OnServiceWorkerStateChanged(handle_id, state); | 348 provider->second->OnServiceWorkerStateChanged(handle_id, state); |
321 } | 349 } |
322 | 350 |
323 void ServiceWorkerDispatcher::OnSetVersionAttributes( | 351 void ServiceWorkerDispatcher::OnSetVersionAttributes( |
324 int thread_id, | 352 int thread_id, |
325 int provider_id, | 353 int provider_id, |
326 int registration_handle_id, | 354 int registration_handle_id, |
327 int changed_mask, | 355 int changed_mask, |
328 const ServiceWorkerVersionAttributes& attributes) { | 356 const ServiceWorkerVersionAttributes& attributes) { |
357 TRACE_EVENT1("ServiceWorker", | |
358 "ServiceWorkerDispatcher::OnSetVersionAttributes", | |
359 "Thread ID", thread_id); | |
329 ChangedVersionAttributesMask mask(changed_mask); | 360 ChangedVersionAttributesMask mask(changed_mask); |
330 if (mask.installing_changed()) { | 361 if (mask.installing_changed()) { |
331 SetInstallingServiceWorker(provider_id, | 362 SetInstallingServiceWorker(provider_id, |
332 registration_handle_id, | 363 registration_handle_id, |
333 attributes.installing); | 364 attributes.installing); |
334 } | 365 } |
335 if (mask.waiting_changed()) { | 366 if (mask.waiting_changed()) { |
336 SetWaitingServiceWorker(provider_id, | 367 SetWaitingServiceWorker(provider_id, |
337 registration_handle_id, | 368 registration_handle_id, |
338 attributes.waiting); | 369 attributes.waiting); |
339 } | 370 } |
340 if (mask.active_changed()) { | 371 if (mask.active_changed()) { |
341 SetActiveServiceWorker(provider_id, | 372 SetActiveServiceWorker(provider_id, |
342 registration_handle_id, | 373 registration_handle_id, |
343 attributes.active); | 374 attributes.active); |
344 } | 375 } |
345 } | 376 } |
346 | 377 |
347 void ServiceWorkerDispatcher::OnUpdateFound( | 378 void ServiceWorkerDispatcher::OnUpdateFound( |
348 int thread_id, | 379 int thread_id, |
349 const ServiceWorkerRegistrationObjectInfo& info) { | 380 const ServiceWorkerRegistrationObjectInfo& info) { |
381 TRACE_EVENT0("ServiceWorker", | |
382 "ServiceWorkerDispatcher::OnUpdateFound"); | |
350 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); | 383 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); |
351 if (found != registrations_.end()) | 384 if (found != registrations_.end()) |
352 found->second->OnUpdateFound(); | 385 found->second->OnUpdateFound(); |
353 } | 386 } |
354 | 387 |
355 void ServiceWorkerDispatcher::SetInstallingServiceWorker( | 388 void ServiceWorkerDispatcher::SetInstallingServiceWorker( |
356 int provider_id, | 389 int provider_id, |
357 int registration_handle_id, | 390 int registration_handle_id, |
358 const ServiceWorkerObjectInfo& info) { | 391 const ServiceWorkerObjectInfo& info) { |
359 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 392 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 if (found != registrations_.end()) { | 466 if (found != registrations_.end()) { |
434 // Populate the .active field with the new worker object. | 467 // Populate the .active field with the new worker object. |
435 found->second->SetActive(GetServiceWorker(info, false)); | 468 found->second->SetActive(GetServiceWorker(info, false)); |
436 } | 469 } |
437 } | 470 } |
438 | 471 |
439 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( | 472 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( |
440 int thread_id, | 473 int thread_id, |
441 int provider_id, | 474 int provider_id, |
442 const ServiceWorkerObjectInfo& info) { | 475 const ServiceWorkerObjectInfo& info) { |
476 TRACE_EVENT2("ServiceWorker", | |
477 "ServiceWorkerDispatcher::OnSetControllerServiceWorker", | |
478 "Thread ID", thread_id, | |
479 "Provider ID", provider_id); | |
443 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 480 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
444 if (provider != provider_contexts_.end()) { | 481 if (provider != provider_contexts_.end()) { |
445 provider->second->OnSetControllerServiceWorker(provider_id, info); | 482 provider->second->OnSetControllerServiceWorker(provider_id, info); |
446 worker_to_provider_[info.handle_id] = provider->second; | 483 worker_to_provider_[info.handle_id] = provider->second; |
447 } | 484 } |
448 | 485 |
449 ScriptClientMap::iterator found = script_clients_.find(provider_id); | 486 ScriptClientMap::iterator found = script_clients_.find(provider_id); |
450 if (found != script_clients_.end()) { | 487 if (found != script_clients_.end()) { |
451 // Populate the .controller field with the new worker object. | 488 // Populate the .controller field with the new worker object. |
452 found->second->setController(GetServiceWorker(info, false)); | 489 found->second->setController(GetServiceWorker(info, false)); |
453 } | 490 } |
454 } | 491 } |
455 | 492 |
456 void ServiceWorkerDispatcher::OnPostMessage( | 493 void ServiceWorkerDispatcher::OnPostMessage( |
457 int thread_id, | 494 int thread_id, |
458 int provider_id, | 495 int provider_id, |
459 const base::string16& message, | 496 const base::string16& message, |
460 const std::vector<int>& sent_message_port_ids, | 497 const std::vector<int>& sent_message_port_ids, |
461 const std::vector<int>& new_routing_ids) { | 498 const std::vector<int>& new_routing_ids) { |
462 // Make sure we're on the main document thread. (That must be the only | 499 // Make sure we're on the main document thread. (That must be the only |
463 // thread we get this message) | 500 // thread we get this message) |
464 DCHECK(ChildThread::current()); | 501 DCHECK(ChildThread::current()); |
502 TRACE_EVENT1("ServiceWorker", | |
503 "ServiceWorkerDispatcher::OnPostMessage", | |
504 "Thread ID", thread_id); | |
465 | 505 |
466 ScriptClientMap::iterator found = script_clients_.find(provider_id); | 506 ScriptClientMap::iterator found = script_clients_.find(provider_id); |
467 if (found == script_clients_.end()) { | 507 if (found == script_clients_.end()) { |
468 // For now we do no queueing for messages sent to nonexistent / unattached | 508 // For now we do no queueing for messages sent to nonexistent / unattached |
469 // client. | 509 // client. |
470 return; | 510 return; |
471 } | 511 } |
472 | 512 |
473 std::vector<WebMessagePortChannelImpl*> ports; | 513 std::vector<WebMessagePortChannelImpl*> ports; |
474 if (!sent_message_port_ids.empty()) { | 514 if (!sent_message_port_ids.empty()) { |
(...skipping 26 matching lines...) Expand all Loading... | |
501 registrations_[registration_handle_id] = registration; | 541 registrations_[registration_handle_id] = registration; |
502 } | 542 } |
503 | 543 |
504 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 544 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
505 int registration_handle_id) { | 545 int registration_handle_id) { |
506 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 546 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
507 registrations_.erase(registration_handle_id); | 547 registrations_.erase(registration_handle_id); |
508 } | 548 } |
509 | 549 |
510 } // namespace content | 550 } // namespace content |
OLD | NEW |