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

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

Issue 594036: Support sending a sliced file in chromium.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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
« no previous file with comments | « net/base/upload_data.h ('k') | net/base/upload_data_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7
8 #include "net/base/file_stream.h" 8 #include "net/base/file_stream.h"
9 #include "net/base/upload_data.h" 9 #include "net/base/upload_data.h"
10 10
11 namespace net { 11 namespace net {
12 12
13 class IOBuffer; 13 class IOBuffer;
14 14
15 class UploadDataStream { 15 class UploadDataStream {
16 public: 16 public:
17 explicit UploadDataStream(const UploadData* data); 17 // Returns a new instance of UploadDataStream if it can be created and
18 // initialized successfully. If not, NULL will be returned and the error
19 // code will be set if the output parameter error_code is not empty.
20 static UploadDataStream* Create(const UploadData* data, int* error_code);
21
18 ~UploadDataStream(); 22 ~UploadDataStream();
19 23
20 // Returns the stream's buffer and buffer length. 24 // Returns the stream's buffer and buffer length.
21 IOBuffer* buf() const { return buf_; } 25 IOBuffer* buf() const { return buf_; }
22 size_t buf_len() const { return buf_len_; } 26 size_t buf_len() const { return buf_len_; }
23 27
24 // Call to indicate that a portion of the stream's buffer was consumed. This 28 // Call to indicate that a portion of the stream's buffer was consumed. This
25 // call modifies the stream's buffer so that it contains the next segment of 29 // call modifies the stream's buffer so that it contains the next segment of
26 // the upload data to be consumed. 30 // the upload data to be consumed.
27 void DidConsume(size_t num_bytes); 31 void DidConsume(size_t num_bytes);
28 32
29 // Returns the total size of the data stream and the current position. 33 // Returns the total size of the data stream and the current position.
30 // size() is not to be used to determine whether the stream has ended 34 // size() is not to be used to determine whether the stream has ended
31 // because it is possible for the stream to end before its size is reached, 35 // because it is possible for the stream to end before its size is reached,
32 // for example, if the file is truncated. 36 // for example, if the file is truncated.
33 uint64 size() const { return total_size_; } 37 uint64 size() const { return total_size_; }
34 uint64 position() const { return current_position_; } 38 uint64 position() const { return current_position_; }
35 39
36 // Returns whether there is no more data to read, regardless of whether 40 // Returns whether there is no more data to read, regardless of whether
37 // position < size. 41 // position < size.
38 bool eof() const { return eof_; } 42 bool eof() const { return eof_; }
39 43
40 private: 44 private:
45 // Protects from public access since now we have a static creator function
46 // which will do both creation and initialization and might return an error.
47 explicit UploadDataStream(const UploadData* data);
48
41 // Fills the buffer with any remaining data and sets eof_ if there was nothing 49 // Fills the buffer with any remaining data and sets eof_ if there was nothing
42 // left to fill the buffer with. 50 // left to fill the buffer with.
43 void FillBuf(); 51 // Returns OK if the operation succeeds. Otherwise error code is returned.
52 int FillBuf();
44 53
45 const UploadData* data_; 54 const UploadData* data_;
46 55
47 // This buffer is filled with data to be uploaded. The data to be sent is 56 // This buffer is filled with data to be uploaded. The data to be sent is
48 // always at the front of the buffer. If we cannot send all of the buffer at 57 // always at the front of the buffer. If we cannot send all of the buffer at
49 // once, then we memmove the remaining portion and back-fill the buffer for 58 // once, then we memmove the remaining portion and back-fill the buffer for
50 // the next "write" call. buf_len_ indicates how much data is in the buffer. 59 // the next "write" call. buf_len_ indicates how much data is in the buffer.
51 enum { kBufSize = 16384 }; 60 enum { kBufSize = 16384 };
52 scoped_refptr<IOBuffer> buf_; 61 scoped_refptr<IOBuffer> buf_;
53 size_t buf_len_; 62 size_t buf_len_;
(...skipping 19 matching lines...) Expand all
73 82
74 // Whether there is no data left to read. 83 // Whether there is no data left to read.
75 bool eof_; 84 bool eof_;
76 85
77 DISALLOW_EVIL_CONSTRUCTORS(UploadDataStream); 86 DISALLOW_EVIL_CONSTRUCTORS(UploadDataStream);
78 }; 87 };
79 88
80 } // namespace net 89 } // namespace net
81 90
82 #endif // NET_BASE_UPLOAD_DATA_STREAM_H_ 91 #endif // NET_BASE_UPLOAD_DATA_STREAM_H_
OLDNEW
« no previous file with comments | « net/base/upload_data.h ('k') | net/base/upload_data_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698