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_context_core.h" | 5 #include "content/browser/service_worker/service_worker_context_core.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/barrier_closure.h" | 11 #include "base/barrier_closure.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
21 #include "content/browser/frame_host/render_frame_host_impl.h" | 21 #include "content/browser/frame_host/render_frame_host_impl.h" |
22 #include "content/browser/service_worker/embedded_worker_registry.h" | 22 #include "content/browser/service_worker/embedded_worker_registry.h" |
23 #include "content/browser/service_worker/embedded_worker_status.h" | 23 #include "content/browser/service_worker/embedded_worker_status.h" |
24 #include "content/browser/service_worker/service_worker_context_observer.h" | 24 #include "content/browser/service_worker/service_worker_context_core_observer.h" |
25 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 25 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
26 #include "content/browser/service_worker/service_worker_database_task_manager.h" | 26 #include "content/browser/service_worker/service_worker_database_task_manager.h" |
27 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | 27 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
28 #include "content/browser/service_worker/service_worker_info.h" | 28 #include "content/browser/service_worker/service_worker_info.h" |
29 #include "content/browser/service_worker/service_worker_job_coordinator.h" | 29 #include "content/browser/service_worker/service_worker_job_coordinator.h" |
30 #include "content/browser/service_worker/service_worker_process_manager.h" | 30 #include "content/browser/service_worker/service_worker_process_manager.h" |
31 #include "content/browser/service_worker/service_worker_provider_host.h" | 31 #include "content/browser/service_worker/service_worker_provider_host.h" |
32 #include "content/browser/service_worker/service_worker_register_job.h" | 32 #include "content/browser/service_worker/service_worker_register_job.h" |
33 #include "content/browser/service_worker/service_worker_registration.h" | 33 #include "content/browser/service_worker/service_worker_registration.h" |
34 #include "content/browser/service_worker/service_worker_storage.h" | 34 #include "content/browser/service_worker/service_worker_storage.h" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 232 } |
233 return false; | 233 return false; |
234 } | 234 } |
235 | 235 |
236 ServiceWorkerContextCore::ServiceWorkerContextCore( | 236 ServiceWorkerContextCore::ServiceWorkerContextCore( |
237 const base::FilePath& path, | 237 const base::FilePath& path, |
238 std::unique_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, | 238 std::unique_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, |
239 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, | 239 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, |
240 storage::QuotaManagerProxy* quota_manager_proxy, | 240 storage::QuotaManagerProxy* quota_manager_proxy, |
241 storage::SpecialStoragePolicy* special_storage_policy, | 241 storage::SpecialStoragePolicy* special_storage_policy, |
242 base::ObserverListThreadSafe<ServiceWorkerContextObserver>* observer_list, | 242 base::ObserverListThreadSafe<ServiceWorkerContextCoreObserver>* |
| 243 observer_list, |
243 ServiceWorkerContextWrapper* wrapper) | 244 ServiceWorkerContextWrapper* wrapper) |
244 : wrapper_(wrapper), | 245 : wrapper_(wrapper), |
245 providers_(base::MakeUnique<ProcessToProviderMap>()), | 246 providers_(base::MakeUnique<ProcessToProviderMap>()), |
246 provider_by_uuid_(base::MakeUnique<ProviderByClientUUIDMap>()), | 247 provider_by_uuid_(base::MakeUnique<ProviderByClientUUIDMap>()), |
247 force_update_on_page_load_(false), | 248 force_update_on_page_load_(false), |
248 next_handle_id_(0), | 249 next_handle_id_(0), |
249 next_registration_handle_id_(0), | 250 next_registration_handle_id_(0), |
250 was_service_worker_registered_(false), | 251 was_service_worker_registered_(false), |
251 observer_list_(observer_list), | 252 observer_list_(observer_list), |
252 weak_factory_(this) { | 253 weak_factory_(this) { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 callback.Run(status, status_message, kInvalidServiceWorkerRegistrationId); | 508 callback.Run(status, status_message, kInvalidServiceWorkerRegistrationId); |
508 return; | 509 return; |
509 } | 510 } |
510 | 511 |
511 DCHECK(registration); | 512 DCHECK(registration); |
512 callback.Run(status, status_message, registration->id()); | 513 callback.Run(status, status_message, registration->id()); |
513 // TODO(falken): At this point the registration promise is resolved, but we | 514 // TODO(falken): At this point the registration promise is resolved, but we |
514 // haven't persisted anything to storage yet. So we should either call | 515 // haven't persisted anything to storage yet. So we should either call |
515 // OnRegistrationStored somewhere else or change its name. | 516 // OnRegistrationStored somewhere else or change its name. |
516 if (observer_list_.get()) { | 517 if (observer_list_.get()) { |
517 observer_list_->Notify(FROM_HERE, | 518 observer_list_->Notify( |
518 &ServiceWorkerContextObserver::OnRegistrationStored, | 519 FROM_HERE, &ServiceWorkerContextCoreObserver::OnRegistrationStored, |
519 registration->id(), pattern); | 520 registration->id(), pattern); |
520 } | 521 } |
521 } | 522 } |
522 | 523 |
523 void ServiceWorkerContextCore::UpdateComplete( | 524 void ServiceWorkerContextCore::UpdateComplete( |
524 const ServiceWorkerContextCore::UpdateCallback& callback, | 525 const ServiceWorkerContextCore::UpdateCallback& callback, |
525 ServiceWorkerStatusCode status, | 526 ServiceWorkerStatusCode status, |
526 const std::string& status_message, | 527 const std::string& status_message, |
527 ServiceWorkerRegistration* registration) { | 528 ServiceWorkerRegistration* registration) { |
528 if (status != SERVICE_WORKER_OK) { | 529 if (status != SERVICE_WORKER_OK) { |
529 DCHECK(!registration); | 530 DCHECK(!registration); |
530 callback.Run(status, status_message, kInvalidServiceWorkerRegistrationId); | 531 callback.Run(status, status_message, kInvalidServiceWorkerRegistrationId); |
531 return; | 532 return; |
532 } | 533 } |
533 | 534 |
534 DCHECK(registration); | 535 DCHECK(registration); |
535 callback.Run(status, status_message, registration->id()); | 536 callback.Run(status, status_message, registration->id()); |
536 } | 537 } |
537 | 538 |
538 void ServiceWorkerContextCore::UnregistrationComplete( | 539 void ServiceWorkerContextCore::UnregistrationComplete( |
539 const GURL& pattern, | 540 const GURL& pattern, |
540 const ServiceWorkerContextCore::UnregistrationCallback& callback, | 541 const ServiceWorkerContextCore::UnregistrationCallback& callback, |
541 int64_t registration_id, | 542 int64_t registration_id, |
542 ServiceWorkerStatusCode status) { | 543 ServiceWorkerStatusCode status) { |
543 callback.Run(status); | 544 callback.Run(status); |
544 if (status == SERVICE_WORKER_OK && observer_list_.get()) { | 545 if (status == SERVICE_WORKER_OK && observer_list_.get()) { |
545 observer_list_->Notify(FROM_HERE, | 546 observer_list_->Notify( |
546 &ServiceWorkerContextObserver::OnRegistrationDeleted, | 547 FROM_HERE, &ServiceWorkerContextCoreObserver::OnRegistrationDeleted, |
547 registration_id, pattern); | 548 registration_id, pattern); |
548 } | 549 } |
549 } | 550 } |
550 | 551 |
551 ServiceWorkerRegistration* ServiceWorkerContextCore::GetLiveRegistration( | 552 ServiceWorkerRegistration* ServiceWorkerContextCore::GetLiveRegistration( |
552 int64_t id) { | 553 int64_t id) { |
553 RegistrationsMap::iterator it = live_registrations_.find(id); | 554 RegistrationsMap::iterator it = live_registrations_.find(id); |
554 return (it != live_registrations_.end()) ? it->second : nullptr; | 555 return (it != live_registrations_.end()) ? it->second : nullptr; |
555 } | 556 } |
556 | 557 |
557 void ServiceWorkerContextCore::AddLiveRegistration( | 558 void ServiceWorkerContextCore::AddLiveRegistration( |
558 ServiceWorkerRegistration* registration) { | 559 ServiceWorkerRegistration* registration) { |
559 // TODO(nhiroki): Change CHECK to DCHECK after https://crbug.com/619294 is | 560 // TODO(nhiroki): Change CHECK to DCHECK after https://crbug.com/619294 is |
560 // fixed. | 561 // fixed. |
561 CHECK(!GetLiveRegistration(registration->id())); | 562 CHECK(!GetLiveRegistration(registration->id())); |
562 live_registrations_[registration->id()] = registration; | 563 live_registrations_[registration->id()] = registration; |
563 if (observer_list_.get()) { | 564 if (observer_list_.get()) { |
564 observer_list_->Notify(FROM_HERE, | 565 observer_list_->Notify( |
565 &ServiceWorkerContextObserver::OnNewLiveRegistration, | 566 FROM_HERE, &ServiceWorkerContextCoreObserver::OnNewLiveRegistration, |
566 registration->id(), registration->pattern()); | 567 registration->id(), registration->pattern()); |
567 } | 568 } |
568 } | 569 } |
569 | 570 |
570 void ServiceWorkerContextCore::RemoveLiveRegistration(int64_t id) { | 571 void ServiceWorkerContextCore::RemoveLiveRegistration(int64_t id) { |
571 live_registrations_.erase(id); | 572 live_registrations_.erase(id); |
572 } | 573 } |
573 | 574 |
574 ServiceWorkerVersion* ServiceWorkerContextCore::GetLiveVersion(int64_t id) { | 575 ServiceWorkerVersion* ServiceWorkerContextCore::GetLiveVersion(int64_t id) { |
575 VersionMap::iterator it = live_versions_.find(id); | 576 VersionMap::iterator it = live_versions_.find(id); |
576 return (it != live_versions_.end()) ? it->second : nullptr; | 577 return (it != live_versions_.end()) ? it->second : nullptr; |
(...skipping 28 matching lines...) Expand all Loading... |
605 | 606 |
606 void ServiceWorkerContextCore::AddLiveVersion(ServiceWorkerVersion* version) { | 607 void ServiceWorkerContextCore::AddLiveVersion(ServiceWorkerVersion* version) { |
607 // TODO(horo): If we will see crashes here, we have to find the root cause of | 608 // TODO(horo): If we will see crashes here, we have to find the root cause of |
608 // the version ID conflict. Otherwise change CHECK to DCHECK. | 609 // the version ID conflict. Otherwise change CHECK to DCHECK. |
609 CHECK(!GetLiveVersion(version->version_id())); | 610 CHECK(!GetLiveVersion(version->version_id())); |
610 live_versions_[version->version_id()] = version; | 611 live_versions_[version->version_id()] = version; |
611 version->AddListener(this); | 612 version->AddListener(this); |
612 if (observer_list_.get()) { | 613 if (observer_list_.get()) { |
613 ServiceWorkerVersionInfo version_info = version->GetInfo(); | 614 ServiceWorkerVersionInfo version_info = version->GetInfo(); |
614 observer_list_->Notify(FROM_HERE, | 615 observer_list_->Notify(FROM_HERE, |
615 &ServiceWorkerContextObserver::OnNewLiveVersion, | 616 &ServiceWorkerContextCoreObserver::OnNewLiveVersion, |
616 version_info); | 617 version_info); |
617 } | 618 } |
618 } | 619 } |
619 | 620 |
620 void ServiceWorkerContextCore::RemoveLiveVersion(int64_t id) { | 621 void ServiceWorkerContextCore::RemoveLiveVersion(int64_t id) { |
621 live_versions_.erase(id); | 622 live_versions_.erase(id); |
622 } | 623 } |
623 | 624 |
624 std::vector<ServiceWorkerRegistrationInfo> | 625 std::vector<ServiceWorkerRegistrationInfo> |
625 ServiceWorkerContextCore::GetAllLiveRegistrationInfo() { | 626 ServiceWorkerContextCore::GetAllLiveRegistrationInfo() { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 auto it = failure_counts_.find(version_id); | 763 auto it = failure_counts_.find(version_id); |
763 if (it == failure_counts_.end()) | 764 if (it == failure_counts_.end()) |
764 return 0; | 765 return 0; |
765 return it->second.count; | 766 return it->second.count; |
766 } | 767 } |
767 | 768 |
768 void ServiceWorkerContextCore::OnRunningStateChanged( | 769 void ServiceWorkerContextCore::OnRunningStateChanged( |
769 ServiceWorkerVersion* version) { | 770 ServiceWorkerVersion* version) { |
770 if (!observer_list_) | 771 if (!observer_list_) |
771 return; | 772 return; |
772 observer_list_->Notify(FROM_HERE, | 773 observer_list_->Notify( |
773 &ServiceWorkerContextObserver::OnRunningStateChanged, | 774 FROM_HERE, &ServiceWorkerContextCoreObserver::OnRunningStateChanged, |
774 version->version_id(), version->running_status()); | 775 version->version_id(), version->running_status()); |
775 } | 776 } |
776 | 777 |
777 void ServiceWorkerContextCore::OnVersionStateChanged( | 778 void ServiceWorkerContextCore::OnVersionStateChanged( |
778 ServiceWorkerVersion* version) { | 779 ServiceWorkerVersion* version) { |
779 if (!observer_list_) | 780 if (!observer_list_) |
780 return; | 781 return; |
781 observer_list_->Notify(FROM_HERE, | 782 observer_list_->Notify( |
782 &ServiceWorkerContextObserver::OnVersionStateChanged, | 783 FROM_HERE, &ServiceWorkerContextCoreObserver::OnVersionStateChanged, |
783 version->version_id(), version->status()); | 784 version->version_id(), version->status()); |
784 } | 785 } |
785 | 786 |
786 void ServiceWorkerContextCore::OnDevToolsRoutingIdChanged( | 787 void ServiceWorkerContextCore::OnDevToolsRoutingIdChanged( |
787 ServiceWorkerVersion* version) { | 788 ServiceWorkerVersion* version) { |
788 if (!observer_list_ || !version->embedded_worker()) | 789 if (!observer_list_ || !version->embedded_worker()) |
789 return; | 790 return; |
790 observer_list_->Notify( | 791 observer_list_->Notify( |
791 FROM_HERE, | 792 FROM_HERE, |
792 &ServiceWorkerContextObserver::OnVersionDevToolsRoutingIdChanged, | 793 &ServiceWorkerContextCoreObserver::OnVersionDevToolsRoutingIdChanged, |
793 version->version_id(), version->embedded_worker()->process_id(), | 794 version->version_id(), version->embedded_worker()->process_id(), |
794 version->embedded_worker()->worker_devtools_agent_route_id()); | 795 version->embedded_worker()->worker_devtools_agent_route_id()); |
795 } | 796 } |
796 | 797 |
797 void ServiceWorkerContextCore::OnMainScriptHttpResponseInfoSet( | 798 void ServiceWorkerContextCore::OnMainScriptHttpResponseInfoSet( |
798 ServiceWorkerVersion* version) { | 799 ServiceWorkerVersion* version) { |
799 if (!observer_list_) | 800 if (!observer_list_) |
800 return; | 801 return; |
801 const net::HttpResponseInfo* info = version->GetMainScriptHttpResponseInfo(); | 802 const net::HttpResponseInfo* info = version->GetMainScriptHttpResponseInfo(); |
802 DCHECK(info); | 803 DCHECK(info); |
803 base::Time lastModified; | 804 base::Time lastModified; |
804 if (info->headers) | 805 if (info->headers) |
805 info->headers->GetLastModifiedValue(&lastModified); | 806 info->headers->GetLastModifiedValue(&lastModified); |
806 observer_list_->Notify( | 807 observer_list_->Notify( |
807 FROM_HERE, &ServiceWorkerContextObserver::OnMainScriptHttpResponseInfoSet, | 808 FROM_HERE, |
| 809 &ServiceWorkerContextCoreObserver::OnMainScriptHttpResponseInfoSet, |
808 version->version_id(), info->response_time, lastModified); | 810 version->version_id(), info->response_time, lastModified); |
809 } | 811 } |
810 | 812 |
811 void ServiceWorkerContextCore::OnErrorReported( | 813 void ServiceWorkerContextCore::OnErrorReported( |
812 ServiceWorkerVersion* version, | 814 ServiceWorkerVersion* version, |
813 const base::string16& error_message, | 815 const base::string16& error_message, |
814 int line_number, | 816 int line_number, |
815 int column_number, | 817 int column_number, |
816 const GURL& source_url) { | 818 const GURL& source_url) { |
817 if (!observer_list_) | 819 if (!observer_list_) |
818 return; | 820 return; |
819 observer_list_->Notify( | 821 observer_list_->Notify( |
820 FROM_HERE, &ServiceWorkerContextObserver::OnErrorReported, | 822 FROM_HERE, &ServiceWorkerContextCoreObserver::OnErrorReported, |
821 version->version_id(), version->embedded_worker()->process_id(), | 823 version->version_id(), version->embedded_worker()->process_id(), |
822 version->embedded_worker()->thread_id(), | 824 version->embedded_worker()->thread_id(), |
823 ServiceWorkerContextObserver::ErrorInfo(error_message, line_number, | 825 ServiceWorkerContextCoreObserver::ErrorInfo(error_message, line_number, |
824 column_number, source_url)); | 826 column_number, source_url)); |
825 } | 827 } |
826 | 828 |
827 void ServiceWorkerContextCore::OnReportConsoleMessage( | 829 void ServiceWorkerContextCore::OnReportConsoleMessage( |
828 ServiceWorkerVersion* version, | 830 ServiceWorkerVersion* version, |
829 int source_identifier, | 831 int source_identifier, |
830 int message_level, | 832 int message_level, |
831 const base::string16& message, | 833 const base::string16& message, |
832 int line_number, | 834 int line_number, |
833 const GURL& source_url) { | 835 const GURL& source_url) { |
834 if (!observer_list_) | 836 if (!observer_list_) |
835 return; | 837 return; |
836 observer_list_->Notify( | 838 observer_list_->Notify( |
837 FROM_HERE, &ServiceWorkerContextObserver::OnReportConsoleMessage, | 839 FROM_HERE, &ServiceWorkerContextCoreObserver::OnReportConsoleMessage, |
838 version->version_id(), version->embedded_worker()->process_id(), | 840 version->version_id(), version->embedded_worker()->process_id(), |
839 version->embedded_worker()->thread_id(), | 841 version->embedded_worker()->thread_id(), |
840 ServiceWorkerContextObserver::ConsoleMessage( | 842 ServiceWorkerContextCoreObserver::ConsoleMessage( |
841 source_identifier, message_level, message, line_number, source_url)); | 843 source_identifier, message_level, message, line_number, source_url)); |
842 } | 844 } |
843 | 845 |
844 void ServiceWorkerContextCore::OnControlleeAdded( | 846 void ServiceWorkerContextCore::OnControlleeAdded( |
845 ServiceWorkerVersion* version, | 847 ServiceWorkerVersion* version, |
846 ServiceWorkerProviderHost* provider_host) { | 848 ServiceWorkerProviderHost* provider_host) { |
847 if (!observer_list_) | 849 if (!observer_list_) |
848 return; | 850 return; |
849 observer_list_->Notify( | 851 observer_list_->Notify( |
850 FROM_HERE, &ServiceWorkerContextObserver::OnControlleeAdded, | 852 FROM_HERE, &ServiceWorkerContextCoreObserver::OnControlleeAdded, |
851 version->version_id(), provider_host->client_uuid(), | 853 version->version_id(), provider_host->client_uuid(), |
852 provider_host->process_id(), provider_host->route_id(), | 854 provider_host->process_id(), provider_host->route_id(), |
853 provider_host->web_contents_getter(), provider_host->provider_type()); | 855 provider_host->web_contents_getter(), provider_host->provider_type()); |
854 } | 856 } |
855 | 857 |
856 void ServiceWorkerContextCore::OnControlleeRemoved( | 858 void ServiceWorkerContextCore::OnControlleeRemoved( |
857 ServiceWorkerVersion* version, | 859 ServiceWorkerVersion* version, |
858 ServiceWorkerProviderHost* provider_host) { | 860 ServiceWorkerProviderHost* provider_host) { |
859 if (!observer_list_) | 861 if (!observer_list_) |
860 return; | 862 return; |
861 observer_list_->Notify(FROM_HERE, | 863 observer_list_->Notify(FROM_HERE, |
862 &ServiceWorkerContextObserver::OnControlleeRemoved, | 864 &ServiceWorkerContextCoreObserver::OnControlleeRemoved, |
863 version->version_id(), provider_host->client_uuid()); | 865 version->version_id(), provider_host->client_uuid()); |
864 } | 866 } |
865 | 867 |
866 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { | 868 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { |
867 return wrapper_->process_manager(); | 869 return wrapper_->process_manager(); |
868 } | 870 } |
869 | 871 |
870 void ServiceWorkerContextCore::DidFindRegistrationForCheckHasServiceWorker( | 872 void ServiceWorkerContextCore::DidFindRegistrationForCheckHasServiceWorker( |
871 const GURL& other_url, | 873 const GURL& other_url, |
872 const ServiceWorkerContext::CheckHasServiceWorkerCallback callback, | 874 const ServiceWorkerContext::CheckHasServiceWorkerCallback callback, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 int service_worker_provider_id, | 916 int service_worker_provider_id, |
915 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info) { | 917 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info) { |
916 ServiceWorkerProviderHost* provider_host = | 918 ServiceWorkerProviderHost* provider_host = |
917 GetProviderHost(render_process_id, service_worker_provider_id); | 919 GetProviderHost(render_process_id, service_worker_provider_id); |
918 if (!provider_host) | 920 if (!provider_host) |
919 return; | 921 return; |
920 provider_host->BindWorkerFetchContext(std::move(client_ptr_info)); | 922 provider_host->BindWorkerFetchContext(std::move(client_ptr_info)); |
921 } | 923 } |
922 | 924 |
923 } // namespace content | 925 } // namespace content |
OLD | NEW |