OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_controllee_request_handl
er.h" | 5 #include "content/browser/service_worker/service_worker_controllee_request_handl
er.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 if (!is_main_resource_load_) | 152 if (!is_main_resource_load_) |
153 use_network_ = true; | 153 use_network_ = true; |
154 | 154 |
155 job.reset(); | 155 job.reset(); |
156 ClearJob(); | 156 ClearJob(); |
157 } | 157 } |
158 | 158 |
159 return job.release(); | 159 return job.release(); |
160 } | 160 } |
161 | 161 |
| 162 void ServiceWorkerControlleeRequestHandler::MaybeCreateLoaderFactory( |
| 163 const ResourceRequest& resource_request, |
| 164 ResourceContext* resource_context, |
| 165 base::OnceCallback<void(mojom::URLLoaderFactory*)> factory_callback) { |
| 166 DCHECK(is_main_resource_load_); |
| 167 ClearJob(); |
| 168 |
| 169 // TODO(kinuko): Keep ServiceWorkerResponseInfo somewhere around |
| 170 // and reset the data every time we restart. |
| 171 |
| 172 if (!context_ || !provider_host_) { |
| 173 // We can't do anything other than to fall back to network. |
| 174 std::move(factory_callback).Run(nullptr); |
| 175 return; |
| 176 } |
| 177 |
| 178 // In fallback cases we basically 'forward' the request, so we should |
| 179 // never see use_network_ gets true. |
| 180 DCHECK(!use_network_); |
| 181 |
| 182 url_job_ = |
| 183 base::MakeUnique<ServiceWorkerURLJobWrapper>(std::move(factory_callback)); |
| 184 |
| 185 resource_context_ = resource_context; |
| 186 |
| 187 PrepareForMainResource(resource_request.url, |
| 188 resource_request.first_party_for_cookies); |
| 189 |
| 190 if (url_job_->ShouldFallbackToNetwork()) { |
| 191 // We're falling back to the next URLLoaderRequestHandler, forward |
| 192 // the request and clear job now. |
| 193 url_job_->FallbackToNetwork(); |
| 194 ClearJob(); |
| 195 return; |
| 196 } |
| 197 |
| 198 // We will asynchronously continue on DidLookupRegistrationForMainResource. |
| 199 } |
| 200 |
162 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( | 201 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( |
163 const GURL& url, | 202 const GURL& url, |
164 const GURL& first_party_for_cookies) { | 203 const GURL& first_party_for_cookies) { |
165 DCHECK(!JobWasCanceled()); | 204 DCHECK(!JobWasCanceled()); |
166 DCHECK(context_); | 205 DCHECK(context_); |
167 DCHECK(provider_host_); | 206 DCHECK(provider_host_); |
168 TRACE_EVENT_ASYNC_BEGIN1( | 207 TRACE_EVENT_ASYNC_BEGIN1( |
169 "ServiceWorker", | 208 "ServiceWorker", |
170 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 209 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
171 url_job_.get(), "URL", url.spec()); | 210 url_job_.get(), "URL", url.spec()); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 | 498 |
460 void ServiceWorkerControlleeRequestHandler::ClearJob() { | 499 void ServiceWorkerControlleeRequestHandler::ClearJob() { |
461 url_job_.reset(); | 500 url_job_.reset(); |
462 } | 501 } |
463 | 502 |
464 bool ServiceWorkerControlleeRequestHandler::JobWasCanceled() const { | 503 bool ServiceWorkerControlleeRequestHandler::JobWasCanceled() const { |
465 return !url_job_ || url_job_->WasCanceled(); | 504 return !url_job_ || url_job_->WasCanceled(); |
466 } | 505 } |
467 | 506 |
468 } // namespace content | 507 } // namespace content |
OLD | NEW |