OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/base/upload_bytes_element_reader.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "net/base/net_errors.h" |
| 9 |
| 10 namespace net { |
| 11 |
| 12 UploadBytesElementReader::UploadBytesElementReader(const char* bytes, |
| 13 int bytes_length) |
| 14 : bytes_(bytes), |
| 15 bytes_length_(bytes_length), |
| 16 offset_(0) { |
| 17 } |
| 18 |
| 19 UploadBytesElementReader::~UploadBytesElementReader() { |
| 20 } |
| 21 |
| 22 int UploadBytesElementReader::InitSync() { |
| 23 return OK; |
| 24 } |
| 25 |
| 26 uint64 UploadBytesElementReader::GetContentLength() const { |
| 27 return bytes_length_; |
| 28 } |
| 29 |
| 30 uint64 UploadBytesElementReader::BytesRemaining() const { |
| 31 return bytes_length_ - offset_; |
| 32 } |
| 33 |
| 34 int UploadBytesElementReader::ReadSync(char* buf, int buf_length) { |
| 35 DCHECK_LT(0, buf_length); |
| 36 |
| 37 const size_t num_bytes_to_read = |
| 38 std::min(BytesRemaining(), static_cast<uint64>(buf_length)); |
| 39 |
| 40 // Check if we have anything to copy first, because we are getting |
| 41 // the address of an element in |bytes_| and that will throw an |
| 42 // exception if |bytes_| is an empty vector. |
| 43 if (num_bytes_to_read > 0) |
| 44 memcpy(buf, bytes_ + offset_, num_bytes_to_read); |
| 45 |
| 46 offset_ += num_bytes_to_read; |
| 47 return num_bytes_to_read; |
| 48 } |
| 49 |
| 50 bool UploadBytesElementReader::IsInMemory() const { |
| 51 return true; |
| 52 } |
| 53 |
| 54 } // namespace net |
OLD | NEW |