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

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

Issue 996123002: ServiceWorker: Ensure live registration during starting worker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 embedded_worker()->worker_devtools_agent_route_id()); 370 embedded_worker()->worker_devtools_agent_route_id());
371 } 371 }
372 372
373 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { 373 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) {
374 StartWorker(false, callback); 374 StartWorker(false, callback);
375 } 375 }
376 376
377 void ServiceWorkerVersion::StartWorker( 377 void ServiceWorkerVersion::StartWorker(
378 bool pause_after_download, 378 bool pause_after_download,
379 const StatusCallback& callback) { 379 const StatusCallback& callback) {
380 if (is_doomed()) { 380 if (!context_) {
381 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); 381 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED));
382 return; 382 return;
383 } 383 }
384
385 // Ensure live registration during starting worker so that the worker can get
386 // associated with registration on SWDispatcherHost::OnSetHostedVersionId().
387 context_->storage()->FindRegistrationForId(
388 registration_id_,
389 scope_.GetOrigin(),
390 base::Bind(&ServiceWorkerVersion::DidEnsureLiveRegistration,
391 weak_factory_.GetWeakPtr(),
392 pause_after_download,
393 callback));
394 }
395
396 void ServiceWorkerVersion::DidEnsureLiveRegistration(
397 bool pause_after_download,
398 const StatusCallback& callback,
399 ServiceWorkerStatusCode status,
400 const scoped_refptr<ServiceWorkerRegistration>& protect) {
401 if (status != SERVICE_WORKER_OK || is_doomed()) {
402 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED));
403 return;
404 }
405
384 switch (running_status()) { 406 switch (running_status()) {
385 case RUNNING: 407 case RUNNING:
386 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); 408 RunSoon(base::Bind(callback, SERVICE_WORKER_OK));
387 return; 409 return;
388 case STOPPING: 410 case STOPPING:
389 case STOPPED: 411 case STOPPED:
390 case STARTING: 412 case STARTING:
391 if (!timeout_timer_.IsRunning()) 413 if (!timeout_timer_.IsRunning())
392 StartTimeoutTimer(); 414 StartTimeoutTimer();
393 start_callbacks_.push_back(callback); 415 start_callbacks_.push_back(callback);
394 if (running_status() == STOPPED) { 416 if (running_status() == STOPPED) {
395 DCHECK(!cache_listener_.get()); 417 DCHECK(!cache_listener_.get());
396 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_)); 418 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_));
397 embedded_worker_->Start( 419 embedded_worker_->Start(
398 version_id_, scope_, script_url_, pause_after_download, 420 version_id_, scope_, script_url_, pause_after_download,
399 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, 421 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated,
400 weak_factory_.GetWeakPtr())); 422 weak_factory_.GetWeakPtr(),
423 protect));
kinuko 2015/03/11 14:41:56 I wonder just keeping this 'protect' in start_call
michaeln 2015/03/11 20:18:56 That sounds pretty good provided it can be made to
nhiroki 2015/03/12 05:27:11 Good idea. Modified the CL in this way.
401 } 424 }
402 return; 425 return;
403 } 426 }
404 } 427 }
405 428
406 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { 429 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) {
407 if (running_status() == STOPPED) { 430 if (running_status() == STOPPED) {
408 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); 431 RunSoon(base::Bind(callback, SERVICE_WORKER_OK));
409 return; 432 return;
410 } 433 }
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 streaming_url_request_jobs_.clear(); 897 streaming_url_request_jobs_.clear();
875 898
876 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); 899 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
877 900
878 // There should be no more communication from/to a stopped worker. Deleting 901 // There should be no more communication from/to a stopped worker. Deleting
879 // the listener prevents any pending completion callbacks from causing 902 // the listener prevents any pending completion callbacks from causing
880 // messages to be sent to the stopped worker. 903 // messages to be sent to the stopped worker.
881 cache_listener_.reset(); 904 cache_listener_.reset();
882 905
883 // Restart worker if we have any start callbacks and the worker isn't doomed. 906 // Restart worker if we have any start callbacks and the worker isn't doomed.
884 if (should_restart) { 907 if (should_restart)
885 if (embedded_worker_->devtools_attached()) 908 StartWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
886 ClearTick(&start_time_);
887 else
888 RestartTick(&start_time_);
889 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_));
890 embedded_worker_->Start(
891 version_id_, scope_, script_url_, false /* pause_after_download */,
892 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated,
893 weak_factory_.GetWeakPtr()));
nhiroki 2015/03/11 09:08:08 kinuko@ or falken@: I'm not really sure whether th
kinuko 2015/03/11 14:41:57 It's minor and is probably ok, but it looks just c
nhiroki 2015/03/12 05:27:11 Reverted this because it's no longer necessary to
894 }
895 } 909 }
896 910
897 void ServiceWorkerVersion::OnReportException( 911 void ServiceWorkerVersion::OnReportException(
898 const base::string16& error_message, 912 const base::string16& error_message,
899 int line_number, 913 int line_number,
900 int column_number, 914 int column_number,
901 const GURL& source_url) { 915 const GURL& source_url) {
902 FOR_EACH_OBSERVER( 916 FOR_EACH_OBSERVER(
903 Listener, 917 Listener,
904 listeners_, 918 listeners_,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 OnSkipWaiting) 970 OnSkipWaiting)
957 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients, 971 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients,
958 OnClaimClients) 972 OnClaimClients)
959 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_Pong, OnPongFromWorker) 973 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_Pong, OnPongFromWorker)
960 IPC_MESSAGE_UNHANDLED(handled = false) 974 IPC_MESSAGE_UNHANDLED(handled = false)
961 IPC_END_MESSAGE_MAP() 975 IPC_END_MESSAGE_MAP()
962 return handled; 976 return handled;
963 } 977 }
964 978
965 void ServiceWorkerVersion::OnStartSentAndScriptEvaluated( 979 void ServiceWorkerVersion::OnStartSentAndScriptEvaluated(
980 scoped_refptr<ServiceWorkerRegistration> protect,
966 ServiceWorkerStatusCode status) { 981 ServiceWorkerStatusCode status) {
967 if (status != SERVICE_WORKER_OK) 982 if (status != SERVICE_WORKER_OK)
968 RunCallbacks(this, &start_callbacks_, status); 983 RunCallbacks(this, &start_callbacks_, status);
969 } 984 }
970 985
971 void ServiceWorkerVersion::DispatchInstallEventAfterStartWorker( 986 void ServiceWorkerVersion::DispatchInstallEventAfterStartWorker(
972 const StatusCallback& callback) { 987 const StatusCallback& callback) {
973 DCHECK_EQ(RUNNING, running_status()) 988 DCHECK_EQ(RUNNING, running_status())
974 << "Worker stopped too soon after it was started."; 989 << "Worker stopped too soon after it was started.";
975 990
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 int request_id) { 1630 int request_id) {
1616 callbacks->Remove(request_id); 1631 callbacks->Remove(request_id);
1617 if (is_doomed_) { 1632 if (is_doomed_) {
1618 // The stop should be already scheduled, but try to stop immediately, in 1633 // The stop should be already scheduled, but try to stop immediately, in
1619 // order to release worker resources soon. 1634 // order to release worker resources soon.
1620 StopWorkerIfIdle(); 1635 StopWorkerIfIdle();
1621 } 1636 }
1622 } 1637 }
1623 1638
1624 } // namespace content 1639 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698