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