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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 463 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
464 "456327 URLRequestHttpJob::MaybeStartTransactionInternal")); | 464 "456327 URLRequestHttpJob::MaybeStartTransactionInternal")); |
465 | 465 |
466 OnCallToDelegateComplete(); | 466 OnCallToDelegateComplete(); |
467 if (result == OK) { | 467 if (result == OK) { |
468 StartTransactionInternal(); | 468 StartTransactionInternal(); |
469 } else { | 469 } else { |
470 std::string source("delegate"); | 470 std::string source("delegate"); |
471 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, | 471 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, |
472 NetLog::StringCallback("source", &source)); | 472 NetLog::StringCallback("source", &source)); |
473 NotifyCanceled(); | |
474 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); | 473 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
475 } | 474 } |
476 } | 475 } |
477 | 476 |
478 void URLRequestHttpJob::StartTransactionInternal() { | 477 void URLRequestHttpJob::StartTransactionInternal() { |
479 // This should only be called while the request's status is IO_PENDING. | 478 // This should only be called while the request's status is IO_PENDING. |
480 DCHECK_EQ(URLRequestStatus::IO_PENDING, request_->status().status()); | 479 DCHECK_EQ(URLRequestStatus::IO_PENDING, request_->status().status()); |
481 | 480 |
482 // NOTE: This method assumes that request_info_ is already setup properly. | 481 // NOTE: This method assumes that request_info_ is already setup properly. |
483 | 482 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 http_user_agent_settings_->GetAcceptLanguage(); | 643 http_user_agent_settings_->GetAcceptLanguage(); |
645 if (!accept_language.empty()) { | 644 if (!accept_language.empty()) { |
646 request_info_.extra_headers.SetHeaderIfMissing( | 645 request_info_.extra_headers.SetHeaderIfMissing( |
647 HttpRequestHeaders::kAcceptLanguage, | 646 HttpRequestHeaders::kAcceptLanguage, |
648 accept_language); | 647 accept_language); |
649 } | 648 } |
650 } | 649 } |
651 } | 650 } |
652 | 651 |
653 void URLRequestHttpJob::AddCookieHeaderAndStart() { | 652 void URLRequestHttpJob::AddCookieHeaderAndStart() { |
654 // No matter what, we want to report our status as IO pending since we will | |
655 // be notifying our consumer asynchronously via OnStartCompleted. | |
656 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | |
657 | |
658 // If the request was destroyed, then there is no more work to do. | 653 // If the request was destroyed, then there is no more work to do. |
659 if (!request_) | 654 if (!request_) |
660 return; | 655 return; |
661 | 656 |
662 CookieStore* cookie_store = request_->context()->cookie_store(); | 657 CookieStore* cookie_store = request_->context()->cookie_store(); |
663 if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) { | 658 if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) { |
664 cookie_store->GetAllCookiesForURLAsync( | 659 cookie_store->GetAllCookiesForURLAsync( |
665 request_->url(), | 660 request_->url(), |
666 base::Bind(&URLRequestHttpJob::CheckCookiePolicyAndLoad, | 661 base::Bind(&URLRequestHttpJob::CheckCookiePolicyAndLoad, |
667 weak_factory_.GetWeakPtr())); | 662 weak_factory_.GetWeakPtr())); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 SaveNextCookie(); | 738 SaveNextCookie(); |
744 } | 739 } |
745 | 740 |
746 // If the save occurs synchronously, SaveNextCookie will loop and save the next | 741 // If the save occurs synchronously, SaveNextCookie will loop and save the next |
747 // cookie. If the save is deferred, the callback is responsible for continuing | 742 // cookie. If the save is deferred, the callback is responsible for continuing |
748 // to iterate through the cookies. | 743 // to iterate through the cookies. |
749 // TODO(erikwright): Modify the CookieStore API to indicate via return value | 744 // TODO(erikwright): Modify the CookieStore API to indicate via return value |
750 // whether it completed synchronously or asynchronously. | 745 // whether it completed synchronously or asynchronously. |
751 // See http://crbug.com/131066. | 746 // See http://crbug.com/131066. |
752 void URLRequestHttpJob::SaveNextCookie() { | 747 void URLRequestHttpJob::SaveNextCookie() { |
753 // No matter what, we want to report our status as IO pending since we will | |
754 // be notifying our consumer asynchronously via OnStartCompleted. | |
755 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | |
756 | |
757 // Used to communicate with the callback. See the implementation of | 748 // Used to communicate with the callback. See the implementation of |
758 // OnCookieSaved. | 749 // OnCookieSaved. |
759 scoped_refptr<SharedBoolean> callback_pending = new SharedBoolean(false); | 750 scoped_refptr<SharedBoolean> callback_pending = new SharedBoolean(false); |
760 scoped_refptr<SharedBoolean> save_next_cookie_running = | 751 scoped_refptr<SharedBoolean> save_next_cookie_running = |
761 new SharedBoolean(true); | 752 new SharedBoolean(true); |
762 | 753 |
763 if (!(request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) && | 754 if (!(request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) && |
764 request_->context()->cookie_store() && response_cookies_.size() > 0) { | 755 request_->context()->cookie_store() && response_cookies_.size() > 0) { |
765 CookieOptions options; | 756 CookieOptions options; |
766 options.set_include_httponly(); | 757 options.set_include_httponly(); |
(...skipping 21 matching lines...) Expand all Loading... |
788 } | 779 } |
789 ++response_cookies_save_index_; | 780 ++response_cookies_save_index_; |
790 } | 781 } |
791 } | 782 } |
792 | 783 |
793 save_next_cookie_running->data = false; | 784 save_next_cookie_running->data = false; |
794 | 785 |
795 if (!callback_pending->data) { | 786 if (!callback_pending->data) { |
796 response_cookies_.clear(); | 787 response_cookies_.clear(); |
797 response_cookies_save_index_ = 0; | 788 response_cookies_save_index_ = 0; |
798 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status | |
799 NotifyHeadersComplete(); | 789 NotifyHeadersComplete(); |
800 return; | 790 return; |
801 } | 791 } |
802 } | 792 } |
803 | 793 |
804 // |save_next_cookie_running| is true when the callback is bound and set to | 794 // |save_next_cookie_running| is true when the callback is bound and set to |
805 // false when SaveNextCookie exits, allowing the callback to determine if the | 795 // false when SaveNextCookie exits, allowing the callback to determine if the |
806 // save occurred synchronously or asynchronously. | 796 // save occurred synchronously or asynchronously. |
807 // |callback_pending| is false when the callback is invoked and will be set to | 797 // |callback_pending| is false when the callback is invoked and will be set to |
808 // true by the callback, allowing SaveNextCookie to detect whether the save | 798 // true by the callback, allowing SaveNextCookie to detect whether the save |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 if (!request_) | 919 if (!request_) |
930 return; | 920 return; |
931 | 921 |
932 // If the job is done (due to cancellation), can just ignore this | 922 // If the job is done (due to cancellation), can just ignore this |
933 // notification. | 923 // notification. |
934 if (done_) | 924 if (done_) |
935 return; | 925 return; |
936 | 926 |
937 receive_headers_end_ = base::TimeTicks::Now(); | 927 receive_headers_end_ = base::TimeTicks::Now(); |
938 | 928 |
939 // Clear the IO_PENDING status | |
940 SetStatus(URLRequestStatus()); | |
941 | |
942 const URLRequestContext* context = request_->context(); | 929 const URLRequestContext* context = request_->context(); |
943 | 930 |
944 if (result == OK) { | 931 if (result == OK) { |
945 if (transaction_ && transaction_->GetResponseInfo()) { | 932 if (transaction_ && transaction_->GetResponseInfo()) { |
946 SetProxyServer(transaction_->GetResponseInfo()->proxy_server); | 933 SetProxyServer(transaction_->GetResponseInfo()->proxy_server); |
947 } | 934 } |
948 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); | 935 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); |
949 | 936 |
950 if (headers) { | 937 if (headers) { |
951 void* iter = NULL; | 938 void* iter = NULL; |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 void URLRequestHttpJob::ContinueWithCertificate( | 1285 void URLRequestHttpJob::ContinueWithCertificate( |
1299 X509Certificate* client_cert, | 1286 X509Certificate* client_cert, |
1300 SSLPrivateKey* client_private_key) { | 1287 SSLPrivateKey* client_private_key) { |
1301 DCHECK(transaction_.get()); | 1288 DCHECK(transaction_.get()); |
1302 | 1289 |
1303 DCHECK(!response_info_) << "should not have a response yet"; | 1290 DCHECK(!response_info_) << "should not have a response yet"; |
1304 receive_headers_end_ = base::TimeTicks(); | 1291 receive_headers_end_ = base::TimeTicks(); |
1305 | 1292 |
1306 ResetTimer(); | 1293 ResetTimer(); |
1307 | 1294 |
1308 // No matter what, we want to report our status as IO pending since we will | |
1309 // be notifying our consumer asynchronously via OnStartCompleted. | |
1310 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | |
1311 | |
1312 int rv = transaction_->RestartWithCertificate(client_cert, client_private_key, | 1295 int rv = transaction_->RestartWithCertificate(client_cert, client_private_key, |
1313 start_callback_); | 1296 start_callback_); |
1314 if (rv == ERR_IO_PENDING) | 1297 if (rv == ERR_IO_PENDING) |
1315 return; | 1298 return; |
1316 | 1299 |
1317 // The transaction started synchronously, but we need to notify the | 1300 // The transaction started synchronously, but we need to notify the |
1318 // URLRequest delegate via the message loop. | 1301 // URLRequest delegate via the message loop. |
1319 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1302 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1320 FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, | 1303 FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
1321 weak_factory_.GetWeakPtr(), rv)); | 1304 weak_factory_.GetWeakPtr(), rv)); |
1322 } | 1305 } |
1323 | 1306 |
1324 void URLRequestHttpJob::ContinueDespiteLastError() { | 1307 void URLRequestHttpJob::ContinueDespiteLastError() { |
1325 // If the transaction was destroyed, then the job was cancelled. | 1308 // If the transaction was destroyed, then the job was cancelled. |
1326 if (!transaction_.get()) | 1309 if (!transaction_.get()) |
1327 return; | 1310 return; |
1328 | 1311 |
1329 DCHECK(!response_info_) << "should not have a response yet"; | 1312 DCHECK(!response_info_) << "should not have a response yet"; |
1330 receive_headers_end_ = base::TimeTicks(); | 1313 receive_headers_end_ = base::TimeTicks(); |
1331 | 1314 |
1332 ResetTimer(); | 1315 ResetTimer(); |
1333 | 1316 |
1334 // No matter what, we want to report our status as IO pending since we will | |
1335 // be notifying our consumer asynchronously via OnStartCompleted. | |
1336 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | |
1337 | |
1338 int rv = transaction_->RestartIgnoringLastError(start_callback_); | 1317 int rv = transaction_->RestartIgnoringLastError(start_callback_); |
1339 if (rv == ERR_IO_PENDING) | 1318 if (rv == ERR_IO_PENDING) |
1340 return; | 1319 return; |
1341 | 1320 |
1342 // The transaction started synchronously, but we need to notify the | 1321 // The transaction started synchronously, but we need to notify the |
1343 // URLRequest delegate via the message loop. | 1322 // URLRequest delegate via the message loop. |
1344 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1323 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1345 FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, | 1324 FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
1346 weak_factory_.GetWeakPtr(), rv)); | 1325 weak_factory_.GetWeakPtr(), rv)); |
1347 } | 1326 } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 return override_response_headers_.get() ? | 1589 return override_response_headers_.get() ? |
1611 override_response_headers_.get() : | 1590 override_response_headers_.get() : |
1612 transaction_->GetResponseInfo()->headers.get(); | 1591 transaction_->GetResponseInfo()->headers.get(); |
1613 } | 1592 } |
1614 | 1593 |
1615 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1594 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1616 awaiting_callback_ = false; | 1595 awaiting_callback_ = false; |
1617 } | 1596 } |
1618 | 1597 |
1619 } // namespace net | 1598 } // namespace net |
OLD | NEW |