| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/test/access_token_fetcher.h" | 5 #include "remoting/test/access_token_fetcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 namespace remoting { | 26 namespace remoting { |
| 27 namespace test { | 27 namespace test { |
| 28 | 28 |
| 29 AccessTokenFetcher::AccessTokenFetcher() { | 29 AccessTokenFetcher::AccessTokenFetcher() { |
| 30 oauth_client_info_ = { | 30 oauth_client_info_ = { |
| 31 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING), | 31 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING), |
| 32 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING), | 32 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING), |
| 33 kOauthRedirectUrl}; | 33 kOauthRedirectUrl}; |
| 34 } | 34 } |
| 35 | 35 |
| 36 AccessTokenFetcher::~AccessTokenFetcher() {} | 36 AccessTokenFetcher::~AccessTokenFetcher() { |
| 37 } |
| 37 | 38 |
| 38 void AccessTokenFetcher::GetAccessTokenFromAuthCode( | 39 void AccessTokenFetcher::GetAccessTokenFromAuthCode( |
| 39 const std::string& auth_code, | 40 const std::string& auth_code, |
| 40 const AccessTokenCallback& callback) { | 41 const AccessTokenCallback& callback) { |
| 41 DCHECK(!auth_code.empty()); | 42 DCHECK(!auth_code.empty()); |
| 42 DCHECK(!callback.is_null()); | 43 DCHECK(!callback.is_null()); |
| 43 DCHECK(access_token_callback_.is_null()); | 44 DCHECK(access_token_callback_.is_null()); |
| 44 | 45 |
| 45 DVLOG(2) << "Calling GetTokensFromAuthCode to exchange auth_code for token"; | 46 DVLOG(2) << "Calling GetTokensFromAuthCode to exchange auth_code for token"; |
| 46 | 47 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 63 DCHECK(access_token_callback_.is_null()); | 64 DCHECK(access_token_callback_.is_null()); |
| 64 | 65 |
| 65 DVLOG(2) << "Calling RefreshToken to generate a new access token"; | 66 DVLOG(2) << "Calling RefreshToken to generate a new access token"; |
| 66 | 67 |
| 67 access_token_.clear(); | 68 access_token_.clear(); |
| 68 refresh_token_ = refresh_token; | 69 refresh_token_ = refresh_token; |
| 69 access_token_callback_ = callback; | 70 access_token_callback_ = callback; |
| 70 | 71 |
| 71 // Create a new GaiaOAuthClient for each request to GAIA. | 72 // Create a new GaiaOAuthClient for each request to GAIA. |
| 72 CreateNewGaiaOAuthClientInstance(); | 73 CreateNewGaiaOAuthClientInstance(); |
| 73 auth_client_->RefreshToken( | 74 auth_client_->RefreshToken(oauth_client_info_, refresh_token_, |
| 74 oauth_client_info_, | 75 std::vector<std::string>(), // scopes |
| 75 refresh_token_, | 76 kMaxGetTokensRetries, |
| 76 std::vector<std::string>(), // scopes | 77 this); // GaiaOAuthClient::Delegate* delegate |
| 77 kMaxGetTokensRetries, | |
| 78 this); // GaiaOAuthClient::Delegate* delegate | |
| 79 } | 78 } |
| 80 | 79 |
| 81 void AccessTokenFetcher::CreateNewGaiaOAuthClientInstance() { | 80 void AccessTokenFetcher::CreateNewGaiaOAuthClientInstance() { |
| 82 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter; | 81 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter; |
| 83 request_context_getter = new remoting::URLRequestContextGetter( | 82 request_context_getter = new remoting::URLRequestContextGetter( |
| 84 base::ThreadTaskRunnerHandle::Get(), // network_runner | 83 base::ThreadTaskRunnerHandle::Get(), // network_runner |
| 85 base::ThreadTaskRunnerHandle::Get()); // file_runner | 84 base::ThreadTaskRunnerHandle::Get()); // file_runner |
| 86 | 85 |
| 87 auth_client_.reset(new gaia::GaiaOAuthClient(request_context_getter.get())); | 86 auth_client_.reset(new gaia::GaiaOAuthClient(request_context_getter.get())); |
| 88 } | 87 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 172 |
| 174 access_token_callback_.Run(access_token_, refresh_token_); | 173 access_token_callback_.Run(access_token_, refresh_token_); |
| 175 access_token_callback_.Reset(); | 174 access_token_callback_.Reset(); |
| 176 } | 175 } |
| 177 | 176 |
| 178 void AccessTokenFetcher::ValidateAccessToken() { | 177 void AccessTokenFetcher::ValidateAccessToken() { |
| 179 DVLOG(2) << "Calling GetTokenInfo to validate access token"; | 178 DVLOG(2) << "Calling GetTokenInfo to validate access token"; |
| 180 | 179 |
| 181 // Create a new GaiaOAuthClient for each request to GAIA. | 180 // Create a new GaiaOAuthClient for each request to GAIA. |
| 182 CreateNewGaiaOAuthClientInstance(); | 181 CreateNewGaiaOAuthClientInstance(); |
| 183 auth_client_->GetTokenInfo( | 182 auth_client_->GetTokenInfo(access_token_, kMaxGetTokensRetries, |
| 184 access_token_, | 183 this); // GaiaOAuthClient::Delegate* delegate |
| 185 kMaxGetTokensRetries, | |
| 186 this); // GaiaOAuthClient::Delegate* delegate | |
| 187 } | 184 } |
| 188 | 185 |
| 189 } // namespace test | 186 } // namespace test |
| 190 } // namespace remoting | 187 } // namespace remoting |
| OLD | NEW |