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 "storage/browser/blob/blob_url_request_job.h" | 5 #include "storage/browser/blob/blob_url_request_job.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/files/file_util_proxy.h" | 15 #include "base/files/file_util_proxy.h" |
16 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
23 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
25 #include "net/disk_cache/disk_cache.h" | |
25 #include "net/http/http_request_headers.h" | 26 #include "net/http/http_request_headers.h" |
26 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
27 #include "net/http/http_response_info.h" | 28 #include "net/http/http_response_info.h" |
28 #include "net/http/http_util.h" | 29 #include "net/http/http_util.h" |
29 #include "net/url_request/url_request.h" | 30 #include "net/url_request/url_request.h" |
30 #include "net/url_request/url_request_context.h" | 31 #include "net/url_request/url_request_context.h" |
31 #include "net/url_request/url_request_error_job.h" | 32 #include "net/url_request/url_request_error_job.h" |
32 #include "net/url_request/url_request_status.h" | 33 #include "net/url_request/url_request_status.h" |
33 #include "storage/browser/fileapi/file_stream_reader.h" | 34 #include "storage/browser/fileapi/file_stream_reader.h" |
34 #include "storage/browser/fileapi/file_system_context.h" | 35 #include "storage/browser/fileapi/file_system_context.h" |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 // If nothing to read for current item, advance to next item. | 350 // If nothing to read for current item, advance to next item. |
350 if (bytes_to_read == 0) { | 351 if (bytes_to_read == 0) { |
351 AdvanceItem(); | 352 AdvanceItem(); |
352 return true; | 353 return true; |
353 } | 354 } |
354 | 355 |
355 // Do the reading. | 356 // Do the reading. |
356 const BlobDataItem& item = *items.at(current_item_index_); | 357 const BlobDataItem& item = *items.at(current_item_index_); |
357 if (item.type() == DataElement::TYPE_BYTES) | 358 if (item.type() == DataElement::TYPE_BYTES) |
358 return ReadBytesItem(item, bytes_to_read); | 359 return ReadBytesItem(item, bytes_to_read); |
360 if (item.type() == DataElement::TYPE_DISK_CACHE_ENTRY) | |
361 return ReadDiskCacheEntryItem(item, bytes_to_read); | |
359 if (!IsFileType(item.type())) { | 362 if (!IsFileType(item.type())) { |
360 NOTREACHED(); | 363 NOTREACHED(); |
361 return false; | 364 return false; |
362 } | 365 } |
363 storage::FileStreamReader* const reader = | 366 storage::FileStreamReader* const reader = |
364 GetFileStreamReader(current_item_index_); | 367 GetFileStreamReader(current_item_index_); |
365 if (!reader) { | 368 if (!reader) { |
366 NotifyFailure(net::ERR_FAILED); | 369 NotifyFailure(net::ERR_FAILED); |
367 return false; | 370 return false; |
368 } | 371 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 } | 464 } |
462 | 465 |
463 void BlobURLRequestJob::DeleteCurrentFileReader() { | 466 void BlobURLRequestJob::DeleteCurrentFileReader() { |
464 IndexToReaderMap::iterator found = index_to_reader_.find(current_item_index_); | 467 IndexToReaderMap::iterator found = index_to_reader_.find(current_item_index_); |
465 if (found != index_to_reader_.end() && found->second) { | 468 if (found != index_to_reader_.end() && found->second) { |
466 delete found->second; | 469 delete found->second; |
467 index_to_reader_.erase(found); | 470 index_to_reader_.erase(found); |
468 } | 471 } |
469 } | 472 } |
470 | 473 |
474 bool BlobURLRequestJob::ReadDiskCacheEntryItem(const BlobDataItem& item, | |
475 int bytes_to_read) { | |
476 DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read); | |
477 | |
478 const int result = item.disk_cache_entry()->ReadData( | |
479 item.disk_cache_stream_index(), current_item_offset_, read_buf_.get(), | |
480 bytes_to_read, base::Bind(&BlobURLRequestJob::DidReadDiskCacheEntry, | |
481 base::Unretained(this))); | |
jkarlin
2015/06/12 15:53:38
Is base::Unretained safe here? Aren't jobs cleared
gavinp
2015/06/12 18:10:30
But we're mid-read, so isn't the URLRequest::Deleg
jkarlin
2015/06/12 19:17:52
I don't know how blob URLRequests are routed. Do t
mmenke
2015/06/12 19:23:36
Blob URL requests do indeed go through the RDH (Or
mmenke
2015/06/12 19:38:44
Sorry..scratch that. The UserData stapling is for
| |
482 DCHECK_LT(result, 0); | |
jkarlin
2015/06/12 15:53:38
The header doesn't say that ReadData is async only
gavinp
2015/06/12 18:10:30
True enough; and the memory cache is actually sync
| |
483 if (result == net::ERR_IO_PENDING) | |
484 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); | |
485 else | |
486 NotifyFailure(result); | |
487 return false; | |
488 } | |
489 | |
490 void BlobURLRequestJob::DidReadDiskCacheEntry(int result) { | |
491 if (result <= 0) { | |
jkarlin
2015/06/12 15:53:38
What if the item was 0 bytes?
gavinp
2015/06/12 18:10:30
Then we never called ReadDiskCacheEntryItem and th
| |
492 NotifyFailure(net::ERR_FAILED); | |
493 return; | |
494 } | |
495 SetStatus(net::URLRequestStatus()); | |
496 | |
497 AdvanceBytesRead(result); | |
498 | |
499 if (!read_buf_->BytesRemaining()) { | |
500 int bytes_read = BytesReadCompleted(); | |
501 NotifyReadComplete(bytes_read); | |
502 return; | |
503 } | |
504 | |
505 int bytes_read = 0; | |
506 if (ReadLoop(&bytes_read)) | |
507 NotifyReadComplete(bytes_read); | |
508 } | |
509 | |
471 int BlobURLRequestJob::BytesReadCompleted() { | 510 int BlobURLRequestJob::BytesReadCompleted() { |
472 int bytes_read = read_buf_->BytesConsumed(); | 511 int bytes_read = read_buf_->BytesConsumed(); |
473 read_buf_ = NULL; | 512 read_buf_ = NULL; |
474 return bytes_read; | 513 return bytes_read; |
475 } | 514 } |
476 | 515 |
477 int BlobURLRequestJob::ComputeBytesToRead() const { | 516 int BlobURLRequestJob::ComputeBytesToRead() const { |
478 int64 current_item_length = item_length_list_[current_item_index_]; | 517 int64 current_item_length = item_length_list_[current_item_index_]; |
479 | 518 |
480 int64 item_remaining = current_item_length - current_item_offset_; | 519 int64 item_remaining = current_item_length - current_item_offset_; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 | 680 |
642 default: | 681 default: |
643 break; | 682 break; |
644 } | 683 } |
645 | 684 |
646 NOTREACHED(); | 685 NOTREACHED(); |
647 return false; | 686 return false; |
648 } | 687 } |
649 | 688 |
650 } // namespace storage | 689 } // namespace storage |
OLD | NEW |