OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_request_job.h" | 5 #include "content/browser/appcache/appcache_url_request_job.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 range_response_info_.reset( | 328 range_response_info_.reset( |
329 new net::HttpResponseInfo(*info_->http_response_info())); | 329 new net::HttpResponseInfo(*info_->http_response_info())); |
330 net::HttpResponseHeaders* headers = range_response_info_->headers.get(); | 330 net::HttpResponseHeaders* headers = range_response_info_->headers.get(); |
331 headers->UpdateWithNewRange( | 331 headers->UpdateWithNewRange( |
332 range_requested_, resource_size, true /* replace status line */); | 332 range_requested_, resource_size, true /* replace status line */); |
333 } | 333 } |
334 | 334 |
335 void AppCacheURLRequestJob::OnReadComplete(int result) { | 335 void AppCacheURLRequestJob::OnReadComplete(int result) { |
336 DCHECK(is_delivering_appcache_response()); | 336 DCHECK(is_delivering_appcache_response()); |
337 if (result == 0) { | 337 if (result == 0) { |
338 NotifyDone(net::URLRequestStatus()); | |
339 AppCacheHistograms::CountResponseRetrieval( | 338 AppCacheHistograms::CountResponseRetrieval( |
340 true, is_main_resource_, manifest_url_.GetOrigin()); | 339 true, is_main_resource_, manifest_url_.GetOrigin()); |
341 } else if (result < 0) { | 340 } else if (result < 0) { |
342 if (storage_->service()->storage() == storage_) { | 341 if (storage_->service()->storage() == storage_) { |
343 storage_->service()->CheckAppCacheResponse(manifest_url_, cache_id_, | 342 storage_->service()->CheckAppCacheResponse(manifest_url_, cache_id_, |
344 entry_.response_id()); | 343 entry_.response_id()); |
345 } | 344 } |
346 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, result)); | |
347 AppCacheHistograms::CountResponseRetrieval( | 345 AppCacheHistograms::CountResponseRetrieval( |
348 false, is_main_resource_, manifest_url_.GetOrigin()); | 346 false, is_main_resource_, manifest_url_.GetOrigin()); |
349 } else { | |
350 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status | |
351 } | 347 } |
352 NotifyReadComplete(result); | 348 ReadRawDataComplete(result); |
353 } | 349 } |
354 | 350 |
355 // net::URLRequestJob overrides ------------------------------------------------ | 351 // net::URLRequestJob overrides ------------------------------------------------ |
356 | 352 |
357 void AppCacheURLRequestJob::Start() { | 353 void AppCacheURLRequestJob::Start() { |
358 DCHECK(!has_been_started()); | 354 DCHECK(!has_been_started()); |
359 has_been_started_ = true; | 355 has_been_started_ = true; |
360 start_time_tick_ = base::TimeTicks::Now(); | 356 start_time_tick_ = base::TimeTicks::Now(); |
361 MaybeBeginDelivery(); | 357 MaybeBeginDelivery(); |
362 } | 358 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 return; | 407 return; |
412 *info = *http_info(); | 408 *info = *http_info(); |
413 } | 409 } |
414 | 410 |
415 int AppCacheURLRequestJob::GetResponseCode() const { | 411 int AppCacheURLRequestJob::GetResponseCode() const { |
416 if (!http_info()) | 412 if (!http_info()) |
417 return -1; | 413 return -1; |
418 return http_info()->headers->response_code(); | 414 return http_info()->headers->response_code(); |
419 } | 415 } |
420 | 416 |
421 bool AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size, | 417 int AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size) { |
422 int *bytes_read) { | |
423 DCHECK(is_delivering_appcache_response()); | 418 DCHECK(is_delivering_appcache_response()); |
424 DCHECK_NE(buf_size, 0); | 419 DCHECK_NE(buf_size, 0); |
425 DCHECK(bytes_read); | |
426 DCHECK(!reader_->IsReadPending()); | 420 DCHECK(!reader_->IsReadPending()); |
427 reader_->ReadData( | 421 reader_->ReadData(buf, buf_size, |
428 buf, buf_size, base::Bind(&AppCacheURLRequestJob::OnReadComplete, | 422 base::Bind(&AppCacheURLRequestJob::OnReadComplete, |
429 base::Unretained(this))); | 423 base::Unretained(this))); |
430 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); | 424 return net::ERR_IO_PENDING; |
431 return false; | |
432 } | 425 } |
433 | 426 |
434 void AppCacheURLRequestJob::SetExtraRequestHeaders( | 427 void AppCacheURLRequestJob::SetExtraRequestHeaders( |
435 const net::HttpRequestHeaders& headers) { | 428 const net::HttpRequestHeaders& headers) { |
436 std::string value; | 429 std::string value; |
437 std::vector<net::HttpByteRange> ranges; | 430 std::vector<net::HttpByteRange> ranges; |
438 if (!headers.GetHeader(net::HttpRequestHeaders::kRange, &value) || | 431 if (!headers.GetHeader(net::HttpRequestHeaders::kRange, &value) || |
439 !net::HttpUtil::ParseRangeHeader(value, &ranges)) { | 432 !net::HttpUtil::ParseRangeHeader(value, &ranges)) { |
440 return; | 433 return; |
441 } | 434 } |
442 | 435 |
443 // If multiple ranges are requested, we play dumb and | 436 // If multiple ranges are requested, we play dumb and |
444 // return the entire response with 200 OK. | 437 // return the entire response with 200 OK. |
445 if (ranges.size() == 1U) | 438 if (ranges.size() == 1U) |
446 range_requested_ = ranges[0]; | 439 range_requested_ = ranges[0]; |
447 } | 440 } |
448 | 441 |
449 } // namespace content | 442 } // namespace content |
OLD | NEW |