Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: google_apis/gaia/gaia_auth_fetcher.cc

Issue 1117703002: Adjust URLFetcher::Create API so that object is returned as scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unneeded Pass() calls Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « google_apis/gaia/gaia_auth_fetcher.h ('k') | google_apis/gaia/gaia_oauth_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "google_apis/gaia/gaia_auth_fetcher.h" 5 #include "google_apis/gaia/gaia_auth_fetcher.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 bool GaiaAuthFetcher::HasPendingFetch() { 218 bool GaiaAuthFetcher::HasPendingFetch() {
219 return fetch_pending_; 219 return fetch_pending_;
220 } 220 }
221 221
222 void GaiaAuthFetcher::CancelRequest() { 222 void GaiaAuthFetcher::CancelRequest() {
223 fetcher_.reset(); 223 fetcher_.reset();
224 fetch_pending_ = false; 224 fetch_pending_ = false;
225 } 225 }
226 226
227 // static 227 // static
228 net::URLFetcher* GaiaAuthFetcher::CreateGaiaFetcher( 228 scoped_ptr<net::URLFetcher> GaiaAuthFetcher::CreateGaiaFetcher(
229 net::URLRequestContextGetter* getter, 229 net::URLRequestContextGetter* getter,
230 const std::string& body, 230 const std::string& body,
231 const std::string& headers, 231 const std::string& headers,
232 const GURL& gaia_gurl, 232 const GURL& gaia_gurl,
233 int load_flags, 233 int load_flags,
234 net::URLFetcherDelegate* delegate) { 234 net::URLFetcherDelegate* delegate) {
235 net::URLFetcher* to_return = net::URLFetcher::Create( 235 scoped_ptr<net::URLFetcher> to_return = net::URLFetcher::Create(
236 0, gaia_gurl, 236 0, gaia_gurl, body.empty() ? net::URLFetcher::GET : net::URLFetcher::POST,
237 body.empty() ? net::URLFetcher::GET : net::URLFetcher::POST,
238 delegate); 237 delegate);
239 to_return->SetRequestContext(getter); 238 to_return->SetRequestContext(getter);
240 to_return->SetUploadData("application/x-www-form-urlencoded", body); 239 to_return->SetUploadData("application/x-www-form-urlencoded", body);
241 240
242 DVLOG(2) << "Gaia fetcher URL: " << gaia_gurl.spec(); 241 DVLOG(2) << "Gaia fetcher URL: " << gaia_gurl.spec();
243 DVLOG(2) << "Gaia fetcher headers: " << headers; 242 DVLOG(2) << "Gaia fetcher headers: " << headers;
244 DVLOG(2) << "Gaia fetcher body: " << body; 243 DVLOG(2) << "Gaia fetcher body: " << body;
245 244
246 // The Gaia token exchange requests do not require any cookie-based 245 // The Gaia token exchange requests do not require any cookie-based
247 // identification as part of requests. We suppress sending any cookies to 246 // identification as part of requests. We suppress sending any cookies to
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 DVLOG(1) << "Starting new ClientLogin fetch for:" << username; 585 DVLOG(1) << "Starting new ClientLogin fetch for:" << username;
587 586
588 // Must outlive fetcher_. 587 // Must outlive fetcher_.
589 request_body_ = MakeClientLoginBody(username, 588 request_body_ = MakeClientLoginBody(username,
590 password, 589 password,
591 source_, 590 source_,
592 service, 591 service,
593 login_token, 592 login_token,
594 login_captcha, 593 login_captcha,
595 allow_hosted_accounts); 594 allow_hosted_accounts);
596 fetcher_.reset(CreateGaiaFetcher(getter_, 595 fetcher_ =
597 request_body_, 596 CreateGaiaFetcher(getter_, request_body_, std::string(),
598 std::string(), 597 client_login_gurl_, kLoadFlagsIgnoreCookies, this);
599 client_login_gurl_,
600 kLoadFlagsIgnoreCookies,
601 this));
602 fetch_pending_ = true; 598 fetch_pending_ = true;
603 fetcher_->Start(); 599 fetcher_->Start();
604 } 600 }
605 601
606 void GaiaAuthFetcher::StartIssueAuthToken(const std::string& sid, 602 void GaiaAuthFetcher::StartIssueAuthToken(const std::string& sid,
607 const std::string& lsid, 603 const std::string& lsid,
608 const char* const service) { 604 const char* const service) {
609 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 605 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
610 606
611 DVLOG(1) << "Starting IssueAuthToken for: " << service; 607 DVLOG(1) << "Starting IssueAuthToken for: " << service;
612 requested_service_ = service; 608 requested_service_ = service;
613 request_body_ = MakeIssueAuthTokenBody(sid, lsid, service); 609 request_body_ = MakeIssueAuthTokenBody(sid, lsid, service);
614 fetcher_.reset(CreateGaiaFetcher(getter_, 610 fetcher_ =
615 request_body_, 611 CreateGaiaFetcher(getter_, request_body_, std::string(),
616 std::string(), 612 issue_auth_token_gurl_, kLoadFlagsIgnoreCookies, this);
617 issue_auth_token_gurl_,
618 kLoadFlagsIgnoreCookies,
619 this));
620 fetch_pending_ = true; 613 fetch_pending_ = true;
621 fetcher_->Start(); 614 fetcher_->Start();
622 } 615 }
623 616
624 void GaiaAuthFetcher::StartLsoForOAuthLoginTokenExchange( 617 void GaiaAuthFetcher::StartLsoForOAuthLoginTokenExchange(
625 const std::string& auth_token) { 618 const std::string& auth_token) {
626 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 619 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
627 620
628 DVLOG(1) << "Starting OAuth login token exchange with auth_token"; 621 DVLOG(1) << "Starting OAuth login token exchange with auth_token";
629 request_body_ = MakeGetAuthCodeBody(false); 622 request_body_ = MakeGetAuthCodeBody(false);
630 client_login_to_oauth2_gurl_ = 623 client_login_to_oauth2_gurl_ =
631 GaiaUrls::GetInstance()->client_login_to_oauth2_url(); 624 GaiaUrls::GetInstance()->client_login_to_oauth2_url();
632 625
633 fetcher_.reset(CreateGaiaFetcher(getter_, 626 fetcher_ = CreateGaiaFetcher(
634 request_body_, 627 getter_, request_body_, MakeGetAuthCodeHeader(auth_token),
635 MakeGetAuthCodeHeader(auth_token), 628 client_login_to_oauth2_gurl_, kLoadFlagsIgnoreCookies, this);
636 client_login_to_oauth2_gurl_,
637 kLoadFlagsIgnoreCookies,
638 this));
639 fetch_pending_ = true; 629 fetch_pending_ = true;
640 fetcher_->Start(); 630 fetcher_->Start();
641 } 631 }
642 632
643 void GaiaAuthFetcher::StartRevokeOAuth2Token(const std::string& auth_token) { 633 void GaiaAuthFetcher::StartRevokeOAuth2Token(const std::string& auth_token) {
644 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 634 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
645 635
646 DVLOG(1) << "Starting OAuth2 token revocation"; 636 DVLOG(1) << "Starting OAuth2 token revocation";
647 request_body_ = MakeRevokeTokenBody(auth_token); 637 request_body_ = MakeRevokeTokenBody(auth_token);
648 fetcher_.reset(CreateGaiaFetcher(getter_, 638 fetcher_ =
649 request_body_, 639 CreateGaiaFetcher(getter_, request_body_, std::string(),
650 std::string(), 640 oauth2_revoke_gurl_, kLoadFlagsIgnoreCookies, this);
651 oauth2_revoke_gurl_,
652 kLoadFlagsIgnoreCookies,
653 this));
654 fetch_pending_ = true; 641 fetch_pending_ = true;
655 fetcher_->Start(); 642 fetcher_->Start();
656 } 643 }
657 644
658 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( 645 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange(
659 const std::string& session_index) { 646 const std::string& session_index) {
660 StartCookieForOAuthLoginTokenExchangeWithDeviceId(session_index, 647 StartCookieForOAuthLoginTokenExchangeWithDeviceId(session_index,
661 std::string()); 648 std::string());
662 } 649 }
663 650
(...skipping 11 matching lines...) Expand all
675 client_login_to_oauth2_gurl_ = 662 client_login_to_oauth2_gurl_ =
676 client_login_to_oauth2_gurl_.Resolve("?authuser=" + session_index); 663 client_login_to_oauth2_gurl_.Resolve("?authuser=" + session_index);
677 } 664 }
678 665
679 std::string device_id_header; 666 std::string device_id_header;
680 if (!device_id.empty()) { 667 if (!device_id.empty()) {
681 device_id_header = 668 device_id_header =
682 base::StringPrintf(kDeviceIdHeaderFormat, device_id.c_str()); 669 base::StringPrintf(kDeviceIdHeaderFormat, device_id.c_str());
683 } 670 }
684 671
685 fetcher_.reset(CreateGaiaFetcher(getter_, 672 fetcher_ =
686 request_body_, 673 CreateGaiaFetcher(getter_, request_body_, device_id_header,
687 device_id_header, 674 client_login_to_oauth2_gurl_, net::LOAD_NORMAL, this);
688 client_login_to_oauth2_gurl_,
689 net::LOAD_NORMAL,
690 this));
691 fetch_pending_ = true; 675 fetch_pending_ = true;
692 fetcher_->Start(); 676 fetcher_->Start();
693 } 677 }
694 678
695 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( 679 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange(
696 const std::string& auth_code) { 680 const std::string& auth_code) {
697 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 681 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
698 682
699 DVLOG(1) << "Starting OAuth token pair fetch"; 683 DVLOG(1) << "Starting OAuth token pair fetch";
700 request_body_ = MakeGetTokenPairBody(auth_code); 684 request_body_ = MakeGetTokenPairBody(auth_code);
701 fetcher_.reset(CreateGaiaFetcher(getter_, 685 fetcher_ =
702 request_body_, 686 CreateGaiaFetcher(getter_, request_body_, std::string(),
703 std::string(), 687 oauth2_token_gurl_, kLoadFlagsIgnoreCookies, this);
704 oauth2_token_gurl_,
705 kLoadFlagsIgnoreCookies,
706 this));
707 fetch_pending_ = true; 688 fetch_pending_ = true;
708 fetcher_->Start(); 689 fetcher_->Start();
709 } 690 }
710 691
711 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid) { 692 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid) {
712 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 693 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
713 694
714 DVLOG(1) << "Starting GetUserInfo for lsid=" << lsid; 695 DVLOG(1) << "Starting GetUserInfo for lsid=" << lsid;
715 request_body_ = MakeGetUserInfoBody(lsid); 696 request_body_ = MakeGetUserInfoBody(lsid);
716 fetcher_.reset(CreateGaiaFetcher(getter_, 697 fetcher_ =
717 request_body_, 698 CreateGaiaFetcher(getter_, request_body_, std::string(),
718 std::string(), 699 get_user_info_gurl_, kLoadFlagsIgnoreCookies, this);
719 get_user_info_gurl_,
720 kLoadFlagsIgnoreCookies,
721 this));
722 fetch_pending_ = true; 700 fetch_pending_ = true;
723 fetcher_->Start(); 701 fetcher_->Start();
724 } 702 }
725 703
726 void GaiaAuthFetcher::StartMergeSession(const std::string& uber_token, 704 void GaiaAuthFetcher::StartMergeSession(const std::string& uber_token,
727 const std::string& external_cc_result) { 705 const std::string& external_cc_result) {
728 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 706 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
729 707
730 DVLOG(1) << "Starting MergeSession with uber_token=" << uber_token; 708 DVLOG(1) << "Starting MergeSession with uber_token=" << uber_token;
731 709
732 // The continue URL is a required parameter of the MergeSession API, but in 710 // The continue URL is a required parameter of the MergeSession API, but in
733 // this case we don't actually need or want to navigate to it. Setting it to 711 // this case we don't actually need or want to navigate to it. Setting it to
734 // an arbitrary Google URL. 712 // an arbitrary Google URL.
735 // 713 //
736 // In order for the new session to be merged correctly, the server needs to 714 // In order for the new session to be merged correctly, the server needs to
737 // know what sessions already exist in the browser. The fetcher needs to be 715 // know what sessions already exist in the browser. The fetcher needs to be
738 // created such that it sends the cookies with the request, which is 716 // created such that it sends the cookies with the request, which is
739 // different from all other requests the fetcher can make. 717 // different from all other requests the fetcher can make.
740 std::string continue_url("http://www.google.com"); 718 std::string continue_url("http://www.google.com");
741 request_body_ = MakeMergeSessionBody(uber_token, external_cc_result, 719 request_body_ = MakeMergeSessionBody(uber_token, external_cc_result,
742 continue_url, source_); 720 continue_url, source_);
743 fetcher_.reset(CreateGaiaFetcher(getter_, 721 fetcher_ = CreateGaiaFetcher(getter_, request_body_, std::string(),
744 request_body_, 722 merge_session_gurl_, net::LOAD_NORMAL, this);
745 std::string(),
746 merge_session_gurl_,
747 net::LOAD_NORMAL,
748 this));
749 fetch_pending_ = true; 723 fetch_pending_ = true;
750 fetcher_->Start(); 724 fetcher_->Start();
751 } 725 }
752 726
753 void GaiaAuthFetcher::StartTokenFetchForUberAuthExchange( 727 void GaiaAuthFetcher::StartTokenFetchForUberAuthExchange(
754 const std::string& access_token) { 728 const std::string& access_token) {
755 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 729 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
756 730
757 DVLOG(1) << "Starting StartTokenFetchForUberAuthExchange with access_token=" 731 DVLOG(1) << "Starting StartTokenFetchForUberAuthExchange with access_token="
758 << access_token; 732 << access_token;
759 std::string authentication_header = 733 std::string authentication_header =
760 base::StringPrintf(kOAuthHeaderFormat, access_token.c_str()); 734 base::StringPrintf(kOAuthHeaderFormat, access_token.c_str());
761 fetcher_.reset(CreateGaiaFetcher(getter_, 735 fetcher_ = CreateGaiaFetcher(getter_, std::string(), authentication_header,
762 std::string(), 736 uberauth_token_gurl_, net::LOAD_NORMAL, this);
763 authentication_header,
764 uberauth_token_gurl_,
765 net::LOAD_NORMAL,
766 this));
767 fetch_pending_ = true; 737 fetch_pending_ = true;
768 fetcher_->Start(); 738 fetcher_->Start();
769 } 739 }
770 740
771 void GaiaAuthFetcher::StartOAuthLogin(const std::string& access_token, 741 void GaiaAuthFetcher::StartOAuthLogin(const std::string& access_token,
772 const std::string& service) { 742 const std::string& service) {
773 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 743 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
774 744
775 request_body_ = MakeOAuthLoginBody(service, source_); 745 request_body_ = MakeOAuthLoginBody(service, source_);
776 std::string authentication_header = 746 std::string authentication_header =
777 base::StringPrintf(kOAuth2BearerHeaderFormat, access_token.c_str()); 747 base::StringPrintf(kOAuth2BearerHeaderFormat, access_token.c_str());
778 fetcher_.reset(CreateGaiaFetcher(getter_, 748 fetcher_ = CreateGaiaFetcher(getter_, request_body_, authentication_header,
779 request_body_, 749 oauth_login_gurl_, net::LOAD_NORMAL, this);
780 authentication_header,
781 oauth_login_gurl_,
782 net::LOAD_NORMAL,
783 this));
784 fetch_pending_ = true; 750 fetch_pending_ = true;
785 fetcher_->Start(); 751 fetcher_->Start();
786 } 752 }
787 753
788 void GaiaAuthFetcher::StartListAccounts() { 754 void GaiaAuthFetcher::StartListAccounts() {
789 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 755 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
790 756
791 fetcher_.reset(CreateGaiaFetcher(getter_, 757 fetcher_ = CreateGaiaFetcher(getter_,
792 " ", // To force an HTTP POST. 758 " ", // To force an HTTP POST.
793 "Origin: https://www.google.com", 759 "Origin: https://www.google.com",
794 list_accounts_gurl_, 760 list_accounts_gurl_, net::LOAD_NORMAL, this);
795 net::LOAD_NORMAL,
796 this));
797 fetch_pending_ = true; 761 fetch_pending_ = true;
798 fetcher_->Start(); 762 fetcher_->Start();
799 } 763 }
800 764
801 void GaiaAuthFetcher::StartGetCheckConnectionInfo() { 765 void GaiaAuthFetcher::StartGetCheckConnectionInfo() {
802 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 766 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
803 767
804 fetcher_.reset(CreateGaiaFetcher(getter_, 768 fetcher_ = CreateGaiaFetcher(getter_, std::string(), std::string(),
805 std::string(), 769 get_check_connection_info_url_,
806 std::string(), 770 kLoadFlagsIgnoreCookies, this);
807 get_check_connection_info_url_,
808 kLoadFlagsIgnoreCookies,
809 this));
810 fetch_pending_ = true; 771 fetch_pending_ = true;
811 fetcher_->Start(); 772 fetcher_->Start();
812 } 773 }
813 774
814 void GaiaAuthFetcher::StartListIDPSessions(const std::string& scopes, 775 void GaiaAuthFetcher::StartListIDPSessions(const std::string& scopes,
815 const std::string& domain) { 776 const std::string& domain) {
816 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 777 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
817 778
818 request_body_ = MakeListIDPSessionsBody(scopes, domain); 779 request_body_ = MakeListIDPSessionsBody(scopes, domain);
819 fetcher_.reset(CreateGaiaFetcher(getter_, 780 fetcher_ = CreateGaiaFetcher(getter_, request_body_, std::string(),
820 request_body_, 781 oauth2_iframe_url_, net::LOAD_NORMAL, this);
821 std::string(),
822 oauth2_iframe_url_,
823 net::LOAD_NORMAL,
824 this));
825 requested_service_ = kListIdpServiceRequested; 782 requested_service_ = kListIdpServiceRequested;
826 fetch_pending_ = true; 783 fetch_pending_ = true;
827 fetcher_->Start(); 784 fetcher_->Start();
828 } 785 }
829 786
830 void GaiaAuthFetcher::StartGetTokenResponse(const std::string& scopes, 787 void GaiaAuthFetcher::StartGetTokenResponse(const std::string& scopes,
831 const std::string& domain, 788 const std::string& domain,
832 const std::string& login_hint) { 789 const std::string& login_hint) {
833 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 790 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
834 791
835 request_body_ = MakeGetTokenResponseBody(scopes, domain, login_hint); 792 request_body_ = MakeGetTokenResponseBody(scopes, domain, login_hint);
836 fetcher_.reset(CreateGaiaFetcher(getter_, 793 fetcher_ = CreateGaiaFetcher(getter_, request_body_, std::string(),
837 request_body_, 794 oauth2_iframe_url_, net::LOAD_NORMAL, this);
838 std::string(),
839 oauth2_iframe_url_,
840 net::LOAD_NORMAL,
841 this));
842 795
843 requested_service_ = kGetTokenResponseRequested; 796 requested_service_ = kGetTokenResponseRequested;
844 fetch_pending_ = true; 797 fetch_pending_ = true;
845 fetcher_->Start(); 798 fetcher_->Start();
846 } 799 }
847 800
848 // static 801 // static
849 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( 802 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError(
850 const std::string& data, 803 const std::string& data,
851 const net::URLRequestStatus& status) { 804 const net::URLRequestStatus& status) {
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 return alleged_error.find(kSecondFactor) != 1106 return alleged_error.find(kSecondFactor) !=
1154 std::string::npos; 1107 std::string::npos;
1155 } 1108 }
1156 1109
1157 // static 1110 // static
1158 bool GaiaAuthFetcher::IsWebLoginRequiredSuccess( 1111 bool GaiaAuthFetcher::IsWebLoginRequiredSuccess(
1159 const std::string& alleged_error) { 1112 const std::string& alleged_error) {
1160 return alleged_error.find(kWebLoginRequired) != 1113 return alleged_error.find(kWebLoginRequired) !=
1161 std::string::npos; 1114 std::string::npos;
1162 } 1115 }
OLDNEW
« no previous file with comments | « google_apis/gaia/gaia_auth_fetcher.h ('k') | google_apis/gaia/gaia_oauth_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698