| 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 331 |
| 332 void ServiceWorkerRegisterJob::OnStartWorkerFinished( | 332 void ServiceWorkerRegisterJob::OnStartWorkerFinished( |
| 333 ServiceWorkerStatusCode status) { | 333 ServiceWorkerStatusCode status) { |
| 334 // "If serviceWorker fails to start up..." then reject the promise with an | 334 // "If serviceWorker fails to start up..." then reject the promise with an |
| 335 // error and abort. | 335 // error and abort. |
| 336 if (status != SERVICE_WORKER_OK) { | 336 if (status != SERVICE_WORKER_OK) { |
| 337 Complete(status); | 337 Complete(status); |
| 338 return; | 338 return; |
| 339 } | 339 } |
| 340 | 340 |
| 341 // "Resolve promise with serviceWorker." | |
| 342 DCHECK(!registration()->installing_version()); | |
| 343 ResolvePromise(status, registration(), new_version()); | |
| 344 InstallAndContinue(); | 341 InstallAndContinue(); |
| 345 } | 342 } |
| 346 | 343 |
| 347 // This function corresponds to the spec's _Install algorithm. | 344 // This function corresponds to the spec's [[Install]] algorithm. |
| 348 void ServiceWorkerRegisterJob::InstallAndContinue() { | 345 void ServiceWorkerRegisterJob::InstallAndContinue() { |
| 349 SetPhase(INSTALL); | 346 SetPhase(INSTALL); |
| 350 | 347 |
| 351 // "3. Set registration.installingWorker to worker." | 348 // "2. Set registration.installingWorker to worker." |
| 352 registration()->SetInstallingVersion(new_version()); | 349 registration()->SetInstallingVersion(new_version()); |
| 353 | 350 |
| 351 // "3. Resolve promise with registration." |
| 352 ResolvePromise(SERVICE_WORKER_OK, registration(), new_version()); |
| 353 |
| 354 // "4. Run the [[UpdateState]] algorithm passing registration.installingWorker | 354 // "4. Run the [[UpdateState]] algorithm passing registration.installingWorker |
| 355 // and "installing" as the arguments." | 355 // and "installing" as the arguments." |
| 356 new_version()->SetStatus(ServiceWorkerVersion::INSTALLING); | 356 new_version()->SetStatus(ServiceWorkerVersion::INSTALLING); |
| 357 | 357 |
| 358 // TODO(nhiroki,michaeln): "5. Fire a simple event named updatefound..." | 358 // "5. Fire a simple event named updatefound..." |
| 359 registration()->NotifyUpdateFound(); |
| 359 | 360 |
| 360 // "6. Fire an event named install..." | 361 // "6. Fire an event named install..." |
| 361 new_version()->DispatchInstallEvent( | 362 new_version()->DispatchInstallEvent( |
| 362 -1, | 363 -1, |
| 363 base::Bind(&ServiceWorkerRegisterJob::OnInstallFinished, | 364 base::Bind(&ServiceWorkerRegisterJob::OnInstallFinished, |
| 364 weak_factory_.GetWeakPtr())); | 365 weak_factory_.GetWeakPtr())); |
| 365 } | 366 } |
| 366 | 367 |
| 367 void ServiceWorkerRegisterJob::OnInstallFinished( | 368 void ServiceWorkerRegisterJob::OnInstallFinished( |
| 368 ServiceWorkerStatusCode status) { | 369 ServiceWorkerStatusCode status) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 ServiceWorkerProviderHost* host = it->GetProviderHost(); | 535 ServiceWorkerProviderHost* host = it->GetProviderHost(); |
| 535 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 536 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
| 536 host->document_url())) { | 537 host->document_url())) { |
| 537 if (host->CanAssociateRegistration(registration)) | 538 if (host->CanAssociateRegistration(registration)) |
| 538 host->AssociateRegistration(registration); | 539 host->AssociateRegistration(registration); |
| 539 } | 540 } |
| 540 } | 541 } |
| 541 } | 542 } |
| 542 | 543 |
| 543 } // namespace content | 544 } // namespace content |
| OLD | NEW |