| 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 "google_apis/gaia/oauth2_api_call_flow.h" | 5 #include "google_apis/gaia/oauth2_api_call_flow.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "google_apis/gaia/gaia_urls.h" | 12 #include "google_apis/gaia/gaia_urls.h" |
| 13 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h" |
| 13 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
| 14 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
| 15 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
| 16 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
| 17 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| 18 #include "net/url_request/url_request_status.h" | 19 #include "net/url_request/url_request_status.h" |
| 19 | 20 |
| 20 using net::ResponseCookies; | 21 using net::ResponseCookies; |
| 21 using net::URLFetcher; | 22 using net::URLFetcher; |
| 22 using net::URLFetcherDelegate; | 23 using net::URLFetcherDelegate; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 CHECK(state_ == INITIAL || state_ == API_CALL_DONE); | 103 CHECK(state_ == INITIAL || state_ == API_CALL_DONE); |
| 103 CHECK(!tried_mint_access_token_); | 104 CHECK(!tried_mint_access_token_); |
| 104 state_ = MINT_ACCESS_TOKEN_STARTED; | 105 state_ = MINT_ACCESS_TOKEN_STARTED; |
| 105 tried_mint_access_token_ = true; | 106 tried_mint_access_token_ = true; |
| 106 | 107 |
| 107 oauth2_access_token_fetcher_.reset(CreateAccessTokenFetcher()); | 108 oauth2_access_token_fetcher_.reset(CreateAccessTokenFetcher()); |
| 108 oauth2_access_token_fetcher_->Start( | 109 oauth2_access_token_fetcher_->Start( |
| 109 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), | 110 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), |
| 110 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), | 111 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), |
| 111 refresh_token_, | 112 refresh_token_, |
| 112 scopes_); | 113 scopes_, |
| 114 this); |
| 113 } | 115 } |
| 114 | 116 |
| 115 void OAuth2ApiCallFlow::EndMintAccessToken( | 117 void OAuth2ApiCallFlow::EndMintAccessToken( |
| 116 const GoogleServiceAuthError* error) { | 118 const GoogleServiceAuthError* error) { |
| 117 CHECK_EQ(MINT_ACCESS_TOKEN_STARTED, state_); | 119 CHECK_EQ(MINT_ACCESS_TOKEN_STARTED, state_); |
| 118 | 120 |
| 119 if (!error) { | 121 if (!error) { |
| 120 state_ = MINT_ACCESS_TOKEN_DONE; | 122 state_ = MINT_ACCESS_TOKEN_DONE; |
| 121 BeginApiCall(); | 123 BeginApiCall(); |
| 122 } else { | 124 } else { |
| 123 state_ = ERROR_STATE; | 125 state_ = ERROR_STATE; |
| 124 ProcessMintAccessTokenFailure(*error); | 126 ProcessMintAccessTokenFailure(*error); |
| 125 } | 127 } |
| 126 } | 128 } |
| 127 | 129 |
| 128 OAuth2AccessTokenFetcher* OAuth2ApiCallFlow::CreateAccessTokenFetcher() { | 130 OAuth2AccessTokenFetcher* OAuth2ApiCallFlow::CreateAccessTokenFetcher() { |
| 129 return new OAuth2AccessTokenFetcher(this, context_); | 131 return new OAuth2AccessTokenFetcherImpl(context_); |
| 130 } | 132 } |
| 131 | 133 |
| 132 void OAuth2ApiCallFlow::OnURLFetchComplete(const net::URLFetcher* source) { | 134 void OAuth2ApiCallFlow::OnURLFetchComplete(const net::URLFetcher* source) { |
| 133 CHECK(source); | 135 CHECK(source); |
| 134 CHECK_EQ(API_CALL_STARTED, state_); | 136 CHECK_EQ(API_CALL_STARTED, state_); |
| 135 EndApiCall(source); | 137 EndApiCall(source); |
| 136 } | 138 } |
| 137 | 139 |
| 138 void OAuth2ApiCallFlow::OnGetTokenSuccess(const std::string& access_token, | 140 void OAuth2ApiCallFlow::OnGetTokenSuccess(const std::string& access_token, |
| 139 const base::Time& expiration_time) { | 141 const base::Time& expiration_time) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 163 // especially at startup and after sign-in on ChromeOS. Retrying once should | 165 // especially at startup and after sign-in on ChromeOS. Retrying once should |
| 164 // be enough in those cases; let the fetcher retry up to 3 times just in case. | 166 // be enough in those cases; let the fetcher retry up to 3 times just in case. |
| 165 // http://crbug.com/163710 | 167 // http://crbug.com/163710 |
| 166 result->SetAutomaticallyRetryOnNetworkChanges(3); | 168 result->SetAutomaticallyRetryOnNetworkChanges(3); |
| 167 | 169 |
| 168 if (!empty_body) | 170 if (!empty_body) |
| 169 result->SetUploadData("application/x-www-form-urlencoded", body); | 171 result->SetUploadData("application/x-www-form-urlencoded", body); |
| 170 | 172 |
| 171 return result; | 173 return result; |
| 172 } | 174 } |
| OLD | NEW |