Chromium Code Reviews| Index: content/browser/appcache/appcache_url_loader_job.cc |
| diff --git a/content/browser/appcache/appcache_url_loader_job.cc b/content/browser/appcache/appcache_url_loader_job.cc |
| index 55c5f2e40952b2aaca16562141761fb75cc7b799..d6bf8a6345a5b6f289ea08341e61a83563c19340 100644 |
| --- a/content/browser/appcache/appcache_url_loader_job.cc |
| +++ b/content/browser/appcache/appcache_url_loader_job.cc |
| @@ -6,12 +6,19 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "content/browser/appcache/appcache_histograms.h" |
| +#include "content/browser/appcache/appcache_subresource_url_factory.h" |
| +#include "content/browser/url_loader_factory_getter.h" |
| #include "content/common/net_adapters.h" |
| #include "content/public/common/resource_type.h" |
| #include "net/http/http_status_code.h" |
| namespace content { |
| +SubresourceLoadInfo::SubresourceLoadInfo() |
| + : routing_id(-1), request_id(-1), options(0) {} |
| + |
| +SubresourceLoadInfo::~SubresourceLoadInfo() {} |
| + |
| AppCacheURLLoaderJob::~AppCacheURLLoaderJob() { |
| if (storage_.get()) |
| storage_->CancelDelegateCallbacks(this); |
| @@ -34,6 +41,9 @@ void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url, |
| delivery_type_ = APPCACHED_DELIVERY; |
| + load_timing_info_.request_start_time = base::Time::Now(); |
| + load_timing_info_.request_start = base::TimeTicks::Now(); |
| + |
| AppCacheHistograms::AddAppCacheJobStartDelaySample(base::TimeTicks::Now() - |
| start_time_tick_); |
| @@ -59,11 +69,22 @@ void AppCacheURLLoaderJob::DeliverNetworkResponse() { |
| AppCacheHistograms::AddNetworkJobStartDelaySample(base::TimeTicks::Now() - |
| start_time_tick_); |
| - DCHECK(!loader_callback_.is_null()); |
| - // In network service land, if we are processing a navigation request, we |
| - // need to inform the loader callback that we are not going to handle this |
| - // request. The loader callback is valid only for navigation requests. |
| - std::move(loader_callback_).Run(StartLoaderCallback()); |
| + if (IsResourceTypeFrame(request_.resource_type)) { |
| + DCHECK(!loader_callback_.is_null()); |
| + // In network service land, if we are processing a navigation request, we |
| + // need to inform the loader callback that we are not going to handle this |
| + // request. The loader callback is valid only for navigation requests. |
| + std::move(loader_callback_).Run(StartLoaderCallback()); |
|
kinuko
2017/07/03 06:34:15
nit: maybe rename loader_callback_ to main_resourc
ananta
2017/07/03 07:36:47
Done.
|
| + } else { |
| + default_url_loader_factory_getter_->GetNetworkFactory() |
| + ->get() |
| + ->CreateLoaderAndStart( |
| + mojo::MakeRequest(&network_loader_request_), |
| + subresource_load_info_->routing_id, |
| + subresource_load_info_->request_id, subresource_load_info_->options, |
| + subresource_load_info_->request, std::move(client_info_), |
| + subresource_load_info_->traffic_annotation); |
| + } |
| } |
| void AppCacheURLLoaderJob::DeliverErrorResponse() { |
| @@ -99,12 +120,31 @@ AppCacheURLLoaderJob* AppCacheURLLoaderJob::AsURLLoaderJob() { |
| } |
| void AppCacheURLLoaderJob::FollowRedirect() { |
| - DCHECK(false); |
| + if (network_loader_request_) |
| + network_loader_request_->FollowRedirect(); |
| } |
| void AppCacheURLLoaderJob::SetPriority(net::RequestPriority priority, |
| int32_t intra_priority_value) { |
| - NOTREACHED() << "We don't support SetPriority()"; |
| + if (network_loader_request_) |
| + network_loader_request_->SetPriority(priority, intra_priority_value); |
| +} |
| + |
| +void AppCacheURLLoaderJob::SetSubresourceLoadInfo( |
| + std::unique_ptr<SubresourceLoadInfo> subresource_load_info, |
| + AppCacheRequestHandler* handler, |
| + URLLoaderFactoryGetter* default_url_loader) { |
| + subresource_load_info_ = std::move(subresource_load_info); |
| + |
| + associated_binding_.reset(new mojo::AssociatedBinding<mojom::URLLoader>( |
| + this, std::move(subresource_load_info_->url_loader_request))); |
| + associated_binding_->set_connection_error_handler(base::Bind( |
| + &AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this))); |
| + |
| + client_info_ = std::move(subresource_load_info_->client); |
| + |
| + handler_.reset(handler); |
| + default_url_loader_factory_getter_ = default_url_loader; |
| } |
| void AppCacheURLLoaderJob::Start(mojom::URLLoaderRequest request, |
| @@ -151,9 +191,11 @@ void AppCacheURLLoaderJob::OnResponseInfoLoaded( |
| if (is_range_request()) |
| SetupRangeResponse(); |
| - DCHECK(!loader_callback_.is_null()); |
| - std::move(loader_callback_) |
| - .Run(base::Bind(&AppCacheURLLoaderJob::Start, StaticAsWeakPtr(this))); |
| + if (IsResourceTypeFrame(request_.resource_type)) { |
| + DCHECK(!loader_callback_.is_null()); |
| + std::move(loader_callback_) |
| + .Run(base::Bind(&AppCacheURLLoaderJob::Start, StaticAsWeakPtr(this))); |
| + } |
| response_body_stream_ = std::move(data_pipe_.producer_handle); |
| @@ -185,6 +227,12 @@ void AppCacheURLLoaderJob::OnResponseInfoLoaded( |
| void AppCacheURLLoaderJob::OnReadComplete(int result) { |
| DLOG(WARNING) << "AppCache read completed with result: " << result; |
| + if (result <= 0) { |
| + writable_handle_watcher_.Cancel(); |
| + pending_write_->Complete(0); |
| + pending_write_ = nullptr; |
| + } |
| + |
| bool is_main_resource = IsResourceTypeFrame(request_.resource_type); |
| if (result == 0) { |
| @@ -216,7 +264,6 @@ void AppCacheURLLoaderJob::OnConnectionError() { |
| void AppCacheURLLoaderJob::SendResponseInfo() { |
| DCHECK(client_info_); |
| - |
| // If this is null it means the response information was sent to the client. |
| if (!data_pipe_.consumer_handle.is_valid()) |
| return; |
| @@ -227,18 +274,28 @@ void AppCacheURLLoaderJob::SendResponseInfo() { |
| ResourceResponseHead response_head; |
| response_head.headers = http_info->headers; |
| + response_head.appcache_id = cache_id_; |
| + response_head.appcache_manifest_url = manifest_url_; |
| - // TODO(ananta) |
| - // Copy more fields. |
| http_info->headers->GetMimeType(&response_head.mime_type); |
| http_info->headers->GetCharset(&response_head.charset); |
| + // TODO(ananta) |
| + // Verify if the times sent here are correct. |
| response_head.request_time = http_info->request_time; |
| response_head.response_time = http_info->response_time; |
| response_head.content_length = |
| is_range_request() ? range_response_info_->headers->GetContentLength() |
| : info_->response_data_size(); |
| + response_head.connection_info = http_info->connection_info; |
| + response_head.socket_address = http_info->socket_address; |
| + response_head.was_fetched_via_spdy = http_info->was_fetched_via_spdy; |
| + response_head.was_alpn_negotiated = http_info->was_alpn_negotiated; |
| + response_head.alpn_negotiated_protocol = http_info->alpn_negotiated_protocol; |
| + |
| + response_head.load_timing = load_timing_info_; |
| + |
| client_info_->OnReceiveResponse(response_head, http_info->ssl_info, |
| mojom::DownloadedTempFilePtr()); |
| @@ -289,10 +346,26 @@ void AppCacheURLLoaderJob::OnResponseBodyStreamReady(MojoResult result) { |
| void AppCacheURLLoaderJob::NotifyCompleted(int error_code) { |
| if (storage_.get()) |
| storage_->CancelDelegateCallbacks(this); |
| - // TODO(ananta) |
| - // Fill other details in the ResourceRequestCompletionStatus structure. |
| + |
| + const net::HttpResponseInfo* http_info = is_range_request() |
| + ? range_response_info_.get() |
| + : info_->http_response_info(); |
| + |
| ResourceRequestCompletionStatus request_complete_data; |
| request_complete_data.error_code = error_code; |
| + |
| + // TODO(ananta) |
| + // Fill other details in the ResourceRequestCompletionStatus structure in |
| + // case of an error. |
| + if (!request_complete_data.error_code) { |
| + request_complete_data.exists_in_cache = http_info->was_cached; |
| + request_complete_data.completion_time = base::TimeTicks::Now(); |
| + request_complete_data.encoded_body_length = |
| + is_range_request() ? range_response_info_->headers->GetContentLength() |
| + : info_->response_data_size(); |
| + request_complete_data.decoded_body_length = |
| + request_complete_data.encoded_body_length; |
| + } |
| client_info_->OnComplete(request_complete_data); |
| } |