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

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

Issue 1439953006: Reland: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address David's comment 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 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, ERR_INVALID_URL)); 213 NotifyStartError(
214 URLRequestStatus(URLRequestStatus::FAILED, ERR_INVALID_URL));
214 // FIXME(brettw): this should emulate a network error, and not just fail 215 // FIXME(brettw): this should emulate a network error, and not just fail
215 // initiating a connection 216 // initiating a connection
216 return; 217 return;
217 } 218 }
218 } 219 }
219 220
220 AdvanceJob(); 221 AdvanceJob();
221 222
222 this->NotifyHeadersComplete(); 223 this->NotifyHeadersComplete();
223 } 224 }
224 225
225 bool URLRequestTestJob::ReadRawData(IOBuffer* buf, 226 int URLRequestTestJob::ReadRawData(IOBuffer* buf, int buf_size) {
226 int buf_size,
227 int* bytes_read) {
228 if (stage_ == WAITING) { 227 if (stage_ == WAITING) {
229 async_buf_ = buf; 228 async_buf_ = buf;
230 async_buf_size_ = buf_size; 229 async_buf_size_ = buf_size;
231 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 230 return ERR_IO_PENDING;
232 return false;
233 } 231 }
234 232
235 DCHECK(bytes_read); 233 if (offset_ >= static_cast<int>(response_data_.length()))
236 *bytes_read = 0; 234 return 0; // done reading
237
238 if (offset_ >= static_cast<int>(response_data_.length())) {
239 return true; // done reading
240 }
241 235
242 int to_read = buf_size; 236 int to_read = buf_size;
243 if (to_read + offset_ > static_cast<int>(response_data_.length())) 237 if (to_read + offset_ > static_cast<int>(response_data_.length()))
244 to_read = static_cast<int>(response_data_.length()) - offset_; 238 to_read = static_cast<int>(response_data_.length()) - offset_;
245 239
246 memcpy(buf->data(), &response_data_.c_str()[offset_], to_read); 240 memcpy(buf->data(), &response_data_.c_str()[offset_], to_read);
247 offset_ += to_read; 241 offset_ += to_read;
248 242
249 *bytes_read = to_read; 243 return to_read;
250 return true;
251 } 244 }
252 245
253 void URLRequestTestJob::GetResponseInfo(HttpResponseInfo* info) { 246 void URLRequestTestJob::GetResponseInfo(HttpResponseInfo* info) {
254 if (response_headers_.get()) 247 if (response_headers_.get())
255 info->headers = response_headers_; 248 info->headers = response_headers_;
256 } 249 }
257 250
258 void URLRequestTestJob::GetLoadTimingInfo( 251 void URLRequestTestJob::GetLoadTimingInfo(
259 LoadTimingInfo* load_timing_info) const { 252 LoadTimingInfo* load_timing_info) const {
260 // Preserve the times the URLRequest is responsible for, but overwrite all 253 // Preserve the times the URLRequest is responsible for, but overwrite all
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 291
299 void URLRequestTestJob::ProcessNextOperation() { 292 void URLRequestTestJob::ProcessNextOperation() {
300 switch (stage_) { 293 switch (stage_) {
301 case WAITING: 294 case WAITING:
302 // Must call AdvanceJob() prior to NotifyReadComplete() since that may 295 // Must call AdvanceJob() prior to NotifyReadComplete() since that may
303 // delete |this|. 296 // delete |this|.
304 AdvanceJob(); 297 AdvanceJob();
305 stage_ = DATA_AVAILABLE; 298 stage_ = DATA_AVAILABLE;
306 // OK if ReadRawData wasn't called yet. 299 // OK if ReadRawData wasn't called yet.
307 if (async_buf_) { 300 if (async_buf_) {
308 int bytes_read; 301 int result = ReadRawData(async_buf_, async_buf_size_);
309 if (!ReadRawData(async_buf_, async_buf_size_, &bytes_read)) 302 if (result < 0)
310 NOTREACHED() << "This should not return false in DATA_AVAILABLE."; 303 NOTREACHED() << "Reads should not fail in DATA_AVAILABLE.";
311 SetStatus(URLRequestStatus()); // clear the io pending flag
312 if (NextReadAsync()) { 304 if (NextReadAsync()) {
313 // Make all future reads return io pending until the next 305 // Make all future reads return io pending until the next
314 // ProcessNextOperation(). 306 // ProcessNextOperation().
315 stage_ = WAITING; 307 stage_ = WAITING;
316 } 308 }
317 NotifyReadComplete(bytes_read); 309 ReadRawDataComplete(result);
318 } 310 }
319 break; 311 break;
320 case DATA_AVAILABLE: 312 case DATA_AVAILABLE:
321 AdvanceJob(); 313 AdvanceJob();
322 stage_ = ALL_DATA; // done sending data 314 stage_ = ALL_DATA; // done sending data
323 break; 315 break;
324 case ALL_DATA: 316 case ALL_DATA:
325 stage_ = DONE; 317 stage_ = DONE;
326 return; 318 return;
327 case DONE: 319 case DONE:
(...skipping 25 matching lines...) Expand all
353 345
354 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); 346 URLRequestTestJob* next_job(g_pending_jobs.Get().front());
355 g_pending_jobs.Get().pop_front(); 347 g_pending_jobs.Get().pop_front();
356 348
357 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q 349 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q
358 next_job->ProcessNextOperation(); 350 next_job->ProcessNextOperation();
359 return true; 351 return true;
360 } 352 }
361 353
362 } // namespace net 354 } // 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