| 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 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 // Activate ping/pong now that JavaScript execution will start. | 802 // Activate ping/pong now that JavaScript execution will start. |
| 803 ping_state_ = PINGING; | 803 ping_state_ = PINGING; |
| 804 } | 804 } |
| 805 | 805 |
| 806 void ServiceWorkerVersion::OnStarting() { | 806 void ServiceWorkerVersion::OnStarting() { |
| 807 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 807 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| 808 } | 808 } |
| 809 | 809 |
| 810 void ServiceWorkerVersion::OnStarted() { | 810 void ServiceWorkerVersion::OnStarted() { |
| 811 DCHECK_EQ(RUNNING, running_status()); | 811 DCHECK_EQ(RUNNING, running_status()); |
| 812 DCHECK(cache_listener_.get()); | |
| 813 RestartTick(&idle_time_); | 812 RestartTick(&idle_time_); |
| 814 | 813 |
| 815 // Fire all start callbacks. | 814 // Fire all start callbacks. |
| 816 scoped_refptr<ServiceWorkerVersion> protect(this); | 815 scoped_refptr<ServiceWorkerVersion> protect(this); |
| 817 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); | 816 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); |
| 818 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 817 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| 819 } | 818 } |
| 820 | 819 |
| 821 void ServiceWorkerVersion::OnStopping() { | 820 void ServiceWorkerVersion::OnStopping() { |
| 822 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 821 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 RunIDMapCallbacks(&geofencing_callbacks_, | 862 RunIDMapCallbacks(&geofencing_callbacks_, |
| 864 SERVICE_WORKER_ERROR_FAILED); | 863 SERVICE_WORKER_ERROR_FAILED); |
| 865 RunIDMapCallbacks(&cross_origin_connect_callbacks_, | 864 RunIDMapCallbacks(&cross_origin_connect_callbacks_, |
| 866 SERVICE_WORKER_ERROR_FAILED, | 865 SERVICE_WORKER_ERROR_FAILED, |
| 867 false); | 866 false); |
| 868 | 867 |
| 869 streaming_url_request_jobs_.clear(); | 868 streaming_url_request_jobs_.clear(); |
| 870 | 869 |
| 871 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 870 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| 872 | 871 |
| 873 // There should be no more communication from/to a stopped worker. Deleting | |
| 874 // the listener prevents any pending completion callbacks from causing | |
| 875 // messages to be sent to the stopped worker. | |
| 876 cache_listener_.reset(); | |
| 877 | |
| 878 // Restart worker if we have any start callbacks and the worker isn't doomed. | 872 // Restart worker if we have any start callbacks and the worker isn't doomed. |
| 879 if (should_restart) { | 873 if (should_restart) { |
| 880 if (embedded_worker_->devtools_attached()) | 874 if (embedded_worker_->devtools_attached()) |
| 881 ClearTick(&start_time_); | 875 ClearTick(&start_time_); |
| 882 else | 876 else |
| 883 RestartTick(&start_time_); | 877 RestartTick(&start_time_); |
| 884 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_)); | |
| 885 embedded_worker_->Start( | 878 embedded_worker_->Start( |
| 886 version_id_, scope_, script_url_, false /* pause_after_download */, | 879 version_id_, scope_, script_url_, false /* pause_after_download */, |
| 887 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, | 880 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, |
| 888 weak_factory_.GetWeakPtr())); | 881 weak_factory_.GetWeakPtr())); |
| 889 } | 882 } |
| 890 } | 883 } |
| 891 | 884 |
| 892 void ServiceWorkerVersion::OnReportException( | 885 void ServiceWorkerVersion::OnReportException( |
| 893 const base::string16& error_message, | 886 const base::string16& error_message, |
| 894 int line_number, | 887 int line_number, |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1432 return; | 1425 return; |
| 1433 case STOPPING: | 1426 case STOPPING: |
| 1434 case STOPPED: | 1427 case STOPPED: |
| 1435 case STARTING: | 1428 case STARTING: |
| 1436 if (!timeout_timer_.IsRunning()) | 1429 if (!timeout_timer_.IsRunning()) |
| 1437 StartTimeoutTimer(); | 1430 StartTimeoutTimer(); |
| 1438 // Start callbacks keep the live registration. | 1431 // Start callbacks keep the live registration. |
| 1439 start_callbacks_.push_back( | 1432 start_callbacks_.push_back( |
| 1440 base::Bind(&RunStartWorkerCallback, callback, protect)); | 1433 base::Bind(&RunStartWorkerCallback, callback, protect)); |
| 1441 if (running_status() == STOPPED) { | 1434 if (running_status() == STOPPED) { |
| 1442 DCHECK(!cache_listener_.get()); | |
| 1443 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_)); | |
| 1444 embedded_worker_->Start( | 1435 embedded_worker_->Start( |
| 1445 version_id_, scope_, script_url_, pause_after_download, | 1436 version_id_, scope_, script_url_, pause_after_download, |
| 1446 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, | 1437 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, |
| 1447 weak_factory_.GetWeakPtr())); | 1438 weak_factory_.GetWeakPtr())); |
| 1448 } | 1439 } |
| 1449 return; | 1440 return; |
| 1450 } | 1441 } |
| 1451 } | 1442 } |
| 1452 | 1443 |
| 1453 void ServiceWorkerVersion::DidClaimClients( | 1444 void ServiceWorkerVersion::DidClaimClients( |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 int request_id) { | 1643 int request_id) { |
| 1653 callbacks->Remove(request_id); | 1644 callbacks->Remove(request_id); |
| 1654 if (is_doomed_) { | 1645 if (is_doomed_) { |
| 1655 // The stop should be already scheduled, but try to stop immediately, in | 1646 // The stop should be already scheduled, but try to stop immediately, in |
| 1656 // order to release worker resources soon. | 1647 // order to release worker resources soon. |
| 1657 StopWorkerIfIdle(); | 1648 StopWorkerIfIdle(); |
| 1658 } | 1649 } |
| 1659 } | 1650 } |
| 1660 | 1651 |
| 1661 } // namespace content | 1652 } // namespace content |
| OLD | NEW |