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

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

Issue 9242018: Factor out chunk encoding logic into HttpStreamParser::EncodeChunk(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add NET_EXPORT_PRIVATE to fix windows builds Created 8 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
« no previous file with comments | « no previous file | net/base/upload_data_stream.cc » ('j') | net/base/upload_data_stream.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "net/base/net_export.h" 10 #include "net/base/net_export.h"
(...skipping 12 matching lines...) Expand all
23 // initialized successfully. If not, NULL will be returned and the error 23 // initialized successfully. If not, NULL will be returned and the error
24 // code will be set if the output parameter error_code is not empty. 24 // code will be set if the output parameter error_code is not empty.
25 static UploadDataStream* Create(UploadData* data, int* error_code); 25 static UploadDataStream* Create(UploadData* data, int* error_code);
26 26
27 // Returns the stream's buffer and buffer length. 27 // Returns the stream's buffer and buffer length.
28 IOBuffer* buf() const { return buf_; } 28 IOBuffer* buf() const { return buf_; }
29 size_t buf_len() const { return buf_len_; } 29 size_t buf_len() const { return buf_len_; }
30 30
31 // TODO(satish): We should ideally have UploadDataStream expose a Read() 31 // TODO(satish): We should ideally have UploadDataStream expose a Read()
32 // method which returns data in a caller provided IOBuffer. That would do away 32 // method which returns data in a caller provided IOBuffer. That would do away
33 // with this method and make the interface cleaner as well with less memmove 33 // with this constant and make the interface cleaner as well with less memmove
34 // calls. 34 // calls.
35 size_t GetMaxBufferSize() const { return kBufSize; } 35 //
36 // The size of the stream's buffer pointed by buf().
37 static const size_t kBufferSize;
36 38
37 // Call to indicate that a portion of the stream's buffer was consumed. This 39 // Call to indicate that a portion of the stream's buffer was consumed. This
38 // call modifies the stream's buffer so that it contains the next segment of 40 // call modifies the stream's buffer so that it contains the next segment of
39 // the upload data to be consumed. 41 // the upload data to be consumed.
40 void MarkConsumedAndFillBuffer(size_t num_bytes); 42 void MarkConsumedAndFillBuffer(size_t num_bytes);
41 43
42 // Sets the callback to be invoked when new chunks are available to upload. 44 // Sets the callback to be invoked when new chunks are available to upload.
43 void set_chunk_callback(ChunkCallback* callback) { 45 void set_chunk_callback(ChunkCallback* callback) {
44 data_->set_chunk_callback(callback); 46 data_->set_chunk_callback(callback);
45 } 47 }
(...skipping 14 matching lines...) Expand all
60 // Returns whether the data available in buf() includes the last chunk in a 62 // Returns whether the data available in buf() includes the last chunk in a
61 // chunked data stream. This method returns true once the final chunk has been 63 // chunked data stream. This method returns true once the final chunk has been
62 // placed in the IOBuffer returned by buf(), in contrast to eof() which 64 // placed in the IOBuffer returned by buf(), in contrast to eof() which
63 // returns true only after the data in buf() has been consumed. 65 // returns true only after the data in buf() has been consumed.
64 bool IsOnLastChunk() const; 66 bool IsOnLastChunk() const;
65 67
66 // This method is provided only to be used by unit tests. 68 // This method is provided only to be used by unit tests.
67 static void set_merge_chunks(bool merge) { merge_chunks_ = merge; } 69 static void set_merge_chunks(bool merge) { merge_chunks_ = merge; }
68 70
69 private: 71 private:
70 enum { kBufSize = 16384 };
71
72 // Protects from public access since now we have a static creator function 72 // Protects from public access since now we have a static creator function
73 // which will do both creation and initialization and might return an error. 73 // which will do both creation and initialization and might return an error.
74 explicit UploadDataStream(UploadData* data); 74 explicit UploadDataStream(UploadData* data);
75 75
76 // Fills the buffer with any remaining data and sets eof_ if there was nothing 76 // Fills the buffer with any remaining data and sets eof_ if there was nothing
77 // left to fill the buffer with. 77 // left to fill the buffer with.
78 // Returns OK if the operation succeeds. Otherwise error code is returned. 78 // Returns OK if the operation succeeds. Otherwise error code is returned.
79 int FillBuf(); 79 int FillBuf();
80 80
81 scoped_refptr<UploadData> data_; 81 scoped_refptr<UploadData> data_;
(...skipping 30 matching lines...) Expand all
112 // TODO(satish): Remove this once we have a better way to unit test POST 112 // TODO(satish): Remove this once we have a better way to unit test POST
113 // requests with chunked uploads. 113 // requests with chunked uploads.
114 static bool merge_chunks_; 114 static bool merge_chunks_;
115 115
116 DISALLOW_COPY_AND_ASSIGN(UploadDataStream); 116 DISALLOW_COPY_AND_ASSIGN(UploadDataStream);
117 }; 117 };
118 118
119 } // namespace net 119 } // namespace net
120 120
121 #endif // NET_BASE_UPLOAD_DATA_STREAM_H_ 121 #endif // NET_BASE_UPLOAD_DATA_STREAM_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/upload_data_stream.cc » ('j') | net/base/upload_data_stream.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698