diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-24 17:45:18 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-24 17:45:18 +0000 |
commit | 135e429c705aa5b8fd26f2b0a46ad63451817b3c (patch) | |
tree | ab44eda5270efd52b532f42516f5858e4caeceda /net/base/upload_data_stream.h | |
parent | a40d8c32ae648aa2f2cf998158e2930928b8d4cb (diff) | |
download | chromium_src-135e429c705aa5b8fd26f2b0a46ad63451817b3c.zip chromium_src-135e429c705aa5b8fd26f2b0a46ad63451817b3c.tar.gz chromium_src-135e429c705aa5b8fd26f2b0a46ad63451817b3c.tar.bz2 |
Improve readability of UploadDataStream.
Many variable names in the code are misleading or not descriptive.
In particular, next_element_* are misleading as these are referring
to the current element currently being read.
Along the way, add some comments, and clean up some pieces of code.
BUG=72001
TEST=run tests via try bots
Review URL: http://codereview.chromium.org/9212015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/upload_data_stream.h')
-rw-r--r-- | net/base/upload_data_stream.h | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/net/base/upload_data_stream.h b/net/base/upload_data_stream.h index e71cc68..f0a59fa 100644 --- a/net/base/upload_data_stream.h +++ b/net/base/upload_data_stream.h @@ -22,7 +22,7 @@ class NET_EXPORT UploadDataStream { // Returns a new instance of UploadDataStream if it can be created and // initialized successfully. If not, NULL will be returned and the error // code will be set if the output parameter error_code is not empty. - static UploadDataStream* Create(UploadData* data, int* error_code); + static UploadDataStream* Create(UploadData* upload_data, int* error_code); // Returns the stream's buffer. IOBuffer* buf() const { return buf_; } @@ -44,7 +44,7 @@ class NET_EXPORT UploadDataStream { // Sets the callback to be invoked when new chunks are available to upload. void set_chunk_callback(ChunkCallback* callback) { - data_->set_chunk_callback(callback); + upload_data_->set_chunk_callback(callback); } // Returns the total size of the data stream and the current position. @@ -54,7 +54,7 @@ class NET_EXPORT UploadDataStream { uint64 size() const { return total_size_; } uint64 position() const { return current_position_; } - bool is_chunked() const { return data_->is_chunked(); } + bool is_chunked() const { return upload_data_->is_chunked(); } // Returns whether there is no more data to read, regardless of whether // position < size. @@ -75,14 +75,21 @@ class NET_EXPORT UploadDataStream { private: // Protects from public access since now we have a static creator function // which will do both creation and initialization and might return an error. - explicit UploadDataStream(UploadData* data); + explicit UploadDataStream(UploadData* upload_data); // Fills the buffer with any remaining data and sets eof_ if there was nothing // left to fill the buffer with. // Returns OK if the operation succeeds. Otherwise error code is returned. - int FillBuf(); + int FillBuffer(); - scoped_refptr<UploadData> data_; + // Advances to the next element. Updates the internal states. + void AdvanceToNextElement(); + + // Returns true if all data has been consumed from this upload data + // stream. + bool IsEOF() const; + + scoped_refptr<UploadData> upload_data_; // This buffer is filled with data to be uploaded. The data to be sent is // always at the front of the buffer. If we cannot send all of the buffer at @@ -91,22 +98,24 @@ class NET_EXPORT UploadDataStream { scoped_refptr<IOBuffer> buf_; size_t buf_len_; - // Index of the upload element to be written to the send buffer next. - size_t next_element_; + // Index of the current upload element (i.e. the element currently being + // read). The index is used as a cursor to iterate over elements in + // |upload_data_|. + size_t element_index_; - // The byte offset into next_element_'s data buffer if the next element is - // a TYPE_BYTES element. - size_t next_element_offset_; + // The byte offset into the current element's data buffer if the current + // element is a TYPE_BYTES or TYPE_DATA element. + size_t element_offset_; - // A stream to the currently open file, for next_element_ if the next element - // is a TYPE_FILE element. - scoped_ptr<FileStream> next_element_stream_; + // A stream to the currently open file, for the current element if the + // current element is a TYPE_FILE element. + scoped_ptr<FileStream> element_file_stream_; // The number of bytes remaining to be read from the currently open file - // if the next element is of TYPE_FILE. - uint64 next_element_remaining_; + // if the current element is of TYPE_FILE. + uint64 element_file_bytes_remaining_; - // Size and current read position within the stream. + // Size and current read position within the upload data stream. uint64 total_size_; uint64 current_position_; |