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_metrics.h" | 9 #include "content/browser/service_worker/service_worker_metrics.h" |
10 #include "content/browser/service_worker/service_worker_register_job.h" | 10 #include "content/browser/service_worker/service_worker_register_job.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 246 } |
247 | 247 |
248 void ServiceWorkerRegistration::ClearUserData( | 248 void ServiceWorkerRegistration::ClearUserData( |
249 const std::string& key, | 249 const std::string& key, |
250 const StatusCallback& callback) { | 250 const StatusCallback& callback) { |
251 DCHECK(context_); | 251 DCHECK(context_); |
252 context_->storage()->ClearUserData(registration_id_, key, callback); | 252 context_->storage()->ClearUserData(registration_id_, key, callback); |
253 } | 253 } |
254 | 254 |
255 void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) { | 255 void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) { |
| 256 if (!context_) |
| 257 return; |
256 DCHECK_EQ(active_version(), version); | 258 DCHECK_EQ(active_version(), version); |
257 if (is_uninstalling_) | 259 if (is_uninstalling_) |
258 Clear(); | 260 Clear(); |
259 else if (should_activate_when_ready_) | 261 else if (should_activate_when_ready_) |
260 ActivateWaitingVersion(); | 262 ActivateWaitingVersion(); |
261 is_uninstalling_ = false; | 263 is_uninstalling_ = false; |
262 should_activate_when_ready_ = false; | 264 should_activate_when_ready_ = false; |
263 } | 265 } |
264 | 266 |
265 void ServiceWorkerRegistration::ActivateWaitingVersion() { | 267 void ServiceWorkerRegistration::ActivateWaitingVersion() { |
(...skipping 29 matching lines...) Expand all Loading... |
295 // "9. Fire a simple event named controllerchange..." | 297 // "9. Fire a simple event named controllerchange..." |
296 if (activating_version->skip_waiting()) | 298 if (activating_version->skip_waiting()) |
297 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); | 299 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); |
298 | 300 |
299 // "10. Queue a task to fire an event named activate..." | 301 // "10. Queue a task to fire an event named activate..." |
300 activating_version->DispatchActivateEvent( | 302 activating_version->DispatchActivateEvent( |
301 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, | 303 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, |
302 this, activating_version)); | 304 this, activating_version)); |
303 } | 305 } |
304 | 306 |
| 307 void ServiceWorkerRegistration::DeleteVersion( |
| 308 const scoped_refptr<ServiceWorkerVersion>& version) { |
| 309 DCHECK_EQ(id(), version->registration_id()); |
| 310 |
| 311 // "Set registration's active worker to null." (The spec's step order may |
| 312 // differ. It's OK because the other steps queue a task.) |
| 313 UnsetVersion(version.get()); |
| 314 |
| 315 // "Run the Update State algorithm passing registration's active worker and |
| 316 // 'redundant' as the arguments." |
| 317 version->SetStatus(ServiceWorkerVersion::REDUNDANT); |
| 318 |
| 319 // "For each service worker client client whose active worker is |
| 320 // registration's active worker..." set the active worker to null. |
| 321 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
| 322 context_->GetProviderHostIterator(); |
| 323 !it->IsAtEnd(); it->Advance()) { |
| 324 ServiceWorkerProviderHost* host = it->GetProviderHost(); |
| 325 if (host->controlling_version() == version) |
| 326 host->NotifyControllerActivationFailed(); |
| 327 } |
| 328 |
| 329 version->Doom(); |
| 330 |
| 331 if (!active_version() && !waiting_version()) { |
| 332 // Delete the records from the db. |
| 333 context_->storage()->DeleteRegistration( |
| 334 id(), pattern().GetOrigin(), |
| 335 base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this)); |
| 336 // But not from memory if there is a version in the pipeline. |
| 337 if (installing_version()) { |
| 338 is_deleted_ = false; |
| 339 } else { |
| 340 is_uninstalled_ = true; |
| 341 FOR_EACH_OBSERVER(Listener, listeners_, OnRegistrationFailed(this)); |
| 342 } |
| 343 } |
| 344 } |
| 345 |
305 void ServiceWorkerRegistration::OnActivateEventFinished( | 346 void ServiceWorkerRegistration::OnActivateEventFinished( |
306 ServiceWorkerVersion* activating_version, | 347 ServiceWorkerVersion* activating_version, |
307 ServiceWorkerStatusCode status) { | 348 ServiceWorkerStatusCode status) { |
308 if (!context_ || activating_version != active_version()) | 349 if (!context_ || activating_version != active_version()) |
309 return; | 350 return; |
310 ServiceWorkerMetrics::RecordActivateEventStatus(status); | 351 ServiceWorkerMetrics::RecordActivateEventStatus(status); |
311 | 352 |
312 // "If activateFailed is true, then:..." | 353 // "If activateFailed is true, then:..." |
313 if (status != SERVICE_WORKER_OK) { | 354 if (status != SERVICE_WORKER_OK) { |
314 // "Set registration's active worker to null." (The spec's step order may | 355 DeleteVersion(make_scoped_refptr(activating_version)); |
315 // differ. It's OK because the other steps queue a task.) | |
316 UnsetVersion(activating_version); | |
317 | |
318 // "Run the Update State algorithm passing registration's active worker and | |
319 // 'redundant' as the arguments." | |
320 activating_version->SetStatus(ServiceWorkerVersion::REDUNDANT); | |
321 | |
322 // "For each service worker client client whose active worker is | |
323 // registration's active worker..." set the active worker to null. | |
324 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = | |
325 context_->GetProviderHostIterator(); | |
326 !it->IsAtEnd(); it->Advance()) { | |
327 ServiceWorkerProviderHost* host = it->GetProviderHost(); | |
328 if (host->controlling_version() == activating_version) | |
329 host->NotifyControllerActivationFailed(); | |
330 } | |
331 | |
332 activating_version->Doom(); | |
333 if (!waiting_version()) { | |
334 // Delete the records from the db. | |
335 context_->storage()->DeleteRegistration( | |
336 id(), pattern().GetOrigin(), | |
337 base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this)); | |
338 // But not from memory if there is a version in the pipeline. | |
339 if (installing_version()) { | |
340 is_deleted_ = false; | |
341 } else { | |
342 is_uninstalled_ = true; | |
343 FOR_EACH_OBSERVER(Listener, listeners_, OnRegistrationFailed(this)); | |
344 } | |
345 } | |
346 return; | 356 return; |
347 } | 357 } |
348 | 358 |
349 // "Run the Update State algorithm passing registration's active worker and | 359 // "Run the Update State algorithm passing registration's active worker and |
350 // 'activated' as the arguments." | 360 // 'activated' as the arguments." |
351 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); | 361 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); |
352 if (context_) { | 362 if (context_) { |
353 context_->storage()->UpdateToActiveState( | 363 context_->storage()->UpdateToActiveState( |
354 this, | 364 this, |
355 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 365 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 if (!context_) { | 412 if (!context_) { |
403 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 413 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
404 return; | 414 return; |
405 } | 415 } |
406 context_->storage()->NotifyDoneInstallingRegistration( | 416 context_->storage()->NotifyDoneInstallingRegistration( |
407 this, version.get(), status); | 417 this, version.get(), status); |
408 callback.Run(status); | 418 callback.Run(status); |
409 } | 419 } |
410 | 420 |
411 } // namespace content | 421 } // namespace content |
OLD | NEW |