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 "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 bool UploadBytesElementReader::IsInMemory() const { | 42 bool UploadBytesElementReader::IsInMemory() const { |
43 return true; | 43 return true; |
44 } | 44 } |
45 | 45 |
46 int UploadBytesElementReader::Read(IOBuffer* buf, | 46 int UploadBytesElementReader::Read(IOBuffer* buf, |
47 int buf_length, | 47 int buf_length, |
48 const CompletionCallback& callback) { | 48 const CompletionCallback& callback) { |
49 DCHECK_LT(0, buf_length); | 49 DCHECK_LT(0, buf_length); |
50 | 50 |
51 const size_t num_bytes_to_read = | 51 const int num_bytes_to_read = static_cast<int>( |
52 std::min(BytesRemaining(), static_cast<uint64>(buf_length)); | 52 std::min(BytesRemaining(), static_cast<uint64>(buf_length))); |
53 | 53 |
54 // Check if we have anything to copy first, because we are getting | 54 // Check if we have anything to copy first, because we are getting |
55 // the address of an element in |bytes_| and that will throw an | 55 // the address of an element in |bytes_| and that will throw an |
56 // exception if |bytes_| is an empty vector. | 56 // exception if |bytes_| is an empty vector. |
57 if (num_bytes_to_read > 0) | 57 if (num_bytes_to_read > 0) |
58 memcpy(buf->data(), bytes_ + offset_, num_bytes_to_read); | 58 memcpy(buf->data(), bytes_ + offset_, num_bytes_to_read); |
59 | 59 |
60 offset_ += num_bytes_to_read; | 60 offset_ += num_bytes_to_read; |
61 return num_bytes_to_read; | 61 return num_bytes_to_read; |
62 } | 62 } |
63 | 63 |
64 | 64 |
65 UploadOwnedBytesElementReader::UploadOwnedBytesElementReader( | 65 UploadOwnedBytesElementReader::UploadOwnedBytesElementReader( |
66 std::vector<char>* data) | 66 std::vector<char>* data) |
67 : UploadBytesElementReader(vector_as_array(data), data->size()) { | 67 : UploadBytesElementReader(vector_as_array(data), data->size()) { |
68 data_.swap(*data); | 68 data_.swap(*data); |
69 } | 69 } |
70 | 70 |
71 UploadOwnedBytesElementReader::~UploadOwnedBytesElementReader() {} | 71 UploadOwnedBytesElementReader::~UploadOwnedBytesElementReader() {} |
72 | 72 |
73 UploadOwnedBytesElementReader* | 73 UploadOwnedBytesElementReader* |
74 UploadOwnedBytesElementReader::CreateWithString(const std::string& string) { | 74 UploadOwnedBytesElementReader::CreateWithString(const std::string& string) { |
75 std::vector<char> data(string.begin(), string.end()); | 75 std::vector<char> data(string.begin(), string.end()); |
76 return new UploadOwnedBytesElementReader(&data); | 76 return new UploadOwnedBytesElementReader(&data); |
77 } | 77 } |
78 | 78 |
79 } // namespace net | 79 } // namespace net |
OLD | NEW |