| 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 "net/base/upload_data_stream.h" | 5 #include "net/base/upload_data_stream.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "net/base/file_stream.h" | 10 #include "net/base/file_stream.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 current_position_(0), | 24 current_position_(0), |
| 25 initialized_successfully_(false) { | 25 initialized_successfully_(false) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 UploadDataStream::~UploadDataStream() { | 28 UploadDataStream::~UploadDataStream() { |
| 29 } | 29 } |
| 30 | 30 |
| 31 int UploadDataStream::Init() { | 31 int UploadDataStream::Init() { |
| 32 DCHECK(!initialized_successfully_); | 32 DCHECK(!initialized_successfully_); |
| 33 | 33 |
| 34 total_size_ = upload_data_->GetContentLength(); | 34 total_size_ = upload_data_->GetContentLengthSyncHack(); |
| 35 | 35 |
| 36 // If the underlying file has been changed and the expected file | 36 // If the underlying file has been changed and the expected file |
| 37 // modification time is set, treat it as error. Note that the expected | 37 // modification time is set, treat it as error. Note that the expected |
| 38 // modification time from WebKit is based on time_t precision. So we | 38 // modification time from WebKit is based on time_t precision. So we |
| 39 // have to convert both to time_t to compare. This check is used for | 39 // have to convert both to time_t to compare. This check is used for |
| 40 // sliced files. | 40 // sliced files. |
| 41 const std::vector<UploadData::Element>& elements = *upload_data_->elements(); | 41 const std::vector<UploadData::Element>& elements = *upload_data_->elements(); |
| 42 for (size_t i = 0; i < elements.size(); ++i) { | 42 for (size_t i = 0; i < elements.size(); ++i) { |
| 43 const UploadData::Element& element = elements[i]; | 43 const UploadData::Element& element = elements[i]; |
| 44 if (element.type() == UploadData::TYPE_FILE && | 44 if (element.type() == UploadData::TYPE_FILE && |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // Advance to the next element if we have consumed all data in the | 91 // Advance to the next element if we have consumed all data in the |
| 92 // current element. | 92 // current element. |
| 93 if (element_offset_ == element_data.size()) | 93 if (element_offset_ == element_data.size()) |
| 94 advance_to_next_element = true; | 94 advance_to_next_element = true; |
| 95 } else { | 95 } else { |
| 96 DCHECK(element.type() == UploadData::TYPE_FILE); | 96 DCHECK(element.type() == UploadData::TYPE_FILE); |
| 97 | 97 |
| 98 // Open the file of the current element if not yet opened. | 98 // Open the file of the current element if not yet opened. |
| 99 if (!element_file_stream_.get()) { | 99 if (!element_file_stream_.get()) { |
| 100 element_file_bytes_remaining_ = element.GetContentLength(); | 100 element_file_bytes_remaining_ = element.GetContentLength(); |
| 101 // Temporarily allow until fix: http://crbug.com/72001. |
| 102 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 101 element_file_stream_.reset(element.NewFileStreamForReading()); | 103 element_file_stream_.reset(element.NewFileStreamForReading()); |
| 102 } | 104 } |
| 103 | 105 |
| 104 const int num_bytes_to_read = | 106 const int num_bytes_to_read = |
| 105 static_cast<int>(std::min(element_file_bytes_remaining_, | 107 static_cast<int>(std::min(element_file_bytes_remaining_, |
| 106 static_cast<uint64>(free_buffer_space))); | 108 static_cast<uint64>(free_buffer_space))); |
| 107 if (num_bytes_to_read > 0) { | 109 if (num_bytes_to_read > 0) { |
| 108 int num_bytes_consumed = 0; | 110 int num_bytes_consumed = 0; |
| 109 // Temporarily allow until fix: http://crbug.com/72001. | 111 // Temporarily allow until fix: http://crbug.com/72001. |
| 110 base::ThreadRestrictions::ScopedAllowIO allow_io; | 112 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 return false; | 176 return false; |
| 175 } | 177 } |
| 176 | 178 |
| 177 bool UploadDataStream::IsInMemory() const { | 179 bool UploadDataStream::IsInMemory() const { |
| 178 DCHECK(initialized_successfully_); | 180 DCHECK(initialized_successfully_); |
| 179 | 181 |
| 180 return upload_data_->IsInMemory(); | 182 return upload_data_->IsInMemory(); |
| 181 } | 183 } |
| 182 | 184 |
| 183 } // namespace net | 185 } // namespace net |
| OLD | NEW |