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 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1471 DCHECK(!metrics_); | 1471 DCHECK(!metrics_); |
1472 DCHECK(start_worker_first_purpose_); | 1472 DCHECK(start_worker_first_purpose_); |
1473 metrics_.reset(new Metrics(this, start_worker_first_purpose_.value())); | 1473 metrics_.reset(new Metrics(this, start_worker_first_purpose_.value())); |
1474 | 1474 |
1475 // We don't clear |start_worker_first_purpose_| here but clear in | 1475 // We don't clear |start_worker_first_purpose_| here but clear in |
1476 // FinishStartWorker. This is because StartWorkerInternal may be called | 1476 // FinishStartWorker. This is because StartWorkerInternal may be called |
1477 // again from OnStoppedInternal if StopWorker is called before OnStarted. | 1477 // again from OnStoppedInternal if StopWorker is called before OnStarted. |
1478 | 1478 |
1479 StartTimeoutTimer(); | 1479 StartTimeoutTimer(); |
1480 | 1480 |
1481 std::unique_ptr<EmbeddedWorkerStartParams> params( | 1481 auto params = base::MakeUnique<EmbeddedWorkerStartParams>(); |
1482 new EmbeddedWorkerStartParams()); | |
1483 params->service_worker_version_id = version_id_; | 1482 params->service_worker_version_id = version_id_; |
1484 params->scope = scope_; | 1483 params->scope = scope_; |
1485 params->script_url = script_url_; | 1484 params->script_url = script_url_; |
1486 params->is_installed = IsInstalled(status_); | 1485 params->is_installed = IsInstalled(status_); |
1487 params->pause_after_download = pause_after_download_; | 1486 params->pause_after_download = pause_after_download_; |
1488 | 1487 |
1489 embedded_worker_->Start( | 1488 embedded_worker_->Start( |
1490 std::move(params), | 1489 std::move(params), mojo::GetProxy(&event_dispatcher_), |
1491 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, | 1490 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, |
1492 weak_factory_.GetWeakPtr())); | 1491 weak_factory_.GetWeakPtr())); |
1493 } | 1492 } |
1494 | 1493 |
1495 void ServiceWorkerVersion::StartTimeoutTimer() { | 1494 void ServiceWorkerVersion::StartTimeoutTimer() { |
1496 DCHECK(!timeout_timer_.IsRunning()); | 1495 DCHECK(!timeout_timer_.IsRunning()); |
1497 | 1496 |
1498 if (embedded_worker_->devtools_attached()) { | 1497 if (embedded_worker_->devtools_attached()) { |
1499 // Don't record the startup time metric once DevTools is attached. | 1498 // Don't record the startup time metric once DevTools is attached. |
1500 ClearTick(&start_time_); | 1499 ClearTick(&start_time_); |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1830 // TODO(kinuko): Consider if we want to add queue+resend mechanism here. | 1829 // TODO(kinuko): Consider if we want to add queue+resend mechanism here. |
1831 IDMap<PendingRequest, IDMapOwnPointer>::iterator iter(&pending_requests_); | 1830 IDMap<PendingRequest, IDMapOwnPointer>::iterator iter(&pending_requests_); |
1832 while (!iter.IsAtEnd()) { | 1831 while (!iter.IsAtEnd()) { |
1833 TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::Request", | 1832 TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::Request", |
1834 iter.GetCurrentValue(), "Error", "Worker Stopped"); | 1833 iter.GetCurrentValue(), "Error", "Worker Stopped"); |
1835 iter.GetCurrentValue()->error_callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1834 iter.GetCurrentValue()->error_callback.Run(SERVICE_WORKER_ERROR_FAILED); |
1836 iter.Advance(); | 1835 iter.Advance(); |
1837 } | 1836 } |
1838 pending_requests_.Clear(); | 1837 pending_requests_.Clear(); |
1839 external_request_uuid_to_request_id_.clear(); | 1838 external_request_uuid_to_request_id_.clear(); |
1840 | 1839 event_dispatcher_.reset(); |
1841 // Close all mojo services. This will also fire and clear all callbacks | |
1842 // for messages that are still outstanding for those services. | |
1843 mojo_services_.clear(); | |
1844 | 1840 |
1845 // TODO(falken): Call SWURLRequestJob::ClearStream here? | 1841 // TODO(falken): Call SWURLRequestJob::ClearStream here? |
1846 streaming_url_request_jobs_.clear(); | 1842 streaming_url_request_jobs_.clear(); |
1847 | 1843 |
1848 for (auto& observer : listeners_) | 1844 for (auto& observer : listeners_) |
1849 observer.OnRunningStateChanged(this); | 1845 observer.OnRunningStateChanged(this); |
1850 if (should_restart) { | 1846 if (should_restart) { |
1851 StartWorkerInternal(); | 1847 StartWorkerInternal(); |
1852 } else if (!HasWork()) { | 1848 } else if (!HasWork()) { |
1853 for (auto& observer : listeners_) | 1849 for (auto& observer : listeners_) |
1854 observer.OnNoWork(this); | 1850 observer.OnNoWork(this); |
1855 } | 1851 } |
1856 } | 1852 } |
1857 | 1853 |
1858 void ServiceWorkerVersion::OnMojoConnectionError(const char* service_name) { | |
1859 // Simply deleting the service will cause error callbacks to be called from | |
1860 // the destructor of the MojoServiceWrapper instance. | |
1861 mojo_services_.erase(service_name); | |
1862 } | |
1863 | |
1864 void ServiceWorkerVersion::OnBeginEvent() { | 1854 void ServiceWorkerVersion::OnBeginEvent() { |
1865 if (should_exclude_from_uma_ || | 1855 if (should_exclude_from_uma_ || |
1866 running_status() != EmbeddedWorkerStatus::RUNNING || | 1856 running_status() != EmbeddedWorkerStatus::RUNNING || |
1867 idle_time_.is_null()) { | 1857 idle_time_.is_null()) { |
1868 return; | 1858 return; |
1869 } | 1859 } |
1870 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1860 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
1871 idle_time_); | 1861 idle_time_); |
1872 } | 1862 } |
1873 | 1863 |
1874 void ServiceWorkerVersion::FinishStartWorker(ServiceWorkerStatusCode status) { | 1864 void ServiceWorkerVersion::FinishStartWorker(ServiceWorkerStatusCode status) { |
1875 start_worker_first_purpose_ = base::nullopt; | 1865 start_worker_first_purpose_ = base::nullopt; |
1876 RunCallbacks(this, &start_callbacks_, status); | 1866 RunCallbacks(this, &start_callbacks_, status); |
1877 } | 1867 } |
1878 | 1868 |
1879 void ServiceWorkerVersion::CleanUpExternalRequest( | 1869 void ServiceWorkerVersion::CleanUpExternalRequest( |
1880 const std::string& request_uuid, | 1870 const std::string& request_uuid, |
1881 ServiceWorkerStatusCode status) { | 1871 ServiceWorkerStatusCode status) { |
1882 if (status == SERVICE_WORKER_OK) | 1872 if (status == SERVICE_WORKER_OK) |
1883 return; | 1873 return; |
1884 external_request_uuid_to_request_id_.erase(request_uuid); | 1874 external_request_uuid_to_request_id_.erase(request_uuid); |
1885 } | 1875 } |
1886 | 1876 |
1887 } // namespace content | 1877 } // namespace content |
OLD | NEW |