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

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

Issue 203033002: Fix "unreachable code" warnings (MSVC warning 4702) in google_apis/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « google_apis/drive/drive_api_parser.cc ('k') | google_apis/gaia/gaia_auth_fetcher_unittest.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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 "source=%s"; 107 "source=%s";
108 // static 108 // static
109 const char GaiaAuthFetcher::kUberAuthTokenURLFormat[] = 109 const char GaiaAuthFetcher::kUberAuthTokenURLFormat[] =
110 "?source=%s&" 110 "?source=%s&"
111 "issueuberauth=1"; 111 "issueuberauth=1";
112 112
113 const char GaiaAuthFetcher::kOAuthLoginFormat[] = "service=%s&source=%s"; 113 const char GaiaAuthFetcher::kOAuthLoginFormat[] = "service=%s&source=%s";
114 114
115 // static 115 // static
116 const char GaiaAuthFetcher::kAccountDeletedError[] = "AccountDeleted"; 116 const char GaiaAuthFetcher::kAccountDeletedError[] = "AccountDeleted";
117 const char GaiaAuthFetcher::kAccountDeletedErrorCode[] = "adel";
118 // static 117 // static
119 const char GaiaAuthFetcher::kAccountDisabledError[] = "AccountDisabled"; 118 const char GaiaAuthFetcher::kAccountDisabledError[] = "AccountDisabled";
120 const char GaiaAuthFetcher::kAccountDisabledErrorCode[] = "adis";
121 // static 119 // static
122 const char GaiaAuthFetcher::kBadAuthenticationError[] = "BadAuthentication"; 120 const char GaiaAuthFetcher::kBadAuthenticationError[] = "BadAuthentication";
123 const char GaiaAuthFetcher::kBadAuthenticationErrorCode[] = "badauth";
124 // static 121 // static
125 const char GaiaAuthFetcher::kCaptchaError[] = "CaptchaRequired"; 122 const char GaiaAuthFetcher::kCaptchaError[] = "CaptchaRequired";
126 const char GaiaAuthFetcher::kCaptchaErrorCode[] = "cr";
127 // static 123 // static
128 const char GaiaAuthFetcher::kServiceUnavailableError[] = 124 const char GaiaAuthFetcher::kServiceUnavailableError[] =
129 "ServiceUnavailable"; 125 "ServiceUnavailable";
130 const char GaiaAuthFetcher::kServiceUnavailableErrorCode[] =
131 "ire";
132 // static 126 // static
133 const char GaiaAuthFetcher::kErrorParam[] = "Error"; 127 const char GaiaAuthFetcher::kErrorParam[] = "Error";
134 // static 128 // static
135 const char GaiaAuthFetcher::kErrorUrlParam[] = "Url"; 129 const char GaiaAuthFetcher::kErrorUrlParam[] = "Url";
136 // static 130 // static
137 const char GaiaAuthFetcher::kCaptchaUrlParam[] = "CaptchaUrl"; 131 const char GaiaAuthFetcher::kCaptchaUrlParam[] = "CaptchaUrl";
138 // static 132 // static
139 const char GaiaAuthFetcher::kCaptchaTokenParam[] = "CaptchaToken"; 133 const char GaiaAuthFetcher::kCaptchaTokenParam[] = "CaptchaToken";
140 134
141 // static 135 // static
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 fetcher_->Start(); 680 fetcher_->Start();
687 } 681 }
688 682
689 // static 683 // static
690 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( 684 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError(
691 const std::string& data, 685 const std::string& data,
692 const net::URLRequestStatus& status) { 686 const net::URLRequestStatus& status) {
693 if (!status.is_success()) { 687 if (!status.is_success()) {
694 if (status.status() == net::URLRequestStatus::CANCELED) { 688 if (status.status() == net::URLRequestStatus::CANCELED) {
695 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); 689 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED);
696 } else {
697 DLOG(WARNING) << "Could not reach Google Accounts servers: errno "
698 << status.error();
699 return GoogleServiceAuthError::FromConnectionError(status.error());
700 } 690 }
701 } else { 691 DLOG(WARNING) << "Could not reach Google Accounts servers: errno "
702 if (IsSecondFactorSuccess(data)) { 692 << status.error();
703 return GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR); 693 return GoogleServiceAuthError::FromConnectionError(status.error());
704 } 694 }
705 695
706 std::string error; 696 if (IsSecondFactorSuccess(data))
707 std::string url; 697 return GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR);
708 std::string captcha_url;
709 std::string captcha_token;
710 ParseClientLoginFailure(data, &error, &url, &captcha_url, &captcha_token);
711 DLOG(WARNING) << "ClientLogin failed with " << error;
712 698
713 if (error == kCaptchaError) { 699 std::string error;
714 GURL image_url( 700 std::string url;
715 GaiaUrls::GetInstance()->captcha_base_url().Resolve(captcha_url)); 701 std::string captcha_url;
716 GURL unlock_url(url); 702 std::string captcha_token;
717 return GoogleServiceAuthError::FromClientLoginCaptchaChallenge( 703 ParseClientLoginFailure(data, &error, &url, &captcha_url, &captcha_token);
718 captcha_token, image_url, unlock_url); 704 DLOG(WARNING) << "ClientLogin failed with " << error;
719 }
720 if (error == kAccountDeletedError)
721 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DELETED);
722 if (error == kAccountDisabledError)
723 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DISABLED);
724 if (error == kBadAuthenticationError) {
725 return GoogleServiceAuthError(
726 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
727 }
728 if (error == kServiceUnavailableError) {
729 return GoogleServiceAuthError(
730 GoogleServiceAuthError::SERVICE_UNAVAILABLE);
731 }
732 705
733 DLOG(WARNING) << "Incomprehensible response from Google Accounts servers."; 706 if (error == kCaptchaError) {
707 return GoogleServiceAuthError::FromClientLoginCaptchaChallenge(
708 captcha_token,
709 GURL(GaiaUrls::GetInstance()->captcha_base_url().Resolve(captcha_url)),
710 GURL(url));
711 }
712 if (error == kAccountDeletedError)
713 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DELETED);
714 if (error == kAccountDisabledError)
715 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DISABLED);
716 if (error == kBadAuthenticationError) {
717 return GoogleServiceAuthError(
718 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
719 }
720 if (error == kServiceUnavailableError) {
734 return GoogleServiceAuthError( 721 return GoogleServiceAuthError(
735 GoogleServiceAuthError::SERVICE_UNAVAILABLE); 722 GoogleServiceAuthError::SERVICE_UNAVAILABLE);
736 } 723 }
737 724
738 NOTREACHED(); 725 DLOG(WARNING) << "Incomprehensible response from Google Accounts servers.";
739 return GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE); 726 return GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE);
740 } 727 }
741 728
742 // static
743 GoogleServiceAuthError GaiaAuthFetcher::GenerateOAuthLoginError(
744 const std::string& data,
745 const net::URLRequestStatus& status) {
746 if (!status.is_success()) {
747 if (status.status() == net::URLRequestStatus::CANCELED) {
748 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED);
749 } else {
750 DLOG(WARNING) << "Could not reach Google Accounts servers: errno "
751 << status.error();
752 return GoogleServiceAuthError::FromConnectionError(status.error());
753 }
754 } else {
755 if (IsSecondFactorSuccess(data)) {
756 return GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR);
757 }
758
759 std::string error;
760 std::string url;
761 std::string captcha_url;
762 std::string captcha_token;
763 ParseClientLoginFailure(data, &error, &url, &captcha_url, &captcha_token);
764 LOG(WARNING) << "OAuthLogin failed with " << error;
765
766 if (error == kCaptchaErrorCode) {
767 GURL image_url(
768 GaiaUrls::GetInstance()->captcha_base_url().Resolve(captcha_url));
769 GURL unlock_url(url);
770 return GoogleServiceAuthError::FromClientLoginCaptchaChallenge(
771 captcha_token, image_url, unlock_url);
772 }
773 if (error == kAccountDeletedErrorCode)
774 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DELETED);
775 if (error == kAccountDisabledErrorCode)
776 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DISABLED);
777 if (error == kBadAuthenticationErrorCode) {
778 return GoogleServiceAuthError(
779 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
780 }
781 if (error == kServiceUnavailableErrorCode) {
782 return GoogleServiceAuthError(
783 GoogleServiceAuthError::SERVICE_UNAVAILABLE);
784 }
785
786 DLOG(WARNING) << "Incomprehensible response from Google Accounts servers.";
787 return GoogleServiceAuthError(
788 GoogleServiceAuthError::SERVICE_UNAVAILABLE);
789 }
790
791 NOTREACHED();
792 return GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE);
793 }
794
795 void GaiaAuthFetcher::OnClientLoginFetched(const std::string& data, 729 void GaiaAuthFetcher::OnClientLoginFetched(const std::string& data,
796 const net::URLRequestStatus& status, 730 const net::URLRequestStatus& status,
797 int response_code) { 731 int response_code) {
798 if (status.is_success() && response_code == net::HTTP_OK) { 732 if (status.is_success() && response_code == net::HTTP_OK) {
799 DVLOG(1) << "ClientLogin successful!"; 733 DVLOG(1) << "ClientLogin successful!";
800 std::string sid; 734 std::string sid;
801 std::string lsid; 735 std::string lsid;
802 std::string token; 736 std::string token;
803 ParseClientLoginResponse(data, &sid, &lsid, &token); 737 ParseClientLoginResponse(data, &sid, &lsid, &token);
804 consumer_->OnClientLoginSuccess( 738 consumer_->OnClientLoginSuccess(
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 NOTREACHED(); 921 NOTREACHED();
988 } 922 }
989 } 923 }
990 924
991 // static 925 // static
992 bool GaiaAuthFetcher::IsSecondFactorSuccess( 926 bool GaiaAuthFetcher::IsSecondFactorSuccess(
993 const std::string& alleged_error) { 927 const std::string& alleged_error) {
994 return alleged_error.find(kSecondFactor) != 928 return alleged_error.find(kSecondFactor) !=
995 std::string::npos; 929 std::string::npos;
996 } 930 }
OLDNEW
« no previous file with comments | « google_apis/drive/drive_api_parser.cc ('k') | google_apis/gaia/gaia_auth_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698