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 |
(...skipping 14 matching lines...) Expand all Loading... | |
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" |
35 #include "content/browser/service_worker/service_worker_version.h" | |
35 #include "content/common/service_worker/service_worker_utils.h" | 36 #include "content/common/service_worker/service_worker_utils.h" |
36 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
37 #include "ipc/ipc_message.h" | 38 #include "ipc/ipc_message.h" |
38 #include "net/http/http_response_headers.h" | 39 #include "net/http/http_response_headers.h" |
39 #include "net/http/http_response_info.h" | 40 #include "net/http/http_response_info.h" |
40 #include "storage/browser/quota/quota_manager_proxy.h" | 41 #include "storage/browser/quota/quota_manager_proxy.h" |
41 #include "url/gurl.h" | 42 #include "url/gurl.h" |
42 | 43 |
43 namespace content { | 44 namespace content { |
44 namespace { | 45 namespace { |
45 | 46 |
47 void CheckFetchHandlerOfRegisteredServiceWorker( | |
falken
2017/03/17 07:54:37
This name is a bit inconsistent with SW nomenclatu
piotrs
2017/03/21 00:00:43
Chunk of the work of this method is taking right s
| |
48 const ServiceWorkerContext::CheckServiceWorkerStatusCallback callback, | |
49 scoped_refptr<ServiceWorkerRegistration> registration) { | |
50 ServiceWorkerVersion* sw_version = registration->active_version() | |
51 ? registration->active_version() | |
52 : registration->waiting_version(); | |
falken
2017/03/17 07:54:37
Are you sure you want the active version to overri
piotrs
2017/03/21 00:00:43
Done + added a comment for posterity as it's possi
| |
53 | |
54 DCHECK(sw_version); | |
55 | |
56 ServiceWorkerVersion::FetchHandlerExistence existence = | |
57 sw_version->fetch_handler_existence(); | |
58 | |
59 DCHECK(existence != ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); | |
falken
2017/03/17 07:54:37
nit: Is it possible to use DCHECK_NE here?
piotrs
2017/03/21 00:00:44
Done.
| |
60 | |
61 callback.Run(existence == ServiceWorkerVersion::FetchHandlerExistence::EXISTS | |
62 ? ServiceWorkerStatus::SERVICE_WORKER_WITH_FETCH_HANDLER | |
63 : ServiceWorkerStatus::SERVICE_WORKER_NO_FETCH_HANDLER); | |
64 } | |
65 | |
46 void SuccessCollectorCallback(const base::Closure& done_closure, | 66 void SuccessCollectorCallback(const base::Closure& done_closure, |
47 bool* overall_success, | 67 bool* overall_success, |
48 ServiceWorkerStatusCode status) { | 68 ServiceWorkerStatusCode status) { |
49 if (status != ServiceWorkerStatusCode::SERVICE_WORKER_OK) { | 69 if (status != ServiceWorkerStatusCode::SERVICE_WORKER_OK) { |
50 *overall_success = false; | 70 *overall_success = false; |
51 } | 71 } |
52 done_closure.Run(); | 72 done_closure.Run(); |
53 } | 73 } |
54 | 74 |
55 void SuccessReportingCallback( | 75 void SuccessReportingCallback( |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 scoped_refptr<ClearAllServiceWorkersHelper> helper( | 710 scoped_refptr<ClearAllServiceWorkersHelper> helper( |
691 new ClearAllServiceWorkersHelper(callback)); | 711 new ClearAllServiceWorkersHelper(callback)); |
692 if (!was_service_worker_registered_) | 712 if (!was_service_worker_registered_) |
693 return; | 713 return; |
694 was_service_worker_registered_ = false; | 714 was_service_worker_registered_ = false; |
695 storage()->GetAllRegistrationsInfos( | 715 storage()->GetAllRegistrationsInfos( |
696 base::Bind(&ClearAllServiceWorkersHelper::DidGetAllRegistrations, helper, | 716 base::Bind(&ClearAllServiceWorkersHelper::DidGetAllRegistrations, helper, |
697 AsWeakPtr())); | 717 AsWeakPtr())); |
698 } | 718 } |
699 | 719 |
700 void ServiceWorkerContextCore::CheckHasServiceWorker( | 720 void ServiceWorkerContextCore::CheckServiceWorkerStatus( |
701 const GURL& url, | 721 const GURL& url, |
702 const GURL& other_url, | 722 const GURL& other_url, |
703 const ServiceWorkerContext::CheckHasServiceWorkerCallback callback) { | 723 const ServiceWorkerContext::CheckServiceWorkerStatusCallback callback) { |
704 storage()->FindRegistrationForDocument( | 724 storage()->FindRegistrationForDocument( |
705 url, base::Bind(&ServiceWorkerContextCore:: | 725 url, base::Bind(&ServiceWorkerContextCore:: |
706 DidFindRegistrationForCheckHasServiceWorker, | 726 DidFindRegistrationForCheckServiceWorkerStatus, |
707 AsWeakPtr(), other_url, callback)); | 727 AsWeakPtr(), other_url, callback)); |
708 } | 728 } |
709 | 729 |
710 void ServiceWorkerContextCore::UpdateVersionFailureCount( | 730 void ServiceWorkerContextCore::UpdateVersionFailureCount( |
711 int64_t version_id, | 731 int64_t version_id, |
712 ServiceWorkerStatusCode status) { | 732 ServiceWorkerStatusCode status) { |
713 // Don't count these, they aren't start worker failures. | 733 // Don't count these, they aren't start worker failures. |
714 if (status == SERVICE_WORKER_ERROR_DISALLOWED) | 734 if (status == SERVICE_WORKER_ERROR_DISALLOWED) |
715 return; | 735 return; |
716 | 736 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
843 return; | 863 return; |
844 observer_list_->Notify(FROM_HERE, | 864 observer_list_->Notify(FROM_HERE, |
845 &ServiceWorkerContextObserver::OnControlleeRemoved, | 865 &ServiceWorkerContextObserver::OnControlleeRemoved, |
846 version->version_id(), provider_host->client_uuid()); | 866 version->version_id(), provider_host->client_uuid()); |
847 } | 867 } |
848 | 868 |
849 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { | 869 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { |
850 return wrapper_->process_manager(); | 870 return wrapper_->process_manager(); |
851 } | 871 } |
852 | 872 |
853 void ServiceWorkerContextCore::DidFindRegistrationForCheckHasServiceWorker( | 873 void ServiceWorkerContextCore::DidFindRegistrationForCheckServiceWorkerStatus( |
854 const GURL& other_url, | 874 const GURL& other_url, |
855 const ServiceWorkerContext::CheckHasServiceWorkerCallback callback, | 875 const ServiceWorkerContext::CheckServiceWorkerStatusCallback callback, |
856 ServiceWorkerStatusCode status, | 876 ServiceWorkerStatusCode status, |
857 scoped_refptr<ServiceWorkerRegistration> registration) { | 877 scoped_refptr<ServiceWorkerRegistration> registration) { |
858 if (status != SERVICE_WORKER_OK) { | 878 if (status != SERVICE_WORKER_OK) { |
859 callback.Run(false); | 879 callback.Run(ServiceWorkerStatus::NO_SERVICE_WORKER); |
860 return; | 880 return; |
861 } | 881 } |
862 | 882 |
863 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), other_url)) { | 883 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), other_url)) { |
864 callback.Run(false); | 884 callback.Run(ServiceWorkerStatus::NO_SERVICE_WORKER); |
865 return; | 885 return; |
866 } | 886 } |
867 | 887 |
868 if (registration->is_uninstalling() || registration->is_uninstalled()) { | 888 if (registration->is_uninstalling() || registration->is_uninstalled()) { |
869 callback.Run(false); | 889 callback.Run(ServiceWorkerStatus::NO_SERVICE_WORKER); |
870 return; | 890 return; |
871 } | 891 } |
872 | 892 |
873 if (!registration->active_version() && !registration->waiting_version()) { | 893 if (!registration->active_version() && !registration->waiting_version()) { |
874 registration->RegisterRegistrationFinishedCallback( | 894 registration->RegisterRegistrationFinishedCallback( |
875 base::Bind(&ServiceWorkerContextCore:: | 895 base::Bind(&ServiceWorkerContextCore:: |
876 OnRegistrationFinishedForCheckHasServiceWorker, | 896 OnRegistrationFinishedForCheckServiceWorkerStatus, |
877 AsWeakPtr(), callback, registration)); | 897 AsWeakPtr(), callback, registration)); |
878 return; | 898 return; |
879 } | 899 } |
880 | 900 |
881 callback.Run(true); | 901 CheckFetchHandlerOfRegisteredServiceWorker(callback, registration); |
882 } | 902 } |
883 | 903 |
884 void ServiceWorkerContextCore::OnRegistrationFinishedForCheckHasServiceWorker( | 904 void ServiceWorkerContextCore:: |
885 const ServiceWorkerContext::CheckHasServiceWorkerCallback callback, | 905 OnRegistrationFinishedForCheckServiceWorkerStatus( |
886 scoped_refptr<ServiceWorkerRegistration> registration) { | 906 const ServiceWorkerContext::CheckServiceWorkerStatusCallback callback, |
887 callback.Run(registration->active_version() || | 907 scoped_refptr<ServiceWorkerRegistration> registration) { |
888 registration->waiting_version()); | 908 if (!registration->active_version() && !registration->waiting_version()) { |
909 callback.Run(ServiceWorkerStatus::NO_SERVICE_WORKER); | |
910 return; | |
911 } | |
912 | |
913 CheckFetchHandlerOfRegisteredServiceWorker(callback, registration); | |
889 } | 914 } |
890 | 915 |
891 } // namespace content | 916 } // namespace content |
OLD | NEW |