Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: content/browser/service_worker/service_worker_version.cc

Issue 992353003: Decouple Cache Storage messaging from Service Worker/Embedded Worker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused public stubs Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 case RUNNING: 385 case RUNNING:
386 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); 386 RunSoon(base::Bind(callback, SERVICE_WORKER_OK));
387 return; 387 return;
388 case STOPPING: 388 case STOPPING:
389 case STOPPED: 389 case STOPPED:
390 case STARTING: 390 case STARTING:
391 if (!timeout_timer_.IsRunning()) 391 if (!timeout_timer_.IsRunning())
392 StartTimeoutTimer(); 392 StartTimeoutTimer();
393 start_callbacks_.push_back(callback); 393 start_callbacks_.push_back(callback);
394 if (running_status() == STOPPED) { 394 if (running_status() == STOPPED) {
395 DCHECK(!cache_listener_.get());
396 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_));
397 embedded_worker_->Start( 395 embedded_worker_->Start(
398 version_id_, scope_, script_url_, pause_after_download, 396 version_id_, scope_, script_url_, pause_after_download,
399 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, 397 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated,
400 weak_factory_.GetWeakPtr())); 398 weak_factory_.GetWeakPtr()));
401 } 399 }
402 return; 400 return;
403 } 401 }
404 } 402 }
405 403
406 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { 404 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) {
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 // Activate ping/pong now that JavaScript execution will start. 805 // Activate ping/pong now that JavaScript execution will start.
808 ping_state_ = PINGING; 806 ping_state_ = PINGING;
809 } 807 }
810 808
811 void ServiceWorkerVersion::OnStarting() { 809 void ServiceWorkerVersion::OnStarting() {
812 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); 810 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
813 } 811 }
814 812
815 void ServiceWorkerVersion::OnStarted() { 813 void ServiceWorkerVersion::OnStarted() {
816 DCHECK_EQ(RUNNING, running_status()); 814 DCHECK_EQ(RUNNING, running_status());
817 DCHECK(cache_listener_.get());
818 RestartTick(&idle_time_); 815 RestartTick(&idle_time_);
819 816
820 // Fire all start callbacks. 817 // Fire all start callbacks.
821 scoped_refptr<ServiceWorkerVersion> protect(this); 818 scoped_refptr<ServiceWorkerVersion> protect(this);
822 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); 819 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK);
823 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); 820 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
824 } 821 }
825 822
826 void ServiceWorkerVersion::OnStopping() { 823 void ServiceWorkerVersion::OnStopping() {
827 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); 824 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 RunIDMapCallbacks(&geofencing_callbacks_, 865 RunIDMapCallbacks(&geofencing_callbacks_,
869 SERVICE_WORKER_ERROR_FAILED); 866 SERVICE_WORKER_ERROR_FAILED);
870 RunIDMapCallbacks(&cross_origin_connect_callbacks_, 867 RunIDMapCallbacks(&cross_origin_connect_callbacks_,
871 SERVICE_WORKER_ERROR_FAILED, 868 SERVICE_WORKER_ERROR_FAILED,
872 false); 869 false);
873 870
874 streaming_url_request_jobs_.clear(); 871 streaming_url_request_jobs_.clear();
875 872
876 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); 873 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
877 874
878 // There should be no more communication from/to a stopped worker. Deleting
879 // the listener prevents any pending completion callbacks from causing
880 // messages to be sent to the stopped worker.
881 cache_listener_.reset();
882
883 // Restart worker if we have any start callbacks and the worker isn't doomed. 875 // Restart worker if we have any start callbacks and the worker isn't doomed.
884 if (should_restart) { 876 if (should_restart) {
885 if (embedded_worker_->devtools_attached()) 877 if (embedded_worker_->devtools_attached())
886 ClearTick(&start_time_); 878 ClearTick(&start_time_);
887 else 879 else
888 RestartTick(&start_time_); 880 RestartTick(&start_time_);
889 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_));
890 embedded_worker_->Start( 881 embedded_worker_->Start(
891 version_id_, scope_, script_url_, false /* pause_after_download */, 882 version_id_, scope_, script_url_, false /* pause_after_download */,
892 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, 883 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated,
893 weak_factory_.GetWeakPtr())); 884 weak_factory_.GetWeakPtr()));
894 } 885 }
895 } 886 }
896 887
897 void ServiceWorkerVersion::OnReportException( 888 void ServiceWorkerVersion::OnReportException(
898 const base::string16& error_message, 889 const base::string16& error_message,
899 int line_number, 890 int line_number,
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 int request_id) { 1606 int request_id) {
1616 callbacks->Remove(request_id); 1607 callbacks->Remove(request_id);
1617 if (is_doomed_) { 1608 if (is_doomed_) {
1618 // The stop should be already scheduled, but try to stop immediately, in 1609 // The stop should be already scheduled, but try to stop immediately, in
1619 // order to release worker resources soon. 1610 // order to release worker resources soon.
1620 StopWorkerIfIdle(); 1611 StopWorkerIfIdle();
1621 } 1612 }
1622 } 1613 }
1623 1614
1624 } // namespace content 1615 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698