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 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 // Activate ping/pong now that JavaScript execution will start. | 809 // Activate ping/pong now that JavaScript execution will start. |
810 ping_state_ = PINGING; | 810 ping_state_ = PINGING; |
811 } | 811 } |
812 | 812 |
813 void ServiceWorkerVersion::OnStarting() { | 813 void ServiceWorkerVersion::OnStarting() { |
814 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 814 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
815 } | 815 } |
816 | 816 |
817 void ServiceWorkerVersion::OnStarted() { | 817 void ServiceWorkerVersion::OnStarted() { |
818 DCHECK_EQ(RUNNING, running_status()); | 818 DCHECK_EQ(RUNNING, running_status()); |
819 DCHECK(cache_listener_.get()); | |
820 RestartTick(&idle_time_); | 819 RestartTick(&idle_time_); |
821 | 820 |
822 // Fire all start callbacks. | 821 // Fire all start callbacks. |
823 scoped_refptr<ServiceWorkerVersion> protect(this); | 822 scoped_refptr<ServiceWorkerVersion> protect(this); |
824 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); | 823 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); |
825 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 824 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
826 } | 825 } |
827 | 826 |
828 void ServiceWorkerVersion::OnStopping() { | 827 void ServiceWorkerVersion::OnStopping() { |
829 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 828 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 RunIDMapCallbacks(&geofencing_callbacks_, | 869 RunIDMapCallbacks(&geofencing_callbacks_, |
871 SERVICE_WORKER_ERROR_FAILED); | 870 SERVICE_WORKER_ERROR_FAILED); |
872 RunIDMapCallbacks(&cross_origin_connect_callbacks_, | 871 RunIDMapCallbacks(&cross_origin_connect_callbacks_, |
873 SERVICE_WORKER_ERROR_FAILED, | 872 SERVICE_WORKER_ERROR_FAILED, |
874 false); | 873 false); |
875 | 874 |
876 streaming_url_request_jobs_.clear(); | 875 streaming_url_request_jobs_.clear(); |
877 | 876 |
878 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 877 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
879 | 878 |
880 // There should be no more communication from/to a stopped worker. Deleting | |
881 // the listener prevents any pending completion callbacks from causing | |
882 // messages to be sent to the stopped worker. | |
883 cache_listener_.reset(); | |
884 | |
885 // Restart worker if we have any start callbacks and the worker isn't doomed. | 879 // Restart worker if we have any start callbacks and the worker isn't doomed. |
886 if (should_restart) | 880 if (should_restart) |
887 StartWorkerInternal(false /* pause_after_download */); | 881 StartWorkerInternal(false /* pause_after_download */); |
888 } | 882 } |
889 | 883 |
890 void ServiceWorkerVersion::OnReportException( | 884 void ServiceWorkerVersion::OnReportException( |
891 const base::string16& error_message, | 885 const base::string16& error_message, |
892 int line_number, | 886 int line_number, |
893 int column_number, | 887 int column_number, |
894 const GURL& source_url) { | 888 const GURL& source_url) { |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 base::Bind(&RunStartWorkerCallback, callback, protect)); | 1448 base::Bind(&RunStartWorkerCallback, callback, protect)); |
1455 StartWorkerInternal(pause_after_download); | 1449 StartWorkerInternal(pause_after_download); |
1456 return; | 1450 return; |
1457 } | 1451 } |
1458 } | 1452 } |
1459 | 1453 |
1460 void ServiceWorkerVersion::StartWorkerInternal(bool pause_after_download) { | 1454 void ServiceWorkerVersion::StartWorkerInternal(bool pause_after_download) { |
1461 if (!timeout_timer_.IsRunning()) | 1455 if (!timeout_timer_.IsRunning()) |
1462 StartTimeoutTimer(); | 1456 StartTimeoutTimer(); |
1463 if (running_status() == STOPPED) { | 1457 if (running_status() == STOPPED) { |
1464 DCHECK(!cache_listener_.get()); | |
1465 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_)); | |
1466 embedded_worker_->Start( | 1458 embedded_worker_->Start( |
1467 version_id_, scope_, script_url_, pause_after_download, | 1459 version_id_, scope_, script_url_, pause_after_download, |
1468 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, | 1460 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, |
1469 weak_factory_.GetWeakPtr())); | 1461 weak_factory_.GetWeakPtr())); |
1470 } | 1462 } |
1471 } | 1463 } |
1472 | 1464 |
1473 void ServiceWorkerVersion::DidClaimClients( | 1465 void ServiceWorkerVersion::DidClaimClients( |
1474 int request_id, ServiceWorkerStatusCode status) { | 1466 int request_id, ServiceWorkerStatusCode status) { |
1475 if (status == SERVICE_WORKER_ERROR_STATE) { | 1467 if (status == SERVICE_WORKER_ERROR_STATE) { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1675 int request_id) { | 1667 int request_id) { |
1676 callbacks->Remove(request_id); | 1668 callbacks->Remove(request_id); |
1677 if (is_doomed_) { | 1669 if (is_doomed_) { |
1678 // The stop should be already scheduled, but try to stop immediately, in | 1670 // The stop should be already scheduled, but try to stop immediately, in |
1679 // order to release worker resources soon. | 1671 // order to release worker resources soon. |
1680 StopWorkerIfIdle(); | 1672 StopWorkerIfIdle(); |
1681 } | 1673 } |
1682 } | 1674 } |
1683 | 1675 |
1684 } // namespace content | 1676 } // namespace content |
OLD | NEW |