| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/legacy/supervised_user_refresh_token_fe
tcher.h" | 5 #include "chrome/browser/supervised_user/legacy/supervised_user_refresh_token_fe
tcher.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 const std::string& token); | 101 const std::string& token); |
| 102 OAuth2TokenService* oauth2_token_service_; | 102 OAuth2TokenService* oauth2_token_service_; |
| 103 std::string account_id_; | 103 std::string account_id_; |
| 104 std::string device_id_; | 104 std::string device_id_; |
| 105 URLRequestContextGetter* context_; | 105 URLRequestContextGetter* context_; |
| 106 | 106 |
| 107 std::string device_name_; | 107 std::string device_name_; |
| 108 std::string supervised_user_id_; | 108 std::string supervised_user_id_; |
| 109 TokenCallback callback_; | 109 TokenCallback callback_; |
| 110 | 110 |
| 111 scoped_ptr<OAuth2TokenService::Request> access_token_request_; | 111 std::unique_ptr<OAuth2TokenService::Request> access_token_request_; |
| 112 std::string access_token_; | 112 std::string access_token_; |
| 113 bool access_token_expired_; | 113 bool access_token_expired_; |
| 114 scoped_ptr<URLFetcher> url_fetcher_; | 114 std::unique_ptr<URLFetcher> url_fetcher_; |
| 115 scoped_ptr<GaiaOAuthClient> gaia_oauth_client_; | 115 std::unique_ptr<GaiaOAuthClient> gaia_oauth_client_; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 SupervisedUserRefreshTokenFetcherImpl::SupervisedUserRefreshTokenFetcherImpl( | 118 SupervisedUserRefreshTokenFetcherImpl::SupervisedUserRefreshTokenFetcherImpl( |
| 119 OAuth2TokenService* oauth2_token_service, | 119 OAuth2TokenService* oauth2_token_service, |
| 120 const std::string& account_id, | 120 const std::string& account_id, |
| 121 const std::string& device_id, | 121 const std::string& device_id, |
| 122 URLRequestContextGetter* context) | 122 URLRequestContextGetter* context) |
| 123 : OAuth2TokenService::Consumer("supervised_user"), | 123 : OAuth2TokenService::Consumer("supervised_user"), |
| 124 oauth2_token_service_(oauth2_token_service), | 124 oauth2_token_service_(oauth2_token_service), |
| 125 account_id_(account_id), | 125 account_id_(account_id), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 // TODO(bauerb): We should return the HTTP response code somehow. | 215 // TODO(bauerb): We should return the HTTP response code somehow. |
| 216 DLOG(WARNING) << "HTTP error " << response_code; | 216 DLOG(WARNING) << "HTTP error " << response_code; |
| 217 DispatchGoogleServiceAuthError( | 217 DispatchGoogleServiceAuthError( |
| 218 GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED), | 218 GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED), |
| 219 std::string()); | 219 std::string()); |
| 220 return; | 220 return; |
| 221 } | 221 } |
| 222 | 222 |
| 223 std::string response_body; | 223 std::string response_body; |
| 224 source->GetResponseAsString(&response_body); | 224 source->GetResponseAsString(&response_body); |
| 225 scoped_ptr<base::Value> value = base::JSONReader::Read(response_body); | 225 std::unique_ptr<base::Value> value = base::JSONReader::Read(response_body); |
| 226 base::DictionaryValue* dict = NULL; | 226 base::DictionaryValue* dict = NULL; |
| 227 if (!value.get() || !value->GetAsDictionary(&dict)) { | 227 if (!value.get() || !value->GetAsDictionary(&dict)) { |
| 228 DispatchNetworkError(net::ERR_INVALID_RESPONSE); | 228 DispatchNetworkError(net::ERR_INVALID_RESPONSE); |
| 229 return; | 229 return; |
| 230 } | 230 } |
| 231 std::string auth_code; | 231 std::string auth_code; |
| 232 if (!dict->GetString(kCodeKey, &auth_code)) { | 232 if (!dict->GetString(kCodeKey, &auth_code)) { |
| 233 DispatchNetworkError(net::ERR_INVALID_RESPONSE); | 233 DispatchNetworkError(net::ERR_INVALID_RESPONSE); |
| 234 return; | 234 return; |
| 235 } | 235 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 void SupervisedUserRefreshTokenFetcherImpl::DispatchGoogleServiceAuthError( | 282 void SupervisedUserRefreshTokenFetcherImpl::DispatchGoogleServiceAuthError( |
| 283 const GoogleServiceAuthError& error, | 283 const GoogleServiceAuthError& error, |
| 284 const std::string& token) { | 284 const std::string& token) { |
| 285 callback_.Run(error, token); | 285 callback_.Run(error, token); |
| 286 callback_.Reset(); | 286 callback_.Reset(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 } // namespace | 289 } // namespace |
| 290 | 290 |
| 291 // static | 291 // static |
| 292 scoped_ptr<SupervisedUserRefreshTokenFetcher> | 292 std::unique_ptr<SupervisedUserRefreshTokenFetcher> |
| 293 SupervisedUserRefreshTokenFetcher::Create( | 293 SupervisedUserRefreshTokenFetcher::Create( |
| 294 OAuth2TokenService* oauth2_token_service, | 294 OAuth2TokenService* oauth2_token_service, |
| 295 const std::string& account_id, | 295 const std::string& account_id, |
| 296 const std::string& device_id, | 296 const std::string& device_id, |
| 297 URLRequestContextGetter* context) { | 297 URLRequestContextGetter* context) { |
| 298 scoped_ptr<SupervisedUserRefreshTokenFetcher> fetcher( | 298 std::unique_ptr<SupervisedUserRefreshTokenFetcher> fetcher( |
| 299 new SupervisedUserRefreshTokenFetcherImpl(oauth2_token_service, | 299 new SupervisedUserRefreshTokenFetcherImpl( |
| 300 account_id, | 300 oauth2_token_service, account_id, device_id, context)); |
| 301 device_id, | |
| 302 context)); | |
| 303 return fetcher; | 301 return fetcher; |
| 304 } | 302 } |
| 305 | 303 |
| 306 SupervisedUserRefreshTokenFetcher::~SupervisedUserRefreshTokenFetcher() {} | 304 SupervisedUserRefreshTokenFetcher::~SupervisedUserRefreshTokenFetcher() {} |
| OLD | NEW |