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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 DCHECK(access_token_callback_.is_null()); | 45 DCHECK(access_token_callback_.is_null()); |
46 | 46 |
47 VLOG(2) << "Calling GetTokensFromAuthCode to exchange auth_code for token"; | 47 VLOG(2) << "Calling GetTokensFromAuthCode to exchange auth_code for token"; |
48 | 48 |
49 access_token_.clear(); | 49 access_token_.clear(); |
50 refresh_token_.clear(); | 50 refresh_token_.clear(); |
51 access_token_callback_ = callback; | 51 access_token_callback_ = callback; |
52 | 52 |
53 // Create a new GaiaOAuthClient for each request to GAIA. | 53 // Create a new GaiaOAuthClient for each request to GAIA. |
54 CreateNewGaiaOAuthClientInstance(); | 54 CreateNewGaiaOAuthClientInstance(); |
55 auth_client_->GetTokensFromAuthCode( | 55 auth_client_->GetTokensFromAuthCode(oauth_client_info_, auth_code, |
56 oauth_client_info_, auth_code, kMaxGetTokensRetries, | 56 kMaxGetTokensRetries, |
57 this); // GaiaOAuthClient::Delegate* delegate | 57 /*delegate=*/this); |
58 } | 58 } |
59 | 59 |
60 void AccessTokenFetcher::GetAccessTokenFromRefreshToken( | 60 void AccessTokenFetcher::GetAccessTokenFromRefreshToken( |
61 const std::string& refresh_token, | 61 const std::string& refresh_token, |
62 const AccessTokenCallback& callback) { | 62 const AccessTokenCallback& callback) { |
63 DCHECK(!refresh_token.empty()); | 63 DCHECK(!refresh_token.empty()); |
64 DCHECK(!callback.is_null()); | 64 DCHECK(!callback.is_null()); |
65 DCHECK(access_token_callback_.is_null()); | 65 DCHECK(access_token_callback_.is_null()); |
66 | 66 |
67 VLOG(2) << "Calling RefreshToken to generate a new access token"; | 67 VLOG(2) << "Calling RefreshToken to generate a new access token"; |
68 | 68 |
69 access_token_.clear(); | 69 access_token_.clear(); |
70 refresh_token_ = refresh_token; | 70 refresh_token_ = refresh_token; |
71 access_token_callback_ = callback; | 71 access_token_callback_ = callback; |
72 | 72 |
73 // Create a new GaiaOAuthClient for each request to GAIA. | 73 // Create a new GaiaOAuthClient for each request to GAIA. |
74 CreateNewGaiaOAuthClientInstance(); | 74 CreateNewGaiaOAuthClientInstance(); |
75 auth_client_->RefreshToken(oauth_client_info_, refresh_token_, | 75 auth_client_->RefreshToken(oauth_client_info_, refresh_token_, |
76 std::vector<std::string>(), // scopes | 76 /*scopes=*/std::vector<std::string>(), |
77 kMaxGetTokensRetries, | 77 kMaxGetTokensRetries, |
78 this); // GaiaOAuthClient::Delegate* delegate | 78 /*delegate=*/this); |
79 } | 79 } |
80 | 80 |
81 void AccessTokenFetcher::CreateNewGaiaOAuthClientInstance() { | 81 void AccessTokenFetcher::CreateNewGaiaOAuthClientInstance() { |
82 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter; | 82 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter; |
83 request_context_getter = new remoting::URLRequestContextGetter( | 83 request_context_getter = new remoting::URLRequestContextGetter( |
84 base::ThreadTaskRunnerHandle::Get(), // network_runner | 84 base::ThreadTaskRunnerHandle::Get(), // network_runner |
85 base::ThreadTaskRunnerHandle::Get()); // file_runner | 85 base::ThreadTaskRunnerHandle::Get()); // file_runner |
86 | 86 |
87 auth_client_.reset(new gaia::GaiaOAuthClient(request_context_getter.get())); | 87 auth_client_.reset(new gaia::GaiaOAuthClient(request_context_getter.get())); |
88 } | 88 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 base::ResetAndReturn(&access_token_callback_) | 174 base::ResetAndReturn(&access_token_callback_) |
175 .Run(access_token_, refresh_token_); | 175 .Run(access_token_, refresh_token_); |
176 } | 176 } |
177 | 177 |
178 void AccessTokenFetcher::ValidateAccessToken() { | 178 void AccessTokenFetcher::ValidateAccessToken() { |
179 VLOG(2) << "Calling GetTokenInfo to validate access token"; | 179 VLOG(2) << "Calling GetTokenInfo to validate access token"; |
180 | 180 |
181 // Create a new GaiaOAuthClient for each request to GAIA. | 181 // Create a new GaiaOAuthClient for each request to GAIA. |
182 CreateNewGaiaOAuthClientInstance(); | 182 CreateNewGaiaOAuthClientInstance(); |
183 auth_client_->GetTokenInfo(access_token_, kMaxGetTokensRetries, | 183 auth_client_->GetTokenInfo(access_token_, kMaxGetTokensRetries, |
184 this); // GaiaOAuthClient::Delegate* delegate | 184 /*delegate=*/this); |
185 } | 185 } |
186 | 186 |
187 } // namespace test | 187 } // namespace test |
188 } // namespace remoting | 188 } // namespace remoting |
OLD | NEW |