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