| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 358 } |
| 359 | 359 |
| 360 void ServiceWorkerVersion::RegisterStatusChangeCallback( | 360 void ServiceWorkerVersion::RegisterStatusChangeCallback( |
| 361 const base::Closure& callback) { | 361 const base::Closure& callback) { |
| 362 status_change_callbacks_.push_back(callback); | 362 status_change_callbacks_.push_back(callback); |
| 363 } | 363 } |
| 364 | 364 |
| 365 ServiceWorkerVersionInfo ServiceWorkerVersion::GetInfo() { | 365 ServiceWorkerVersionInfo ServiceWorkerVersion::GetInfo() { |
| 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 367 return ServiceWorkerVersionInfo( | 367 return ServiceWorkerVersionInfo( |
| 368 running_status(), | 368 running_status(), status(), script_url(), registration_id(), version_id(), |
| 369 status(), | 369 embedded_worker()->process_id(), embedded_worker()->thread_id(), |
| 370 script_url(), | |
| 371 version_id(), | |
| 372 embedded_worker()->process_id(), | |
| 373 embedded_worker()->thread_id(), | |
| 374 embedded_worker()->worker_devtools_agent_route_id()); | 370 embedded_worker()->worker_devtools_agent_route_id()); |
| 375 } | 371 } |
| 376 | 372 |
| 377 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { | 373 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { |
| 378 StartWorker(false, callback); | 374 StartWorker(false, callback); |
| 379 } | 375 } |
| 380 | 376 |
| 381 void ServiceWorkerVersion::StartWorker( | 377 void ServiceWorkerVersion::StartWorker( |
| 382 bool pause_after_download, | 378 bool pause_after_download, |
| 383 const StatusCallback& callback) { | 379 const StatusCallback& callback) { |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() { | 801 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() { |
| 806 return main_script_http_info_.get(); | 802 return main_script_http_info_.get(); |
| 807 } | 803 } |
| 808 | 804 |
| 809 void ServiceWorkerVersion::OnScriptLoaded() { | 805 void ServiceWorkerVersion::OnScriptLoaded() { |
| 810 DCHECK_EQ(STARTING, running_status()); | 806 DCHECK_EQ(STARTING, running_status()); |
| 811 // Activate ping/pong now that JavaScript execution will start. | 807 // Activate ping/pong now that JavaScript execution will start. |
| 812 ping_state_ = PINGING; | 808 ping_state_ = PINGING; |
| 813 } | 809 } |
| 814 | 810 |
| 811 void ServiceWorkerVersion::OnStarting() { |
| 812 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| 813 } |
| 814 |
| 815 void ServiceWorkerVersion::OnStarted() { | 815 void ServiceWorkerVersion::OnStarted() { |
| 816 DCHECK_EQ(RUNNING, running_status()); | 816 DCHECK_EQ(RUNNING, running_status()); |
| 817 DCHECK(cache_listener_.get()); | 817 DCHECK(cache_listener_.get()); |
| 818 RestartTick(&idle_time_); | 818 RestartTick(&idle_time_); |
| 819 | 819 |
| 820 // Fire all start callbacks. | 820 // Fire all start callbacks. |
| 821 scoped_refptr<ServiceWorkerVersion> protect(this); | 821 scoped_refptr<ServiceWorkerVersion> protect(this); |
| 822 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); | 822 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); |
| 823 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStarted(this)); | 823 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| 824 } |
| 825 |
| 826 void ServiceWorkerVersion::OnStopping() { |
| 827 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| 824 } | 828 } |
| 825 | 829 |
| 826 void ServiceWorkerVersion::OnStopped( | 830 void ServiceWorkerVersion::OnStopped( |
| 827 EmbeddedWorkerInstance::Status old_status) { | 831 EmbeddedWorkerInstance::Status old_status) { |
| 828 DCHECK_EQ(STOPPED, running_status()); | 832 DCHECK_EQ(STOPPED, running_status()); |
| 829 scoped_refptr<ServiceWorkerVersion> protect(this); | 833 scoped_refptr<ServiceWorkerVersion> protect(this); |
| 830 | 834 |
| 831 bool should_restart = !is_doomed() && !start_callbacks_.empty() && | 835 bool should_restart = !is_doomed() && !start_callbacks_.empty() && |
| 832 (old_status != EmbeddedWorkerInstance::STARTING); | 836 (old_status != EmbeddedWorkerInstance::STARTING); |
| 833 | 837 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 862 RunIDMapCallbacks(&push_callbacks_, | 866 RunIDMapCallbacks(&push_callbacks_, |
| 863 SERVICE_WORKER_ERROR_FAILED); | 867 SERVICE_WORKER_ERROR_FAILED); |
| 864 RunIDMapCallbacks(&geofencing_callbacks_, | 868 RunIDMapCallbacks(&geofencing_callbacks_, |
| 865 SERVICE_WORKER_ERROR_FAILED); | 869 SERVICE_WORKER_ERROR_FAILED); |
| 866 RunIDMapCallbacks(&cross_origin_connect_callbacks_, | 870 RunIDMapCallbacks(&cross_origin_connect_callbacks_, |
| 867 SERVICE_WORKER_ERROR_FAILED, | 871 SERVICE_WORKER_ERROR_FAILED, |
| 868 false); | 872 false); |
| 869 | 873 |
| 870 streaming_url_request_jobs_.clear(); | 874 streaming_url_request_jobs_.clear(); |
| 871 | 875 |
| 872 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStopped(this)); | 876 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| 873 | 877 |
| 874 // There should be no more communication from/to a stopped worker. Deleting | 878 // There should be no more communication from/to a stopped worker. Deleting |
| 875 // the listener prevents any pending completion callbacks from causing | 879 // the listener prevents any pending completion callbacks from causing |
| 876 // messages to be sent to the stopped worker. | 880 // messages to be sent to the stopped worker. |
| 877 cache_listener_.reset(); | 881 cache_listener_.reset(); |
| 878 | 882 |
| 879 // Restart worker if we have any start callbacks and the worker isn't doomed. | 883 // Restart worker if we have any start callbacks and the worker isn't doomed. |
| 880 if (should_restart) { | 884 if (should_restart) { |
| 881 if (embedded_worker_->devtools_attached()) | 885 if (embedded_worker_->devtools_attached()) |
| 882 ClearTick(&start_time_); | 886 ClearTick(&start_time_); |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1611 int request_id) { | 1615 int request_id) { |
| 1612 callbacks->Remove(request_id); | 1616 callbacks->Remove(request_id); |
| 1613 if (is_doomed_) { | 1617 if (is_doomed_) { |
| 1614 // The stop should be already scheduled, but try to stop immediately, in | 1618 // The stop should be already scheduled, but try to stop immediately, in |
| 1615 // order to release worker resources soon. | 1619 // order to release worker resources soon. |
| 1616 StopWorkerIfIdle(); | 1620 StopWorkerIfIdle(); |
| 1617 } | 1621 } |
| 1618 } | 1622 } |
| 1619 | 1623 |
| 1620 } // namespace content | 1624 } // namespace content |
| OLD | NEW |