| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/host/gaia_oauth_client.h" | 5 #include "remoting/host/gaia_oauth_client.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 void GaiaOAuthClient::Core::HandleResponse( | 131 void GaiaOAuthClient::Core::HandleResponse( |
| 132 const content::URLFetcher* source, | 132 const content::URLFetcher* source, |
| 133 bool* should_retry_request) { | 133 bool* should_retry_request) { |
| 134 *should_retry_request = false; | 134 *should_retry_request = false; |
| 135 // RC_BAD_REQUEST means the arguments are invalid. No point retrying. We are | 135 // RC_BAD_REQUEST means the arguments are invalid. No point retrying. We are |
| 136 // done here. | 136 // done here. |
| 137 if (source->GetResponseCode() == net::HTTP_BAD_REQUEST) { | 137 if (source->GetResponseCode() == net::HTTP_BAD_REQUEST) { |
| 138 LOG(ERROR) << "Gaia response: response code=net::HTTP_BAD_REQUEST."; |
| 138 delegate_->OnOAuthError(); | 139 delegate_->OnOAuthError(); |
| 139 return; | 140 return; |
| 140 } | 141 } |
| 141 std::string access_token; | 142 std::string access_token; |
| 142 std::string refresh_token; | 143 std::string refresh_token; |
| 143 int expires_in_seconds = 0; | 144 int expires_in_seconds = 0; |
| 144 if (source->GetResponseCode() == net::HTTP_OK) { | 145 if (source->GetResponseCode() == net::HTTP_OK) { |
| 145 std::string data; | 146 std::string data; |
| 146 source->GetResponseAsString(&data); | 147 source->GetResponseAsString(&data); |
| 147 scoped_ptr<Value> message_value(base::JSONReader::Read(data)); | 148 scoped_ptr<Value> message_value(base::JSONReader::Read(data)); |
| 148 if (message_value.get() && | 149 if (message_value.get() && |
| 149 message_value->IsType(Value::TYPE_DICTIONARY)) { | 150 message_value->IsType(Value::TYPE_DICTIONARY)) { |
| 150 scoped_ptr<DictionaryValue> response_dict( | 151 scoped_ptr<DictionaryValue> response_dict( |
| 151 static_cast<DictionaryValue*>(message_value.release())); | 152 static_cast<DictionaryValue*>(message_value.release())); |
| 152 response_dict->GetString(kAccessTokenValue, &access_token); | 153 response_dict->GetString(kAccessTokenValue, &access_token); |
| 153 response_dict->GetString(kRefreshTokenValue, &refresh_token); | 154 response_dict->GetString(kRefreshTokenValue, &refresh_token); |
| 154 response_dict->GetInteger(kExpiresInValue, &expires_in_seconds); | 155 response_dict->GetInteger(kExpiresInValue, &expires_in_seconds); |
| 155 } | 156 } |
| 157 VLOG(1) << "Gaia response: acess_token='" << access_token |
| 158 << "', refresh_token='" << refresh_token |
| 159 << "', expires in " << expires_in_seconds << " second(s)"; |
| 160 } else { |
| 161 LOG(ERROR) << "Gaia response: response code=" << source->GetResponseCode(); |
| 156 } | 162 } |
| 157 if (access_token.empty()) { | 163 if (access_token.empty()) { |
| 158 // If we don't have an access token yet and the the error was not | 164 // If we don't have an access token yet and the the error was not |
| 159 // RC_BAD_REQUEST, we may need to retry. | 165 // RC_BAD_REQUEST, we may need to retry. |
| 160 if ((-1 != source->GetMaxRetries()) && | 166 if ((-1 != source->GetMaxRetries()) && |
| 161 (num_retries_ > source->GetMaxRetries())) { | 167 (num_retries_ > source->GetMaxRetries())) { |
| 162 // Retry limit reached. Give up. | 168 // Retry limit reached. Give up. |
| 163 delegate_->OnNetworkError(source->GetResponseCode()); | 169 delegate_->OnNetworkError(source->GetResponseCode()); |
| 164 } else { | 170 } else { |
| 165 *should_retry_request = true; | 171 *should_retry_request = true; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 const std::string& refresh_token, | 204 const std::string& refresh_token, |
| 199 int max_retries, | 205 int max_retries, |
| 200 Delegate* delegate) { | 206 Delegate* delegate) { |
| 201 return core_->RefreshToken(oauth_client_info, | 207 return core_->RefreshToken(oauth_client_info, |
| 202 refresh_token, | 208 refresh_token, |
| 203 max_retries, | 209 max_retries, |
| 204 delegate); | 210 delegate); |
| 205 } | 211 } |
| 206 | 212 |
| 207 } // namespace remoting | 213 } // namespace remoting |
| OLD | NEW |