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/debug/trace_event.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( | 102 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( |
103 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | 103 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); |
104 callbacks->onError(error.release()); | 104 callbacks->onError(error.release()); |
105 return; | 105 return; |
106 } | 106 } |
107 | 107 |
108 int request_id = pending_registration_callbacks_.Add(callbacks); | 108 int request_id = pending_registration_callbacks_.Add(callbacks); |
109 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | 109 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", |
110 "ServiceWorkerDispatcher::RegisterServiceWorker", | 110 "ServiceWorkerDispatcher::RegisterServiceWorker", |
111 request_id, | 111 request_id, |
112 "Pettern", pattern.spec(), | 112 "Scope", pattern.spec(), |
113 "Script URL", script_url.spec()); | 113 "Script URL", script_url.spec()); |
114 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 114 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
115 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); | 115 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); |
116 } | 116 } |
117 | 117 |
118 void ServiceWorkerDispatcher::UnregisterServiceWorker( | 118 void ServiceWorkerDispatcher::UnregisterServiceWorker( |
119 int provider_id, | 119 int provider_id, |
120 const GURL& pattern, | 120 const GURL& pattern, |
121 WebServiceWorkerUnregistrationCallbacks* callbacks) { | 121 WebServiceWorkerUnregistrationCallbacks* callbacks) { |
122 DCHECK(callbacks); | 122 DCHECK(callbacks); |
123 | 123 |
124 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { | 124 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { |
125 scoped_ptr<WebServiceWorkerUnregistrationCallbacks> | 125 scoped_ptr<WebServiceWorkerUnregistrationCallbacks> |
126 owned_callbacks(callbacks); | 126 owned_callbacks(callbacks); |
127 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( | 127 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( |
128 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | 128 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); |
129 callbacks->onError(error.release()); | 129 callbacks->onError(error.release()); |
130 return; | 130 return; |
131 } | 131 } |
132 | 132 |
133 int request_id = pending_unregistration_callbacks_.Add(callbacks); | 133 int request_id = pending_unregistration_callbacks_.Add(callbacks); |
134 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 134 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
135 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 135 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
136 request_id, | 136 request_id, |
137 "Pettern", pattern.spec()); | 137 "Scope", pattern.spec()); |
138 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 138 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
139 CurrentWorkerId(), request_id, provider_id, pattern)); | 139 CurrentWorkerId(), request_id, provider_id, pattern)); |
140 } | 140 } |
141 | 141 |
142 void ServiceWorkerDispatcher::GetRegistration( | 142 void ServiceWorkerDispatcher::GetRegistration( |
143 int provider_id, | 143 int provider_id, |
144 const GURL& document_url, | 144 const GURL& document_url, |
145 WebServiceWorkerRegistrationCallbacks* callbacks) { | 145 WebServiceWorkerRegistrationCallbacks* callbacks) { |
146 DCHECK(callbacks); | 146 DCHECK(callbacks); |
147 | 147 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 318 |
319 void ServiceWorkerDispatcher::OnRegistered( | 319 void ServiceWorkerDispatcher::OnRegistered( |
320 int thread_id, | 320 int thread_id, |
321 int request_id, | 321 int request_id, |
322 const ServiceWorkerRegistrationObjectInfo& info, | 322 const ServiceWorkerRegistrationObjectInfo& info, |
323 const ServiceWorkerVersionAttributes& attrs) { | 323 const ServiceWorkerVersionAttributes& attrs) { |
324 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", | 324 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", |
325 "ServiceWorkerDispatcher::RegisterServiceWorker", | 325 "ServiceWorkerDispatcher::RegisterServiceWorker", |
326 request_id, | 326 request_id, |
327 "OnRegistered"); | 327 "OnRegistered"); |
| 328 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 329 "ServiceWorkerDispatcher::RegisterServiceWorker", |
| 330 request_id); |
328 WebServiceWorkerRegistrationCallbacks* callbacks = | 331 WebServiceWorkerRegistrationCallbacks* callbacks = |
329 pending_registration_callbacks_.Lookup(request_id); | 332 pending_registration_callbacks_.Lookup(request_id); |
330 DCHECK(callbacks); | 333 DCHECK(callbacks); |
331 if (!callbacks) | 334 if (!callbacks) |
332 return; | 335 return; |
333 | 336 |
334 callbacks->onSuccess(FindOrCreateRegistration(info, attrs)); | 337 callbacks->onSuccess(FindOrCreateRegistration(info, attrs)); |
335 pending_registration_callbacks_.Remove(request_id); | 338 pending_registration_callbacks_.Remove(request_id); |
336 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
337 "ServiceWorkerDispatcher::RegisterServiceWorker", | |
338 request_id); | |
339 } | 339 } |
340 | 340 |
341 void ServiceWorkerDispatcher::OnUnregistered(int thread_id, | 341 void ServiceWorkerDispatcher::OnUnregistered(int thread_id, |
342 int request_id, | 342 int request_id, |
343 bool is_success) { | 343 bool is_success) { |
344 WebServiceWorkerUnregistrationCallbacks* callbacks = | |
345 pending_unregistration_callbacks_.Lookup(request_id); | |
346 TRACE_EVENT_ASYNC_STEP_INTO0( | 344 TRACE_EVENT_ASYNC_STEP_INTO0( |
347 "ServiceWorker", | 345 "ServiceWorker", |
348 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 346 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
349 request_id, | 347 request_id, |
350 "OnUnregistered"); | 348 "OnUnregistered"); |
| 349 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 350 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
| 351 request_id); |
| 352 WebServiceWorkerUnregistrationCallbacks* callbacks = |
| 353 pending_unregistration_callbacks_.Lookup(request_id); |
351 DCHECK(callbacks); | 354 DCHECK(callbacks); |
352 if (!callbacks) | 355 if (!callbacks) |
353 return; | 356 return; |
354 callbacks->onSuccess(&is_success); | 357 callbacks->onSuccess(&is_success); |
355 pending_unregistration_callbacks_.Remove(request_id); | 358 pending_unregistration_callbacks_.Remove(request_id); |
356 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
357 "ServiceWorkerDispatcher::UnregisterServiceWorker", | |
358 request_id); | |
359 } | 359 } |
360 | 360 |
361 void ServiceWorkerDispatcher::OnDidGetRegistration( | 361 void ServiceWorkerDispatcher::OnDidGetRegistration( |
362 int thread_id, | 362 int thread_id, |
363 int request_id, | 363 int request_id, |
364 const ServiceWorkerRegistrationObjectInfo& info, | 364 const ServiceWorkerRegistrationObjectInfo& info, |
365 const ServiceWorkerVersionAttributes& attrs) { | 365 const ServiceWorkerVersionAttributes& attrs) { |
366 WebServiceWorkerRegistrationCallbacks* callbacks = | |
367 pending_get_registration_callbacks_.Lookup(request_id); | |
368 TRACE_EVENT_ASYNC_STEP_INTO0( | 366 TRACE_EVENT_ASYNC_STEP_INTO0( |
369 "ServiceWorker", | 367 "ServiceWorker", |
370 "ServiceWorkerDispatcher::GetRegistration", | 368 "ServiceWorkerDispatcher::GetRegistration", |
371 request_id, | 369 request_id, |
372 "OnDidGetRegistration"); | 370 "OnDidGetRegistration"); |
| 371 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 372 "ServiceWorkerDispatcher::GetRegistration", |
| 373 request_id); |
| 374 WebServiceWorkerRegistrationCallbacks* callbacks = |
| 375 pending_get_registration_callbacks_.Lookup(request_id); |
373 DCHECK(callbacks); | 376 DCHECK(callbacks); |
374 if (!callbacks) | 377 if (!callbacks) |
375 return; | 378 return; |
376 | 379 |
377 WebServiceWorkerRegistrationImpl* registration = NULL; | 380 WebServiceWorkerRegistrationImpl* registration = NULL; |
378 if (info.handle_id != kInvalidServiceWorkerHandleId) | 381 if (info.handle_id != kInvalidServiceWorkerHandleId) |
379 registration = FindOrCreateRegistration(info, attrs); | 382 registration = FindOrCreateRegistration(info, attrs); |
380 | 383 |
381 callbacks->onSuccess(registration); | 384 callbacks->onSuccess(registration); |
382 pending_get_registration_callbacks_.Remove(request_id); | 385 pending_get_registration_callbacks_.Remove(request_id); |
383 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
384 "ServiceWorkerDispatcher::GetRegistration", | |
385 request_id); | |
386 } | 386 } |
387 | 387 |
388 void ServiceWorkerDispatcher::OnRegistrationError( | 388 void ServiceWorkerDispatcher::OnRegistrationError( |
389 int thread_id, | 389 int thread_id, |
390 int request_id, | 390 int request_id, |
391 WebServiceWorkerError::ErrorType error_type, | 391 WebServiceWorkerError::ErrorType error_type, |
392 const base::string16& message) { | 392 const base::string16& message) { |
393 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", | 393 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", |
394 "ServiceWorkerDispatcher::RegisterServiceWorker", | 394 "ServiceWorkerDispatcher::RegisterServiceWorker", |
395 request_id, | 395 request_id, |
396 "OnRegistrationError"); | 396 "OnRegistrationError"); |
| 397 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 398 "ServiceWorkerDispatcher::RegisterServiceWorker", |
| 399 request_id); |
397 WebServiceWorkerRegistrationCallbacks* callbacks = | 400 WebServiceWorkerRegistrationCallbacks* callbacks = |
398 pending_registration_callbacks_.Lookup(request_id); | 401 pending_registration_callbacks_.Lookup(request_id); |
399 DCHECK(callbacks); | 402 DCHECK(callbacks); |
400 if (!callbacks) | 403 if (!callbacks) |
401 return; | 404 return; |
402 | 405 |
403 scoped_ptr<WebServiceWorkerError> error( | 406 scoped_ptr<WebServiceWorkerError> error( |
404 new WebServiceWorkerError(error_type, message)); | 407 new WebServiceWorkerError(error_type, message)); |
405 callbacks->onError(error.release()); | 408 callbacks->onError(error.release()); |
406 pending_registration_callbacks_.Remove(request_id); | 409 pending_registration_callbacks_.Remove(request_id); |
407 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
408 "ServiceWorkerDispatcher::RegisterServiceWorker", | |
409 request_id); | |
410 } | 410 } |
411 | 411 |
412 void ServiceWorkerDispatcher::OnUnregistrationError( | 412 void ServiceWorkerDispatcher::OnUnregistrationError( |
413 int thread_id, | 413 int thread_id, |
414 int request_id, | 414 int request_id, |
415 WebServiceWorkerError::ErrorType error_type, | 415 WebServiceWorkerError::ErrorType error_type, |
416 const base::string16& message) { | 416 const base::string16& message) { |
417 TRACE_EVENT_ASYNC_STEP_INTO0( | 417 TRACE_EVENT_ASYNC_STEP_INTO0( |
418 "ServiceWorker", | 418 "ServiceWorker", |
419 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 419 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
420 request_id, | 420 request_id, |
421 "OnUnregistrationError"); | 421 "OnUnregistrationError"); |
| 422 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 423 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
| 424 request_id); |
422 WebServiceWorkerUnregistrationCallbacks* callbacks = | 425 WebServiceWorkerUnregistrationCallbacks* callbacks = |
423 pending_unregistration_callbacks_.Lookup(request_id); | 426 pending_unregistration_callbacks_.Lookup(request_id); |
424 DCHECK(callbacks); | 427 DCHECK(callbacks); |
425 if (!callbacks) | 428 if (!callbacks) |
426 return; | 429 return; |
427 | 430 |
428 scoped_ptr<WebServiceWorkerError> error( | 431 scoped_ptr<WebServiceWorkerError> error( |
429 new WebServiceWorkerError(error_type, message)); | 432 new WebServiceWorkerError(error_type, message)); |
430 callbacks->onError(error.release()); | 433 callbacks->onError(error.release()); |
431 pending_unregistration_callbacks_.Remove(request_id); | 434 pending_unregistration_callbacks_.Remove(request_id); |
432 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
433 "ServiceWorkerDispatcher::UnregisterServiceWorker", | |
434 request_id); | |
435 } | 435 } |
436 | 436 |
437 void ServiceWorkerDispatcher::OnGetRegistrationError( | 437 void ServiceWorkerDispatcher::OnGetRegistrationError( |
438 int thread_id, | 438 int thread_id, |
439 int request_id, | 439 int request_id, |
440 WebServiceWorkerError::ErrorType error_type, | 440 WebServiceWorkerError::ErrorType error_type, |
441 const base::string16& message) { | 441 const base::string16& message) { |
442 TRACE_EVENT_ASYNC_STEP_INTO0( | 442 TRACE_EVENT_ASYNC_STEP_INTO0( |
443 "ServiceWorker", | 443 "ServiceWorker", |
444 "ServiceWorkerDispatcher::GetRegistration", | 444 "ServiceWorkerDispatcher::GetRegistration", |
445 request_id, | 445 request_id, |
446 "OnGetRegistrationError"); | 446 "OnGetRegistrationError"); |
| 447 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 448 "ServiceWorkerDispatcher::GetRegistration", |
| 449 request_id); |
447 WebServiceWorkerGetRegistrationCallbacks* callbacks = | 450 WebServiceWorkerGetRegistrationCallbacks* callbacks = |
448 pending_get_registration_callbacks_.Lookup(request_id); | 451 pending_get_registration_callbacks_.Lookup(request_id); |
449 DCHECK(callbacks); | 452 DCHECK(callbacks); |
450 if (!callbacks) | 453 if (!callbacks) |
451 return; | 454 return; |
452 | 455 |
453 scoped_ptr<WebServiceWorkerError> error( | 456 scoped_ptr<WebServiceWorkerError> error( |
454 new WebServiceWorkerError(error_type, message)); | 457 new WebServiceWorkerError(error_type, message)); |
455 callbacks->onError(error.release()); | 458 callbacks->onError(error.release()); |
456 pending_get_registration_callbacks_.Remove(request_id); | 459 pending_get_registration_callbacks_.Remove(request_id); |
457 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
458 "ServiceWorkerDispatcher::GetRegistration", | |
459 request_id); | |
460 } | 460 } |
461 | 461 |
462 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( | 462 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( |
463 int thread_id, | 463 int thread_id, |
464 int handle_id, | 464 int handle_id, |
465 blink::WebServiceWorkerState state) { | 465 blink::WebServiceWorkerState state) { |
466 TRACE_EVENT2("ServiceWorker", | 466 TRACE_EVENT2("ServiceWorker", |
467 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", | 467 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", |
468 "Thread ID", thread_id, | 468 "Thread ID", thread_id, |
469 "State", state); | 469 "State", state); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 attrs.installing, thread_safe_sender_.get()); | 730 attrs.installing, thread_safe_sender_.get()); |
731 ServiceWorkerHandleReference::Adopt( | 731 ServiceWorkerHandleReference::Adopt( |
732 attrs.waiting, thread_safe_sender_.get()); | 732 attrs.waiting, thread_safe_sender_.get()); |
733 ServiceWorkerHandleReference::Adopt( | 733 ServiceWorkerHandleReference::Adopt( |
734 attrs.active, thread_safe_sender_.get()); | 734 attrs.active, thread_safe_sender_.get()); |
735 } | 735 } |
736 return registration; | 736 return registration; |
737 } | 737 } |
738 | 738 |
739 } // namespace content | 739 } // namespace content |
OLD | NEW |