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_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 Loading... | |
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() { | |
michaeln
2014/06/19 01:12:32
The Complete() method does cleanup related to not
falken
2014/06/19 03:45:56
Yes, looks reasonable to go through Complete with
nhiroki
2014/06/19 05:05:55
Hmmm... I noticed this might cause a messy thing..
nhiroki
2014/06/19 05:53:09
Updated. In the latest patchset, Abort() calls onl
| |
69 SetPhase(ABORT); | |
70 if (!is_promise_resolved_) | |
71 ResolvePromise(SERVICE_WORKER_ERROR_ABORT, NULL, NULL); | |
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 Loading... | |
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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 if (!host->IsContextAlive()) | 454 if (!host->IsContextAlive()) |
446 continue; | 455 continue; |
447 if (host->waiting_version() && | 456 if (host->waiting_version() && |
448 host->waiting_version()->version_id() == version_id) { | 457 host->waiting_version()->version_id() == version_id) { |
449 host->SetWaitingVersion(NULL); | 458 host->SetWaitingVersion(NULL); |
450 } | 459 } |
451 } | 460 } |
452 } | 461 } |
453 | 462 |
454 } // namespace content | 463 } // namespace content |
OLD | NEW |