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 DidStartWorker( |
| 86 scoped_refptr<ServiceWorkerVersion> version, |
| 87 ServiceWorkerContext::StartActiveWorkerCallback info_callback) { |
| 88 EmbeddedWorkerInstance* instance = version->embedded_worker(); |
| 89 std::move(info_callback).Run(instance->process_id(), instance->thread_id()); |
| 90 } |
| 91 |
| 92 void DidFailStartWorker(base::OnceClosure error_callback, |
| 93 ServiceWorkerStatusCode code) { |
| 94 std::move(error_callback).Run(); |
| 95 } |
| 96 |
| 97 void FoundReadyRegistrationForStartActiveWorker( |
| 98 ServiceWorkerContext::StartActiveWorkerCallback info_callback, |
| 99 base::OnceClosure failure_callback, |
| 100 ServiceWorkerStatusCode service_worker_status, |
| 101 scoped_refptr<ServiceWorkerRegistration> service_worker_registration) { |
| 102 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 103 if (service_worker_status == SERVICE_WORKER_OK) { |
| 104 // Note: There might be a remote possibility that |
| 105 // |service_worker_registration|'s active version might change between here |
| 106 // and DidStartWorker, so bind |active_version| to RunAfterStartWorker. |
| 107 scoped_refptr<ServiceWorkerVersion> active_version = |
| 108 service_worker_registration->active_version(); |
| 109 DCHECK(active_version.get()); |
| 110 active_version->RunAfterStartWorker( |
| 111 ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST, |
| 112 base::Bind(&DidStartWorker, active_version, |
| 113 base::Passed(&info_callback)), |
| 114 base::Bind(&DidFailStartWorker, 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::StartActiveWorkerForPattern( |
| 880 const GURL& pattern, |
| 881 StartActiveWorkerCallback info_callback, |
| 882 base::OnceClosure failure_callback) { |
| 883 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 884 FindReadyRegistrationForPattern( |
| 885 pattern, base::Bind(&FoundReadyRegistrationForStartActiveWorker, |
| 886 base::Passed(&info_callback), |
| 887 base::Passed(&failure_callback))); |
| 888 } |
| 889 |
844 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( | 890 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( |
845 ServiceWorkerStatusCode status) { | 891 ServiceWorkerStatusCode status) { |
846 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 892 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
847 if (status != SERVICE_WORKER_OK) { | 893 if (status != SERVICE_WORKER_OK) { |
848 context_core_.reset(); | 894 context_core_.reset(); |
849 return; | 895 return; |
850 } | 896 } |
851 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 897 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
852 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 898 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
853 context_core_->OnStorageWiped(); | 899 context_core_->OnStorageWiped(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 service_worker_provider_id, | 1005 service_worker_provider_id, |
960 std::move(client_ptr_info)); | 1006 std::move(client_ptr_info)); |
961 } | 1007 } |
962 | 1008 |
963 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 1009 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
964 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1010 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
965 return context_core_.get(); | 1011 return context_core_.get(); |
966 } | 1012 } |
967 | 1013 |
968 } // namespace content | 1014 } // namespace content |
OLD | NEW |