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 "webkit/browser/blob/blob_url_request_job.h" | 5 #include "webkit/browser/blob/blob_url_request_job.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 file_system_context_(file_system_context), | 73 file_system_context_(file_system_context), |
74 file_thread_proxy_(file_thread_proxy), | 74 file_thread_proxy_(file_thread_proxy), |
75 total_size_(0), | 75 total_size_(0), |
76 remaining_bytes_(0), | 76 remaining_bytes_(0), |
77 pending_get_file_info_count_(0), | 77 pending_get_file_info_count_(0), |
78 current_item_index_(0), | 78 current_item_index_(0), |
79 current_item_offset_(0), | 79 current_item_offset_(0), |
80 error_(false), | 80 error_(false), |
81 headers_set_(false), | 81 headers_set_(false), |
82 byte_range_set_(false) { | 82 byte_range_set_(false) { |
83 DCHECK(file_thread_proxy_); | 83 DCHECK(file_thread_proxy_.get()); |
84 } | 84 } |
85 | 85 |
86 void BlobURLRequestJob::Start() { | 86 void BlobURLRequestJob::Start() { |
87 // Continue asynchronously. | 87 // Continue asynchronously. |
88 base::MessageLoop::current()->PostTask( | 88 base::MessageLoop::current()->PostTask( |
89 FROM_HERE, | 89 FROM_HERE, |
90 base::Bind(&BlobURLRequestJob::DidStart, weak_factory_.GetWeakPtr())); | 90 base::Bind(&BlobURLRequestJob::DidStart, weak_factory_.GetWeakPtr())); |
91 } | 91 } |
92 | 92 |
93 void BlobURLRequestJob::Kill() { | 93 void BlobURLRequestJob::Kill() { |
(...skipping 20 matching lines...) Expand all Loading... |
114 dest_size = static_cast<int>(remaining_bytes_); | 114 dest_size = static_cast<int>(remaining_bytes_); |
115 | 115 |
116 // If we should copy zero bytes because |remaining_bytes_| is zero, short | 116 // If we should copy zero bytes because |remaining_bytes_| is zero, short |
117 // circuit here. | 117 // circuit here. |
118 if (!dest_size) { | 118 if (!dest_size) { |
119 *bytes_read = 0; | 119 *bytes_read = 0; |
120 return true; | 120 return true; |
121 } | 121 } |
122 | 122 |
123 // Keep track of the buffer. | 123 // Keep track of the buffer. |
124 DCHECK(!read_buf_); | 124 DCHECK(!read_buf_.get()); |
125 read_buf_ = new net::DrainableIOBuffer(dest, dest_size); | 125 read_buf_ = new net::DrainableIOBuffer(dest, dest_size); |
126 | 126 |
127 return ReadLoop(bytes_read); | 127 return ReadLoop(bytes_read); |
128 } | 128 } |
129 | 129 |
130 bool BlobURLRequestJob::GetMimeType(std::string* mime_type) const { | 130 bool BlobURLRequestJob::GetMimeType(std::string* mime_type) const { |
131 if (!response_info_) | 131 if (!response_info_) |
132 return false; | 132 return false; |
133 | 133 |
134 return response_info_->headers->GetMimeType(mime_type); | 134 return response_info_->headers->GetMimeType(mime_type); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 | 172 |
173 void BlobURLRequestJob::DidStart() { | 173 void BlobURLRequestJob::DidStart() { |
174 // We only support GET request per the spec. | 174 // We only support GET request per the spec. |
175 if (request()->method() != "GET") { | 175 if (request()->method() != "GET") { |
176 NotifyFailure(net::ERR_METHOD_NOT_SUPPORTED); | 176 NotifyFailure(net::ERR_METHOD_NOT_SUPPORTED); |
177 return; | 177 return; |
178 } | 178 } |
179 | 179 |
180 // If the blob data is not present, bail out. | 180 // If the blob data is not present, bail out. |
181 if (!blob_data_) { | 181 if (!blob_data_.get()) { |
182 NotifyFailure(net::ERR_FILE_NOT_FOUND); | 182 NotifyFailure(net::ERR_FILE_NOT_FOUND); |
183 return; | 183 return; |
184 } | 184 } |
185 | 185 |
186 CountSize(); | 186 CountSize(); |
187 } | 187 } |
188 | 188 |
189 bool BlobURLRequestJob::AddItemLength(size_t index, int64 item_length) { | 189 bool BlobURLRequestJob::AddItemLength(size_t index, int64 item_length) { |
190 if (item_length > kint64max - total_size_) { | 190 if (item_length > kint64max - total_size_) { |
191 NotifyFailure(net::ERR_FAILED); | 191 NotifyFailure(net::ERR_FAILED); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 385 |
386 AdvanceBytesRead(bytes_to_read); | 386 AdvanceBytesRead(bytes_to_read); |
387 return true; | 387 return true; |
388 } | 388 } |
389 | 389 |
390 bool BlobURLRequestJob::ReadFileItem(FileStreamReader* reader, | 390 bool BlobURLRequestJob::ReadFileItem(FileStreamReader* reader, |
391 int bytes_to_read) { | 391 int bytes_to_read) { |
392 DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read); | 392 DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read); |
393 DCHECK(reader); | 393 DCHECK(reader); |
394 const int result = reader->Read( | 394 const int result = reader->Read( |
395 read_buf_, bytes_to_read, | 395 read_buf_.get(), |
396 base::Bind(&BlobURLRequestJob::DidReadFile, | 396 bytes_to_read, |
397 base::Unretained(this))); | 397 base::Bind(&BlobURLRequestJob::DidReadFile, base::Unretained(this))); |
398 if (result >= 0) { | 398 if (result >= 0) { |
399 // Data is immediately available. | 399 // Data is immediately available. |
400 if (GetStatus().is_io_pending()) | 400 if (GetStatus().is_io_pending()) |
401 DidReadFile(result); | 401 DidReadFile(result); |
402 else | 402 else |
403 AdvanceBytesRead(result); | 403 AdvanceBytesRead(result); |
404 return true; | 404 return true; |
405 } | 405 } |
406 if (result == net::ERR_IO_PENDING) | 406 if (result == net::ERR_IO_PENDING) |
407 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); | 407 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 void BlobURLRequestJob::CreateFileStreamReader(size_t index, | 578 void BlobURLRequestJob::CreateFileStreamReader(size_t index, |
579 int64 additional_offset) { | 579 int64 additional_offset) { |
580 DCHECK_LT(index, blob_data_->items().size()); | 580 DCHECK_LT(index, blob_data_->items().size()); |
581 const BlobData::Item& item = blob_data_->items().at(index); | 581 const BlobData::Item& item = blob_data_->items().at(index); |
582 DCHECK(IsFileType(item.type())); | 582 DCHECK(IsFileType(item.type())); |
583 DCHECK_EQ(0U, index_to_reader_.count(index)); | 583 DCHECK_EQ(0U, index_to_reader_.count(index)); |
584 | 584 |
585 FileStreamReader* reader = NULL; | 585 FileStreamReader* reader = NULL; |
586 switch (item.type()) { | 586 switch (item.type()) { |
587 case BlobData::Item::TYPE_FILE: | 587 case BlobData::Item::TYPE_FILE: |
588 reader = new LocalFileStreamReader( | 588 reader = new LocalFileStreamReader(file_thread_proxy_.get(), |
589 file_thread_proxy_, | 589 item.path(), |
590 item.path(), | 590 item.offset() + additional_offset, |
591 item.offset() + additional_offset, | 591 item.expected_modification_time()); |
592 item.expected_modification_time()); | |
593 break; | 592 break; |
594 case BlobData::Item::TYPE_FILE_FILESYSTEM: | 593 case BlobData::Item::TYPE_FILE_FILESYSTEM: |
595 reader = file_system_context_->CreateFileStreamReader( | 594 reader = file_system_context_->CreateFileStreamReader( |
596 fileapi::FileSystemURL(file_system_context_->CrackURL(item.url())), | 595 fileapi::FileSystemURL(file_system_context_->CrackURL(item.url())), |
597 item.offset() + additional_offset, | 596 item.offset() + additional_offset, |
598 item.expected_modification_time()).release(); | 597 item.expected_modification_time()).release(); |
599 break; | 598 break; |
600 default: | 599 default: |
601 NOTREACHED(); | 600 NOTREACHED(); |
602 } | 601 } |
603 DCHECK(reader); | 602 DCHECK(reader); |
604 index_to_reader_[index] = reader; | 603 index_to_reader_[index] = reader; |
605 } | 604 } |
606 | 605 |
607 } // namespace webkit_blob | 606 } // namespace webkit_blob |
OLD | NEW |