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