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

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

Issue 345583002: ServiceWorker: Add a function to abort all pending jobs in SWJobCoordinator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments and add test cases Created 6 years, 6 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 | Annotate | Revision Log
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_register_job.h" 5 #include "content/browser/service_worker/service_worker_register_job.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "content/browser/service_worker/service_worker_context_core.h" 10 #include "content/browser/service_worker/service_worker_context_core.h"
(...skipping 20 matching lines...) Expand all
31 const GURL& script_url) 31 const GURL& script_url)
32 : context_(context), 32 : context_(context),
33 pattern_(pattern), 33 pattern_(pattern),
34 script_url_(script_url), 34 script_url_(script_url),
35 phase_(INITIAL), 35 phase_(INITIAL),
36 is_promise_resolved_(false), 36 is_promise_resolved_(false),
37 promise_resolved_status_(SERVICE_WORKER_OK), 37 promise_resolved_status_(SERVICE_WORKER_OK),
38 weak_factory_(this) {} 38 weak_factory_(this) {}
39 39
40 ServiceWorkerRegisterJob::~ServiceWorkerRegisterJob() { 40 ServiceWorkerRegisterJob::~ServiceWorkerRegisterJob() {
41 DCHECK(!context_ || phase_ == INITIAL || phase_ == COMPLETE) 41 DCHECK(!context_ ||
42 phase_ == INITIAL || phase_ == COMPLETE || phase_ == ABORT)
42 << "Jobs should only be interrupted during shutdown."; 43 << "Jobs should only be interrupted during shutdown.";
43 } 44 }
44 45
45 void ServiceWorkerRegisterJob::AddCallback(const RegistrationCallback& callback, 46 void ServiceWorkerRegisterJob::AddCallback(const RegistrationCallback& callback,
46 int process_id) { 47 int process_id) {
47 if (!is_promise_resolved_) { 48 if (!is_promise_resolved_) {
48 callbacks_.push_back(callback); 49 callbacks_.push_back(callback);
49 if (process_id != -1 && (phase_ < UPDATE || !pending_version())) 50 if (process_id != -1 && (phase_ < UPDATE || !pending_version()))
50 pending_process_ids_.push_back(process_id); 51 pending_process_ids_.push_back(process_id);
51 return; 52 return;
52 } 53 }
53 RunSoon(base::Bind( 54 RunSoon(base::Bind(
54 callback, promise_resolved_status_, 55 callback, promise_resolved_status_,
55 promise_resolved_registration_, promise_resolved_version_)); 56 promise_resolved_registration_, promise_resolved_version_));
56 } 57 }
57 58
58 void ServiceWorkerRegisterJob::Start() { 59 void ServiceWorkerRegisterJob::Start() {
59 SetPhase(START); 60 SetPhase(START);
60 context_->storage()->FindRegistrationForPattern( 61 context_->storage()->FindRegistrationForPattern(
61 pattern_, 62 pattern_,
62 base::Bind( 63 base::Bind(
63 &ServiceWorkerRegisterJob::HandleExistingRegistrationAndContinue, 64 &ServiceWorkerRegisterJob::HandleExistingRegistrationAndContinue,
64 weak_factory_.GetWeakPtr())); 65 weak_factory_.GetWeakPtr()));
65 } 66 }
66 67
68 void ServiceWorkerRegisterJob::Abort() {
69 SetPhase(ABORT);
70 SetPhase(COMPLETE);
falken 2014/06/19 08:10:56 This looks awkward, can we remove the SetPhase(COM
nhiroki 2014/06/19 10:04:05 Done.
71 CompleteInternal(SERVICE_WORKER_ERROR_ABORT);
72 }
73
67 bool ServiceWorkerRegisterJob::Equals(ServiceWorkerRegisterJobBase* job) { 74 bool ServiceWorkerRegisterJob::Equals(ServiceWorkerRegisterJobBase* job) {
68 if (job->GetType() != GetType()) 75 if (job->GetType() != GetType())
69 return false; 76 return false;
70 ServiceWorkerRegisterJob* register_job = 77 ServiceWorkerRegisterJob* register_job =
71 static_cast<ServiceWorkerRegisterJob*>(job); 78 static_cast<ServiceWorkerRegisterJob*>(job);
72 return register_job->pattern_ == pattern_ && 79 return register_job->pattern_ == pattern_ &&
73 register_job->script_url_ == script_url_; 80 register_job->script_url_ == script_url_;
74 } 81 }
75 82
76 RegistrationJobType ServiceWorkerRegisterJob::GetType() { 83 RegistrationJobType ServiceWorkerRegisterJob::GetType() {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 break; 131 break;
125 case STORE: 132 case STORE:
126 DCHECK(phase_ == INSTALL) << phase_; 133 DCHECK(phase_ == INSTALL) << phase_;
127 break; 134 break;
128 case ACTIVATE: 135 case ACTIVATE:
129 DCHECK(phase_ == STORE) << phase_; 136 DCHECK(phase_ == STORE) << phase_;
130 break; 137 break;
131 case COMPLETE: 138 case COMPLETE:
132 DCHECK(phase_ != INITIAL && phase_ != COMPLETE) << phase_; 139 DCHECK(phase_ != INITIAL && phase_ != COMPLETE) << phase_;
133 break; 140 break;
141 case ABORT:
142 break;
134 } 143 }
135 phase_ = phase; 144 phase_ = phase;
136 } 145 }
137 146
138 // This function corresponds to the steps in Register following 147 // This function corresponds to the steps in Register following
139 // "Let serviceWorkerRegistration be _GetRegistration(scope)" 148 // "Let serviceWorkerRegistration be _GetRegistration(scope)"
140 // |existing_registration| corresponds to serviceWorkerRegistration. 149 // |existing_registration| corresponds to serviceWorkerRegistration.
141 // Throughout this file, comments in quotes are excerpts from the spec. 150 // Throughout this file, comments in quotes are excerpts from the spec.
142 void ServiceWorkerRegisterJob::HandleExistingRegistrationAndContinue( 151 void ServiceWorkerRegisterJob::HandleExistingRegistrationAndContinue(
143 ServiceWorkerStatusCode status, 152 ServiceWorkerStatusCode status,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 return; 362 return;
354 } 363 }
355 context_->storage()->UpdateToActiveState( 364 context_->storage()->UpdateToActiveState(
356 registration(), 365 registration(),
357 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 366 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
358 Complete(SERVICE_WORKER_OK); 367 Complete(SERVICE_WORKER_OK);
359 } 368 }
360 369
361 void ServiceWorkerRegisterJob::Complete(ServiceWorkerStatusCode status) { 370 void ServiceWorkerRegisterJob::Complete(ServiceWorkerStatusCode status) {
362 SetPhase(COMPLETE); 371 SetPhase(COMPLETE);
372 CompleteInternal(status);
373 context_->job_coordinator()->FinishJob(pattern_, this);
falken 2014/06/19 08:10:56 I think this is OK. Another option could be to kee
nhiroki 2014/06/19 10:04:05 Updated. I think new code looks simpler than the p
374 }
375
376 void ServiceWorkerRegisterJob::CompleteInternal(
377 ServiceWorkerStatusCode status) {
378 DCHECK_EQ(COMPLETE, phase_);
363 if (status != SERVICE_WORKER_OK) { 379 if (status != SERVICE_WORKER_OK) {
364 if (registration() && registration()->waiting_version()) { 380 if (registration() && registration()->waiting_version()) {
365 DisassociateWaitingVersionFromDocuments( 381 DisassociateWaitingVersionFromDocuments(
366 context_, registration()->waiting_version()->version_id()); 382 context_, registration()->waiting_version()->version_id());
367 registration()->set_waiting_version(NULL); 383 registration()->set_waiting_version(NULL);
368 } 384 }
369 if (registration() && !registration()->active_version()) { 385 if (registration() && !registration()->active_version()) {
370 context_->storage()->DeleteRegistration( 386 context_->storage()->DeleteRegistration(
371 registration()->id(), 387 registration()->id(),
372 registration()->script_url().GetOrigin(), 388 registration()->script_url().GetOrigin(),
373 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 389 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
374 } 390 }
375 if (!is_promise_resolved_) 391 if (!is_promise_resolved_)
376 ResolvePromise(status, NULL, NULL); 392 ResolvePromise(status, NULL, NULL);
377 } 393 }
378 DCHECK(callbacks_.empty()); 394 DCHECK(callbacks_.empty());
379 if (registration()) { 395 if (registration()) {
380 context_->storage()->NotifyDoneInstallingRegistration( 396 context_->storage()->NotifyDoneInstallingRegistration(
381 registration(), pending_version(), status); 397 registration(), pending_version(), status);
382 } 398 }
383 context_->job_coordinator()->FinishJob(pattern_, this);
384 } 399 }
385 400
386 void ServiceWorkerRegisterJob::ResolvePromise( 401 void ServiceWorkerRegisterJob::ResolvePromise(
387 ServiceWorkerStatusCode status, 402 ServiceWorkerStatusCode status,
388 ServiceWorkerRegistration* registration, 403 ServiceWorkerRegistration* registration,
389 ServiceWorkerVersion* version) { 404 ServiceWorkerVersion* version) {
390 DCHECK(!is_promise_resolved_); 405 DCHECK(!is_promise_resolved_);
391 is_promise_resolved_ = true; 406 is_promise_resolved_ = true;
392 promise_resolved_status_ = status; 407 promise_resolved_status_ = status;
393 promise_resolved_registration_ = registration; 408 promise_resolved_registration_ = registration;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 if (!host->IsContextAlive()) 460 if (!host->IsContextAlive())
446 continue; 461 continue;
447 if (host->waiting_version() && 462 if (host->waiting_version() &&
448 host->waiting_version()->version_id() == version_id) { 463 host->waiting_version()->version_id() == version_id) {
449 host->SetWaitingVersion(NULL); 464 host->SetWaitingVersion(NULL);
450 } 465 }
451 } 466 }
452 } 467 }
453 468
454 } // namespace content 469 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698