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 #ifndef NET_BASE_UPLOAD_DATA_H_ | 5 #ifndef NET_BASE_UPLOAD_DATA_H_ |
6 #define NET_BASE_UPLOAD_DATA_H_ | 6 #define NET_BASE_UPLOAD_DATA_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 | 122 |
123 // Reads up to |buf_len| bytes synchronously. Returns the number of bytes | 123 // Reads up to |buf_len| bytes synchronously. Returns the number of bytes |
124 // read. This function never fails. If there's less data to read than we | 124 // read. This function never fails. If there's less data to read than we |
125 // initially observed, then pad with zero (this can happen with files). | 125 // initially observed, then pad with zero (this can happen with files). |
126 // |buf_len| must be greater than 0. | 126 // |buf_len| must be greater than 0. |
127 int ReadSync(char* buf, int buf_len); | 127 int ReadSync(char* buf, int buf_len); |
128 | 128 |
129 // Returns the number of bytes remaining to read. | 129 // Returns the number of bytes remaining to read. |
130 uint64 BytesRemaining(); | 130 uint64 BytesRemaining(); |
131 | 131 |
132 // Resets the offset to zero, so that the element can be reread. | 132 // Resets the offset to zero and closes the file stream if opened, so |
133 void ResetOffset() { offset_ = 0; } | 133 // that the element can be reread. |
134 void ResetOffset(); | |
134 | 135 |
135 private: | 136 private: |
136 // Returns a FileStream opened for reading for this element, positioned | 137 // Returns a FileStream opened for reading for this element, positioned |
137 // at |file_range_offset_|. Returns NULL if the file is not openable. | 138 // at |file_range_offset_|. Returns NULL if the file is not openable. |
138 FileStream* OpenFileStream(); | 139 FileStream* OpenFileStream(); |
139 | 140 |
140 // Reads up to |buf_len| bytes synchronously from memory (i.e. type_ is | 141 // Reads up to |buf_len| bytes synchronously from memory (i.e. type_ is |
141 // TYPE_BYTES or TYPE_CHUNK). | 142 // TYPE_BYTES or TYPE_CHUNK). |
142 int ReadFromMemorySync(char* buf, int buf_len); | 143 int ReadFromMemorySync(char* buf, int buf_len); |
143 | 144 |
(...skipping 17 matching lines...) Expand all Loading... | |
161 bool is_last_chunk_; | 162 bool is_last_chunk_; |
162 bool override_content_length_; | 163 bool override_content_length_; |
163 bool content_length_computed_; | 164 bool content_length_computed_; |
164 uint64 content_length_; | 165 uint64 content_length_; |
165 | 166 |
166 // The byte offset from the beginning of the element data. Used to track | 167 // The byte offset from the beginning of the element data. Used to track |
167 // the current position when reading data. | 168 // the current position when reading data. |
168 size_t offset_; | 169 size_t offset_; |
169 | 170 |
170 // The stream of the element data, if this element is of TYPE_FILE. | 171 // The stream of the element data, if this element is of TYPE_FILE. |
171 FileStream* file_stream_; | 172 FileStream* file_stream_; |
willchan no longer on Chromium
2012/05/21 18:12:51
Hm, why isn't this a scoped_ptr? It looks like we
satorux1
2012/05/21 19:37:00
IIRC, I once tried to make it a scoped_ptr but fai
willchan no longer on Chromium
2012/05/21 20:27:40
Ugh, so fragile :( This code sucks.
wtc
2012/05/21 23:13:11
Should we use base/memory/linked_ptr.h to deal wit
willchan no longer on Chromium
2012/05/21 23:38:55
I don't think we should do this. The fundamental p
| |
172 | 173 |
173 FRIEND_TEST_ALL_PREFIXES(UploadDataStreamTest, FileSmallerThanLength); | 174 FRIEND_TEST_ALL_PREFIXES(UploadDataStreamTest, FileSmallerThanLength); |
174 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest, | 175 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest, |
175 UploadFileSmallerThanLength); | 176 UploadFileSmallerThanLength); |
176 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy2Test, | 177 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy2Test, |
177 UploadFileSmallerThanLength); | 178 UploadFileSmallerThanLength); |
178 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy3Test, | 179 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy3Test, |
179 UploadFileSmallerThanLength); | 180 UploadFileSmallerThanLength); |
180 }; | 181 }; |
181 | 182 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 | 277 |
277 inline bool operator!=(const UploadData::Element& a, | 278 inline bool operator!=(const UploadData::Element& a, |
278 const UploadData::Element& b) { | 279 const UploadData::Element& b) { |
279 return !(a == b); | 280 return !(a == b); |
280 } | 281 } |
281 #endif // defined(UNIT_TEST) | 282 #endif // defined(UNIT_TEST) |
282 | 283 |
283 } // namespace net | 284 } // namespace net |
284 | 285 |
285 #endif // NET_BASE_UPLOAD_DATA_H_ | 286 #endif // NET_BASE_UPLOAD_DATA_H_ |
OLD | NEW |