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

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

Issue 985663002: Implement ServiceWorkerRegistration related DevTools events [2/2 chromium] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed to push model 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 const net::HttpResponseInfo* 804 const net::HttpResponseInfo*
809 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() { 805 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() {
810 return main_script_http_info_.get(); 806 return main_script_http_info_.get();
811 } 807 }
812 808
813 void ServiceWorkerVersion::OnScriptLoaded() { 809 void ServiceWorkerVersion::OnScriptLoaded() {
814 DCHECK_EQ(STARTING, running_status()); 810 DCHECK_EQ(STARTING, running_status());
815 StartTimeoutTimer(); 811 StartTimeoutTimer();
816 } 812 }
817 813
814 void ServiceWorkerVersion::OnStarting() {
815 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
816 }
817
818 void ServiceWorkerVersion::OnStarted() { 818 void ServiceWorkerVersion::OnStarted() {
819 DCHECK_EQ(RUNNING, running_status()); 819 DCHECK_EQ(RUNNING, running_status());
820 DCHECK(cache_listener_.get()); 820 DCHECK(cache_listener_.get());
821 RestartTick(&idle_time_); 821 RestartTick(&idle_time_);
822 822
823 // Fire all start callbacks. 823 // Fire all start callbacks.
824 scoped_refptr<ServiceWorkerVersion> protect(this); 824 scoped_refptr<ServiceWorkerVersion> protect(this);
825 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); 825 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK);
826 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStarted(this)); 826 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
827 }
828
829 void ServiceWorkerVersion::OnStopping() {
830 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
827 } 831 }
828 832
829 void ServiceWorkerVersion::OnStopped( 833 void ServiceWorkerVersion::OnStopped(
830 EmbeddedWorkerInstance::Status old_status) { 834 EmbeddedWorkerInstance::Status old_status) {
831 DCHECK_EQ(STOPPED, running_status()); 835 DCHECK_EQ(STOPPED, running_status());
832 scoped_refptr<ServiceWorkerVersion> protect(this); 836 scoped_refptr<ServiceWorkerVersion> protect(this);
833 837
834 bool should_restart = !is_doomed() && !start_callbacks_.empty() && 838 bool should_restart = !is_doomed() && !start_callbacks_.empty() &&
835 (old_status != EmbeddedWorkerInstance::STARTING); 839 (old_status != EmbeddedWorkerInstance::STARTING);
836 840
(...skipping 28 matching lines...) Expand all
865 RunIDMapCallbacks(&push_callbacks_, 869 RunIDMapCallbacks(&push_callbacks_,
866 SERVICE_WORKER_ERROR_FAILED); 870 SERVICE_WORKER_ERROR_FAILED);
867 RunIDMapCallbacks(&geofencing_callbacks_, 871 RunIDMapCallbacks(&geofencing_callbacks_,
868 SERVICE_WORKER_ERROR_FAILED); 872 SERVICE_WORKER_ERROR_FAILED);
869 RunIDMapCallbacks(&cross_origin_connect_callbacks_, 873 RunIDMapCallbacks(&cross_origin_connect_callbacks_,
870 SERVICE_WORKER_ERROR_FAILED, 874 SERVICE_WORKER_ERROR_FAILED,
871 false); 875 false);
872 876
873 streaming_url_request_jobs_.clear(); 877 streaming_url_request_jobs_.clear();
874 878
875 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStopped(this)); 879 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
876 880
877 // There should be no more communication from/to a stopped worker. Deleting 881 // There should be no more communication from/to a stopped worker. Deleting
878 // the listener prevents any pending completion callbacks from causing 882 // the listener prevents any pending completion callbacks from causing
879 // messages to be sent to the stopped worker. 883 // messages to be sent to the stopped worker.
880 cache_listener_.reset(); 884 cache_listener_.reset();
881 885
882 // Restart worker if we have any start callbacks and the worker isn't doomed. 886 // Restart worker if we have any start callbacks and the worker isn't doomed.
883 if (should_restart) { 887 if (should_restart) {
884 start_worker_timeout_timer_.Reset(); 888 start_worker_timeout_timer_.Reset();
885 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_)); 889 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_));
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 int request_id) { 1594 int request_id) {
1591 callbacks->Remove(request_id); 1595 callbacks->Remove(request_id);
1592 if (is_doomed_) { 1596 if (is_doomed_) {
1593 // The stop should be already scheduled, but try to stop immediately, in 1597 // The stop should be already scheduled, but try to stop immediately, in
1594 // order to release worker resources soon. 1598 // order to release worker resources soon.
1595 StopWorkerIfIdle(); 1599 StopWorkerIfIdle();
1596 } 1600 }
1597 } 1601 }
1598 1602
1599 } // namespace content 1603 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698