| 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( | 162 void ServiceWorkerControlleeRequestHandler::MaybeCreateLoader( |
| 163 const ResourceRequest& resource_request, | 163 const ResourceRequest& resource_request, |
| 164 ResourceContext* resource_context, | 164 ResourceContext* resource_context, |
| 165 base::OnceCallback<void(mojom::URLLoaderFactory*)> factory_callback) { | 165 URLLoaderCallback callback) { |
| 166 DCHECK(is_main_resource_load_); | 166 DCHECK(is_main_resource_load_); |
| 167 ClearJob(); | 167 ClearJob(); |
| 168 | 168 |
| 169 // TODO(kinuko): Keep ServiceWorkerResponseInfo somewhere around | 169 // TODO(kinuko): Keep ServiceWorkerResponseInfo somewhere around |
| 170 // and reset the data every time we restart. | 170 // and reset the data every time we restart. |
| 171 | 171 |
| 172 if (!context_ || !provider_host_) { | 172 if (!context_ || !provider_host_) { |
| 173 // We can't do anything other than to fall back to network. | 173 // We can't do anything other than to fall back to network. |
| 174 std::move(factory_callback).Run(nullptr); | 174 std::move(callback).Run(nullptr); |
| 175 return; | 175 return; |
| 176 } | 176 } |
| 177 | 177 |
| 178 // In fallback cases we basically 'forward' the request, so we should | 178 // In fallback cases we basically 'forward' the request, so we should |
| 179 // never see use_network_ gets true. | 179 // never see use_network_ gets true. |
| 180 DCHECK(!use_network_); | 180 DCHECK(!use_network_); |
| 181 | 181 |
| 182 url_job_ = | 182 url_job_ = base::MakeUnique<ServiceWorkerURLJobWrapper>(std::move(callback)); |
| 183 base::MakeUnique<ServiceWorkerURLJobWrapper>(std::move(factory_callback)); | |
| 184 | 183 |
| 185 resource_context_ = resource_context; | 184 resource_context_ = resource_context; |
| 186 | 185 |
| 187 PrepareForMainResource(resource_request.url, | 186 PrepareForMainResource(resource_request.url, |
| 188 resource_request.first_party_for_cookies); | 187 resource_request.first_party_for_cookies); |
| 189 | 188 |
| 190 if (url_job_->ShouldFallbackToNetwork()) { | 189 if (url_job_->ShouldFallbackToNetwork()) { |
| 191 // We're falling back to the next URLLoaderRequestHandler, forward | 190 // We're falling back to the next URLLoaderRequestHandler, forward |
| 192 // the request and clear job now. | 191 // the request and clear job now. |
| 193 url_job_->FallbackToNetwork(); | 192 url_job_->FallbackToNetwork(); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 497 |
| 499 void ServiceWorkerControlleeRequestHandler::ClearJob() { | 498 void ServiceWorkerControlleeRequestHandler::ClearJob() { |
| 500 url_job_.reset(); | 499 url_job_.reset(); |
| 501 } | 500 } |
| 502 | 501 |
| 503 bool ServiceWorkerControlleeRequestHandler::JobWasCanceled() const { | 502 bool ServiceWorkerControlleeRequestHandler::JobWasCanceled() const { |
| 504 return !url_job_ || url_job_->WasCanceled(); | 503 return !url_job_ || url_job_->WasCanceled(); |
| 505 } | 504 } |
| 506 | 505 |
| 507 } // namespace content | 506 } // namespace content |
| OLD | NEW |