1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_BASE_CHUNKED_UPLOAD_DATA_STREAM_H_
6 #define NET_BASE_CHUNKED_UPLOAD_DATA_STREAM_H_
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_vector.h"
13 #include "net/base/completion_callback.h"
14 #include "net/base/net_export.h"
15 #include "net/base/upload_data_stream.h"
21 // Class with a push-based interface for uploading data. Buffers all data until
22 // the request is completed. Not recommended for uploading large amounts of
23 // seekable data, due to this buffering behavior.
24 class NET_EXPORT ChunkedUploadDataStream
: public UploadDataStream
{
26 explicit ChunkedUploadDataStream(int64_t identifier
);
28 ~ChunkedUploadDataStream() override
;
30 // Adds data to the stream. |is_done| should be true if this is the last
31 // data to be appended. |data_len| must not be 0 unless |is_done| is true.
32 // Once called with |is_done| being true, must never be called again.
33 // TODO(mmenke): Consider using IOBuffers instead, to reduce data copies.
34 void AppendData(const char* data
, int data_len
, bool is_done
);
37 // UploadDataStream implementation.
38 int InitInternal() override
;
39 int ReadInternal(IOBuffer
* buf
, int buf_len
) override
;
40 void ResetInternal() override
;
42 int ReadChunk(IOBuffer
* buf
, int buf_len
);
44 // Index and offset of next element of |upload_data_| to be read.
48 // True once all data has been appended to the stream.
49 bool all_data_appended_
;
51 ScopedVector
<std::vector
<char>> upload_data_
;
53 // Buffer to write the next read's data to. Only set when a call to
54 // ReadInternal reads no data.
55 scoped_refptr
<IOBuffer
> read_buffer_
;
58 DISALLOW_COPY_AND_ASSIGN(ChunkedUploadDataStream
);
63 #endif // NET_BASE_CHUNKED_UPLOAD_DATA_STREAM_H_