| 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_bytes_element_reader.h" | 5 #include "net/base/upload_bytes_element_reader.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 | 10 |
| 11 namespace net { | 11 namespace net { |
| 12 | 12 |
| 13 UploadBytesElementReader::UploadBytesElementReader(const char* bytes, | 13 UploadBytesElementReader::UploadBytesElementReader(const char* bytes, |
| 14 int length) | 14 uint64 length) |
| 15 : bytes_(bytes), | 15 : bytes_(bytes), |
| 16 length_(length), | 16 length_(length), |
| 17 offset_(0) { | 17 offset_(0) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 UploadBytesElementReader::~UploadBytesElementReader() { | 20 UploadBytesElementReader::~UploadBytesElementReader() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 const UploadBytesElementReader* | 23 const UploadBytesElementReader* |
| 24 UploadBytesElementReader::AsBytesReader() const { | 24 UploadBytesElementReader::AsBytesReader() const { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // Check if we have anything to copy first, because we are getting | 62 // Check if we have anything to copy first, because we are getting |
| 63 // the address of an element in |bytes_| and that will throw an | 63 // the address of an element in |bytes_| and that will throw an |
| 64 // exception if |bytes_| is an empty vector. | 64 // exception if |bytes_| is an empty vector. |
| 65 if (num_bytes_to_read > 0) | 65 if (num_bytes_to_read > 0) |
| 66 memcpy(buf->data(), bytes_ + offset_, num_bytes_to_read); | 66 memcpy(buf->data(), bytes_ + offset_, num_bytes_to_read); |
| 67 | 67 |
| 68 offset_ += num_bytes_to_read; | 68 offset_ += num_bytes_to_read; |
| 69 return num_bytes_to_read; | 69 return num_bytes_to_read; |
| 70 } | 70 } |
| 71 | 71 |
| 72 |
| 73 UploadOwnedBytesElementReader::UploadOwnedBytesElementReader( |
| 74 std::vector<char>* data) |
| 75 : UploadBytesElementReader(&(*data)[0], data->size()) { |
| 76 data_.swap(*data); |
| 77 } |
| 78 |
| 79 UploadOwnedBytesElementReader::~UploadOwnedBytesElementReader() {} |
| 80 |
| 81 UploadOwnedBytesElementReader* |
| 82 UploadOwnedBytesElementReader::CreateWithString(const std::string& string) { |
| 83 std::vector<char> data(string.begin(), string.end()); |
| 84 return new UploadOwnedBytesElementReader(&data); |
| 85 } |
| 86 |
| 72 } // namespace net | 87 } // namespace net |
| OLD | NEW |