| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/base/file_stream.h" | 10 #include "net/base/file_stream.h" |
| 10 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 12 | 13 |
| 13 namespace net { | 14 namespace net { |
| 14 | 15 |
| 15 bool UploadDataStream::merge_chunks_ = true; | 16 bool UploadDataStream::merge_chunks_ = true; |
| 16 | 17 |
| 17 UploadDataStream::~UploadDataStream() { | 18 UploadDataStream::~UploadDataStream() { |
| 18 } | 19 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 102 } |
| 102 next_element_remaining_ = element.GetContentLength(); | 103 next_element_remaining_ = element.GetContentLength(); |
| 103 next_element_stream_.reset(element.NewFileStreamForReading()); | 104 next_element_stream_.reset(element.NewFileStreamForReading()); |
| 104 } | 105 } |
| 105 | 106 |
| 106 int rv = 0; | 107 int rv = 0; |
| 107 int count = | 108 int count = |
| 108 static_cast<int>(std::min(next_element_remaining_, | 109 static_cast<int>(std::min(next_element_remaining_, |
| 109 static_cast<uint64>(size_remaining))); | 110 static_cast<uint64>(size_remaining))); |
| 110 if (count > 0) { | 111 if (count > 0) { |
| 112 // Temporarily allow until fix: http://crbug.com/72001. |
| 113 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 111 if (next_element_stream_.get()) | 114 if (next_element_stream_.get()) |
| 112 rv = next_element_stream_->Read(buf_->data() + buf_len_, count, NULL); | 115 rv = next_element_stream_->Read(buf_->data() + buf_len_, count, NULL); |
| 113 if (rv <= 0) { | 116 if (rv <= 0) { |
| 114 // If there's less data to read than we initially observed, then | 117 // If there's less data to read than we initially observed, then |
| 115 // pad with zero. Otherwise the server will hang waiting for the | 118 // pad with zero. Otherwise the server will hang waiting for the |
| 116 // rest of the data. | 119 // rest of the data. |
| 117 memset(buf_->data() + buf_len_, 0, count); | 120 memset(buf_->data() + buf_len_, 0, count); |
| 118 rv = count; | 121 rv = count; |
| 119 } | 122 } |
| 120 buf_len_ += rv; | 123 buf_len_ += rv; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 151 bool UploadDataStream::IsOnLastChunk() const { | 154 bool UploadDataStream::IsOnLastChunk() const { |
| 152 const std::vector<UploadData::Element>& elements = *data_->elements(); | 155 const std::vector<UploadData::Element>& elements = *data_->elements(); |
| 153 DCHECK(data_->is_chunked()); | 156 DCHECK(data_->is_chunked()); |
| 154 return (eof_ || | 157 return (eof_ || |
| 155 (!elements.empty() && | 158 (!elements.empty() && |
| 156 next_element_ == elements.size() && | 159 next_element_ == elements.size() && |
| 157 elements.back().is_last_chunk())); | 160 elements.back().is_last_chunk())); |
| 158 } | 161 } |
| 159 | 162 |
| 160 } // namespace net | 163 } // namespace net |
| OLD | NEW |