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