Chromium Code Reviews| Index: net/base/upload_data_stream.h |
| diff --git a/net/base/upload_data_stream.h b/net/base/upload_data_stream.h |
| index 0d179d217bcfdd80c8d0915c84268e5fda856167..fcb7e9b24e9a92734deb7392abd7507f033e6f40 100644 |
| --- a/net/base/upload_data_stream.h |
| +++ b/net/base/upload_data_stream.h |
| @@ -7,6 +7,7 @@ |
| #pragma once |
| #include "base/scoped_ptr.h" |
| +#include "net/base/completion_callback.h" |
| #include "net/base/upload_data.h" |
| namespace net { |
| @@ -14,8 +15,19 @@ namespace net { |
| class FileStream; |
| class IOBuffer; |
| -class UploadDataStream { |
| +class UploadDataStream : public UploadData::ChunkCallback { |
| public: |
| + // Interface implemented by callers who require callbacks when new chunks |
| + // of data are received. |
| + class ChunkCallback { |
|
vandebo (ex-Chrome)
2011/01/14 05:53:44
This interface class is the same as UploadData::Ch
Satish
2011/01/14 18:09:29
Wan-Teh suggests I rename this to Delegate. I'm no
|
| + public: |
| + // Invoked when a new data chunk was given for a chunked transfer upload. |
| + virtual void OnChunkAvailable() = 0; |
| + |
| + protected: |
| + virtual ~ChunkCallback() {} |
| + }; |
| + |
| // 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. |
| @@ -32,6 +44,11 @@ class UploadDataStream { |
| // the upload data to be consumed. |
| void DidConsume(size_t num_bytes); |
| + // Sets the callback to be invoked when new data is available to upload. |
| + // The callback is invoked only once and needs to be set again if the caller |
| + // needs to be indicated again in future. |
| + void set_chunk_callback(ChunkCallback* callback); |
| + |
| // Returns the total size of the data stream and the current position. |
| // size() is not to be used to determine whether the stream has ended |
| // because it is possible for the stream to end before its size is reached, |
| @@ -39,10 +56,17 @@ class UploadDataStream { |
| uint64 size() const { return total_size_; } |
| uint64 position() const { return current_position_; } |
| + bool is_chunked() const { return data_->is_chunked(); } |
| + |
| // Returns whether there is no more data to read, regardless of whether |
| // position < size. |
| bool eof() const { return eof_; } |
| + // UploadData::ChunkCallback members. |
| + |
| + // Callback invoked by UploadData when new data is available. |
| + void OnChunkAvailable(); |
| + |
| 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. |
| @@ -63,8 +87,8 @@ class UploadDataStream { |
| scoped_refptr<IOBuffer> buf_; |
| size_t buf_len_; |
| - // Iterator to the upload element to be written to the send buffer next. |
| - std::vector<UploadData::Element>::iterator next_element_; |
| + // Index of the upload element to be written to the send buffer next. |
| + size_t next_element_; |
|
wtc
2011/01/14 03:09:31
Why does next_element_ need to be an array index?
Satish
2011/01/14 18:09:29
Yes
|
| // The byte offset into next_element_'s data buffer if the next element is |
| // a TYPE_BYTES element. |
| @@ -82,6 +106,12 @@ class UploadDataStream { |
| uint64 total_size_; |
| uint64 current_position_; |
| + // Whether we have run out of data and waiting for more to come in. |
| + bool waiting_for_data_; |
| + |
| + // Callback to be invoked by us when new data is available. |
| + ChunkCallback* chunk_callback_; |
| + |
| // Whether there is no data left to read. |
| bool eof_; |