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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "content/browser/service_worker/embedded_worker_status.h" | 13 #include "content/browser/service_worker/embedded_worker_status.h" |
14 #include "content/browser/service_worker/service_worker_context_core.h" | 14 #include "content/browser/service_worker/service_worker_context_core.h" |
15 #include "content/browser/service_worker/service_worker_job_coordinator.h" | 15 #include "content/browser/service_worker/service_worker_job_coordinator.h" |
16 #include "content/browser/service_worker/service_worker_metrics.h" | 16 #include "content/browser/service_worker/service_worker_metrics.h" |
17 #include "content/browser/service_worker/service_worker_registration.h" | 17 #include "content/browser/service_worker/service_worker_registration.h" |
18 #include "content/browser/service_worker/service_worker_storage.h" | 18 #include "content/browser/service_worker/service_worker_storage.h" |
19 #include "content/browser/service_worker/service_worker_write_to_cache_job.h" | 19 #include "content/browser/service_worker/service_worker_write_to_cache_job.h" |
20 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" | |
20 #include "content/common/service_worker/service_worker_messages.h" | 21 #include "content/common/service_worker/service_worker_messages.h" |
21 #include "content/common/service_worker/service_worker_types.h" | 22 #include "content/common/service_worker/service_worker_types.h" |
22 #include "content/common/service_worker/service_worker_utils.h" | 23 #include "content/common/service_worker/service_worker_utils.h" |
23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
24 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
25 | 26 |
26 namespace content { | 27 namespace content { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 void RunSoon(const base::Closure& closure) { | 31 void RunSoon(const base::Closure& closure) { |
31 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); | 32 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); |
32 } | 33 } |
33 | 34 |
34 } // namespace | 35 } // namespace |
35 | 36 |
36 typedef ServiceWorkerRegisterJobBase::RegistrationJobType RegistrationJobType; | 37 typedef ServiceWorkerRegisterJobBase::RegistrationJobType RegistrationJobType; |
37 | 38 |
38 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( | 39 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( |
39 base::WeakPtr<ServiceWorkerContextCore> context, | 40 base::WeakPtr<ServiceWorkerContextCore> context, |
40 const GURL& pattern, | 41 const GURL& pattern, |
41 const GURL& script_url) | 42 const GURL& script_url) |
42 : context_(context), | 43 : context_(context), |
44 install_method_binding_(this), | |
43 job_type_(REGISTRATION_JOB), | 45 job_type_(REGISTRATION_JOB), |
44 pattern_(pattern), | 46 pattern_(pattern), |
45 script_url_(script_url), | 47 script_url_(script_url), |
46 phase_(INITIAL), | 48 phase_(INITIAL), |
47 doom_installing_worker_(false), | 49 doom_installing_worker_(false), |
48 is_promise_resolved_(false), | 50 is_promise_resolved_(false), |
49 should_uninstall_on_failure_(false), | 51 should_uninstall_on_failure_(false), |
50 force_bypass_cache_(false), | 52 force_bypass_cache_(false), |
51 skip_script_comparison_(false), | 53 skip_script_comparison_(false), |
52 promise_resolved_status_(SERVICE_WORKER_OK), | 54 promise_resolved_status_(SERVICE_WORKER_OK), |
53 weak_factory_(this) {} | 55 weak_factory_(this) {} |
54 | 56 |
55 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( | 57 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( |
56 base::WeakPtr<ServiceWorkerContextCore> context, | 58 base::WeakPtr<ServiceWorkerContextCore> context, |
57 ServiceWorkerRegistration* registration, | 59 ServiceWorkerRegistration* registration, |
58 bool force_bypass_cache, | 60 bool force_bypass_cache, |
59 bool skip_script_comparison) | 61 bool skip_script_comparison) |
60 : context_(context), | 62 : context_(context), |
63 install_method_binding_(this), | |
61 job_type_(UPDATE_JOB), | 64 job_type_(UPDATE_JOB), |
62 pattern_(registration->pattern()), | 65 pattern_(registration->pattern()), |
63 phase_(INITIAL), | 66 phase_(INITIAL), |
64 doom_installing_worker_(false), | 67 doom_installing_worker_(false), |
65 is_promise_resolved_(false), | 68 is_promise_resolved_(false), |
66 should_uninstall_on_failure_(false), | 69 should_uninstall_on_failure_(false), |
67 force_bypass_cache_(force_bypass_cache), | 70 force_bypass_cache_(force_bypass_cache), |
68 skip_script_comparison_(skip_script_comparison), | 71 skip_script_comparison_(skip_script_comparison), |
69 promise_resolved_status_(SERVICE_WORKER_OK), | 72 promise_resolved_status_(SERVICE_WORKER_OK), |
70 weak_factory_(this) { | 73 weak_factory_(this) { |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 | 427 |
425 void ServiceWorkerRegisterJob::DispatchInstallEvent() { | 428 void ServiceWorkerRegisterJob::DispatchInstallEvent() { |
426 DCHECK_EQ(ServiceWorkerVersion::INSTALLING, new_version()->status()) | 429 DCHECK_EQ(ServiceWorkerVersion::INSTALLING, new_version()->status()) |
427 << new_version()->status(); | 430 << new_version()->status(); |
428 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, new_version()->running_status()) | 431 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, new_version()->running_status()) |
429 << "Worker stopped too soon after it was started."; | 432 << "Worker stopped too soon after it was started."; |
430 int request_id = new_version()->StartRequest( | 433 int request_id = new_version()->StartRequest( |
431 ServiceWorkerMetrics::EventType::INSTALL, | 434 ServiceWorkerMetrics::EventType::INSTALL, |
432 base::Bind(&ServiceWorkerRegisterJob::OnInstallFailed, | 435 base::Bind(&ServiceWorkerRegisterJob::OnInstallFailed, |
433 weak_factory_.GetWeakPtr())); | 436 weak_factory_.GetWeakPtr())); |
434 new_version() | 437 |
shimazu
2017/04/05 05:01:27
DCHECK(!install_method_binding_.is_bound());
| |
435 ->RegisterRequestCallback<ServiceWorkerHostMsg_InstallEventFinished>( | 438 mojom::InstallEventMethodAssociatedPtrInfo install_method_ptr_info; |
436 request_id, base::Bind(&ServiceWorkerRegisterJob::OnInstallFinished, | 439 install_method_binding_.Bind(&install_method_ptr_info); |
437 weak_factory_.GetWeakPtr())); | 440 |
438 new_version()->DispatchEvent({request_id}, | 441 new_version()->event_dispatcher()->DispatchInstallEvent( |
439 ServiceWorkerMsg_InstallEvent(request_id)); | 442 std::move(install_method_ptr_info), |
443 base::Bind(&ServiceWorkerRegisterJob::OnInstallFinished, | |
444 weak_factory_.GetWeakPtr(), request_id)); | |
shimazu
2017/04/05 05:01:27
I think it's good to create a receiver class like
| |
445 } | |
446 | |
447 void ServiceWorkerRegisterJob::Register( | |
448 const std::vector<GURL>& sub_scopes, | |
449 const std::vector<url::Origin>& origins) { | |
450 new_version()->RegisterForeignFetchScopes(sub_scopes, origins); | |
440 } | 451 } |
441 | 452 |
442 void ServiceWorkerRegisterJob::OnInstallFinished( | 453 void ServiceWorkerRegisterJob::OnInstallFinished( |
443 int request_id, | 454 int request_id, |
444 blink::WebServiceWorkerEventResult result, | 455 ServiceWorkerStatusCode status, |
445 bool has_fetch_handler, | 456 bool has_fetch_handler, |
446 base::Time dispatch_event_time) { | 457 base::Time dispatch_event_time) { |
447 new_version()->FinishRequest( | 458 new_version()->FinishRequest(request_id, status == SERVICE_WORKER_OK, |
448 request_id, result == blink::WebServiceWorkerEventResultCompleted, | 459 dispatch_event_time); |
449 dispatch_event_time); | |
450 | |
451 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
452 switch (result) { | |
453 case blink::WebServiceWorkerEventResultCompleted: | |
454 status = SERVICE_WORKER_OK; | |
455 break; | |
456 case blink::WebServiceWorkerEventResultRejected: | |
457 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; | |
458 break; | |
459 default: | |
460 NOTREACHED(); | |
461 } | |
462 | 460 |
463 if (status != SERVICE_WORKER_OK) { | 461 if (status != SERVICE_WORKER_OK) { |
464 OnInstallFailed(status); | 462 OnInstallFailed(status); |
465 return; | 463 return; |
466 } | 464 } |
467 | 465 |
468 ServiceWorkerMetrics::RecordInstallEventStatus(status); | 466 ServiceWorkerMetrics::RecordInstallEventStatus(status); |
469 ServiceWorkerMetrics::RecordForeignFetchRegistrationCount( | 467 ServiceWorkerMetrics::RecordForeignFetchRegistrationCount( |
470 new_version()->foreign_fetch_scopes().size(), | 468 new_version()->foreign_fetch_scopes().size(), |
471 new_version()->foreign_fetch_origins().size()); | 469 new_version()->foreign_fetch_origins().size()); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 new_version()->force_bypass_cache_for_scripts() || | 646 new_version()->force_bypass_cache_for_scripts() || |
649 registration()->last_update_check().is_null()) { | 647 registration()->last_update_check().is_null()) { |
650 registration()->set_last_update_check(base::Time::Now()); | 648 registration()->set_last_update_check(base::Time::Now()); |
651 | 649 |
652 if (registration()->has_installed_version()) | 650 if (registration()->has_installed_version()) |
653 context_->storage()->UpdateLastUpdateCheckTime(registration()); | 651 context_->storage()->UpdateLastUpdateCheckTime(registration()); |
654 } | 652 } |
655 } | 653 } |
656 | 654 |
657 } // namespace content | 655 } // namespace content |
OLD | NEW |