Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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/appcache/appcache_url_loader_job.h" | 5 #include "content/browser/appcache/appcache_url_loader_job.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "content/browser/appcache/appcache_histograms.h" | 8 #include "content/browser/appcache/appcache_histograms.h" |
| 9 #include "content/browser/appcache/appcache_subresource_url_factory.h" | 9 #include "content/browser/appcache/appcache_subresource_url_factory.h" |
| 10 #include "content/browser/appcache/appcache_url_loader_request.h" | 10 #include "content/browser/appcache/appcache_url_loader_request.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 | 217 |
| 218 associated_binding_.reset(new mojo::AssociatedBinding<mojom::URLLoader>( | 218 associated_binding_.reset(new mojo::AssociatedBinding<mojom::URLLoader>( |
| 219 this, std::move(subresource_load_info_->url_loader_request))); | 219 this, std::move(subresource_load_info_->url_loader_request))); |
| 220 associated_binding_->set_connection_error_handler(base::Bind( | 220 associated_binding_->set_connection_error_handler(base::Bind( |
| 221 &AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this))); | 221 &AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this))); |
| 222 | 222 |
| 223 client_ = std::move(subresource_load_info_->client); | 223 client_ = std::move(subresource_load_info_->client); |
| 224 default_url_loader_factory_getter_ = default_url_loader; | 224 default_url_loader_factory_getter_ = default_url_loader; |
| 225 } | 225 } |
| 226 | 226 |
| 227 void AppCacheURLLoaderJob::BindRequest(mojom::URLLoaderClientPtr client, | |
| 228 mojom::URLLoaderRequest request) { | |
| 229 DCHECK(!binding_.is_bound()); | |
| 230 binding_.Bind(std::move(request)); | |
| 231 | |
| 232 client_ = std::move(client); | |
| 233 | |
| 234 binding_.set_connection_error_handler(base::Bind( | |
| 235 &AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this))); | |
| 236 } | |
| 237 | |
| 227 void AppCacheURLLoaderJob::Start(mojom::URLLoaderRequest request, | 238 void AppCacheURLLoaderJob::Start(mojom::URLLoaderRequest request, |
| 228 mojom::URLLoaderClientPtr client) { | 239 mojom::URLLoaderClientPtr client) { |
| 229 DCHECK(!binding_.is_bound()); | 240 BindRequest(std::move(client), std::move(request)); |
| 230 binding_.Bind(std::move(request)); | |
| 231 | |
| 232 binding_.set_connection_error_handler(base::Bind( | |
| 233 &AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this))); | |
| 234 | |
| 235 client_ = std::move(client); | |
| 236 | |
| 237 // Send the cached AppCacheResponse if any. | 241 // Send the cached AppCacheResponse if any. |
| 238 if (info_.get()) | 242 if (info_.get()) |
| 239 SendResponseInfo(); | 243 SendResponseInfo(); |
| 240 } | 244 } |
| 241 | 245 |
| 242 AppCacheURLLoaderJob::AppCacheURLLoaderJob( | 246 AppCacheURLLoaderJob::AppCacheURLLoaderJob( |
| 243 const ResourceRequest& request, | 247 const ResourceRequest& request, |
| 244 AppCacheURLLoaderRequest* appcache_request, | 248 AppCacheURLLoaderRequest* appcache_request, |
| 245 AppCacheStorage* storage) | 249 AppCacheStorage* storage) |
| 246 : request_(request), | 250 : request_(request), |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 265 } | 269 } |
| 266 | 270 |
| 267 if (response_info) { | 271 if (response_info) { |
| 268 info_ = response_info; | 272 info_ = response_info; |
| 269 reader_.reset( | 273 reader_.reset( |
| 270 storage_->CreateResponseReader(manifest_url_, entry_.response_id())); | 274 storage_->CreateResponseReader(manifest_url_, entry_.response_id())); |
| 271 | 275 |
| 272 if (is_range_request()) | 276 if (is_range_request()) |
| 273 SetupRangeResponse(); | 277 SetupRangeResponse(); |
| 274 | 278 |
| 275 if (IsResourceTypeFrame(request_.resource_type)) { | 279 if (IsResourceTypeFrame(request_.resource_type) && !client_) { |
|
michaeln
2017/07/26 23:08:41
i don't understand the purpose of the !client_ che
ananta
2017/07/27 02:40:25
For fallback responses the callback would be null.
| |
| 276 DCHECK(!main_resource_loader_callback_.is_null()); | 280 DCHECK(!main_resource_loader_callback_.is_null()); |
| 277 std::move(main_resource_loader_callback_) | 281 std::move(main_resource_loader_callback_) |
| 278 .Run(base::Bind(&AppCacheURLLoaderJob::Start, StaticAsWeakPtr(this))); | 282 .Run(base::Bind(&AppCacheURLLoaderJob::Start, StaticAsWeakPtr(this))); |
| 279 } | 283 } |
| 280 | 284 |
| 281 response_body_stream_ = std::move(data_pipe_.producer_handle); | 285 response_body_stream_ = std::move(data_pipe_.producer_handle); |
| 282 | 286 |
| 283 // TODO(ananta) | 287 // TODO(ananta) |
| 284 // Move the asynchronous reading and mojo pipe handling code to a helper | 288 // Move the asynchronous reading and mojo pipe handling code to a helper |
| 285 // class. That would also need a change to BlobURLLoader. | 289 // class. That would also need a change to BlobURLLoader. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 DCHECK(false); | 426 DCHECK(false); |
| 423 NotifyCompleted(net::ERR_FAILED); | 427 NotifyCompleted(net::ERR_FAILED); |
| 424 } | 428 } |
| 425 ReadMore(); | 429 ReadMore(); |
| 426 } | 430 } |
| 427 | 431 |
| 428 void AppCacheURLLoaderJob::NotifyCompleted(int error_code) { | 432 void AppCacheURLLoaderJob::NotifyCompleted(int error_code) { |
| 429 if (storage_.get()) | 433 if (storage_.get()) |
| 430 storage_->CancelDelegateCallbacks(this); | 434 storage_->CancelDelegateCallbacks(this); |
| 431 | 435 |
| 432 const net::HttpResponseInfo* http_info = is_range_request() | 436 const net::HttpResponseInfo* http_info = |
| 433 ? range_response_info_.get() | 437 is_range_request() ? range_response_info_.get() |
| 434 : info_->http_response_info(); | 438 : (info_ ? info_->http_response_info() : nullptr); |
| 435 | 439 |
| 436 ResourceRequestCompletionStatus request_complete_data; | 440 ResourceRequestCompletionStatus request_complete_data; |
| 437 request_complete_data.error_code = error_code; | 441 request_complete_data.error_code = error_code; |
| 438 | 442 |
| 439 // TODO(ananta) | 443 // TODO(ananta) |
| 440 // Fill other details in the ResourceRequestCompletionStatus structure in | 444 // Fill other details in the ResourceRequestCompletionStatus structure in |
| 441 // case of an error. | 445 // case of an error. |
| 442 if (!request_complete_data.error_code) { | 446 if (!request_complete_data.error_code) { |
| 443 request_complete_data.exists_in_cache = http_info->was_cached; | 447 request_complete_data.exists_in_cache = http_info->was_cached; |
| 444 request_complete_data.completion_time = base::TimeTicks::Now(); | 448 request_complete_data.completion_time = base::TimeTicks::Now(); |
| 445 request_complete_data.encoded_body_length = | 449 request_complete_data.encoded_body_length = |
| 446 is_range_request() ? range_response_info_->headers->GetContentLength() | 450 is_range_request() ? range_response_info_->headers->GetContentLength() |
| 447 : info_->response_data_size(); | 451 : (info_ ? info_->response_data_size() : 0); |
| 448 request_complete_data.decoded_body_length = | 452 request_complete_data.decoded_body_length = |
| 449 request_complete_data.encoded_body_length; | 453 request_complete_data.encoded_body_length; |
| 450 } | 454 } |
| 451 client_->OnComplete(request_complete_data); | 455 client_->OnComplete(request_complete_data); |
| 452 } | 456 } |
| 453 | 457 |
| 454 void AppCacheURLLoaderJob::DisconnectFromNetworkLoader() { | 458 void AppCacheURLLoaderJob::DisconnectFromNetworkLoader() { |
| 455 // Close the pipe to the network loader as we are delivering a fallback | 459 // Close the pipe to the network loader as we are delivering a fallback |
| 456 // response to the client. | 460 // response to the client. |
| 457 network_loader_client_binding_.Close(); | 461 network_loader_client_binding_.Close(); |
| 458 network_loader_ = nullptr; | 462 network_loader_ = nullptr; |
| 459 } | 463 } |
| 460 | 464 |
| 461 } // namespace content | 465 } // namespace content |
| OLD | NEW |