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_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 } | 359 } |
360 NOTREACHED() << "Unexpected status: " << status; | 360 NOTREACHED() << "Unexpected status: " << status; |
361 return false; | 361 return false; |
362 } | 362 } |
363 | 363 |
364 } // namespace | 364 } // namespace |
365 | 365 |
366 const int ServiceWorkerVersion::kStartWorkerTimeoutMinutes = 5; | 366 const int ServiceWorkerVersion::kStartWorkerTimeoutMinutes = 5; |
367 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5; | 367 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5; |
368 | 368 |
| 369 class ServiceWorkerVersion::ServiceWorkerEventMetrics { |
| 370 public: |
| 371 ServiceWorkerEventMetrics() {} |
| 372 ~ServiceWorkerEventMetrics() { |
| 373 ServiceWorkerMetrics::RecordEventStatus(fired_events, handled_events); |
| 374 } |
| 375 |
| 376 void RecordEventStatus(bool handled) { |
| 377 ++fired_events; |
| 378 if (handled) |
| 379 ++handled_events; |
| 380 } |
| 381 |
| 382 private: |
| 383 size_t fired_events = 0; |
| 384 size_t handled_events = 0; |
| 385 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerEventMetrics); |
| 386 }; |
| 387 |
369 ServiceWorkerVersion::ServiceWorkerVersion( | 388 ServiceWorkerVersion::ServiceWorkerVersion( |
370 ServiceWorkerRegistration* registration, | 389 ServiceWorkerRegistration* registration, |
371 const GURL& script_url, | 390 const GURL& script_url, |
372 int64 version_id, | 391 int64 version_id, |
373 base::WeakPtr<ServiceWorkerContextCore> context) | 392 base::WeakPtr<ServiceWorkerContextCore> context) |
374 : version_id_(version_id), | 393 : version_id_(version_id), |
375 registration_id_(registration->id()), | 394 registration_id_(registration->id()), |
376 script_url_(script_url), | 395 script_url_(script_url), |
377 scope_(registration->pattern()), | 396 scope_(registration->pattern()), |
378 status_(NEW), | 397 status_(NEW), |
379 context_(context), | 398 context_(context), |
380 script_cache_map_(this, context), | 399 script_cache_map_(this, context), |
381 ping_state_(NOT_PINGING), | 400 ping_state_(NOT_PINGING), |
| 401 metrics_(new ServiceWorkerEventMetrics), |
382 weak_factory_(this) { | 402 weak_factory_(this) { |
383 DCHECK(context_); | 403 DCHECK(context_); |
384 DCHECK(registration); | 404 DCHECK(registration); |
385 context_->AddLiveVersion(this); | 405 context_->AddLiveVersion(this); |
386 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); | 406 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); |
387 embedded_worker_->AddListener(this); | 407 embedded_worker_->AddListener(this); |
388 } | 408 } |
389 | 409 |
390 ServiceWorkerVersion::~ServiceWorkerVersion() { | 410 ServiceWorkerVersion::~ServiceWorkerVersion() { |
391 // The user may have closed the tab waiting for SW to start up. | 411 // The user may have closed the tab waiting for SW to start up. |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 const ServiceWorkerResponse& response) { | 1198 const ServiceWorkerResponse& response) { |
1179 TRACE_EVENT1("ServiceWorker", | 1199 TRACE_EVENT1("ServiceWorker", |
1180 "ServiceWorkerVersion::OnFetchEventFinished", | 1200 "ServiceWorkerVersion::OnFetchEventFinished", |
1181 "Request id", request_id); | 1201 "Request id", request_id); |
1182 FetchCallback* callback = fetch_callbacks_.Lookup(request_id); | 1202 FetchCallback* callback = fetch_callbacks_.Lookup(request_id); |
1183 if (!callback) { | 1203 if (!callback) { |
1184 NOTREACHED() << "Got unexpected message: " << request_id; | 1204 NOTREACHED() << "Got unexpected message: " << request_id; |
1185 return; | 1205 return; |
1186 } | 1206 } |
1187 | 1207 |
| 1208 // TODO(kinuko): Record other event statuses too. |
| 1209 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); |
| 1210 metrics_->RecordEventStatus(handled); |
| 1211 |
1188 scoped_refptr<ServiceWorkerVersion> protect(this); | 1212 scoped_refptr<ServiceWorkerVersion> protect(this); |
1189 callback->Run(SERVICE_WORKER_OK, result, response); | 1213 callback->Run(SERVICE_WORKER_OK, result, response); |
1190 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); | 1214 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); |
1191 } | 1215 } |
1192 | 1216 |
1193 void ServiceWorkerVersion::OnSyncEventFinished( | 1217 void ServiceWorkerVersion::OnSyncEventFinished( |
1194 int request_id) { | 1218 int request_id) { |
1195 TRACE_EVENT1("ServiceWorker", | 1219 TRACE_EVENT1("ServiceWorker", |
1196 "ServiceWorkerVersion::OnSyncEventFinished", | 1220 "ServiceWorkerVersion::OnSyncEventFinished", |
1197 "Request id", request_id); | 1221 "Request id", request_id); |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1878 return SERVICE_WORKER_ERROR_ABORT; | 1902 return SERVICE_WORKER_ERROR_ABORT; |
1879 default: | 1903 default: |
1880 return SERVICE_WORKER_ERROR_NETWORK; | 1904 return SERVICE_WORKER_ERROR_NETWORK; |
1881 } | 1905 } |
1882 } | 1906 } |
1883 | 1907 |
1884 return default_code; | 1908 return default_code; |
1885 } | 1909 } |
1886 | 1910 |
1887 } // namespace content | 1911 } // namespace content |
OLD | NEW |