| 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/browser/service_worker/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/message_port_message_filter.h" | 10 #include "content/browser/message_port_message_filter.h" |
| 11 #include "content/browser/message_port_service.h" | 11 #include "content/browser/message_port_service.h" |
| 12 #include "content/browser/service_worker/embedded_worker_registry.h" | 12 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 13 #include "content/browser/service_worker/service_worker_context_core.h" | 13 #include "content/browser/service_worker/service_worker_context_core.h" |
| 14 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 14 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 15 #include "content/browser/service_worker/service_worker_handle.h" | 15 #include "content/browser/service_worker/service_worker_handle.h" |
| 16 #include "content/browser/service_worker/service_worker_metrics.h" |
| 16 #include "content/browser/service_worker/service_worker_registration.h" | 17 #include "content/browser/service_worker/service_worker_registration.h" |
| 17 #include "content/browser/service_worker/service_worker_registration_handle.h" | 18 #include "content/browser/service_worker/service_worker_registration_handle.h" |
| 18 #include "content/browser/service_worker/service_worker_utils.h" | 19 #include "content/browser/service_worker/service_worker_utils.h" |
| 19 #include "content/common/service_worker/embedded_worker_messages.h" | 20 #include "content/common/service_worker/embedded_worker_messages.h" |
| 20 #include "content/common/service_worker/service_worker_messages.h" | 21 #include "content/common/service_worker/service_worker_messages.h" |
| 21 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
| 22 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" | 23 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" |
| 23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 24 | 25 |
| 25 using blink::WebServiceWorkerError; | 26 using blink::WebServiceWorkerError; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (!CanRegisterServiceWorker( | 245 if (!CanRegisterServiceWorker( |
| 245 provider_host->document_url(), pattern, script_url)) { | 246 provider_host->document_url(), pattern, script_url)) { |
| 246 BadMessageReceived(); | 247 BadMessageReceived(); |
| 247 return; | 248 return; |
| 248 } | 249 } |
| 249 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | 250 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", |
| 250 "ServiceWorkerDispatcherHost::RegisterServiceWorker", | 251 "ServiceWorkerDispatcherHost::RegisterServiceWorker", |
| 251 request_id, | 252 request_id, |
| 252 "Pattern", pattern.spec(), | 253 "Pattern", pattern.spec(), |
| 253 "Script URL", script_url.spec()); | 254 "Script URL", script_url.spec()); |
| 255 registration_start_timings_.AddWithID( |
| 256 new base::TimeTicks(base::TimeTicks::Now()), request_id); |
| 257 |
| 254 GetContext()->RegisterServiceWorker( | 258 GetContext()->RegisterServiceWorker( |
| 255 pattern, | 259 pattern, |
| 256 script_url, | 260 script_url, |
| 257 provider_host, | 261 provider_host, |
| 258 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, | 262 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, |
| 259 this, | 263 this, |
| 260 thread_id, | 264 thread_id, |
| 261 provider_id, | 265 provider_id, |
| 262 request_id)); | 266 request_id)); |
| 263 } | 267 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 registration->active_version()); | 476 registration->active_version()); |
| 473 } | 477 } |
| 474 | 478 |
| 475 void ServiceWorkerDispatcherHost::RegistrationComplete( | 479 void ServiceWorkerDispatcherHost::RegistrationComplete( |
| 476 int thread_id, | 480 int thread_id, |
| 477 int provider_id, | 481 int provider_id, |
| 478 int request_id, | 482 int request_id, |
| 479 ServiceWorkerStatusCode status, | 483 ServiceWorkerStatusCode status, |
| 480 int64 registration_id, | 484 int64 registration_id, |
| 481 int64 version_id) { | 485 int64 version_id) { |
| 486 scoped_ptr<base::TimeTicks> registration_start_timing( |
| 487 registration_start_timings_.Lookup(request_id)); |
| 488 registration_start_timings_.Remove(request_id); |
| 489 |
| 482 if (!GetContext()) | 490 if (!GetContext()) |
| 483 return; | 491 return; |
| 484 | 492 |
| 485 if (status != SERVICE_WORKER_OK) { | 493 if (status != SERVICE_WORKER_OK) { |
| 486 SendRegistrationError(thread_id, request_id, status); | 494 SendRegistrationError(thread_id, request_id, status); |
| 487 return; | 495 return; |
| 488 } | 496 } |
| 489 | 497 |
| 490 ServiceWorkerRegistration* registration = | 498 ServiceWorkerRegistration* registration = |
| 491 GetContext()->GetLiveRegistration(registration_id); | 499 GetContext()->GetLiveRegistration(registration_id); |
| 492 DCHECK(registration); | 500 DCHECK(registration); |
| 493 | 501 |
| 494 ServiceWorkerRegistrationObjectInfo info; | 502 ServiceWorkerRegistrationObjectInfo info; |
| 495 ServiceWorkerVersionAttributes attrs; | 503 ServiceWorkerVersionAttributes attrs; |
| 496 GetRegistrationObjectInfoAndVersionAttributes( | 504 GetRegistrationObjectInfoAndVersionAttributes( |
| 497 provider_id, registration, &info, &attrs); | 505 provider_id, registration, &info, &attrs); |
| 498 | 506 |
| 499 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( | 507 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
| 500 thread_id, request_id, info, attrs)); | 508 thread_id, request_id, info, attrs)); |
| 501 TRACE_EVENT_ASYNC_END2("ServiceWorker", | 509 TRACE_EVENT_ASYNC_END2("ServiceWorker", |
| 502 "ServiceWorkerDispatcherHost::RegisterServiceWorker", | 510 "ServiceWorkerDispatcherHost::RegisterServiceWorker", |
| 503 request_id, | 511 request_id, |
| 504 "Registration ID", registration_id, | 512 "Registration ID", registration_id, |
| 505 "Version ID", version_id); | 513 "Version ID", version_id); |
| 514 ServiceWorkerMetrics::MeasureRegistrationTime( |
| 515 base::TimeTicks::Now() - *registration_start_timing); |
| 506 } | 516 } |
| 507 | 517 |
| 508 void ServiceWorkerDispatcherHost::OnWorkerReadyForInspection( | 518 void ServiceWorkerDispatcherHost::OnWorkerReadyForInspection( |
| 509 int embedded_worker_id) { | 519 int embedded_worker_id) { |
| 510 TRACE_EVENT0("ServiceWorker", | 520 TRACE_EVENT0("ServiceWorker", |
| 511 "ServiceWorkerDispatcherHost::OnWorkerReadyForInspection"); | 521 "ServiceWorkerDispatcherHost::OnWorkerReadyForInspection"); |
| 512 if (!GetContext()) | 522 if (!GetContext()) |
| 513 return; | 523 return; |
| 514 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry(); | 524 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry(); |
| 515 if (!registry->CanHandle(embedded_worker_id)) | 525 if (!registry->CanHandle(embedded_worker_id)) |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 status, &error_type, &error_message); | 761 status, &error_type, &error_message); |
| 752 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 762 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
| 753 thread_id, request_id, error_type, error_message)); | 763 thread_id, request_id, error_type, error_message)); |
| 754 } | 764 } |
| 755 | 765 |
| 756 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { | 766 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
| 757 return context_wrapper_->context(); | 767 return context_wrapper_->context(); |
| 758 } | 768 } |
| 759 | 769 |
| 760 } // namespace content | 770 } // namespace content |
| OLD | NEW |