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/message_loop/message_loop_proxy.h" | |
19 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
20 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
21 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
23 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
24 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
25 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
26 #include "net/http/http_request_headers.h" | 25 #include "net/http/http_request_headers.h" |
27 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
28 #include "net/http/http_response_info.h" | 27 #include "net/http/http_response_info.h" |
(...skipping 21 matching lines...) Expand all Loading... |
50 } | 49 } |
51 } | 50 } |
52 | 51 |
53 } // namespace | 52 } // namespace |
54 | 53 |
55 BlobURLRequestJob::BlobURLRequestJob( | 54 BlobURLRequestJob::BlobURLRequestJob( |
56 net::URLRequest* request, | 55 net::URLRequest* request, |
57 net::NetworkDelegate* network_delegate, | 56 net::NetworkDelegate* network_delegate, |
58 scoped_ptr<BlobDataSnapshot> blob_data, | 57 scoped_ptr<BlobDataSnapshot> blob_data, |
59 storage::FileSystemContext* file_system_context, | 58 storage::FileSystemContext* file_system_context, |
60 base::MessageLoopProxy* file_thread_proxy) | 59 base::SingleThreadTaskRunner* file_thread_runner) |
61 : net::URLRequestJob(request, network_delegate), | 60 : net::URLRequestJob(request, network_delegate), |
62 blob_data_(blob_data.Pass()), | 61 blob_data_(blob_data.Pass()), |
63 file_system_context_(file_system_context), | 62 file_system_context_(file_system_context), |
64 file_thread_proxy_(file_thread_proxy), | 63 file_thread_runner_(file_thread_runner), |
65 total_size_(0), | 64 total_size_(0), |
66 remaining_bytes_(0), | 65 remaining_bytes_(0), |
67 pending_get_file_info_count_(0), | 66 pending_get_file_info_count_(0), |
68 current_item_index_(0), | 67 current_item_index_(0), |
69 current_item_offset_(0), | 68 current_item_offset_(0), |
70 error_(false), | 69 error_(false), |
71 byte_range_set_(false), | 70 byte_range_set_(false), |
72 weak_factory_(this) { | 71 weak_factory_(this) { |
73 TRACE_EVENT_ASYNC_BEGIN1("Blob", "BlobRequest", this, "uuid", | 72 TRACE_EVENT_ASYNC_BEGIN1("Blob", "BlobRequest", this, "uuid", |
74 blob_data_ ? blob_data_->uuid() : "NotFound"); | 73 blob_data_ ? blob_data_->uuid() : "NotFound"); |
75 DCHECK(file_thread_proxy_.get()); | 74 DCHECK(file_thread_runner_.get()); |
76 } | 75 } |
77 | 76 |
78 void BlobURLRequestJob::Start() { | 77 void BlobURLRequestJob::Start() { |
79 // Continue asynchronously. | 78 // Continue asynchronously. |
80 base::MessageLoop::current()->PostTask( | 79 base::MessageLoop::current()->PostTask( |
81 FROM_HERE, | 80 FROM_HERE, |
82 base::Bind(&BlobURLRequestJob::DidStart, weak_factory_.GetWeakPtr())); | 81 base::Bind(&BlobURLRequestJob::DidStart, weak_factory_.GetWeakPtr())); |
83 } | 82 } |
84 | 83 |
85 void BlobURLRequestJob::Kill() { | 84 void BlobURLRequestJob::Kill() { |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 const auto& items = blob_data_->items(); | 588 const auto& items = blob_data_->items(); |
590 DCHECK_LT(index, items.size()); | 589 DCHECK_LT(index, items.size()); |
591 const BlobDataItem& item = *items.at(index); | 590 const BlobDataItem& item = *items.at(index); |
592 DCHECK(IsFileType(item.type())); | 591 DCHECK(IsFileType(item.type())); |
593 DCHECK_EQ(0U, index_to_reader_.count(index)); | 592 DCHECK_EQ(0U, index_to_reader_.count(index)); |
594 | 593 |
595 FileStreamReader* reader = NULL; | 594 FileStreamReader* reader = NULL; |
596 switch (item.type()) { | 595 switch (item.type()) { |
597 case DataElement::TYPE_FILE: | 596 case DataElement::TYPE_FILE: |
598 reader = FileStreamReader::CreateForLocalFile( | 597 reader = FileStreamReader::CreateForLocalFile( |
599 file_thread_proxy_.get(), | 598 file_thread_runner_.get(), |
600 item.path(), | 599 item.path(), |
601 item.offset() + additional_offset, | 600 item.offset() + additional_offset, |
602 item.expected_modification_time()); | 601 item.expected_modification_time()); |
603 break; | 602 break; |
604 case DataElement::TYPE_FILE_FILESYSTEM: | 603 case DataElement::TYPE_FILE_FILESYSTEM: |
605 reader = file_system_context_ | 604 reader = file_system_context_ |
606 ->CreateFileStreamReader( | 605 ->CreateFileStreamReader( |
607 storage::FileSystemURL(file_system_context_->CrackURL( | 606 storage::FileSystemURL(file_system_context_->CrackURL( |
608 item.filesystem_url())), | 607 item.filesystem_url())), |
609 item.offset() + additional_offset, | 608 item.offset() + additional_offset, |
610 item.length() == std::numeric_limits<uint64>::max() | 609 item.length() == std::numeric_limits<uint64>::max() |
611 ? storage::kMaximumLength | 610 ? storage::kMaximumLength |
612 : item.length() - additional_offset, | 611 : item.length() - additional_offset, |
613 item.expected_modification_time()) | 612 item.expected_modification_time()) |
614 .release(); | 613 .release(); |
615 break; | 614 break; |
616 default: | 615 default: |
617 NOTREACHED(); | 616 NOTREACHED(); |
618 } | 617 } |
619 DCHECK(reader); | 618 DCHECK(reader); |
620 index_to_reader_[index] = reader; | 619 index_to_reader_[index] = reader; |
621 } | 620 } |
622 | 621 |
623 } // namespace storage | 622 } // namespace storage |
OLD | NEW |