Chromium Code Reviews| 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 <map> | |
| 8 #include <string> | |
| 9 | |
| 7 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 8 #include "base/location.h" | 11 #include "base/location.h" |
| 9 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 10 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 12 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 13 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 stashed_port_manager->AddPort(service_worker.get(), message_port_id, name); | 390 stashed_port_manager->AddPort(service_worker.get(), message_port_id, name); |
| 388 } | 391 } |
| 389 | 392 |
| 390 } // namespace | 393 } // namespace |
| 391 | 394 |
| 392 const int ServiceWorkerVersion::kStartWorkerTimeoutMinutes = 5; | 395 const int ServiceWorkerVersion::kStartWorkerTimeoutMinutes = 5; |
| 393 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5; | 396 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5; |
| 394 | 397 |
| 395 class ServiceWorkerVersion::Metrics { | 398 class ServiceWorkerVersion::Metrics { |
| 396 public: | 399 public: |
| 397 Metrics() {} | 400 using EventType = ServiceWorkerMetrics::EventType; |
| 401 Metrics(const GURL& scope) : scope_(scope) {} | |
|
falken
2015/06/25 09:31:39
nit: explicit
kinuko
2015/07/02 14:27:26
Acknowledged.
| |
| 398 ~Metrics() { | 402 ~Metrics() { |
| 399 ServiceWorkerMetrics::RecordEventStatus(fired_events, handled_events); | 403 for (const auto& ev : event_stats_) { |
| 404 ServiceWorkerMetrics::RecordPerWorkerEventHandledStatus( | |
| 405 scope_, ev.first, ev.second.handled_events, ev.second.fired_events); | |
| 406 } | |
| 400 } | 407 } |
| 401 | 408 |
| 402 void RecordEventStatus(bool handled) { | 409 void RecordEventHandledStatus(EventType event, bool handled) { |
| 403 ++fired_events; | 410 ServiceWorkerMetrics::RecordEventHandledStatus(scope_, event, handled); |
| 411 event_stats_[event].fired_events++; | |
| 404 if (handled) | 412 if (handled) |
| 405 ++handled_events; | 413 event_stats_[event].handled_events++; |
| 406 } | 414 } |
| 407 | 415 |
| 408 private: | 416 private: |
| 409 size_t fired_events = 0; | 417 struct EventStat { |
| 410 size_t handled_events = 0; | 418 size_t fired_events = 0; |
| 419 size_t handled_events = 0; | |
| 420 }; | |
| 421 | |
| 422 const GURL scope_; | |
| 423 std::map<EventType, EventStat> event_stats_; | |
| 411 DISALLOW_COPY_AND_ASSIGN(Metrics); | 424 DISALLOW_COPY_AND_ASSIGN(Metrics); |
| 412 }; | 425 }; |
| 413 | 426 |
| 414 // A controller for periodically sending a ping to the worker to see | 427 // A controller for periodically sending a ping to the worker to see |
| 415 // if the worker is not stalling. | 428 // if the worker is not stalling. |
| 416 class ServiceWorkerVersion::PingController { | 429 class ServiceWorkerVersion::PingController { |
| 417 public: | 430 public: |
| 418 explicit PingController(ServiceWorkerVersion* version) : version_(version) {} | 431 explicit PingController(ServiceWorkerVersion* version) : version_(version) {} |
| 419 ~PingController() {} | 432 ~PingController() {} |
| 420 | 433 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 const GURL& script_url, | 486 const GURL& script_url, |
| 474 int64 version_id, | 487 int64 version_id, |
| 475 base::WeakPtr<ServiceWorkerContextCore> context) | 488 base::WeakPtr<ServiceWorkerContextCore> context) |
| 476 : version_id_(version_id), | 489 : version_id_(version_id), |
| 477 registration_id_(registration->id()), | 490 registration_id_(registration->id()), |
| 478 script_url_(script_url), | 491 script_url_(script_url), |
| 479 scope_(registration->pattern()), | 492 scope_(registration->pattern()), |
| 480 context_(context), | 493 context_(context), |
| 481 script_cache_map_(this, context), | 494 script_cache_map_(this, context), |
| 482 ping_controller_(new PingController(this)), | 495 ping_controller_(new PingController(this)), |
| 483 metrics_(new Metrics), | 496 metrics_(new Metrics(scope_)), |
| 484 weak_factory_(this) { | 497 weak_factory_(this) { |
| 485 DCHECK(context_); | 498 DCHECK(context_); |
| 486 DCHECK(registration); | 499 DCHECK(registration); |
| 487 context_->AddLiveVersion(this); | 500 context_->AddLiveVersion(this); |
| 488 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); | 501 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); |
| 489 embedded_worker_->AddListener(this); | 502 embedded_worker_->AddListener(this); |
| 490 } | 503 } |
| 491 | 504 |
| 492 ServiceWorkerVersion::~ServiceWorkerVersion() { | 505 ServiceWorkerVersion::~ServiceWorkerVersion() { |
| 493 // The user may have closed the tab waiting for SW to start up. | 506 // The user may have closed the tab waiting for SW to start up. |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1340 "ServiceWorkerVersion::OnFetchEventFinished", | 1353 "ServiceWorkerVersion::OnFetchEventFinished", |
| 1341 "Request id", request_id); | 1354 "Request id", request_id); |
| 1342 FetchCallback* callback = fetch_callbacks_.Lookup(request_id); | 1355 FetchCallback* callback = fetch_callbacks_.Lookup(request_id); |
| 1343 if (!callback) { | 1356 if (!callback) { |
| 1344 NOTREACHED() << "Got unexpected message: " << request_id; | 1357 NOTREACHED() << "Got unexpected message: " << request_id; |
| 1345 return; | 1358 return; |
| 1346 } | 1359 } |
| 1347 | 1360 |
| 1348 // TODO(kinuko): Record other event statuses too. | 1361 // TODO(kinuko): Record other event statuses too. |
| 1349 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); | 1362 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); |
| 1350 metrics_->RecordEventStatus(handled); | 1363 metrics_->RecordEventHandledStatus(ServiceWorkerMetrics::EVENT_TYPE_FETCH, |
| 1364 handled); | |
| 1351 | 1365 |
| 1352 scoped_refptr<ServiceWorkerVersion> protect(this); | 1366 scoped_refptr<ServiceWorkerVersion> protect(this); |
| 1353 callback->Run(SERVICE_WORKER_OK, result, response); | 1367 callback->Run(SERVICE_WORKER_OK, result, response); |
| 1354 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); | 1368 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); |
| 1355 } | 1369 } |
| 1356 | 1370 |
| 1357 void ServiceWorkerVersion::OnSyncEventFinished( | 1371 void ServiceWorkerVersion::OnSyncEventFinished( |
| 1358 int request_id, | 1372 int request_id, |
| 1359 blink::WebServiceWorkerEventResult result) { | 1373 blink::WebServiceWorkerEventResult result) { |
| 1360 TRACE_EVENT1("ServiceWorker", | 1374 TRACE_EVENT1("ServiceWorker", |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2111 is_update_scheduled_ = false; | 2125 is_update_scheduled_ = false; |
| 2112 } | 2126 } |
| 2113 | 2127 |
| 2114 if (status != SERVICE_WORKER_OK || registration->active_version() != this) | 2128 if (status != SERVICE_WORKER_OK || registration->active_version() != this) |
| 2115 return; | 2129 return; |
| 2116 context_->UpdateServiceWorker(registration.get(), | 2130 context_->UpdateServiceWorker(registration.get(), |
| 2117 false /* force_bypass_cache */); | 2131 false /* force_bypass_cache */); |
| 2118 } | 2132 } |
| 2119 | 2133 |
| 2120 } // namespace content | 2134 } // namespace content |
| OLD | NEW |