| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 DCHECK(!start_callbacks_.empty()); | 1461 DCHECK(!start_callbacks_.empty()); |
| 1462 break; | 1462 break; |
| 1463 case EmbeddedWorkerStatus::STOPPING: | 1463 case EmbeddedWorkerStatus::STOPPING: |
| 1464 case EmbeddedWorkerStatus::STOPPED: | 1464 case EmbeddedWorkerStatus::STOPPED: |
| 1465 if (start_callbacks_.empty()) { | 1465 if (start_callbacks_.empty()) { |
| 1466 int trace_id = NextTraceId(); | 1466 int trace_id = NextTraceId(); |
| 1467 TRACE_EVENT_ASYNC_BEGIN2( | 1467 TRACE_EVENT_ASYNC_BEGIN2( |
| 1468 "ServiceWorker", "ServiceWorkerVersion::StartWorker", trace_id, | 1468 "ServiceWorker", "ServiceWorkerVersion::StartWorker", trace_id, |
| 1469 "Script", script_url_.spec(), "Purpose", | 1469 "Script", script_url_.spec(), "Purpose", |
| 1470 ServiceWorkerMetrics::EventTypeToString(purpose)); | 1470 ServiceWorkerMetrics::EventTypeToString(purpose)); |
| 1471 DCHECK(!start_worker_first_purpose_); | |
| 1472 start_worker_first_purpose_ = purpose; | |
| 1473 start_callbacks_.push_back( | 1471 start_callbacks_.push_back( |
| 1474 base::Bind(&ServiceWorkerVersion::RecordStartWorkerResult, | 1472 base::Bind(&ServiceWorkerVersion::RecordStartWorkerResult, |
| 1475 weak_factory_.GetWeakPtr(), purpose, prestart_status, | 1473 weak_factory_.GetWeakPtr(), purpose, prestart_status, |
| 1476 trace_id, is_browser_startup_complete)); | 1474 trace_id, is_browser_startup_complete)); |
| 1477 } | 1475 } |
| 1478 break; | 1476 break; |
| 1479 } | 1477 } |
| 1480 | 1478 |
| 1481 // Keep the live registration while starting the worker. | 1479 // Keep the live registration while starting the worker. |
| 1482 start_callbacks_.push_back( | 1480 start_callbacks_.push_back( |
| 1483 base::Bind(&RunStartWorkerCallback, callback, protect)); | 1481 base::Bind(&RunStartWorkerCallback, callback, protect)); |
| 1484 | 1482 |
| 1485 if (running_status() == EmbeddedWorkerStatus::STOPPED) | 1483 if (running_status() == EmbeddedWorkerStatus::STOPPED) |
| 1486 StartWorkerInternal(); | 1484 StartWorkerInternal(); |
| 1487 DCHECK(timeout_timer_.IsRunning()); | 1485 DCHECK(timeout_timer_.IsRunning()); |
| 1488 } | 1486 } |
| 1489 | 1487 |
| 1490 void ServiceWorkerVersion::StartWorkerInternal() { | 1488 void ServiceWorkerVersion::StartWorkerInternal() { |
| 1491 DCHECK_EQ(EmbeddedWorkerStatus::STOPPED, running_status()); | 1489 DCHECK_EQ(EmbeddedWorkerStatus::STOPPED, running_status()); |
| 1492 DCHECK(start_worker_first_purpose_); | |
| 1493 | 1490 |
| 1494 if (!ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)) { | 1491 if (!ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)) { |
| 1495 DCHECK(!event_recorder_); | 1492 DCHECK(!event_recorder_); |
| 1496 event_recorder_ = | 1493 event_recorder_ = |
| 1497 base::MakeUnique<ServiceWorkerMetrics::ScopedEventRecorder>( | 1494 base::MakeUnique<ServiceWorkerMetrics::ScopedEventRecorder>(); |
| 1498 start_worker_first_purpose_.value()); | |
| 1499 } | 1495 } |
| 1500 | 1496 |
| 1501 // We don't clear |start_worker_first_purpose_| here but clear in | |
| 1502 // FinishStartWorker. This is because StartWorkerInternal may be called | |
| 1503 // again from OnStoppedInternal if StopWorker is called before OnStarted. | |
| 1504 | |
| 1505 StartTimeoutTimer(); | 1497 StartTimeoutTimer(); |
| 1506 | 1498 |
| 1507 auto params = base::MakeUnique<EmbeddedWorkerStartParams>(); | 1499 auto params = base::MakeUnique<EmbeddedWorkerStartParams>(); |
| 1508 params->service_worker_version_id = version_id_; | 1500 params->service_worker_version_id = version_id_; |
| 1509 params->scope = scope_; | 1501 params->scope = scope_; |
| 1510 params->script_url = script_url_; | 1502 params->script_url = script_url_; |
| 1511 params->is_installed = IsInstalled(status_); | 1503 params->is_installed = IsInstalled(status_); |
| 1512 params->pause_after_download = pause_after_download_; | 1504 params->pause_after_download = pause_after_download_; |
| 1513 | 1505 |
| 1514 embedded_worker_->Start( | 1506 embedded_worker_->Start( |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1883 idle_time_.is_null()) { | 1875 idle_time_.is_null()) { |
| 1884 return; | 1876 return; |
| 1885 } | 1877 } |
| 1886 if (ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)) | 1878 if (ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)) |
| 1887 return; | 1879 return; |
| 1888 ServiceWorkerMetrics::RecordTimeBetweenEvents(tick_clock_->NowTicks() - | 1880 ServiceWorkerMetrics::RecordTimeBetweenEvents(tick_clock_->NowTicks() - |
| 1889 idle_time_); | 1881 idle_time_); |
| 1890 } | 1882 } |
| 1891 | 1883 |
| 1892 void ServiceWorkerVersion::FinishStartWorker(ServiceWorkerStatusCode status) { | 1884 void ServiceWorkerVersion::FinishStartWorker(ServiceWorkerStatusCode status) { |
| 1893 start_worker_first_purpose_ = base::nullopt; | |
| 1894 RunCallbacks(this, &start_callbacks_, status); | 1885 RunCallbacks(this, &start_callbacks_, status); |
| 1895 } | 1886 } |
| 1896 | 1887 |
| 1897 void ServiceWorkerVersion::CleanUpExternalRequest( | 1888 void ServiceWorkerVersion::CleanUpExternalRequest( |
| 1898 const std::string& request_uuid, | 1889 const std::string& request_uuid, |
| 1899 ServiceWorkerStatusCode status) { | 1890 ServiceWorkerStatusCode status) { |
| 1900 if (status == SERVICE_WORKER_OK) | 1891 if (status == SERVICE_WORKER_OK) |
| 1901 return; | 1892 return; |
| 1902 external_request_uuid_to_request_id_.erase(request_uuid); | 1893 external_request_uuid_to_request_id_.erase(request_uuid); |
| 1903 } | 1894 } |
| 1904 | 1895 |
| 1905 } // namespace content | 1896 } // namespace content |
| OLD | NEW |