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

Side by Side Diff: chrome/browser/chromeos/settings/device_oauth2_token_service.cc

Issue 23382008: Making OAuth2TokenService multi-login aware, updating callers, minor fixes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding the AndroidPO2TS update Created 7 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 5 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 gaia_oauth_client_.reset(new gaia::GaiaOAuthClient( 108 gaia_oauth_client_.reset(new gaia::GaiaOAuthClient(
109 g_browser_process->system_request_context())); 109 g_browser_process->system_request_context()));
110 110
111 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 111 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
112 gaia::OAuthClientInfo client_info; 112 gaia::OAuthClientInfo client_info;
113 client_info.client_id = gaia_urls->oauth2_chrome_client_id(); 113 client_info.client_id = gaia_urls->oauth2_chrome_client_id();
114 client_info.client_secret = gaia_urls->oauth2_chrome_client_secret(); 114 client_info.client_secret = gaia_urls->oauth2_chrome_client_secret();
115 115
116 gaia_oauth_client_->RefreshToken( 116 gaia_oauth_client_->RefreshToken(
117 client_info, 117 client_info,
118 token_service_->GetRefreshToken(), 118 token_service_->GetRefreshToken(std::string()),
119 std::vector<std::string>(1, kServiceScopeGetUserInfo), 119 std::vector<std::string>(1, kServiceScopeGetUserInfo),
120 token_service_->max_refresh_token_validation_retries_, 120 token_service_->max_refresh_token_validation_retries_,
121 this); 121 this);
122 } 122 }
123 123
124 void DeviceOAuth2TokenService::ValidatingConsumer::OnRefreshTokenResponse( 124 void DeviceOAuth2TokenService::ValidatingConsumer::OnRefreshTokenResponse(
125 const std::string& access_token, 125 const std::string& access_token,
126 int expires_in_seconds) { 126 int expires_in_seconds) {
127 gaia_oauth_client_->GetTokenInfo( 127 gaia_oauth_client_->GetTokenInfo(
128 access_token, 128 access_token,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 : refresh_token_is_valid_(false), 214 : refresh_token_is_valid_(false),
215 max_refresh_token_validation_retries_(3), 215 max_refresh_token_validation_retries_(3),
216 url_request_context_getter_(getter), 216 url_request_context_getter_(getter),
217 local_state_(local_state) { 217 local_state_(local_state) {
218 } 218 }
219 219
220 DeviceOAuth2TokenService::~DeviceOAuth2TokenService() { 220 DeviceOAuth2TokenService::~DeviceOAuth2TokenService() {
221 } 221 }
222 222
223 scoped_ptr<OAuth2TokenService::Request> DeviceOAuth2TokenService::StartRequest( 223 scoped_ptr<OAuth2TokenService::Request> DeviceOAuth2TokenService::StartRequest(
224 const std::string& account_id,
224 const OAuth2TokenService::ScopeSet& scopes, 225 const OAuth2TokenService::ScopeSet& scopes,
225 OAuth2TokenService::Consumer* consumer) { 226 OAuth2TokenService::Consumer* consumer) {
226 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 227 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
Roger Tawa OOO till Jul 10th 2013/08/29 15:41:40 Should we DCHECK that |account_id| is empty? Same
fgorski 2013/08/29 23:04:14 Done.
227 228
228 if (refresh_token_is_valid_) { 229 if (refresh_token_is_valid_) {
229 return OAuth2TokenService::StartRequest(scopes, consumer).Pass(); 230 return OAuth2TokenService::StartRequest(
231 account_id, scopes, consumer).Pass();
230 } else { 232 } else {
231 scoped_ptr<ValidatingConsumer> validating_consumer( 233 scoped_ptr<ValidatingConsumer> validating_consumer(
232 new ValidatingConsumer(this, consumer)); 234 new ValidatingConsumer(this, consumer));
233 235
234 scoped_ptr<Request> request = OAuth2TokenService::StartRequest( 236 scoped_ptr<Request> request = OAuth2TokenService::StartRequest(
235 scopes, validating_consumer.get()); 237 account_id, scopes, validating_consumer.get());
236 validating_consumer->StartValidation(request.Pass()); 238 validating_consumer->StartValidation(request.Pass());
237 return validating_consumer.PassAs<Request>(); 239 return validating_consumer.PassAs<Request>();
238 } 240 }
239 } 241 }
240 242
241 void DeviceOAuth2TokenService::OnValidationComplete( 243 void DeviceOAuth2TokenService::OnValidationComplete(
242 bool refresh_token_is_valid) { 244 bool refresh_token_is_valid) {
243 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 245 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
244 refresh_token_is_valid_ = refresh_token_is_valid; 246 refresh_token_is_valid_ = refresh_token_is_valid;
245 } 247 }
246 248
247 // static 249 // static
248 void DeviceOAuth2TokenService::RegisterPrefs(PrefRegistrySimple* registry) { 250 void DeviceOAuth2TokenService::RegisterPrefs(PrefRegistrySimple* registry) {
249 registry->RegisterStringPref(prefs::kDeviceRobotAnyApiRefreshToken, 251 registry->RegisterStringPref(prefs::kDeviceRobotAnyApiRefreshToken,
250 std::string()); 252 std::string());
251 } 253 }
252 254
253 void DeviceOAuth2TokenService::SetAndSaveRefreshToken( 255 void DeviceOAuth2TokenService::SetAndSaveRefreshToken(
254 const std::string& refresh_token) { 256 const std::string& refresh_token) {
255 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 257 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
256 std::string encrypted_refresh_token = 258 std::string encrypted_refresh_token =
257 CryptohomeLibrary::Get()->EncryptWithSystemSalt(refresh_token); 259 CryptohomeLibrary::Get()->EncryptWithSystemSalt(refresh_token);
258 260
259 local_state_->SetString(prefs::kDeviceRobotAnyApiRefreshToken, 261 local_state_->SetString(prefs::kDeviceRobotAnyApiRefreshToken,
260 encrypted_refresh_token); 262 encrypted_refresh_token);
261 } 263 }
262 264
263 std::string DeviceOAuth2TokenService::GetRefreshToken() { 265 std::string DeviceOAuth2TokenService::GetRefreshToken(
266 const std::string& account_id) {
264 if (refresh_token_.empty()) { 267 if (refresh_token_.empty()) {
265 std::string encrypted_refresh_token = 268 std::string encrypted_refresh_token =
266 local_state_->GetString(prefs::kDeviceRobotAnyApiRefreshToken); 269 local_state_->GetString(prefs::kDeviceRobotAnyApiRefreshToken);
267 270
268 refresh_token_ = CryptohomeLibrary::Get()->DecryptWithSystemSalt( 271 refresh_token_ = CryptohomeLibrary::Get()->DecryptWithSystemSalt(
269 encrypted_refresh_token); 272 encrypted_refresh_token);
270 } 273 }
271 return refresh_token_; 274 return refresh_token_;
272 } 275 }
273 276
274 std::string DeviceOAuth2TokenService::GetRobotAccountId() { 277 std::string DeviceOAuth2TokenService::GetRobotAccountId() {
275 policy::BrowserPolicyConnector* connector = 278 policy::BrowserPolicyConnector* connector =
276 g_browser_process->browser_policy_connector(); 279 g_browser_process->browser_policy_connector();
277 if (connector) 280 if (connector)
278 return connector->GetDeviceCloudPolicyManager()->GetRobotAccountId(); 281 return connector->GetDeviceCloudPolicyManager()->GetRobotAccountId();
279 return std::string(); 282 return std::string();
280 } 283 }
281 284
282 net::URLRequestContextGetter* DeviceOAuth2TokenService::GetRequestContext() { 285 net::URLRequestContextGetter* DeviceOAuth2TokenService::GetRequestContext() {
283 return url_request_context_getter_.get(); 286 return url_request_context_getter_.get();
284 } 287 }
285 288
286 } // namespace chromeos 289 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698