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" |
11 #include "content/browser/service_worker/service_worker_job_coordinator.h" | 11 #include "content/browser/service_worker/service_worker_job_coordinator.h" |
12 #include "content/browser/service_worker/service_worker_registration.h" | 12 #include "content/browser/service_worker/service_worker_registration.h" |
13 #include "content/browser/service_worker/service_worker_storage.h" | 13 #include "content/browser/service_worker/service_worker_storage.h" |
14 #include "content/browser/service_worker/service_worker_utils.h" | 14 #include "content/browser/service_worker/service_worker_utils.h" |
15 #include "net/base/net_errors.h" | |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 void RunSoon(const base::Closure& closure) { | 21 void RunSoon(const base::Closure& closure) { |
21 base::MessageLoop::current()->PostTask(FROM_HERE, closure); | 22 base::MessageLoop::current()->PostTask(FROM_HERE, closure); |
22 } | 23 } |
23 | 24 |
24 } // namespace | 25 } // namespace |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 if (pause_after_download) | 327 if (pause_after_download) |
327 new_version()->embedded_worker()->AddListener(this); | 328 new_version()->embedded_worker()->AddListener(this); |
328 new_version()->StartWorker( | 329 new_version()->StartWorker( |
329 pause_after_download, | 330 pause_after_download, |
330 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, | 331 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, |
331 weak_factory_.GetWeakPtr())); | 332 weak_factory_.GetWeakPtr())); |
332 } | 333 } |
333 | 334 |
334 void ServiceWorkerRegisterJob::OnStartWorkerFinished( | 335 void ServiceWorkerRegisterJob::OnStartWorkerFinished( |
335 ServiceWorkerStatusCode status) { | 336 ServiceWorkerStatusCode status) { |
336 // "If serviceWorker fails to start up..." then reject the promise with an | 337 if (status == SERVICE_WORKER_OK) { |
337 // error and abort. | 338 InstallAndContinue(); |
338 if (status != SERVICE_WORKER_OK) { | |
339 Complete(status); | |
340 return; | 339 return; |
341 } | 340 } |
342 | 341 |
343 InstallAndContinue(); | 342 // "If serviceWorker fails to start up..." then reject the promise with an |
343 // error and abort. When there is a main script network error, the status will | |
344 // be updated to a more specific one. | |
345 const net::URLRequestStatus& main_script_status = | |
346 new_version()->script_cache_map()->main_script_status(); | |
347 if (main_script_status.status() != net::URLRequestStatus::SUCCESS) { | |
348 switch (main_script_status.error()) { | |
349 case net::ERR_INSECURE_RESPONSE: | |
350 case net::ERR_UNSAFE_REDIRECT: | |
351 status = SERVICE_WORKER_ERROR_SECURITY; | |
352 break; | |
353 case net::ERR_ABORTED: | |
354 status = SERVICE_WORKER_ERROR_ABORT; | |
355 break; | |
356 case net::ERR_FAILED: | |
357 status = SERVICE_WORKER_ERROR_NETWORK; | |
358 break; | |
359 default: | |
360 NOTREACHED(); | |
horo
2014/09/24 12:55:32
Why don't we handle other error types?
| |
361 } | |
362 } | |
363 Complete(status); | |
344 } | 364 } |
345 | 365 |
346 // This function corresponds to the spec's [[Install]] algorithm. | 366 // This function corresponds to the spec's [[Install]] algorithm. |
347 void ServiceWorkerRegisterJob::InstallAndContinue() { | 367 void ServiceWorkerRegisterJob::InstallAndContinue() { |
348 SetPhase(INSTALL); | 368 SetPhase(INSTALL); |
349 | 369 |
350 // "2. Set registration.installingWorker to worker." | 370 // "2. Set registration.installingWorker to worker." |
351 registration()->SetInstallingVersion(new_version()); | 371 registration()->SetInstallingVersion(new_version()); |
352 | 372 |
353 // "3. Resolve promise with registration." | 373 // "3. Resolve promise with registration." |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 ServiceWorkerProviderHost* host = it->GetProviderHost(); | 557 ServiceWorkerProviderHost* host = it->GetProviderHost(); |
538 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 558 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
539 host->document_url())) { | 559 host->document_url())) { |
540 if (host->CanAssociateRegistration(registration)) | 560 if (host->CanAssociateRegistration(registration)) |
541 host->AssociateRegistration(registration); | 561 host->AssociateRegistration(registration); |
542 } | 562 } |
543 } | 563 } |
544 } | 564 } |
545 | 565 |
546 } // namespace content | 566 } // namespace content |
OLD | NEW |