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 "google_apis/gaia/oauth2_access_token_fetcher.h" | 5 #include "google_apis/gaia/oauth2_access_token_fetcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 const net::URLFetcher* source) { | 122 const net::URLFetcher* source) { |
123 CHECK_EQ(GET_ACCESS_TOKEN_STARTED, state_); | 123 CHECK_EQ(GET_ACCESS_TOKEN_STARTED, state_); |
124 state_ = GET_ACCESS_TOKEN_DONE; | 124 state_ = GET_ACCESS_TOKEN_DONE; |
125 | 125 |
126 URLRequestStatus status = source->GetStatus(); | 126 URLRequestStatus status = source->GetStatus(); |
127 if (!status.is_success()) { | 127 if (!status.is_success()) { |
128 OnGetTokenFailure(CreateAuthError(status)); | 128 OnGetTokenFailure(CreateAuthError(status)); |
129 return; | 129 return; |
130 } | 130 } |
131 | 131 |
| 132 // HTTP_FORBIDDEN (403) is treated as temporary error, because it may be |
| 133 // '403 Rate Limit Exeeded.' |
| 134 if (source->GetResponseCode() == net::HTTP_FORBIDDEN) { |
| 135 OnGetTokenFailure(GoogleServiceAuthError( |
| 136 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 137 return; |
| 138 } |
| 139 |
| 140 // The other errors are treated as permanent error. |
132 if (source->GetResponseCode() != net::HTTP_OK) { | 141 if (source->GetResponseCode() != net::HTTP_OK) { |
133 OnGetTokenFailure(GoogleServiceAuthError( | 142 OnGetTokenFailure(GoogleServiceAuthError( |
134 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); | 143 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); |
135 return; | 144 return; |
136 } | 145 } |
137 | 146 |
138 // The request was successfully fetched and it returned OK. | 147 // The request was successfully fetched and it returned OK. |
139 // Parse out the access token and the expiration time. | 148 // Parse out the access token and the expiration time. |
140 std::string access_token; | 149 std::string access_token; |
141 int expires_in; | 150 int expires_in; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 std::string data; | 223 std::string data; |
215 source->GetResponseAsString(&data); | 224 source->GetResponseAsString(&data); |
216 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | 225 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); |
217 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) | 226 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) |
218 return false; | 227 return false; |
219 | 228 |
220 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 229 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
221 return dict->GetString(kAccessTokenKey, access_token) && | 230 return dict->GetString(kAccessTokenKey, access_token) && |
222 dict->GetInteger(kExpiresInKey, expires_in); | 231 dict->GetInteger(kExpiresInKey, expires_in); |
223 } | 232 } |
OLD | NEW |