OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_STREAM_H_ | 5 #ifndef NET_BASE_UPLOAD_DATA_STREAM_H_ |
6 #define NET_BASE_UPLOAD_DATA_STREAM_H_ | 6 #define NET_BASE_UPLOAD_DATA_STREAM_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "net/base/upload_data.h" | 10 #include "net/base/upload_data.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 // code will be set if the output parameter error_code is not empty. | 23 // code will be set if the output parameter error_code is not empty. |
24 static UploadDataStream* Create(UploadData* data, int* error_code); | 24 static UploadDataStream* Create(UploadData* data, int* error_code); |
25 | 25 |
26 // Returns the stream's buffer and buffer length. | 26 // Returns the stream's buffer and buffer length. |
27 IOBuffer* buf() const { return buf_; } | 27 IOBuffer* buf() const { return buf_; } |
28 size_t buf_len() const { return buf_len_; } | 28 size_t buf_len() const { return buf_len_; } |
29 | 29 |
30 // Call to indicate that a portion of the stream's buffer was consumed. This | 30 // Call to indicate that a portion of the stream's buffer was consumed. This |
31 // call modifies the stream's buffer so that it contains the next segment of | 31 // call modifies the stream's buffer so that it contains the next segment of |
32 // the upload data to be consumed. | 32 // the upload data to be consumed. |
33 void DidConsume(size_t num_bytes); | 33 void ConsumeAndFillBuffer(size_t num_bytes); |
wtc
2011/01/21 19:35:54
How about "MarkConsumedAndFillBuffer"?
| |
34 | |
35 // Sets the callback to be invoked when new chunks are available to upload. | |
36 void set_chunk_callback(ChunkCallback* callback); | |
wtc
2011/01/21 19:35:54
Nit: inline this method, as you inlined is_chunked
| |
34 | 37 |
35 // Returns the total size of the data stream and the current position. | 38 // Returns the total size of the data stream and the current position. |
36 // size() is not to be used to determine whether the stream has ended | 39 // size() is not to be used to determine whether the stream has ended |
37 // because it is possible for the stream to end before its size is reached, | 40 // because it is possible for the stream to end before its size is reached, |
38 // for example, if the file is truncated. | 41 // for example, if the file is truncated. |
39 uint64 size() const { return total_size_; } | 42 uint64 size() const { return total_size_; } |
40 uint64 position() const { return current_position_; } | 43 uint64 position() const { return current_position_; } |
41 | 44 |
45 bool is_chunked() const { return data_->is_chunked(); } | |
46 | |
42 // Returns whether there is no more data to read, regardless of whether | 47 // Returns whether there is no more data to read, regardless of whether |
43 // position < size. | 48 // position < size. |
44 bool eof() const { return eof_; } | 49 bool eof() const { return eof_; } |
45 | 50 |
46 private: | 51 private: |
47 enum { kBufSize = 16384 }; | 52 enum { kBufSize = 16384 }; |
48 | 53 |
49 // Protects from public access since now we have a static creator function | 54 // Protects from public access since now we have a static creator function |
50 // which will do both creation and initialization and might return an error. | 55 // which will do both creation and initialization and might return an error. |
51 explicit UploadDataStream(UploadData* data); | 56 explicit UploadDataStream(UploadData* data); |
52 | 57 |
53 // Fills the buffer with any remaining data and sets eof_ if there was nothing | 58 // Fills the buffer with any remaining data and sets eof_ if there was nothing |
54 // left to fill the buffer with. | 59 // left to fill the buffer with. |
55 // Returns OK if the operation succeeds. Otherwise error code is returned. | 60 // Returns OK if the operation succeeds. Otherwise error code is returned. |
56 int FillBuf(); | 61 int FillBuf(); |
57 | 62 |
58 UploadData* data_; | 63 UploadData* data_; |
59 | 64 |
60 // This buffer is filled with data to be uploaded. The data to be sent is | 65 // This buffer is filled with data to be uploaded. The data to be sent is |
61 // always at the front of the buffer. If we cannot send all of the buffer at | 66 // always at the front of the buffer. If we cannot send all of the buffer at |
62 // once, then we memmove the remaining portion and back-fill the buffer for | 67 // once, then we memmove the remaining portion and back-fill the buffer for |
63 // the next "write" call. buf_len_ indicates how much data is in the buffer. | 68 // the next "write" call. buf_len_ indicates how much data is in the buffer. |
64 scoped_refptr<IOBuffer> buf_; | 69 scoped_refptr<IOBuffer> buf_; |
65 size_t buf_len_; | 70 size_t buf_len_; |
66 | 71 |
67 // Iterator to the upload element to be written to the send buffer next. | 72 // Index of the upload element to be written to the send buffer next. |
68 std::vector<UploadData::Element>::iterator next_element_; | 73 size_t next_element_; |
69 | 74 |
70 // The byte offset into next_element_'s data buffer if the next element is | 75 // The byte offset into next_element_'s data buffer if the next element is |
71 // a TYPE_BYTES element. | 76 // a TYPE_BYTES element. |
72 size_t next_element_offset_; | 77 size_t next_element_offset_; |
73 | 78 |
74 // A stream to the currently open file, for next_element_ if the next element | 79 // A stream to the currently open file, for next_element_ if the next element |
75 // is a TYPE_FILE element. | 80 // is a TYPE_FILE element. |
76 scoped_ptr<FileStream> next_element_stream_; | 81 scoped_ptr<FileStream> next_element_stream_; |
77 | 82 |
78 // The number of bytes remaining to be read from the currently open file | 83 // The number of bytes remaining to be read from the currently open file |
79 // if the next element is of TYPE_FILE. | 84 // if the next element is of TYPE_FILE. |
80 uint64 next_element_remaining_; | 85 uint64 next_element_remaining_; |
81 | 86 |
82 // Size and current read position within the stream. | 87 // Size and current read position within the stream. |
83 uint64 total_size_; | 88 uint64 total_size_; |
84 uint64 current_position_; | 89 uint64 current_position_; |
85 | 90 |
86 // Whether there is no data left to read. | 91 // Whether there is no data left to read. |
87 bool eof_; | 92 bool eof_; |
88 | 93 |
89 DISALLOW_COPY_AND_ASSIGN(UploadDataStream); | 94 DISALLOW_COPY_AND_ASSIGN(UploadDataStream); |
90 }; | 95 }; |
91 | 96 |
92 } // namespace net | 97 } // namespace net |
93 | 98 |
94 #endif // NET_BASE_UPLOAD_DATA_STREAM_H_ | 99 #endif // NET_BASE_UPLOAD_DATA_STREAM_H_ |
OLD | NEW |