Chromium Code Reviews| Index: net/base/upload_data.h |
| diff --git a/net/base/upload_data.h b/net/base/upload_data.h |
| index 6f7216250a40c536a8cbdf1eba70c02d67fdb342..381f7709964ebedab8d434b56cabaa42d3a7fc94 100644 |
| --- a/net/base/upload_data.h |
| +++ b/net/base/upload_data.h |
| @@ -19,12 +19,27 @@ namespace net { |
| class FileStream; |
| +// Interface implemented by callers who require callbacks when new chunks |
| +// of data are added. |
| +class ChunkCallback { |
| + public: |
| + // Invoked when a new data chunk was given for a chunked transfer upload. |
| + virtual void OnChunkAvailable() = 0; |
| + |
| + protected: |
| + virtual ~ChunkCallback() {} |
| +}; |
| + |
| class UploadData : public base::RefCounted<UploadData> { |
| public: |
| enum Type { |
| TYPE_BYTES, |
| TYPE_FILE, |
| - TYPE_BLOB |
| + TYPE_BLOB, |
| + |
| + // A block of bytes to be sent in chunked encoding immediately, without |
| + // waiting for rest of the data. |
| + TYPE_CHUNK, |
| }; |
| class Element { |
| @@ -72,6 +87,13 @@ class UploadData : public base::RefCounted<UploadData> { |
| blob_url_ = blob_url; |
| } |
| + // Though similar to bytes, a chunk indicates that the element is sent via |
| + // chunked transfer encoding and not buffered until the full upload data |
| + // is available. |
| + void SetToChunk(const char* bytes, int bytes_len); |
| + |
| + bool is_last_chunk() const { return is_last_chunk_; } |
| + |
| // Returns the byte-length of the element. For files that do not exist, 0 |
| // is returned. This is done for consistency with Mozilla. |
| // Once called, this function will always return the same value. |
| @@ -97,8 +119,9 @@ class UploadData : public base::RefCounted<UploadData> { |
| uint64 file_range_length_; |
| base::Time expected_file_modification_time_; |
| GURL blob_url_; |
| - bool override_content_length_; |
| - bool content_length_computed_; |
| + bool is_last_chunk_ : 1; |
|
vandebo (ex-Chrome)
2011/01/21 18:08:41
nit: Are the :1's needed? I suspect not.
wtc
2011/01/21 19:35:54
I also recommend removing ": 1". By listing the b
|
| + bool override_content_length_ : 1; |
| + bool content_length_computed_ : 1; |
| uint64 content_length_; |
| FileStream* file_stream_; |
| @@ -119,6 +142,16 @@ class UploadData : public base::RefCounted<UploadData> { |
| void AppendBlob(const GURL& blob_url); |
| + void AppendChunk(const char* bytes, int bytes_len); |
|
vandebo (ex-Chrome)
2011/01/21 18:08:41
nit: Add a comment about a zero size chunk indicat
|
| + |
| + // Sets the callback to be invoked when a new chunk is available to upload. |
| + void set_chunk_callback(ChunkCallback* callback); |
| + |
| + // Initializes the object to send chunks of upload data over time rather |
| + // than all at once. |
| + void set_is_chunked(bool set) { is_chunked_ = set; } |
| + bool is_chunked() const { return is_chunked_; } |
| + |
| // Returns the total size in bytes of the data to upload. |
| uint64 GetContentLength(); |
| @@ -145,6 +178,8 @@ class UploadData : public base::RefCounted<UploadData> { |
| std::vector<Element> elements_; |
| int64 identifier_; |
| + ChunkCallback* chunk_callback_; |
| + bool is_chunked_; |
| DISALLOW_COPY_AND_ASSIGN(UploadData); |
| }; |