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 = GetCookieStore(); | 542 CookieStore* cookie_store = request_->context()->cookie_store(); |
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 GetCookieStore()->GetCookiesWithOptionsAsync( | 561 request_->context()->cookie_store()->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 GetCookieStore() && response_cookies_.size() > 0) { | 641 request_->context()->cookie_store() && |
| 642 response_cookies_.size() > 0) { |
642 CookieOptions options; | 643 CookieOptions options; |
643 options.set_include_httponly(); | 644 options.set_include_httponly(); |
644 options.set_server_time(response_date_); | 645 options.set_server_time(response_date_); |
645 | 646 |
646 net::CookieStore::SetCookiesCallback callback( | 647 net::CookieStore::SetCookiesCallback callback( |
647 base::Bind(&URLRequestHttpJob::OnCookieSaved, | 648 base::Bind(&URLRequestHttpJob::OnCookieSaved, |
648 weak_factory_.GetWeakPtr(), | 649 weak_factory_.GetWeakPtr(), |
649 save_next_cookie_running, | 650 save_next_cookie_running, |
650 callback_pending)); | 651 callback_pending)); |
651 | 652 |
652 // Loop through the cookies as long as SetCookieWithOptionsAsync completes | 653 // Loop through the cookies as long as SetCookieWithOptionsAsync completes |
653 // synchronously. | 654 // synchronously. |
654 while (!callback_pending->data && | 655 while (!callback_pending->data && |
655 response_cookies_save_index_ < response_cookies_.size()) { | 656 response_cookies_save_index_ < response_cookies_.size()) { |
656 if (CanSetCookie( | 657 if (CanSetCookie( |
657 response_cookies_[response_cookies_save_index_], &options)) { | 658 response_cookies_[response_cookies_save_index_], &options)) { |
658 callback_pending->data = true; | 659 callback_pending->data = true; |
659 GetCookieStore()->SetCookieWithOptionsAsync( | 660 request_->context()->cookie_store()->SetCookieWithOptionsAsync( |
660 request_->url(), response_cookies_[response_cookies_save_index_], | 661 request_->url(), response_cookies_[response_cookies_save_index_], |
661 options, callback); | 662 options, callback); |
662 } | 663 } |
663 ++response_cookies_save_index_; | 664 ++response_cookies_save_index_; |
664 } | 665 } |
665 } | 666 } |
666 | 667 |
667 save_next_cookie_running->data = false; | 668 save_next_cookie_running->data = false; |
668 | 669 |
669 if (!callback_pending->data) { | 670 if (!callback_pending->data) { |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1464 return override_response_headers_.get() ? | 1465 return override_response_headers_.get() ? |
1465 override_response_headers_.get() : | 1466 override_response_headers_.get() : |
1466 transaction_->GetResponseInfo()->headers.get(); | 1467 transaction_->GetResponseInfo()->headers.get(); |
1467 } | 1468 } |
1468 | 1469 |
1469 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1470 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1470 awaiting_callback_ = false; | 1471 awaiting_callback_ = false; |
1471 } | 1472 } |
1472 | 1473 |
1473 } // namespace net | 1474 } // namespace net |
OLD | NEW |