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_registration.h" | 5 #include "content/browser/service_worker/service_worker_registration.h" |
6 | 6 |
7 #include "content/browser/service_worker/service_worker_context_core.h" | 7 #include "content/browser/service_worker/service_worker_context_core.h" |
8 #include "content/browser/service_worker/service_worker_info.h" | 8 #include "content/browser/service_worker/service_worker_info.h" |
9 #include "content/browser/service_worker/service_worker_register_job.h" | 9 #include "content/browser/service_worker/service_worker_register_job.h" |
10 #include "content/browser/service_worker/service_worker_utils.h" | 10 #include "content/browser/service_worker/service_worker_utils.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 // "2. Terminate exitingWorker." | 168 // "2. Terminate exitingWorker." |
169 exiting_version->StopWorker( | 169 exiting_version->StopWorker( |
170 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 170 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
171 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and | 171 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and |
172 // "redundant" as the arguments." | 172 // "redundant" as the arguments." |
173 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); | 173 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); |
174 } | 174 } |
175 | 175 |
176 // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker." | 176 // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker." |
177 // "6. Set serviceWorkerRegistration.waitingWorker to null." | 177 // "6. Set serviceWorkerRegistration.waitingWorker to null." |
178 ServiceWorkerRegisterJob::DisassociateVersionFromDocuments( | |
179 context_, activating_version); | |
180 SetActiveVersion(activating_version); | 178 SetActiveVersion(activating_version); |
181 ServiceWorkerRegisterJob::AssociateActiveVersionToDocuments( | |
182 context_, activating_version); | |
183 | 179 |
184 // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and | 180 // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and |
185 // "activating" as arguments." | 181 // "activating" as arguments." |
186 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); | 182 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); |
187 | 183 |
188 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." | 184 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." |
189 | 185 |
190 // "9. Queue a task to fire an event named activate..." | 186 // "9. Queue a task to fire an event named activate..." |
191 activating_version->DispatchActivateEvent( | 187 activating_version->DispatchActivateEvent( |
192 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, | 188 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, |
193 this, activating_version)); | 189 this, activating_version)); |
194 } | 190 } |
195 | 191 |
196 void ServiceWorkerRegistration::OnActivateEventFinished( | 192 void ServiceWorkerRegistration::OnActivateEventFinished( |
197 ServiceWorkerVersion* activating_version, | 193 ServiceWorkerVersion* activating_version, |
198 ServiceWorkerStatusCode status) { | 194 ServiceWorkerStatusCode status) { |
199 if (!context_ || activating_version != active_version()) | 195 if (!context_ || activating_version != active_version()) |
200 return; | 196 return; |
201 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is | 197 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is |
202 // unexpectedly terminated) we may want to retry sending the event again. | 198 // unexpectedly terminated) we may want to retry sending the event again. |
203 if (status != SERVICE_WORKER_OK) { | 199 if (status != SERVICE_WORKER_OK) { |
204 // "11. If activateFailed is true, then:..." | 200 // "11. If activateFailed is true, then:..." |
205 ServiceWorkerRegisterJob::DisassociateVersionFromDocuments( | |
206 context_, activating_version); | |
207 UnsetVersion(activating_version); | 201 UnsetVersion(activating_version); |
208 activating_version->Doom(); | 202 activating_version->Doom(); |
209 if (!waiting_version()) { | 203 if (!waiting_version()) { |
210 // Delete the records from the db. | 204 // Delete the records from the db. |
211 context_->storage()->DeleteRegistration( | 205 context_->storage()->DeleteRegistration( |
212 id(), script_url().GetOrigin(), | 206 id(), script_url().GetOrigin(), |
213 base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this)); | 207 base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this)); |
214 // But not from memory if there is a version in the pipeline. | 208 // But not from memory if there is a version in the pipeline. |
215 if (installing_version()) | 209 if (installing_version()) |
216 is_deleted_ = false; | 210 is_deleted_ = false; |
(...skipping 18 matching lines...) Expand all Loading... |
235 } | 229 } |
236 } | 230 } |
237 | 231 |
238 void ServiceWorkerRegistration::OnDeleteFinished( | 232 void ServiceWorkerRegistration::OnDeleteFinished( |
239 ServiceWorkerStatusCode status) { | 233 ServiceWorkerStatusCode status) { |
240 // Intentionally empty completion callback, used to prevent | 234 // Intentionally empty completion callback, used to prevent |
241 // |this| from being deleted until the storage method completes. | 235 // |this| from being deleted until the storage method completes. |
242 } | 236 } |
243 | 237 |
244 } // namespace content | 238 } // namespace content |
OLD | NEW |