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 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 | 532 |
533 void URLRequestHttpJob::AddCookieHeaderAndStart() { | 533 void URLRequestHttpJob::AddCookieHeaderAndStart() { |
534 // No matter what, we want to report our status as IO pending since we will | 534 // No matter what, we want to report our status as IO pending since we will |
535 // be notifying our consumer asynchronously via OnStartCompleted. | 535 // be notifying our consumer asynchronously via OnStartCompleted. |
536 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 536 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
537 | 537 |
538 // If the request was destroyed, then there is no more work to do. | 538 // If the request was destroyed, then there is no more work to do. |
539 if (!request_) | 539 if (!request_) |
540 return; | 540 return; |
541 | 541 |
542 CookieStore* cookie_store = request_->context()->cookie_store(); | 542 CookieStore* cookie_store = GetCookieStore(); |
543 if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) { | 543 if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) { |
544 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); | 544 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); |
545 if (cookie_monster) { | 545 if (cookie_monster) { |
546 cookie_monster->GetAllCookiesForURLAsync( | 546 cookie_monster->GetAllCookiesForURLAsync( |
547 request_->url(), | 547 request_->url(), |
548 base::Bind(&URLRequestHttpJob::CheckCookiePolicyAndLoad, | 548 base::Bind(&URLRequestHttpJob::CheckCookiePolicyAndLoad, |
549 weak_factory_.GetWeakPtr())); | 549 weak_factory_.GetWeakPtr())); |
550 } else { | 550 } else { |
551 CheckCookiePolicyAndLoad(CookieList()); | 551 CheckCookiePolicyAndLoad(CookieList()); |
552 } | 552 } |
553 } else { | 553 } else { |
554 DoStartTransaction(); | 554 DoStartTransaction(); |
555 } | 555 } |
556 } | 556 } |
557 | 557 |
558 void URLRequestHttpJob::DoLoadCookies() { | 558 void URLRequestHttpJob::DoLoadCookies() { |
559 CookieOptions options; | 559 CookieOptions options; |
560 options.set_include_httponly(); | 560 options.set_include_httponly(); |
561 request_->context()->cookie_store()->GetCookiesWithOptionsAsync( | 561 GetCookieStore()->GetCookiesWithOptionsAsync( |
562 request_->url(), options, | 562 request_->url(), options, |
563 base::Bind(&URLRequestHttpJob::OnCookiesLoaded, | 563 base::Bind(&URLRequestHttpJob::OnCookiesLoaded, |
564 weak_factory_.GetWeakPtr())); | 564 weak_factory_.GetWeakPtr())); |
565 } | 565 } |
566 | 566 |
567 void URLRequestHttpJob::CheckCookiePolicyAndLoad( | 567 void URLRequestHttpJob::CheckCookiePolicyAndLoad( |
568 const CookieList& cookie_list) { | 568 const CookieList& cookie_list) { |
569 if (CanGetCookies(cookie_list)) | 569 if (CanGetCookies(cookie_list)) |
570 DoLoadCookies(); | 570 DoLoadCookies(); |
571 else | 571 else |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 // be notifying our consumer asynchronously via OnStartCompleted. | 631 // be notifying our consumer asynchronously via OnStartCompleted. |
632 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 632 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
633 | 633 |
634 // Used to communicate with the callback. See the implementation of | 634 // Used to communicate with the callback. See the implementation of |
635 // OnCookieSaved. | 635 // OnCookieSaved. |
636 scoped_refptr<SharedBoolean> callback_pending = new SharedBoolean(false); | 636 scoped_refptr<SharedBoolean> callback_pending = new SharedBoolean(false); |
637 scoped_refptr<SharedBoolean> save_next_cookie_running = | 637 scoped_refptr<SharedBoolean> save_next_cookie_running = |
638 new SharedBoolean(true); | 638 new SharedBoolean(true); |
639 | 639 |
640 if (!(request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) && | 640 if (!(request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) && |
641 request_->context()->cookie_store() && | 641 GetCookieStore() && response_cookies_.size() > 0) { |
642 response_cookies_.size() > 0) { | |
643 CookieOptions options; | 642 CookieOptions options; |
644 options.set_include_httponly(); | 643 options.set_include_httponly(); |
645 options.set_server_time(response_date_); | 644 options.set_server_time(response_date_); |
646 | 645 |
647 net::CookieStore::SetCookiesCallback callback( | 646 net::CookieStore::SetCookiesCallback callback( |
648 base::Bind(&URLRequestHttpJob::OnCookieSaved, | 647 base::Bind(&URLRequestHttpJob::OnCookieSaved, |
649 weak_factory_.GetWeakPtr(), | 648 weak_factory_.GetWeakPtr(), |
650 save_next_cookie_running, | 649 save_next_cookie_running, |
651 callback_pending)); | 650 callback_pending)); |
652 | 651 |
653 // Loop through the cookies as long as SetCookieWithOptionsAsync completes | 652 // Loop through the cookies as long as SetCookieWithOptionsAsync completes |
654 // synchronously. | 653 // synchronously. |
655 while (!callback_pending->data && | 654 while (!callback_pending->data && |
656 response_cookies_save_index_ < response_cookies_.size()) { | 655 response_cookies_save_index_ < response_cookies_.size()) { |
657 if (CanSetCookie( | 656 if (CanSetCookie( |
658 response_cookies_[response_cookies_save_index_], &options)) { | 657 response_cookies_[response_cookies_save_index_], &options)) { |
659 callback_pending->data = true; | 658 callback_pending->data = true; |
660 request_->context()->cookie_store()->SetCookieWithOptionsAsync( | 659 GetCookieStore()->SetCookieWithOptionsAsync( |
661 request_->url(), response_cookies_[response_cookies_save_index_], | 660 request_->url(), response_cookies_[response_cookies_save_index_], |
662 options, callback); | 661 options, callback); |
663 } | 662 } |
664 ++response_cookies_save_index_; | 663 ++response_cookies_save_index_; |
665 } | 664 } |
666 } | 665 } |
667 | 666 |
668 save_next_cookie_running->data = false; | 667 save_next_cookie_running->data = false; |
669 | 668 |
670 if (!callback_pending->data) { | 669 if (!callback_pending->data) { |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 return override_response_headers_.get() ? | 1464 return override_response_headers_.get() ? |
1466 override_response_headers_.get() : | 1465 override_response_headers_.get() : |
1467 transaction_->GetResponseInfo()->headers.get(); | 1466 transaction_->GetResponseInfo()->headers.get(); |
1468 } | 1467 } |
1469 | 1468 |
1470 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1469 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1471 awaiting_callback_ = false; | 1470 awaiting_callback_ = false; |
1472 } | 1471 } |
1473 | 1472 |
1474 } // namespace net | 1473 } // namespace net |
OLD | NEW |