Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: net/base/upload_data_stream.h

Issue 6134003: Prototype of chunked transfer encoded POST. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/completion_callback.h"
10 #include "net/base/upload_data.h" 11 #include "net/base/upload_data.h"
11 12
12 namespace net { 13 namespace net {
13 14
14 class FileStream; 15 class FileStream;
15 class IOBuffer; 16 class IOBuffer;
16 17
17 class UploadDataStream { 18 class UploadDataStream {
18 public: 19 public:
19 // Returns a new instance of UploadDataStream if it can be created and 20 // Returns a new instance of UploadDataStream if it can be created and
20 // initialized successfully. If not, NULL will be returned and the error 21 // initialized successfully. If not, NULL will be returned and the error
21 // code will be set if the output parameter error_code is not empty. 22 // code will be set if the output parameter error_code is not empty.
22 static UploadDataStream* Create(UploadData* data, int* error_code); 23 static UploadDataStream* Create(UploadData* data, int* error_code);
23 24
24 ~UploadDataStream(); 25 ~UploadDataStream();
25 26
26 // Returns the stream's buffer and buffer length. 27 // Returns the stream's buffer and buffer length.
27 IOBuffer* buf() const { return buf_; } 28 IOBuffer* buf() const { return buf_; }
28 size_t buf_len() const { return buf_len_; } 29 size_t buf_len() const { return buf_len_; }
29 30
30 // Call to indicate that a portion of the stream's buffer was consumed. This 31 // 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 32 // call modifies the stream's buffer so that it contains the next segment of
32 // the upload data to be consumed. 33 // the upload data to be consumed.
33 void DidConsume(size_t num_bytes); 34 void DidConsume(size_t num_bytes);
34 35
36 // Sets the callback to be invoked when new data is available to upload.
37 void set_data_callback(CompletionCallback* callback);
38
35 // Returns the total size of the data stream and the current position. 39 // 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 40 // 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, 41 // because it is possible for the stream to end before its size is reached,
38 // for example, if the file is truncated. 42 // for example, if the file is truncated.
39 uint64 size() const { return total_size_; } 43 uint64 size() const { return total_size_; }
40 uint64 position() const { return current_position_; } 44 uint64 position() const { return current_position_; }
41 45
46 bool is_chunked() const { return data_->is_chunked(); }
47
42 // Returns whether there is no more data to read, regardless of whether 48 // Returns whether there is no more data to read, regardless of whether
43 // position < size. 49 // position < size.
44 bool eof() const { return eof_; } 50 bool eof() const { return eof_; }
45 51
52 bool waiting_for_data() const { return waiting_for_data_; }
wtc 2011/01/12 02:39:02 It seems that we don't need to add a waiting_for_d
Satish 2011/01/13 17:43:27 Done.
53
46 private: 54 private:
47 // Protects from public access since now we have a static creator function 55 // Protects from public access since now we have a static creator function
48 // which will do both creation and initialization and might return an error. 56 // which will do both creation and initialization and might return an error.
49 explicit UploadDataStream(UploadData* data); 57 explicit UploadDataStream(UploadData* data);
50 58
59 // Callback invoked by UploadData when new data is available.
60 void OnDataAvailable(int result);
61
51 // Fills the buffer with any remaining data and sets eof_ if there was nothing 62 // Fills the buffer with any remaining data and sets eof_ if there was nothing
52 // left to fill the buffer with. 63 // left to fill the buffer with.
53 // Returns OK if the operation succeeds. Otherwise error code is returned. 64 // Returns OK if the operation succeeds. Otherwise error code is returned.
54 int FillBuf(); 65 int FillBuf();
55 66
56 UploadData* data_; 67 UploadData* data_;
57 68
58 // This buffer is filled with data to be uploaded. The data to be sent is 69 // This buffer is filled with data to be uploaded. The data to be sent is
59 // always at the front of the buffer. If we cannot send all of the buffer at 70 // always at the front of the buffer. If we cannot send all of the buffer at
60 // once, then we memmove the remaining portion and back-fill the buffer for 71 // once, then we memmove the remaining portion and back-fill the buffer for
61 // the next "write" call. buf_len_ indicates how much data is in the buffer. 72 // the next "write" call. buf_len_ indicates how much data is in the buffer.
62 enum { kBufSize = 16384 }; 73 enum { kBufSize = 16384 };
63 scoped_refptr<IOBuffer> buf_; 74 scoped_refptr<IOBuffer> buf_;
64 size_t buf_len_; 75 size_t buf_len_;
65 76
66 // Iterator to the upload element to be written to the send buffer next. 77 // Index of the upload element to be written to the send buffer next.
67 std::vector<UploadData::Element>::iterator next_element_; 78 size_t next_element_;
68 79
69 // The byte offset into next_element_'s data buffer if the next element is 80 // The byte offset into next_element_'s data buffer if the next element is
70 // a TYPE_BYTES element. 81 // a TYPE_BYTES element.
71 size_t next_element_offset_; 82 size_t next_element_offset_;
72 83
73 // A stream to the currently open file, for next_element_ if the next element 84 // A stream to the currently open file, for next_element_ if the next element
74 // is a TYPE_FILE element. 85 // is a TYPE_FILE element.
75 scoped_ptr<FileStream> next_element_stream_; 86 scoped_ptr<FileStream> next_element_stream_;
76 87
77 // The number of bytes remaining to be read from the currently open file 88 // The number of bytes remaining to be read from the currently open file
78 // if the next element is of TYPE_FILE. 89 // if the next element is of TYPE_FILE.
79 uint64 next_element_remaining_; 90 uint64 next_element_remaining_;
80 91
81 // Size and current read position within the stream. 92 // Size and current read position within the stream.
82 uint64 total_size_; 93 uint64 total_size_;
83 uint64 current_position_; 94 uint64 current_position_;
84 95
96 // Whether we have run out of data and waiting for more to come in.
97 bool waiting_for_data_;
98
99 // Callback invoked by UploadData when new data is available.
100 CompletionCallbackImpl<UploadDataStream> upload_data_callback_;
101 // Callback to be invoked by us when new data is available.
102 CompletionCallback* data_callback_;
103
85 // Whether there is no data left to read. 104 // Whether there is no data left to read.
86 bool eof_; 105 bool eof_;
87 106
88 DISALLOW_COPY_AND_ASSIGN(UploadDataStream); 107 DISALLOW_COPY_AND_ASSIGN(UploadDataStream);
89 }; 108 };
90 109
91 } // namespace net 110 } // namespace net
92 111
93 #endif // NET_BASE_UPLOAD_DATA_STREAM_H_ 112 #endif // NET_BASE_UPLOAD_DATA_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698