diff options
author | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-26 00:24:15 +0000 |
---|---|---|
committer | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-26 00:24:15 +0000 |
commit | 2c971877da9e062137a6c736165cf4ef98c962a6 (patch) | |
tree | f0cfa6eae47d4aeafb30554c5aa28c6a856d2c8e | |
parent | 24fb0cf39d71a15d6954d45102830fa1d1d790f6 (diff) | |
download | chromium_src-2c971877da9e062137a6c736165cf4ef98c962a6.zip chromium_src-2c971877da9e062137a6c736165cf4ef98c962a6.tar.gz chromium_src-2c971877da9e062137a6c736165cf4ef98c962a6.tar.bz2 |
Addressed remaining comments from http://codereview.chromium.org/7464021/.
BUG=chromium-os:17859
TEST=none
Review URL: http://codereview.chromium.org/7508004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94003 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/login/login_utils.cc | 8 | ||||
-rw-r--r-- | chrome/browser/net/gaia/gaia_oauth_fetcher.cc | 21 | ||||
-rw-r--r-- | chrome/browser/net/gaia/gaia_oauth_fetcher.h | 23 |
3 files changed, 24 insertions, 28 deletions
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index 4ee3742..3eaa808 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -188,7 +188,7 @@ class PolicyOAuthFetcher : public GaiaOAuthConsumer { kServiceScopeChromeOSDeviceManagement), oauth1_token_(oauth1_token), oauth1_secret_(oauth1_secret) { - oauth_fetcher_.SetAutoFetchMask( + oauth_fetcher_.SetAutoFetchLimit( GaiaOAuthFetcher::OAUTH2_SERVICE_ACCESS_TOKEN); } virtual ~PolicyOAuthFetcher() {} @@ -432,6 +432,8 @@ void LoginUtilsImpl::OnProfileCreated(Profile* profile, Status status) { // Fetch OAuth tokens. Use off-the-record profile that was used for // authentication step. It should already contain all needed cookies // that will let us skip GAIA's user authentication. + // + // TODO(rickcam) We should use an isolated App here. FetchOAuthTokens(authenticator_->AuthenticationProfile()); } else { // We don't need authenticator instance any more, reset it so that @@ -514,9 +516,7 @@ void LoginUtilsImpl::FetchOAuthTokens(Profile* profile) { // Let's first get the Oauth request token and OAuth1 token+secret. // One we get that, we will kick off individial requests for OAuth2 tokens for // all our services. - oauth_fetcher_->SetAutoFetchMask( - GaiaOAuthFetcher::OAUTH1_REQUEST_TOKEN | - GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); + oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); oauth_fetcher_->StartGetOAuthTokenRequest(); } diff --git a/chrome/browser/net/gaia/gaia_oauth_fetcher.cc b/chrome/browser/net/gaia/gaia_oauth_fetcher.cc index 9ea2ddc..168b5ca 100644 --- a/chrome/browser/net/gaia/gaia_oauth_fetcher.cc +++ b/chrome/browser/net/gaia/gaia_oauth_fetcher.cc @@ -60,7 +60,7 @@ GaiaOAuthFetcher::GaiaOAuthFetcher(GaiaOAuthConsumer* consumer, service_scope_(service_scope), popup_(NULL), fetch_pending_(false), - auto_fetch_mask_(ALL_OAUTH_STEPS) {} + auto_fetch_limit_(ALL_OAUTH_STEPS) {} GaiaOAuthFetcher::~GaiaOAuthFetcher() {} @@ -107,10 +107,10 @@ URLFetcher* GaiaOAuthFetcher::CreateGaiaFetcher( // static GURL GaiaOAuthFetcher::MakeGetOAuthTokenUrl( - const char* auth1LoginScope, + const char* oauth1_login_scope, const std::string& product_name) { return GURL(std::string(kGetOAuthTokenUrl) + - "?scope=" + auth1LoginScope + + "?scope=" + oauth1_login_scope + "&xoauth_display_name=" + OAuthRequestSigner::Encode(product_name)); } @@ -152,7 +152,7 @@ std::string GaiaOAuthFetcher::MakeOAuthWrapBridgeBody( "anonymous", // oauth_consumer_key "anonymous", // consumer secret oauth1_access_token, // oauth_token - oauth1_access_token_secret, // token secret + oauth1_access_token_secret, // token secret &signed_request); DCHECK(is_signed); return signed_request; @@ -463,7 +463,7 @@ void GaiaOAuthFetcher::OnGetOAuthTokenFetched(const std::string& token) { popped_up->CloseWindow(); } consumer_->OnGetOAuthTokenSuccess(token); - if (ShouldFetch(OAUTH1_ALL_ACCESS_TOKEN)) + if (ShouldAutoFetch(OAUTH1_ALL_ACCESS_TOKEN)) StartOAuthGetAccessToken(token); } @@ -478,7 +478,7 @@ void GaiaOAuthFetcher::OnGetOAuthTokenUrlFetched( if (cookie.Name() == kOAuthTokenCookie) { std::string token = cookie.Value(); consumer_->OnGetOAuthTokenSuccess(token); - if (ShouldFetch(OAUTH1_ALL_ACCESS_TOKEN)) + if (ShouldAutoFetch(OAUTH1_ALL_ACCESS_TOKEN)) StartOAuthGetAccessToken(token); return; } @@ -497,7 +497,7 @@ void GaiaOAuthFetcher::OnOAuthGetAccessTokenFetched( std::string token; ParseOAuthGetAccessTokenResponse(data, &token, &secret); consumer_->OnOAuthGetAccessTokenSuccess(token, secret); - if (ShouldFetch(OAUTH2_SERVICE_ACCESS_TOKEN)) + if (ShouldAutoFetch(OAUTH2_SERVICE_ACCESS_TOKEN)) StartOAuthWrapBridge(token, secret, "3600", service_scope_); } else { consumer_->OnOAuthGetAccessTokenFailure(GenerateAuthError(data, status)); @@ -513,7 +513,7 @@ void GaiaOAuthFetcher::OnOAuthWrapBridgeFetched( std::string expires_in; ParseOAuthWrapBridgeResponse(data, &token, &expires_in); consumer_->OnOAuthWrapBridgeSuccess(token, expires_in); - if (ShouldFetch(USER_INFO)) + if (ShouldAutoFetch(USER_INFO)) StartUserInfo(token); } else { consumer_->OnOAuthWrapBridgeFailure(GenerateAuthError(data, status)); @@ -553,7 +553,6 @@ void GaiaOAuthFetcher::OnURLFetchComplete(const URLFetcher* source, } } -bool GaiaOAuthFetcher::ShouldFetch(AutoFetchFlags fetch_flag) { - return (auto_fetch_mask_ & static_cast<int>(fetch_flag)) == - static_cast<int>(fetch_flag); +bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { + return fetch_step <= auto_fetch_limit_; } diff --git a/chrome/browser/net/gaia/gaia_oauth_fetcher.h b/chrome/browser/net/gaia/gaia_oauth_fetcher.h index 325c20f..d796e95 100644 --- a/chrome/browser/net/gaia/gaia_oauth_fetcher.h +++ b/chrome/browser/net/gaia/gaia_oauth_fetcher.h @@ -43,15 +43,12 @@ class GaiaOAuthFetcher : public URLFetcher::Delegate, public: // Defines steps of OAuth process performed by this class. typedef enum { - OAUTH1_REQUEST_TOKEN = 1 << 0, - OAUTH1_ALL_ACCESS_TOKEN = 1 << 1, - OAUTH2_SERVICE_ACCESS_TOKEN = 1 << 2, - USER_INFO = 1 << 3, - ALL_OAUTH_STEPS = OAUTH1_REQUEST_TOKEN | - OAUTH1_ALL_ACCESS_TOKEN | - OAUTH2_SERVICE_ACCESS_TOKEN | - USER_INFO, - } AutoFetchFlags; + OAUTH1_REQUEST_TOKEN, + OAUTH1_ALL_ACCESS_TOKEN, + OAUTH2_SERVICE_ACCESS_TOKEN, + USER_INFO, + ALL_OAUTH_STEPS, + } AutoFetchLimit; GaiaOAuthFetcher(GaiaOAuthConsumer* consumer, net::URLRequestContextGetter* getter, @@ -63,7 +60,7 @@ class GaiaOAuthFetcher : public URLFetcher::Delegate, // Sets the mask of which OAuth fetch steps should be automatically kicked // of upon successful completition of the previous steps. By default, // this class will chain all steps in OAuth proccess. - void SetAutoFetchMask(int mask) { auto_fetch_mask_ = mask; } + void SetAutoFetchLimit(AutoFetchLimit limit) { auto_fetch_limit_ = limit; } // Obtains an OAuth 1 request token // @@ -178,7 +175,7 @@ class GaiaOAuthFetcher : public URLFetcher::Delegate, const net::URLRequestStatus& status); // Given parameters, create a OAuth v1 request URL. - static GURL MakeGetOAuthTokenUrl(const char* auth1LoginScope, + static GURL MakeGetOAuthTokenUrl(const char* oauth1_login_scope, const std::string& product_name); // Given parameters, create a OAuthGetAccessToken request body. @@ -203,7 +200,7 @@ class GaiaOAuthFetcher : public URLFetcher::Delegate, bool send_cookies, URLFetcher::Delegate* delegate); - bool ShouldFetch(AutoFetchFlags fetch_flag); + bool ShouldAutoFetch(AutoFetchLimit fetch_step); // These fields are common to GaiaOAuthFetcher, same every request GaiaOAuthConsumer* const consumer_; @@ -218,7 +215,7 @@ class GaiaOAuthFetcher : public URLFetcher::Delegate, std::string request_body_; std::string request_headers_; bool fetch_pending_; - int auto_fetch_mask_; + AutoFetchLimit auto_fetch_limit_; DISALLOW_COPY_AND_ASSIGN(GaiaOAuthFetcher); }; |