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

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

Issue 1467603002: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add done_reading_called_ to MockNetworkTransaction 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_http_job.h ('k') | net/url_request/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_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 // URLRequestTestHTTP.BasicAuthWithCookies 407 // URLRequestTestHTTP.BasicAuthWithCookies
408 // where OnBeforeSendHeaders -> OnSendHeaders -> OnBeforeSendHeaders 408 // where OnBeforeSendHeaders -> OnSendHeaders -> OnBeforeSendHeaders
409 // occurs. 409 // occurs.
410 RestartTransactionWithAuth(AuthCredentials()); 410 RestartTransactionWithAuth(AuthCredentials());
411 return; 411 return;
412 } 412 }
413 413
414 URLRequestJob::NotifyHeadersComplete(); 414 URLRequestJob::NotifyHeadersComplete();
415 } 415 }
416 416
417 void URLRequestHttpJob::NotifyDone(const URLRequestStatus& status) {
418 DoneWithRequest(FINISHED);
419 URLRequestJob::NotifyDone(status);
420 }
421
422 void URLRequestHttpJob::DestroyTransaction() { 417 void URLRequestHttpJob::DestroyTransaction() {
423 DCHECK(transaction_.get()); 418 DCHECK(transaction_.get());
424 419
425 DoneWithRequest(ABORTED); 420 DoneWithRequest(ABORTED);
426 421
427 total_received_bytes_from_previous_transactions_ += 422 total_received_bytes_from_previous_transactions_ +=
428 transaction_->GetTotalReceivedBytes(); 423 transaction_->GetTotalReceivedBytes();
429 total_sent_bytes_from_previous_transactions_ += 424 total_sent_bytes_from_previous_transactions_ +=
430 transaction_->GetTotalSentBytes(); 425 transaction_->GetTotalSentBytes();
431 transaction_.reset(); 426 transaction_.reset();
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 986
992 // Check that there are no callbacks to already canceled requests. 987 // Check that there are no callbacks to already canceled requests.
993 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); 988 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status());
994 989
995 SaveCookiesAndNotifyHeadersComplete(result); 990 SaveCookiesAndNotifyHeadersComplete(result);
996 } 991 }
997 992
998 void URLRequestHttpJob::OnReadCompleted(int result) { 993 void URLRequestHttpJob::OnReadCompleted(int result) {
999 read_in_progress_ = false; 994 read_in_progress_ = false;
1000 995
996 DCHECK_NE(ERR_IO_PENDING, result);
997
1001 if (ShouldFixMismatchedContentLength(result)) 998 if (ShouldFixMismatchedContentLength(result))
1002 result = OK; 999 result = OK;
1003 1000
1004 if (result == OK) { 1001 // EOF or error, done with this job.
1005 NotifyDone(URLRequestStatus()); 1002 if (result <= 0)
1006 } else if (result < 0) { 1003 DoneWithRequest(FINISHED);
1007 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result));
1008 } else {
1009 // Clear the IO_PENDING status
1010 SetStatus(URLRequestStatus());
1011 }
1012 1004
1013 NotifyReadComplete(result); 1005 ReadRawDataComplete(result);
1014 } 1006 }
1015 1007
1016 void URLRequestHttpJob::RestartTransactionWithAuth( 1008 void URLRequestHttpJob::RestartTransactionWithAuth(
1017 const AuthCredentials& credentials) { 1009 const AuthCredentials& credentials) {
1018 auth_credentials_ = credentials; 1010 auth_credentials_ = credentials;
1019 1011
1020 // These will be reset in OnStartCompleted. 1012 // These will be reset in OnStartCompleted.
1021 response_info_ = NULL; 1013 response_info_ = NULL;
1022 receive_headers_end_ = base::TimeTicks(); 1014 receive_headers_end_ = base::TimeTicks();
1023 response_cookies_.clear(); 1015 response_cookies_.clear();
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 << " post total = " << postfilter_bytes_read(); 1321 << " post total = " << postfilter_bytes_read();
1330 if (postfilter_bytes_read() == expected_length) { 1322 if (postfilter_bytes_read() == expected_length) {
1331 // Clear the error. 1323 // Clear the error.
1332 return true; 1324 return true;
1333 } 1325 }
1334 } 1326 }
1335 } 1327 }
1336 return false; 1328 return false;
1337 } 1329 }
1338 1330
1339 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, 1331 int URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size) {
1340 int buf_size,
1341 int* bytes_read) {
1342 DCHECK_NE(buf_size, 0); 1332 DCHECK_NE(buf_size, 0);
1343 DCHECK(bytes_read);
1344 DCHECK(!read_in_progress_); 1333 DCHECK(!read_in_progress_);
1345 1334
1346 int rv = transaction_->Read( 1335 int rv = transaction_->Read(
1347 buf, buf_size, 1336 buf, buf_size,
1348 base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this))); 1337 base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this)));
1349 1338
1350 if (ShouldFixMismatchedContentLength(rv)) 1339 if (ShouldFixMismatchedContentLength(rv))
1351 rv = 0; 1340 rv = OK;
1352 1341
1353 if (rv >= 0) { 1342 if (rv == 0 || (rv < 0 && rv != ERR_IO_PENDING))
1354 *bytes_read = rv; 1343 DoneWithRequest(FINISHED);
1355 if (!rv)
1356 DoneWithRequest(FINISHED);
1357 return true;
1358 }
1359 1344
1360 if (rv == ERR_IO_PENDING) { 1345 if (rv == ERR_IO_PENDING)
1361 read_in_progress_ = true; 1346 read_in_progress_ = true;
1362 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
1363 } else {
1364 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
1365 }
1366 1347
1367 return false; 1348 return rv;
1368 } 1349 }
1369 1350
1370 void URLRequestHttpJob::StopCaching() { 1351 void URLRequestHttpJob::StopCaching() {
1371 if (transaction_.get()) 1352 if (transaction_.get())
1372 transaction_->StopCaching(); 1353 transaction_->StopCaching();
1373 } 1354 }
1374 1355
1375 bool URLRequestHttpJob::GetFullRequestHeaders( 1356 bool URLRequestHttpJob::GetFullRequestHeaders(
1376 HttpRequestHeaders* headers) const { 1357 HttpRequestHeaders* headers) const {
1377 if (!transaction_) 1358 if (!transaction_)
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 return override_response_headers_.get() ? 1563 return override_response_headers_.get() ?
1583 override_response_headers_.get() : 1564 override_response_headers_.get() :
1584 transaction_->GetResponseInfo()->headers.get(); 1565 transaction_->GetResponseInfo()->headers.get();
1585 } 1566 }
1586 1567
1587 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1568 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1588 awaiting_callback_ = false; 1569 awaiting_callback_ = false;
1589 } 1570 }
1590 1571
1591 } // namespace net 1572 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698