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_wrapper.h" | 5 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 ServiceWorkerStatusCode status, | 75 ServiceWorkerStatusCode status, |
76 scoped_refptr<ServiceWorkerRegistration> registration) { | 76 scoped_refptr<ServiceWorkerRegistration> registration) { |
77 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 77 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
78 if (status != SERVICE_WORKER_OK || !registration->waiting_version()) | 78 if (status != SERVICE_WORKER_OK || !registration->waiting_version()) |
79 return; | 79 return; |
80 | 80 |
81 registration->waiting_version()->set_skip_waiting(true); | 81 registration->waiting_version()->set_skip_waiting(true); |
82 registration->ActivateWaitingVersionWhenReady(); | 82 registration->ActivateWaitingVersionWhenReady(); |
83 } | 83 } |
84 | 84 |
| 85 void OnServiceWorkerStartedForGetWorkerInfo( |
| 86 scoped_refptr<ServiceWorkerRegistration> service_worker_registration, |
| 87 ServiceWorkerContext::GetWorkerInfoCallback info_callback) { |
| 88 EmbeddedWorkerInstance* instance = |
| 89 service_worker_registration->active_version()->embedded_worker(); |
| 90 std::move(info_callback).Run(instance->process_id(), instance->thread_id()); |
| 91 } |
| 92 |
| 93 void OnServiceWorkerErrorForGetWorkerInfo(base::OnceClosure error_callback, |
| 94 ServiceWorkerStatusCode code) { |
| 95 std::move(error_callback).Run(); |
| 96 } |
| 97 |
| 98 void FoundReadyRegistrationForGetWorkerInfo( |
| 99 ServiceWorkerContext::GetWorkerInfoCallback info_callback, |
| 100 base::OnceClosure failure_callback, |
| 101 ServiceWorkerStatusCode service_worker_status, |
| 102 scoped_refptr<ServiceWorkerRegistration> service_worker_registration) { |
| 103 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 104 if (service_worker_status == SERVICE_WORKER_OK) { |
| 105 DCHECK(service_worker_registration->active_version()); |
| 106 service_worker_registration->active_version()->RunAfterStartWorker( |
| 107 ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST, |
| 108 base::Bind(&OnServiceWorkerStartedForGetWorkerInfo, |
| 109 service_worker_registration, base::Passed(&info_callback)), |
| 110 base::Bind(&OnServiceWorkerErrorForGetWorkerInfo, |
| 111 base::Passed(&failure_callback))); |
| 112 } else { |
| 113 std::move(failure_callback).Run(); |
| 114 } |
| 115 } |
| 116 |
85 } // namespace | 117 } // namespace |
86 | 118 |
87 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( | 119 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( |
88 const std::set<std::string>& header_names) { | 120 const std::set<std::string>& header_names) { |
89 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 121 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
90 tracked_objects::ScopedTracker tracking_profile( | 122 tracked_objects::ScopedTracker tracking_profile( |
91 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 123 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
92 "477117 ServiceWorkerContext::AddExcludedHeadersForFetchEvent")); | 124 "477117 ServiceWorkerContext::AddExcludedHeadersForFetchEvent")); |
93 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 125 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
94 g_excluded_header_name_set.Get().insert(header_names.begin(), | 126 g_excluded_header_name_set.Get().insert(header_names.begin(), |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 int64_t service_worker_version_id, | 866 int64_t service_worker_version_id, |
835 const std::string& request_uuid) { | 867 const std::string& request_uuid) { |
836 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 868 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
837 ServiceWorkerVersion* version = | 869 ServiceWorkerVersion* version = |
838 context()->GetLiveVersion(service_worker_version_id); | 870 context()->GetLiveVersion(service_worker_version_id); |
839 if (!version) | 871 if (!version) |
840 return false; | 872 return false; |
841 return version->FinishExternalRequest(request_uuid); | 873 return version->FinishExternalRequest(request_uuid); |
842 } | 874 } |
843 | 875 |
| 876 void ServiceWorkerContextWrapper::GetWorkerInfoAfterStartWorker( |
| 877 const GURL& origin, |
| 878 GetWorkerInfoCallback info_callback, |
| 879 base::OnceClosure failure_callback) { |
| 880 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 881 FindReadyRegistrationForPattern( |
| 882 origin, base::Bind(&FoundReadyRegistrationForGetWorkerInfo, |
| 883 base::Passed(&info_callback), |
| 884 base::Passed(&failure_callback))); |
| 885 } |
| 886 |
844 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( | 887 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( |
845 ServiceWorkerStatusCode status) { | 888 ServiceWorkerStatusCode status) { |
846 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 889 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
847 if (status != SERVICE_WORKER_OK) { | 890 if (status != SERVICE_WORKER_OK) { |
848 context_core_.reset(); | 891 context_core_.reset(); |
849 return; | 892 return; |
850 } | 893 } |
851 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 894 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
852 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 895 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
853 context_core_->OnStorageWiped(); | 896 context_core_->OnStorageWiped(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 service_worker_provider_id, | 1002 service_worker_provider_id, |
960 std::move(client_ptr_info)); | 1003 std::move(client_ptr_info)); |
961 } | 1004 } |
962 | 1005 |
963 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 1006 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
964 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1007 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
965 return context_core_.get(); | 1008 return context_core_.get(); |
966 } | 1009 } |
967 | 1010 |
968 } // namespace content | 1011 } // namespace content |
OLD | NEW |