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

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

Issue 9452040: net: Move the logic reading upload elements to UploadData::Element. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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.cc » ('j') | net/base/upload_data.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_H_ 5 #ifndef NET_BASE_UPLOAD_DATA_H_
6 #define NET_BASE_UPLOAD_DATA_H_ 6 #define NET_BASE_UPLOAD_DATA_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 bool is_last_chunk() const { return is_last_chunk_; } 103 bool is_last_chunk() const { return is_last_chunk_; }
104 // Sets whether this is the last chunk. Used during IPC marshalling. 104 // Sets whether this is the last chunk. Used during IPC marshalling.
105 void set_is_last_chunk(bool is_last_chunk) { 105 void set_is_last_chunk(bool is_last_chunk) {
106 is_last_chunk_ = is_last_chunk; 106 is_last_chunk_ = is_last_chunk;
107 } 107 }
108 108
109 // Returns the byte-length of the element. For files that do not exist, 0 109 // Returns the byte-length of the element. For files that do not exist, 0
110 // is returned. This is done for consistency with Mozilla. 110 // is returned. This is done for consistency with Mozilla.
111 uint64 GetContentLength(); 111 uint64 GetContentLength();
112 112
113 // Returns a FileStream opened for reading for this element, positioned at 113 // Reads up to |buf_len| bytes synchronously. Returns the number of bytes
114 // |file_range_offset_|. The caller gets ownership and is responsible 114 // read. This function never fails. If there's less data to read than we
115 // for cleaning up the FileStream. Returns NULL if this element is not of 115 // initially observed, then pad with zero (this can happen with files).
116 // type TYPE_FILE or if the file is not openable. 116 int ReadSync(char* buf, int buf_len);
117 FileStream* NewFileStreamForReading(); 117
118 // Returns the number of bytes remaining to read.
119 uint64 BytesRemaining();
118 120
119 private: 121 private:
122 // Returns a FileStream opened for reading for this element, positioned
123 // at |file_range_offset_|. Returns NULL if the file is not openable.
124 FileStream* OpenFileStream();
125
126 // Reads up to |buf_len| bytes synchronously from memory (i.e. type_ is
127 // TYPE_BYTES or TYPE_CHUNK).
128 int ReadFromMemorySync(char* buf, int buf_len);
129
130 // Reads up to |buf_len| bytes synchronously from a file (i.e. type_ is
131 // TYPE_FILE).
132 int ReadFromFileSync(char* buf, int buf_len);
133
120 // Allows tests to override the result of GetContentLength. 134 // Allows tests to override the result of GetContentLength.
121 void SetContentLength(uint64 content_length) { 135 void SetContentLength(uint64 content_length) {
122 override_content_length_ = true; 136 override_content_length_ = true;
123 content_length_ = content_length; 137 content_length_ = content_length;
124 } 138 }
125 139
126 Type type_; 140 Type type_;
127 std::vector<char> bytes_; 141 std::vector<char> bytes_;
128 FilePath file_path_; 142 FilePath file_path_;
129 uint64 file_range_offset_; 143 uint64 file_range_offset_;
130 uint64 file_range_length_; 144 uint64 file_range_length_;
131 base::Time expected_file_modification_time_; 145 base::Time expected_file_modification_time_;
132 GURL blob_url_; 146 GURL blob_url_;
133 bool is_last_chunk_; 147 bool is_last_chunk_;
134 bool override_content_length_; 148 bool override_content_length_;
135 bool content_length_computed_; 149 bool content_length_computed_;
136 uint64 content_length_; 150 uint64 content_length_;
151
152 // The byte offset from the beginning of the element data. Used to track
153 // the current position when reading data.
154 size_t offset_;
155
156 // The stream of the element data, if this element is of TYPE_FILE.
137 FileStream* file_stream_; 157 FileStream* file_stream_;
138 158
139 FRIEND_TEST_ALL_PREFIXES(UploadDataStreamTest, FileSmallerThanLength); 159 FRIEND_TEST_ALL_PREFIXES(UploadDataStreamTest, FileSmallerThanLength);
140 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest, 160 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest,
141 UploadFileSmallerThanLength); 161 UploadFileSmallerThanLength);
142 }; 162 };
143 163
144 UploadData(); 164 UploadData();
145 165
146 void AppendBytes(const char* bytes, int bytes_len); 166 void AppendBytes(const char* bytes, int bytes_len);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 253
234 inline bool operator!=(const UploadData::Element& a, 254 inline bool operator!=(const UploadData::Element& a,
235 const UploadData::Element& b) { 255 const UploadData::Element& b) {
236 return !(a == b); 256 return !(a == b);
237 } 257 }
238 #endif // defined(UNIT_TEST) 258 #endif // defined(UNIT_TEST)
239 259
240 } // namespace net 260 } // namespace net
241 261
242 #endif // NET_BASE_UPLOAD_DATA_H_ 262 #endif // NET_BASE_UPLOAD_DATA_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/upload_data.cc » ('j') | net/base/upload_data.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698