OLD | NEW |
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 20 matching lines...) Expand all Loading... |
31 // through to the target Consumer unless the refresh token validation is | 31 // through to the target Consumer unless the refresh token validation is |
32 // complete. Additionally derives from the RequestImpl, so that it | 32 // complete. Additionally derives from the RequestImpl, so that it |
33 // can be passed back to the caller and directly deleted when cancelling | 33 // can be passed back to the caller and directly deleted when cancelling |
34 // the request. | 34 // the request. |
35 class DeviceOAuth2TokenService::ValidatingConsumer | 35 class DeviceOAuth2TokenService::ValidatingConsumer |
36 : public OAuth2TokenService::Consumer, | 36 : public OAuth2TokenService::Consumer, |
37 public OAuth2TokenService::RequestImpl, | 37 public OAuth2TokenService::RequestImpl, |
38 public gaia::GaiaOAuthClient::Delegate { | 38 public gaia::GaiaOAuthClient::Delegate { |
39 public: | 39 public: |
40 explicit ValidatingConsumer(DeviceOAuth2TokenService* token_service, | 40 explicit ValidatingConsumer(DeviceOAuth2TokenService* token_service, |
| 41 const std::string& account_id, |
41 Consumer* consumer); | 42 Consumer* consumer); |
42 virtual ~ValidatingConsumer(); | 43 virtual ~ValidatingConsumer(); |
43 | 44 |
44 void StartValidation(); | 45 void StartValidation(); |
45 | 46 |
46 // OAuth2TokenService::Consumer | 47 // OAuth2TokenService::Consumer |
47 virtual void OnGetTokenSuccess( | 48 virtual void OnGetTokenSuccess( |
48 const Request* request, | 49 const Request* request, |
49 const std::string& access_token, | 50 const std::string& access_token, |
50 const base::Time& expiration_time) OVERRIDE; | 51 const base::Time& expiration_time) OVERRIDE; |
(...skipping 27 matching lines...) Expand all Loading... |
78 | 79 |
79 // OAuth2TokenService::Consumer results | 80 // OAuth2TokenService::Consumer results |
80 bool token_fetch_done_; | 81 bool token_fetch_done_; |
81 std::string access_token_; | 82 std::string access_token_; |
82 base::Time expiration_time_; | 83 base::Time expiration_time_; |
83 scoped_ptr<GoogleServiceAuthError> error_; | 84 scoped_ptr<GoogleServiceAuthError> error_; |
84 }; | 85 }; |
85 | 86 |
86 DeviceOAuth2TokenService::ValidatingConsumer::ValidatingConsumer( | 87 DeviceOAuth2TokenService::ValidatingConsumer::ValidatingConsumer( |
87 DeviceOAuth2TokenService* token_service, | 88 DeviceOAuth2TokenService* token_service, |
| 89 const std::string& account_id, |
88 Consumer* consumer) | 90 Consumer* consumer) |
89 : OAuth2TokenService::RequestImpl(this), | 91 : OAuth2TokenService::RequestImpl(account_id, this), |
90 token_service_(token_service), | 92 token_service_(token_service), |
91 consumer_(consumer), | 93 consumer_(consumer), |
92 token_validation_done_(false), | 94 token_validation_done_(false), |
93 token_is_valid_(false), | 95 token_is_valid_(false), |
94 token_fetch_done_(false) { | 96 token_fetch_done_(false) { |
95 } | 97 } |
96 | 98 |
97 DeviceOAuth2TokenService::ValidatingConsumer::~ValidatingConsumer() { | 99 DeviceOAuth2TokenService::ValidatingConsumer::~ValidatingConsumer() { |
98 } | 100 } |
99 | 101 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 return connector->GetDeviceCloudPolicyManager()->GetRobotAccountId(); | 271 return connector->GetDeviceCloudPolicyManager()->GetRobotAccountId(); |
270 return std::string(); | 272 return std::string(); |
271 } | 273 } |
272 | 274 |
273 net::URLRequestContextGetter* DeviceOAuth2TokenService::GetRequestContext() { | 275 net::URLRequestContextGetter* DeviceOAuth2TokenService::GetRequestContext() { |
274 return url_request_context_getter_.get(); | 276 return url_request_context_getter_.get(); |
275 } | 277 } |
276 | 278 |
277 scoped_ptr<OAuth2TokenService::RequestImpl> | 279 scoped_ptr<OAuth2TokenService::RequestImpl> |
278 DeviceOAuth2TokenService::CreateRequest( | 280 DeviceOAuth2TokenService::CreateRequest( |
| 281 const std::string& account_id, |
279 OAuth2TokenService::Consumer* consumer) { | 282 OAuth2TokenService::Consumer* consumer) { |
280 if (refresh_token_is_valid_) | 283 if (refresh_token_is_valid_) |
281 return OAuth2TokenService::CreateRequest(consumer); | 284 return OAuth2TokenService::CreateRequest(account_id, consumer); |
282 | 285 |
283 // Substitute our own consumer to wait for refresh token validation. | 286 // Substitute our own consumer to wait for refresh token validation. |
284 scoped_ptr<ValidatingConsumer> validating_consumer( | 287 scoped_ptr<ValidatingConsumer> validating_consumer( |
285 new ValidatingConsumer(this, consumer)); | 288 new ValidatingConsumer(this, account_id, consumer)); |
286 validating_consumer->StartValidation(); | 289 validating_consumer->StartValidation(); |
287 return validating_consumer.PassAs<RequestImpl>(); | 290 return validating_consumer.PassAs<RequestImpl>(); |
288 } | 291 } |
289 | 292 |
290 } // namespace chromeos | 293 } // namespace chromeos |
OLD | NEW |