| 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 // URLRequestTestHTTP.BasicAuthWithCookies | 409 // URLRequestTestHTTP.BasicAuthWithCookies |
| 410 // where OnBeforeSendHeaders -> OnSendHeaders -> OnBeforeSendHeaders | 410 // where OnBeforeSendHeaders -> OnSendHeaders -> OnBeforeSendHeaders |
| 411 // occurs. | 411 // occurs. |
| 412 RestartTransactionWithAuth(AuthCredentials()); | 412 RestartTransactionWithAuth(AuthCredentials()); |
| 413 return; | 413 return; |
| 414 } | 414 } |
| 415 | 415 |
| 416 URLRequestJob::NotifyHeadersComplete(); | 416 URLRequestJob::NotifyHeadersComplete(); |
| 417 } | 417 } |
| 418 | 418 |
| 419 void URLRequestHttpJob::NotifyDone(const URLRequestStatus& status) { | |
| 420 DoneWithRequest(FINISHED); | |
| 421 URLRequestJob::NotifyDone(status); | |
| 422 } | |
| 423 | |
| 424 void URLRequestHttpJob::DestroyTransaction() { | 419 void URLRequestHttpJob::DestroyTransaction() { |
| 425 DCHECK(transaction_.get()); | 420 DCHECK(transaction_.get()); |
| 426 | 421 |
| 427 DoneWithRequest(ABORTED); | 422 DoneWithRequest(ABORTED); |
| 428 | 423 |
| 429 total_received_bytes_from_previous_transactions_ += | 424 total_received_bytes_from_previous_transactions_ += |
| 430 transaction_->GetTotalReceivedBytes(); | 425 transaction_->GetTotalReceivedBytes(); |
| 431 total_sent_bytes_from_previous_transactions_ += | 426 total_sent_bytes_from_previous_transactions_ += |
| 432 transaction_->GetTotalSentBytes(); | 427 transaction_->GetTotalSentBytes(); |
| 433 transaction_.reset(); | 428 transaction_.reset(); |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 | 996 |
| 1002 // Check that there are no callbacks to already canceled requests. | 997 // Check that there are no callbacks to already canceled requests. |
| 1003 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); | 998 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); |
| 1004 | 999 |
| 1005 SaveCookiesAndNotifyHeadersComplete(result); | 1000 SaveCookiesAndNotifyHeadersComplete(result); |
| 1006 } | 1001 } |
| 1007 | 1002 |
| 1008 void URLRequestHttpJob::OnReadCompleted(int result) { | 1003 void URLRequestHttpJob::OnReadCompleted(int result) { |
| 1009 read_in_progress_ = false; | 1004 read_in_progress_ = false; |
| 1010 | 1005 |
| 1006 DCHECK_NE(ERR_IO_PENDING, result); |
| 1007 |
| 1011 if (ShouldFixMismatchedContentLength(result)) | 1008 if (ShouldFixMismatchedContentLength(result)) |
| 1012 result = OK; | 1009 result = OK; |
| 1013 | 1010 |
| 1014 if (result == OK) { | 1011 // EOF or error, done with this job. |
| 1015 NotifyDone(URLRequestStatus()); | 1012 if (result <= 0) |
| 1016 } else if (result < 0) { | 1013 DoneWithRequest(FINISHED); |
| 1017 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | |
| 1018 } else { | |
| 1019 // Clear the IO_PENDING status | |
| 1020 SetStatus(URLRequestStatus()); | |
| 1021 } | |
| 1022 | 1014 |
| 1023 NotifyReadComplete(result); | 1015 ReadRawDataComplete(result); |
| 1024 } | 1016 } |
| 1025 | 1017 |
| 1026 void URLRequestHttpJob::RestartTransactionWithAuth( | 1018 void URLRequestHttpJob::RestartTransactionWithAuth( |
| 1027 const AuthCredentials& credentials) { | 1019 const AuthCredentials& credentials) { |
| 1028 auth_credentials_ = credentials; | 1020 auth_credentials_ = credentials; |
| 1029 | 1021 |
| 1030 // These will be reset in OnStartCompleted. | 1022 // These will be reset in OnStartCompleted. |
| 1031 response_info_ = NULL; | 1023 response_info_ = NULL; |
| 1032 receive_headers_end_ = base::TimeTicks(); | 1024 receive_headers_end_ = base::TimeTicks(); |
| 1033 response_cookies_.clear(); | 1025 response_cookies_.clear(); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 << " post total = " << postfilter_bytes_read(); | 1329 << " post total = " << postfilter_bytes_read(); |
| 1338 if (postfilter_bytes_read() == expected_length) { | 1330 if (postfilter_bytes_read() == expected_length) { |
| 1339 // Clear the error. | 1331 // Clear the error. |
| 1340 return true; | 1332 return true; |
| 1341 } | 1333 } |
| 1342 } | 1334 } |
| 1343 } | 1335 } |
| 1344 return false; | 1336 return false; |
| 1345 } | 1337 } |
| 1346 | 1338 |
| 1347 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size, | 1339 int URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size) { |
| 1348 int* bytes_read) { | |
| 1349 DCHECK_NE(buf_size, 0); | 1340 DCHECK_NE(buf_size, 0); |
| 1350 DCHECK(bytes_read); | |
| 1351 DCHECK(!read_in_progress_); | 1341 DCHECK(!read_in_progress_); |
| 1352 | 1342 |
| 1353 int rv = transaction_->Read( | 1343 int rv = transaction_->Read( |
| 1354 buf, buf_size, | 1344 buf, buf_size, |
| 1355 base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this))); | 1345 base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this))); |
| 1356 | 1346 |
| 1357 if (ShouldFixMismatchedContentLength(rv)) | 1347 if (ShouldFixMismatchedContentLength(rv)) |
| 1358 rv = 0; | 1348 rv = OK; |
| 1359 | 1349 |
| 1360 if (rv >= 0) { | 1350 if (rv == 0 || (rv < 0 && rv != ERR_IO_PENDING)) |
| 1361 *bytes_read = rv; | 1351 DoneWithRequest(FINISHED); |
| 1362 if (!rv) | |
| 1363 DoneWithRequest(FINISHED); | |
| 1364 return true; | |
| 1365 } | |
| 1366 | 1352 |
| 1367 if (rv == ERR_IO_PENDING) { | 1353 if (rv == ERR_IO_PENDING) |
| 1368 read_in_progress_ = true; | 1354 read_in_progress_ = true; |
| 1369 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | |
| 1370 } else { | |
| 1371 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | |
| 1372 } | |
| 1373 | 1355 |
| 1374 return false; | 1356 return rv; |
| 1375 } | 1357 } |
| 1376 | 1358 |
| 1377 void URLRequestHttpJob::StopCaching() { | 1359 void URLRequestHttpJob::StopCaching() { |
| 1378 if (transaction_.get()) | 1360 if (transaction_.get()) |
| 1379 transaction_->StopCaching(); | 1361 transaction_->StopCaching(); |
| 1380 } | 1362 } |
| 1381 | 1363 |
| 1382 bool URLRequestHttpJob::GetFullRequestHeaders( | 1364 bool URLRequestHttpJob::GetFullRequestHeaders( |
| 1383 HttpRequestHeaders* headers) const { | 1365 HttpRequestHeaders* headers) const { |
| 1384 if (!transaction_) | 1366 if (!transaction_) |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 return override_response_headers_.get() ? | 1571 return override_response_headers_.get() ? |
| 1590 override_response_headers_.get() : | 1572 override_response_headers_.get() : |
| 1591 transaction_->GetResponseInfo()->headers.get(); | 1573 transaction_->GetResponseInfo()->headers.get(); |
| 1592 } | 1574 } |
| 1593 | 1575 |
| 1594 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1576 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1595 awaiting_callback_ = false; | 1577 awaiting_callback_ = false; |
| 1596 } | 1578 } |
| 1597 | 1579 |
| 1598 } // namespace net | 1580 } // namespace net |
| OLD | NEW |