| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 // Reset the offset, as upload_data_ may already be read (i.e. UploadData | 64 // Reset the offset, as upload_data_ may already be read (i.e. UploadData |
| 65 // can be reused for a new UploadDataStream). | 65 // can be reused for a new UploadDataStream). |
| 66 upload_data_->ResetOffset(); | 66 upload_data_->ResetOffset(); |
| 67 | 67 |
| 68 initialized_successfully_ = true; | 68 initialized_successfully_ = true; |
| 69 return OK; | 69 return OK; |
| 70 } | 70 } |
| 71 | 71 |
| 72 int UploadDataStream::Read(IOBuffer* buf, int buf_len) { | 72 int UploadDataStream::Read(IOBuffer* buf, int buf_len) { |
| 73 std::vector<UploadData::Element>& elements = *upload_data_->elements(); | 73 std::vector<UploadData::Element>& elements = |
| 74 *upload_data_->elements_mutable(); |
| 74 | 75 |
| 75 int bytes_copied = 0; | 76 int bytes_copied = 0; |
| 76 while (bytes_copied < buf_len && element_index_ < elements.size()) { | 77 while (bytes_copied < buf_len && element_index_ < elements.size()) { |
| 77 UploadData::Element& element = elements[element_index_]; | 78 UploadData::Element& element = elements[element_index_]; |
| 78 | 79 |
| 79 bytes_copied += element.ReadSync(buf->data() + bytes_copied, | 80 bytes_copied += element.ReadSync(buf->data() + bytes_copied, |
| 80 buf_len - bytes_copied); | 81 buf_len - bytes_copied); |
| 81 | 82 |
| 82 if (element.BytesRemaining() == 0) | 83 if (element.BytesRemaining() == 0) |
| 83 ++element_index_; | 84 ++element_index_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 108 return false; | 109 return false; |
| 109 } | 110 } |
| 110 | 111 |
| 111 bool UploadDataStream::IsInMemory() const { | 112 bool UploadDataStream::IsInMemory() const { |
| 112 DCHECK(initialized_successfully_); | 113 DCHECK(initialized_successfully_); |
| 113 | 114 |
| 114 return upload_data_->IsInMemory(); | 115 return upload_data_->IsInMemory(); |
| 115 } | 116 } |
| 116 | 117 |
| 117 } // namespace net | 118 } // namespace net |
| OLD | NEW |