OLD | NEW |
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 Loading... |
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 |
417 void URLRequestHttpJob::DestroyTransaction() { | 422 void URLRequestHttpJob::DestroyTransaction() { |
418 DCHECK(transaction_.get()); | 423 DCHECK(transaction_.get()); |
419 | 424 |
420 DoneWithRequest(ABORTED); | 425 DoneWithRequest(ABORTED); |
421 | 426 |
422 total_received_bytes_from_previous_transactions_ += | 427 total_received_bytes_from_previous_transactions_ += |
423 transaction_->GetTotalReceivedBytes(); | 428 transaction_->GetTotalReceivedBytes(); |
424 total_sent_bytes_from_previous_transactions_ += | 429 total_sent_bytes_from_previous_transactions_ += |
425 transaction_->GetTotalSentBytes(); | 430 transaction_->GetTotalSentBytes(); |
426 transaction_.reset(); | 431 transaction_.reset(); |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 | 991 |
987 // Check that there are no callbacks to already canceled requests. | 992 // Check that there are no callbacks to already canceled requests. |
988 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); | 993 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); |
989 | 994 |
990 SaveCookiesAndNotifyHeadersComplete(result); | 995 SaveCookiesAndNotifyHeadersComplete(result); |
991 } | 996 } |
992 | 997 |
993 void URLRequestHttpJob::OnReadCompleted(int result) { | 998 void URLRequestHttpJob::OnReadCompleted(int result) { |
994 read_in_progress_ = false; | 999 read_in_progress_ = false; |
995 | 1000 |
996 DCHECK_NE(ERR_IO_PENDING, result); | |
997 | |
998 if (ShouldFixMismatchedContentLength(result)) | 1001 if (ShouldFixMismatchedContentLength(result)) |
999 result = OK; | 1002 result = OK; |
1000 | 1003 |
1001 // EOF or error, done with this job. | 1004 if (result == OK) { |
1002 if (result <= 0) | 1005 NotifyDone(URLRequestStatus()); |
1003 DoneWithRequest(FINISHED); | 1006 } else if (result < 0) { |
| 1007 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 1008 } else { |
| 1009 // Clear the IO_PENDING status |
| 1010 SetStatus(URLRequestStatus()); |
| 1011 } |
1004 | 1012 |
1005 ReadRawDataComplete(result); | 1013 NotifyReadComplete(result); |
1006 } | 1014 } |
1007 | 1015 |
1008 void URLRequestHttpJob::RestartTransactionWithAuth( | 1016 void URLRequestHttpJob::RestartTransactionWithAuth( |
1009 const AuthCredentials& credentials) { | 1017 const AuthCredentials& credentials) { |
1010 auth_credentials_ = credentials; | 1018 auth_credentials_ = credentials; |
1011 | 1019 |
1012 // These will be reset in OnStartCompleted. | 1020 // These will be reset in OnStartCompleted. |
1013 response_info_ = NULL; | 1021 response_info_ = NULL; |
1014 receive_headers_end_ = base::TimeTicks(); | 1022 receive_headers_end_ = base::TimeTicks(); |
1015 response_cookies_.clear(); | 1023 response_cookies_.clear(); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 << " post total = " << postfilter_bytes_read(); | 1327 << " post total = " << postfilter_bytes_read(); |
1320 if (postfilter_bytes_read() == expected_length) { | 1328 if (postfilter_bytes_read() == expected_length) { |
1321 // Clear the error. | 1329 // Clear the error. |
1322 return true; | 1330 return true; |
1323 } | 1331 } |
1324 } | 1332 } |
1325 } | 1333 } |
1326 return false; | 1334 return false; |
1327 } | 1335 } |
1328 | 1336 |
1329 int URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size) { | 1337 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, |
| 1338 int buf_size, |
| 1339 int* bytes_read) { |
1330 DCHECK_NE(buf_size, 0); | 1340 DCHECK_NE(buf_size, 0); |
| 1341 DCHECK(bytes_read); |
1331 DCHECK(!read_in_progress_); | 1342 DCHECK(!read_in_progress_); |
1332 | 1343 |
1333 int rv = transaction_->Read( | 1344 int rv = transaction_->Read( |
1334 buf, buf_size, | 1345 buf, buf_size, |
1335 base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this))); | 1346 base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this))); |
1336 | 1347 |
1337 if (ShouldFixMismatchedContentLength(rv)) | 1348 if (ShouldFixMismatchedContentLength(rv)) |
1338 rv = OK; | 1349 rv = 0; |
1339 | 1350 |
1340 if (rv == 0 || (rv < 0 && rv != ERR_IO_PENDING)) | 1351 if (rv >= 0) { |
1341 DoneWithRequest(FINISHED); | 1352 *bytes_read = rv; |
| 1353 if (!rv) |
| 1354 DoneWithRequest(FINISHED); |
| 1355 return true; |
| 1356 } |
1342 | 1357 |
1343 if (rv == ERR_IO_PENDING) | 1358 if (rv == ERR_IO_PENDING) { |
1344 read_in_progress_ = true; | 1359 read_in_progress_ = true; |
| 1360 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 1361 } else { |
| 1362 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 1363 } |
1345 | 1364 |
1346 return rv; | 1365 return false; |
1347 } | 1366 } |
1348 | 1367 |
1349 void URLRequestHttpJob::StopCaching() { | 1368 void URLRequestHttpJob::StopCaching() { |
1350 if (transaction_.get()) | 1369 if (transaction_.get()) |
1351 transaction_->StopCaching(); | 1370 transaction_->StopCaching(); |
1352 } | 1371 } |
1353 | 1372 |
1354 bool URLRequestHttpJob::GetFullRequestHeaders( | 1373 bool URLRequestHttpJob::GetFullRequestHeaders( |
1355 HttpRequestHeaders* headers) const { | 1374 HttpRequestHeaders* headers) const { |
1356 if (!transaction_) | 1375 if (!transaction_) |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1561 return override_response_headers_.get() ? | 1580 return override_response_headers_.get() ? |
1562 override_response_headers_.get() : | 1581 override_response_headers_.get() : |
1563 transaction_->GetResponseInfo()->headers.get(); | 1582 transaction_->GetResponseInfo()->headers.get(); |
1564 } | 1583 } |
1565 | 1584 |
1566 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1585 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1567 awaiting_callback_ = false; | 1586 awaiting_callback_ = false; |
1568 } | 1587 } |
1569 | 1588 |
1570 } // namespace net | 1589 } // namespace net |
OLD | NEW |