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

Side by Side Diff: net/url_request/url_request_test_job.cc

Issue 1459333002: Revert "Reland: URLRequestJob: change ReadRawData contract" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « net/url_request/url_request_test_job.h ('k') | storage/browser/blob/blob_url_request_job.h » ('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) 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 #include "net/url_request/url_request_test_job.h" 5 #include "net/url_request/url_request_test_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 std::string redirect_headers = test_redirect_to_url_2_headers(); 203 std::string redirect_headers = test_redirect_to_url_2_headers();
204 response_headers_ = 204 response_headers_ =
205 new HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders( 205 new HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
206 redirect_headers.c_str(), redirect_headers.size())); 206 redirect_headers.c_str(), redirect_headers.size()));
207 } else { 207 } else {
208 AdvanceJob(); 208 AdvanceJob();
209 209
210 // unexpected url, return error 210 // unexpected url, return error
211 // FIXME(brettw) we may want to use WININET errors or have some more types 211 // FIXME(brettw) we may want to use WININET errors or have some more types
212 // of errors 212 // of errors
213 NotifyStartError( 213 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, ERR_INVALID_URL));
214 URLRequestStatus(URLRequestStatus::FAILED, ERR_INVALID_URL));
215 // FIXME(brettw): this should emulate a network error, and not just fail 214 // FIXME(brettw): this should emulate a network error, and not just fail
216 // initiating a connection 215 // initiating a connection
217 return; 216 return;
218 } 217 }
219 } 218 }
220 219
221 AdvanceJob(); 220 AdvanceJob();
222 221
223 this->NotifyHeadersComplete(); 222 this->NotifyHeadersComplete();
224 } 223 }
225 224
226 int URLRequestTestJob::ReadRawData(IOBuffer* buf, int buf_size) { 225 bool URLRequestTestJob::ReadRawData(IOBuffer* buf,
226 int buf_size,
227 int* bytes_read) {
227 if (stage_ == WAITING) { 228 if (stage_ == WAITING) {
228 async_buf_ = buf; 229 async_buf_ = buf;
229 async_buf_size_ = buf_size; 230 async_buf_size_ = buf_size;
230 return ERR_IO_PENDING; 231 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
232 return false;
231 } 233 }
232 234
233 if (offset_ >= static_cast<int>(response_data_.length())) 235 DCHECK(bytes_read);
234 return 0; // done reading 236 *bytes_read = 0;
237
238 if (offset_ >= static_cast<int>(response_data_.length())) {
239 return true; // done reading
240 }
235 241
236 int to_read = buf_size; 242 int to_read = buf_size;
237 if (to_read + offset_ > static_cast<int>(response_data_.length())) 243 if (to_read + offset_ > static_cast<int>(response_data_.length()))
238 to_read = static_cast<int>(response_data_.length()) - offset_; 244 to_read = static_cast<int>(response_data_.length()) - offset_;
239 245
240 memcpy(buf->data(), &response_data_.c_str()[offset_], to_read); 246 memcpy(buf->data(), &response_data_.c_str()[offset_], to_read);
241 offset_ += to_read; 247 offset_ += to_read;
242 248
243 return to_read; 249 *bytes_read = to_read;
250 return true;
244 } 251 }
245 252
246 void URLRequestTestJob::GetResponseInfo(HttpResponseInfo* info) { 253 void URLRequestTestJob::GetResponseInfo(HttpResponseInfo* info) {
247 if (response_headers_.get()) 254 if (response_headers_.get())
248 info->headers = response_headers_; 255 info->headers = response_headers_;
249 } 256 }
250 257
251 void URLRequestTestJob::GetLoadTimingInfo( 258 void URLRequestTestJob::GetLoadTimingInfo(
252 LoadTimingInfo* load_timing_info) const { 259 LoadTimingInfo* load_timing_info) const {
253 // Preserve the times the URLRequest is responsible for, but overwrite all 260 // Preserve the times the URLRequest is responsible for, but overwrite all
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 298
292 void URLRequestTestJob::ProcessNextOperation() { 299 void URLRequestTestJob::ProcessNextOperation() {
293 switch (stage_) { 300 switch (stage_) {
294 case WAITING: 301 case WAITING:
295 // Must call AdvanceJob() prior to NotifyReadComplete() since that may 302 // Must call AdvanceJob() prior to NotifyReadComplete() since that may
296 // delete |this|. 303 // delete |this|.
297 AdvanceJob(); 304 AdvanceJob();
298 stage_ = DATA_AVAILABLE; 305 stage_ = DATA_AVAILABLE;
299 // OK if ReadRawData wasn't called yet. 306 // OK if ReadRawData wasn't called yet.
300 if (async_buf_) { 307 if (async_buf_) {
301 int result = ReadRawData(async_buf_, async_buf_size_); 308 int bytes_read;
302 if (result < 0) 309 if (!ReadRawData(async_buf_, async_buf_size_, &bytes_read))
303 NOTREACHED() << "Reads should not fail in DATA_AVAILABLE."; 310 NOTREACHED() << "This should not return false in DATA_AVAILABLE.";
311 SetStatus(URLRequestStatus()); // clear the io pending flag
304 if (NextReadAsync()) { 312 if (NextReadAsync()) {
305 // Make all future reads return io pending until the next 313 // Make all future reads return io pending until the next
306 // ProcessNextOperation(). 314 // ProcessNextOperation().
307 stage_ = WAITING; 315 stage_ = WAITING;
308 } 316 }
309 ReadRawDataComplete(result); 317 NotifyReadComplete(bytes_read);
310 } 318 }
311 break; 319 break;
312 case DATA_AVAILABLE: 320 case DATA_AVAILABLE:
313 AdvanceJob(); 321 AdvanceJob();
314 stage_ = ALL_DATA; // done sending data 322 stage_ = ALL_DATA; // done sending data
315 break; 323 break;
316 case ALL_DATA: 324 case ALL_DATA:
317 stage_ = DONE; 325 stage_ = DONE;
318 return; 326 return;
319 case DONE: 327 case DONE:
(...skipping 25 matching lines...) Expand all
345 353
346 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); 354 URLRequestTestJob* next_job(g_pending_jobs.Get().front());
347 g_pending_jobs.Get().pop_front(); 355 g_pending_jobs.Get().pop_front();
348 356
349 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q 357 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q
350 next_job->ProcessNextOperation(); 358 next_job->ProcessNextOperation();
351 return true; 359 return true;
352 } 360 }
353 361
354 } // namespace net 362 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_job.h ('k') | storage/browser/blob/blob_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698