| 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 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 | 608 |
| 609 void URLRequestHttpJob::AddCookieHeaderAndStart() { | 609 void URLRequestHttpJob::AddCookieHeaderAndStart() { |
| 610 // No matter what, we want to report our status as IO pending since we will | 610 // No matter what, we want to report our status as IO pending since we will |
| 611 // be notifying our consumer asynchronously via OnStartCompleted. | 611 // be notifying our consumer asynchronously via OnStartCompleted. |
| 612 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 612 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 613 | 613 |
| 614 // If the request was destroyed, then there is no more work to do. | 614 // If the request was destroyed, then there is no more work to do. |
| 615 if (!request_) | 615 if (!request_) |
| 616 return; | 616 return; |
| 617 | 617 |
| 618 CookieStore* cookie_store = GetCookieStore(); | 618 CookieStore* cookie_store = request_->context()->cookie_store(); |
| 619 if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) { | 619 if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) { |
| 620 cookie_store->GetAllCookiesForURLAsync( | 620 cookie_store->GetAllCookiesForURLAsync( |
| 621 request_->url(), | 621 request_->url(), |
| 622 base::Bind(&URLRequestHttpJob::CheckCookiePolicyAndLoad, | 622 base::Bind(&URLRequestHttpJob::CheckCookiePolicyAndLoad, |
| 623 weak_factory_.GetWeakPtr())); | 623 weak_factory_.GetWeakPtr())); |
| 624 } else { | 624 } else { |
| 625 DoStartTransaction(); | 625 DoStartTransaction(); |
| 626 } | 626 } |
| 627 } | 627 } |
| 628 | 628 |
| 629 void URLRequestHttpJob::DoLoadCookies() { | 629 void URLRequestHttpJob::DoLoadCookies() { |
| 630 CookieOptions options; | 630 CookieOptions options; |
| 631 options.set_include_httponly(); | 631 options.set_include_httponly(); |
| 632 | 632 |
| 633 // TODO(mkwst): Drop this `if` once we decide whether or not to ship | 633 // TODO(mkwst): Drop this `if` once we decide whether or not to ship |
| 634 // first-party cookies: https://crbug.com/459154 | 634 // first-party cookies: https://crbug.com/459154 |
| 635 if (network_delegate() && | 635 if (network_delegate() && |
| 636 network_delegate()->FirstPartyOnlyCookieExperimentEnabled()) | 636 network_delegate()->FirstPartyOnlyCookieExperimentEnabled()) |
| 637 options.set_first_party_url(request_->first_party_for_cookies()); | 637 options.set_first_party_url(request_->first_party_for_cookies()); |
| 638 else | 638 else |
| 639 options.set_include_first_party_only(); | 639 options.set_include_first_party_only(); |
| 640 | 640 |
| 641 GetCookieStore()->GetCookiesWithOptionsAsync( | 641 request_->context()->cookie_store()->GetCookiesWithOptionsAsync( |
| 642 request_->url(), options, | 642 request_->url(), options, base::Bind(&URLRequestHttpJob::OnCookiesLoaded, |
| 643 base::Bind(&URLRequestHttpJob::OnCookiesLoaded, | 643 weak_factory_.GetWeakPtr())); |
| 644 weak_factory_.GetWeakPtr())); | |
| 645 } | 644 } |
| 646 | 645 |
| 647 void URLRequestHttpJob::CheckCookiePolicyAndLoad( | 646 void URLRequestHttpJob::CheckCookiePolicyAndLoad( |
| 648 const CookieList& cookie_list) { | 647 const CookieList& cookie_list) { |
| 649 if (CanGetCookies(cookie_list)) | 648 if (CanGetCookies(cookie_list)) |
| 650 DoLoadCookies(); | 649 DoLoadCookies(); |
| 651 else | 650 else |
| 652 DoStartTransaction(); | 651 DoStartTransaction(); |
| 653 } | 652 } |
| 654 | 653 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 // be notifying our consumer asynchronously via OnStartCompleted. | 710 // be notifying our consumer asynchronously via OnStartCompleted. |
| 712 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 711 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 713 | 712 |
| 714 // Used to communicate with the callback. See the implementation of | 713 // Used to communicate with the callback. See the implementation of |
| 715 // OnCookieSaved. | 714 // OnCookieSaved. |
| 716 scoped_refptr<SharedBoolean> callback_pending = new SharedBoolean(false); | 715 scoped_refptr<SharedBoolean> callback_pending = new SharedBoolean(false); |
| 717 scoped_refptr<SharedBoolean> save_next_cookie_running = | 716 scoped_refptr<SharedBoolean> save_next_cookie_running = |
| 718 new SharedBoolean(true); | 717 new SharedBoolean(true); |
| 719 | 718 |
| 720 if (!(request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) && | 719 if (!(request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) && |
| 721 GetCookieStore() && response_cookies_.size() > 0) { | 720 request_->context()->cookie_store() && response_cookies_.size() > 0) { |
| 722 CookieOptions options; | 721 CookieOptions options; |
| 723 options.set_include_httponly(); | 722 options.set_include_httponly(); |
| 724 options.set_server_time(response_date_); | 723 options.set_server_time(response_date_); |
| 725 | 724 |
| 726 net::CookieStore::SetCookiesCallback callback( | 725 net::CookieStore::SetCookiesCallback callback( |
| 727 base::Bind(&URLRequestHttpJob::OnCookieSaved, | 726 base::Bind(&URLRequestHttpJob::OnCookieSaved, |
| 728 weak_factory_.GetWeakPtr(), | 727 weak_factory_.GetWeakPtr(), |
| 729 save_next_cookie_running, | 728 save_next_cookie_running, |
| 730 callback_pending)); | 729 callback_pending)); |
| 731 | 730 |
| 732 // Loop through the cookies as long as SetCookieWithOptionsAsync completes | 731 // Loop through the cookies as long as SetCookieWithOptionsAsync completes |
| 733 // synchronously. | 732 // synchronously. |
| 734 while (!callback_pending->data && | 733 while (!callback_pending->data && |
| 735 response_cookies_save_index_ < response_cookies_.size()) { | 734 response_cookies_save_index_ < response_cookies_.size()) { |
| 736 if (CanSetCookie( | 735 if (CanSetCookie( |
| 737 response_cookies_[response_cookies_save_index_], &options)) { | 736 response_cookies_[response_cookies_save_index_], &options)) { |
| 738 callback_pending->data = true; | 737 callback_pending->data = true; |
| 739 GetCookieStore()->SetCookieWithOptionsAsync( | 738 request_->context()->cookie_store()->SetCookieWithOptionsAsync( |
| 740 request_->url(), response_cookies_[response_cookies_save_index_], | 739 request_->url(), response_cookies_[response_cookies_save_index_], |
| 741 options, callback); | 740 options, callback); |
| 742 } | 741 } |
| 743 ++response_cookies_save_index_; | 742 ++response_cookies_save_index_; |
| 744 } | 743 } |
| 745 } | 744 } |
| 746 | 745 |
| 747 save_next_cookie_running->data = false; | 746 save_next_cookie_running->data = false; |
| 748 | 747 |
| 749 if (!callback_pending->data) { | 748 if (!callback_pending->data) { |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 return override_response_headers_.get() ? | 1501 return override_response_headers_.get() ? |
| 1503 override_response_headers_.get() : | 1502 override_response_headers_.get() : |
| 1504 transaction_->GetResponseInfo()->headers.get(); | 1503 transaction_->GetResponseInfo()->headers.get(); |
| 1505 } | 1504 } |
| 1506 | 1505 |
| 1507 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1506 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1508 awaiting_callback_ = false; | 1507 awaiting_callback_ = false; |
| 1509 } | 1508 } |
| 1510 | 1509 |
| 1511 } // namespace net | 1510 } // namespace net |
| OLD | NEW |