| 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 LoaderCallback 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(StartLoaderCallback()); |
| 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_ = base::MakeUnique<ServiceWorkerURLJobWrapper>( | 182 url_job_ = base::MakeUnique<ServiceWorkerURLJobWrapper>( |
| 183 std::move(factory_callback), this, resource_request, | 183 std::move(callback), this, resource_request, blob_storage_context_); |
| 184 blob_storage_context_); | |
| 185 | 184 |
| 186 resource_context_ = resource_context; | 185 resource_context_ = resource_context; |
| 187 | 186 |
| 188 PrepareForMainResource(resource_request.url, | 187 PrepareForMainResource(resource_request.url, |
| 189 resource_request.first_party_for_cookies); | 188 resource_request.first_party_for_cookies); |
| 190 | 189 |
| 191 if (url_job_->ShouldFallbackToNetwork()) { | 190 if (url_job_->ShouldFallbackToNetwork()) { |
| 192 // We're falling back to the next URLLoaderRequestHandler, forward | 191 // We're falling back to the next URLLoaderRequestHandler, forward |
| 193 // the request and clear job now. | 192 // the request and clear job now. |
| 194 url_job_->FallbackToNetwork(); | 193 url_job_->FallbackToNetwork(); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 498 |
| 500 void ServiceWorkerControlleeRequestHandler::ClearJob() { | 499 void ServiceWorkerControlleeRequestHandler::ClearJob() { |
| 501 url_job_.reset(); | 500 url_job_.reset(); |
| 502 } | 501 } |
| 503 | 502 |
| 504 bool ServiceWorkerControlleeRequestHandler::JobWasCanceled() const { | 503 bool ServiceWorkerControlleeRequestHandler::JobWasCanceled() const { |
| 505 return !url_job_ || url_job_->WasCanceled(); | 504 return !url_job_ || url_job_->WasCanceled(); |
| 506 } | 505 } |
| 507 | 506 |
| 508 } // namespace content | 507 } // namespace content |
| OLD | NEW |