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

Side by Side Diff: net/http/http_transaction_unittest.h

Issue 18390: Change URLRequest to use a ref-counted buffer for actual IO.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | « net/http/http_transaction.h ('k') | net/http/http_transaction_unittest.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_HTTP_HTTP_TRANSACTION_UNITTEST_H_ 5 #ifndef NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_
6 #define NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ 6 #define NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_
7 7
8 #include "net/http/http_transaction.h" 8 #include "net/http/http_transaction.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 DidFinish(result); 142 DidFinish(result);
143 } else { 143 } else {
144 Read(); 144 Read();
145 } 145 }
146 } 146 }
147 147
148 void DidRead(int result) { 148 void DidRead(int result) {
149 if (result <= 0) { 149 if (result <= 0) {
150 DidFinish(result); 150 DidFinish(result);
151 } else { 151 } else {
152 content_.append(read_buf_, result); 152 content_.append(read_buf_->data(), result);
153 Read(); 153 Read();
154 } 154 }
155 } 155 }
156 156
157 void DidFinish(int result) { 157 void DidFinish(int result) {
158 state_ = DONE; 158 state_ = DONE;
159 error_ = result; 159 error_ = result;
160 if (--quit_counter_ == 0) 160 if (--quit_counter_ == 0)
161 MessageLoop::current()->Quit(); 161 MessageLoop::current()->Quit();
162 } 162 }
163 163
164 void Read() { 164 void Read() {
165 state_ = READING; 165 state_ = READING;
166 int result = trans_->Read(read_buf_, sizeof(read_buf_), this); 166 read_buf_ = new net::IOBuffer(1024);
167 int result = trans_->Read(read_buf_, 1024, this);
167 if (result != net::ERR_IO_PENDING) 168 if (result != net::ERR_IO_PENDING)
168 DidRead(result); 169 DidRead(result);
169 } 170 }
170 171
171 enum State { 172 enum State {
172 IDLE, 173 IDLE,
173 STARTING, 174 STARTING,
174 READING, 175 READING,
175 DONE 176 DONE
176 } state_; 177 } state_;
177 178
178 scoped_ptr<net::HttpTransaction> trans_; 179 scoped_ptr<net::HttpTransaction> trans_;
179 std::string content_; 180 std::string content_;
180 char read_buf_[1024]; 181 scoped_refptr<net::IOBuffer> read_buf_;
181 int error_; 182 int error_;
182 183
183 static int quit_counter_; 184 static int quit_counter_;
184 }; 185 };
185 186
186 //----------------------------------------------------------------------------- 187 //-----------------------------------------------------------------------------
187 // mock network layer 188 // mock network layer
188 189
189 // This transaction class inspects the available set of mock transactions to 190 // This transaction class inspects the available set of mock transactions to
190 // find data for the request URL. It supports IO operations that complete 191 // find data for the request URL. It supports IO operations that complete
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 virtual int RestartIgnoringLastError(net::CompletionCallback* callback) { 231 virtual int RestartIgnoringLastError(net::CompletionCallback* callback) {
231 return net::ERR_FAILED; 232 return net::ERR_FAILED;
232 } 233 }
233 234
234 virtual int RestartWithAuth(const std::wstring& username, 235 virtual int RestartWithAuth(const std::wstring& username,
235 const std::wstring& password, 236 const std::wstring& password,
236 net::CompletionCallback* callback) { 237 net::CompletionCallback* callback) {
237 return net::ERR_FAILED; 238 return net::ERR_FAILED;
238 } 239 }
239 240
240 virtual int Read(char* buf, int buf_len, net::CompletionCallback* callback) { 241 virtual int Read(net::IOBuffer* buf, int buf_len,
242 net::CompletionCallback* callback) {
241 int data_len = static_cast<int>(data_.size()); 243 int data_len = static_cast<int>(data_.size());
242 int num = std::min(buf_len, data_len - data_cursor_); 244 int num = std::min(buf_len, data_len - data_cursor_);
243 if (num) { 245 if (num) {
244 memcpy(buf, data_.data() + data_cursor_, num); 246 memcpy(buf->data(), data_.data() + data_cursor_, num);
245 data_cursor_ += num; 247 data_cursor_ += num;
246 } 248 }
247 if (test_mode_ & TEST_MODE_SYNC_NET_READ) 249 if (test_mode_ & TEST_MODE_SYNC_NET_READ)
248 return num; 250 return num;
249 251
250 CallbackLater(callback, num); 252 CallbackLater(callback, num);
251 return net::ERR_IO_PENDING; 253 return net::ERR_IO_PENDING;
252 } 254 }
253 255
254 virtual const net::HttpResponseInfo* GetResponseInfo() const { 256 virtual const net::HttpResponseInfo* GetResponseInfo() const {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 }; 305 };
304 306
305 307
306 //----------------------------------------------------------------------------- 308 //-----------------------------------------------------------------------------
307 // helpers 309 // helpers
308 310
309 // read the transaction completely 311 // read the transaction completely
310 int ReadTransaction(net::HttpTransaction* trans, std::string* result); 312 int ReadTransaction(net::HttpTransaction* trans, std::string* result);
311 313
312 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ 314 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_
OLDNEW
« no previous file with comments | « net/http/http_transaction.h ('k') | net/http/http_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698