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

Side by Side Diff: net/url_request/url_request_http_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_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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 << " post total = " << postfilter_bytes_read(); 1319 << " post total = " << postfilter_bytes_read();
1328 if (postfilter_bytes_read() == expected_length) { 1320 if (postfilter_bytes_read() == expected_length) {
1329 // Clear the error. 1321 // Clear the error.
1330 return true; 1322 return true;
1331 } 1323 }
1332 } 1324 }
1333 } 1325 }
1334 return false; 1326 return false;
1335 } 1327 }
1336 1328
1337 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, 1329 int URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size) {
1338 int buf_size,
1339 int* bytes_read) {
1340 DCHECK_NE(buf_size, 0); 1330 DCHECK_NE(buf_size, 0);
1341 DCHECK(bytes_read);
1342 DCHECK(!read_in_progress_); 1331 DCHECK(!read_in_progress_);
1343 1332
1344 int rv = transaction_->Read( 1333 int rv = transaction_->Read(
1345 buf, buf_size, 1334 buf, buf_size,
1346 base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this))); 1335 base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this)));
1347 1336
1348 if (ShouldFixMismatchedContentLength(rv)) 1337 if (ShouldFixMismatchedContentLength(rv))
1349 rv = 0; 1338 rv = OK;
1350 1339
1351 if (rv >= 0) { 1340 if (rv == 0 || (rv < 0 && rv != ERR_IO_PENDING))
1352 *bytes_read = rv; 1341 DoneWithRequest(FINISHED);
1353 if (!rv)
1354 DoneWithRequest(FINISHED);
1355 return true;
1356 }
1357 1342
1358 if (rv == ERR_IO_PENDING) { 1343 if (rv == ERR_IO_PENDING)
1359 read_in_progress_ = true; 1344 read_in_progress_ = true;
1360 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
1361 } else {
1362 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
1363 }
1364 1345
1365 return false; 1346 return rv;
1366 } 1347 }
1367 1348
1368 void URLRequestHttpJob::StopCaching() { 1349 void URLRequestHttpJob::StopCaching() {
1369 if (transaction_.get()) 1350 if (transaction_.get())
1370 transaction_->StopCaching(); 1351 transaction_->StopCaching();
1371 } 1352 }
1372 1353
1373 bool URLRequestHttpJob::GetFullRequestHeaders( 1354 bool URLRequestHttpJob::GetFullRequestHeaders(
1374 HttpRequestHeaders* headers) const { 1355 HttpRequestHeaders* headers) const {
1375 if (!transaction_) 1356 if (!transaction_)
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 return override_response_headers_.get() ? 1561 return override_response_headers_.get() ?
1581 override_response_headers_.get() : 1562 override_response_headers_.get() :
1582 transaction_->GetResponseInfo()->headers.get(); 1563 transaction_->GetResponseInfo()->headers.get();
1583 } 1564 }
1584 1565
1585 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1566 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1586 awaiting_callback_ = false; 1567 awaiting_callback_ = false;
1587 } 1568 }
1588 1569
1589 } // namespace net 1570 } // 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