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/common/net_adapters.h" | 9 #include "content/common/net_adapters.h" |
10 #include "content/public/common/resource_type.h" | 10 #include "content/public/common/resource_type.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 delivery_type_ = APPCACHED_DELIVERY; | 35 delivery_type_ = APPCACHED_DELIVERY; |
36 | 36 |
37 AppCacheHistograms::AddAppCacheJobStartDelaySample(base::TimeTicks::Now() - | 37 AppCacheHistograms::AddAppCacheJobStartDelaySample(base::TimeTicks::Now() - |
38 start_time_tick_); | 38 start_time_tick_); |
39 | 39 |
40 manifest_url_ = manifest_url; | 40 manifest_url_ = manifest_url; |
41 cache_id_ = cache_id; | 41 cache_id_ = cache_id; |
42 entry_ = entry; | 42 entry_ = entry; |
43 is_fallback_ = is_fallback; | 43 is_fallback_ = is_fallback; |
44 | 44 |
45 // Handle range requests. | |
46 net::HttpRequestHeaders headers; | |
47 headers.AddHeadersFromString(request_.headers); | |
48 InitializeRangeRequestInfo(headers); | |
49 | |
45 // TODO(ananta) | 50 // TODO(ananta) |
46 // Implement the AppCacheServiceImpl::Observer interface or add weak pointer | 51 // Implement the AppCacheServiceImpl::Observer interface or add weak pointer |
47 // support to it. | 52 // support to it. |
48 storage_->LoadResponseInfo(manifest_url_, entry_.response_id(), this); | 53 storage_->LoadResponseInfo(manifest_url_, entry_.response_id(), this); |
49 } | 54 } |
50 | 55 |
51 void AppCacheURLLoaderJob::DeliverNetworkResponse() { | 56 void AppCacheURLLoaderJob::DeliverNetworkResponse() { |
52 delivery_type_ = NETWORK_DELIVERY; | 57 delivery_type_ = NETWORK_DELIVERY; |
53 | 58 |
54 AppCacheHistograms::AddNetworkJobStartDelaySample(base::TimeTicks::Now() - | 59 AppCacheHistograms::AddNetworkJobStartDelaySample(base::TimeTicks::Now() - |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 if (!storage_.get()) { | 141 if (!storage_.get()) { |
137 DeliverErrorResponse(); | 142 DeliverErrorResponse(); |
138 return; | 143 return; |
139 } | 144 } |
140 | 145 |
141 if (response_info) { | 146 if (response_info) { |
142 info_ = response_info; | 147 info_ = response_info; |
143 reader_.reset( | 148 reader_.reset( |
144 storage_->CreateResponseReader(manifest_url_, entry_.response_id())); | 149 storage_->CreateResponseReader(manifest_url_, entry_.response_id())); |
145 | 150 |
151 if (is_range_request()) | |
152 SetupRangeResponse(reader_.get()); | |
michaeln
2017/06/14 02:37:25
feels a little arbitrary that reader_ is passed in
ananta
2017/06/14 18:52:18
Done. Moved reader_ to the base class
| |
153 | |
146 DCHECK(!loader_callback_.is_null()); | 154 DCHECK(!loader_callback_.is_null()); |
147 std::move(loader_callback_) | 155 std::move(loader_callback_) |
148 .Run(base::Bind(&AppCacheURLLoaderJob::Start, StaticAsWeakPtr(this))); | 156 .Run(base::Bind(&AppCacheURLLoaderJob::Start, StaticAsWeakPtr(this))); |
149 | 157 |
150 // TODO(ananta) | |
151 // Handle range requests. | |
152 | |
153 response_body_stream_ = std::move(data_pipe_.producer_handle); | 158 response_body_stream_ = std::move(data_pipe_.producer_handle); |
154 | 159 |
155 // TODO(ananta) | 160 // TODO(ananta) |
156 // Move the asynchronous reading and mojo pipe handling code to a helper | 161 // Move the asynchronous reading and mojo pipe handling code to a helper |
157 // class. That would also need a change to BlobURLLoader. | 162 // class. That would also need a change to BlobURLLoader. |
158 | 163 |
159 // Wait for the data pipe to be ready to accept data. | 164 // Wait for the data pipe to be ready to accept data. |
160 writable_handle_watcher_.Watch( | 165 writable_handle_watcher_.Watch( |
161 response_body_stream_.get(), MOJO_HANDLE_SIGNAL_WRITABLE, | 166 response_body_stream_.get(), MOJO_HANDLE_SIGNAL_WRITABLE, |
162 base::Bind(&AppCacheURLLoaderJob::OnResponseBodyStreamReady, | 167 base::Bind(&AppCacheURLLoaderJob::OnResponseBodyStreamReady, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 214 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
210 } | 215 } |
211 | 216 |
212 void AppCacheURLLoaderJob::SendResponseInfo() { | 217 void AppCacheURLLoaderJob::SendResponseInfo() { |
213 DCHECK(client_info_); | 218 DCHECK(client_info_); |
214 | 219 |
215 // If this is null it means the response information was sent to the client. | 220 // If this is null it means the response information was sent to the client. |
216 if (!data_pipe_.consumer_handle.is_valid()) | 221 if (!data_pipe_.consumer_handle.is_valid()) |
217 return; | 222 return; |
218 | 223 |
219 const net::HttpResponseInfo* http_info = info_->http_response_info(); | 224 const net::HttpResponseInfo* http_info = is_range_request() |
225 ? range_response_info_.get() | |
226 : info_->http_response_info(); | |
220 | 227 |
221 ResourceResponseHead response_head; | 228 ResourceResponseHead response_head; |
222 response_head.headers = http_info->headers; | 229 response_head.headers = http_info->headers; |
223 | 230 |
224 // TODO(ananta) | 231 // TODO(ananta) |
225 // Copy more fields. | 232 // Copy more fields. |
226 http_info->headers->GetMimeType(&response_head.mime_type); | 233 http_info->headers->GetMimeType(&response_head.mime_type); |
227 http_info->headers->GetCharset(&response_head.charset); | 234 http_info->headers->GetCharset(&response_head.charset); |
228 | 235 |
229 response_head.request_time = http_info->request_time; | 236 response_head.request_time = http_info->request_time; |
230 response_head.response_time = http_info->response_time; | 237 response_head.response_time = http_info->response_time; |
231 response_head.content_length = info_->response_data_size(); | 238 response_head.content_length = |
239 is_range_request() ? range_response_info_->headers->GetContentLength() | |
240 : info_->response_data_size(); | |
232 | 241 |
233 client_info_->OnReceiveResponse(response_head, http_info->ssl_info, | 242 client_info_->OnReceiveResponse(response_head, http_info->ssl_info, |
234 mojom::DownloadedTempFilePtr()); | 243 mojom::DownloadedTempFilePtr()); |
235 | 244 |
236 client_info_->OnStartLoadingResponseBody( | 245 client_info_->OnStartLoadingResponseBody( |
237 std::move(data_pipe_.consumer_handle)); | 246 std::move(data_pipe_.consumer_handle)); |
238 } | 247 } |
239 | 248 |
240 void AppCacheURLLoaderJob::ReadMore() { | 249 void AppCacheURLLoaderJob::ReadMore() { |
241 DCHECK(!pending_write_.get()); | 250 DCHECK(!pending_write_.get()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 if (storage_.get()) | 290 if (storage_.get()) |
282 storage_->CancelDelegateCallbacks(this); | 291 storage_->CancelDelegateCallbacks(this); |
283 // TODO(ananta) | 292 // TODO(ananta) |
284 // Fill other details in the ResourceRequestCompletionStatus structure. | 293 // Fill other details in the ResourceRequestCompletionStatus structure. |
285 ResourceRequestCompletionStatus request_complete_data; | 294 ResourceRequestCompletionStatus request_complete_data; |
286 request_complete_data.error_code = error_code; | 295 request_complete_data.error_code = error_code; |
287 client_info_->OnComplete(request_complete_data); | 296 client_info_->OnComplete(request_complete_data); |
288 } | 297 } |
289 | 298 |
290 } // namespace content | 299 } // namespace content |
OLD | NEW |