| 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 "chrome/common/net/gaia/oauth2_access_token_fetcher.h" | 5 #include "chrome/common/net/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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 static const char kGetAccessTokenBodyWithScopeFormat[] = | 36 static const char kGetAccessTokenBodyWithScopeFormat[] = |
| 37 "client_id=%s&" | 37 "client_id=%s&" |
| 38 "client_secret=%s&" | 38 "client_secret=%s&" |
| 39 "grant_type=refresh_token&" | 39 "grant_type=refresh_token&" |
| 40 "refresh_token=%s&" | 40 "refresh_token=%s&" |
| 41 "scope=%s"; | 41 "scope=%s"; |
| 42 | 42 |
| 43 static const char kAccessTokenKey[] = "access_token"; | 43 static const char kAccessTokenKey[] = "access_token"; |
| 44 | 44 |
| 45 static bool GetStringFromDictionary(const DictionaryValue* dict, | |
| 46 const std::string& key, | |
| 47 std::string* value) { | |
| 48 Value* json_value; | |
| 49 if (!dict->Get(key, &json_value)) | |
| 50 return false; | |
| 51 if (json_value->GetType() != base::Value::TYPE_STRING) | |
| 52 return false; | |
| 53 | |
| 54 StringValue* json_str_value = static_cast<StringValue*>(json_value); | |
| 55 json_str_value->GetAsString(value); | |
| 56 return true; | |
| 57 } | |
| 58 | |
| 59 static GoogleServiceAuthError CreateAuthError(URLRequestStatus status) { | 45 static GoogleServiceAuthError CreateAuthError(URLRequestStatus status) { |
| 60 CHECK(!status.is_success()); | 46 CHECK(!status.is_success()); |
| 61 if (status.status() == URLRequestStatus::CANCELED) { | 47 if (status.status() == URLRequestStatus::CANCELED) { |
| 62 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); | 48 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); |
| 63 } else { | 49 } else { |
| 64 DLOG(WARNING) << "Could not reach Google Accounts servers: errno " | 50 DLOG(WARNING) << "Could not reach Google Accounts servers: errno " |
| 65 << status.error(); | 51 << status.error(); |
| 66 return GoogleServiceAuthError::FromConnectionError(status.error()); | 52 return GoogleServiceAuthError::FromConnectionError(status.error()); |
| 67 } | 53 } |
| 68 } | 54 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 CHECK(source); | 190 CHECK(source); |
| 205 CHECK(access_token); | 191 CHECK(access_token); |
| 206 std::string data; | 192 std::string data; |
| 207 source->GetResponseAsString(&data); | 193 source->GetResponseAsString(&data); |
| 208 base::JSONReader reader; | 194 base::JSONReader reader; |
| 209 scoped_ptr<base::Value> value(reader.Read(data, false)); | 195 scoped_ptr<base::Value> value(reader.Read(data, false)); |
| 210 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) | 196 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) |
| 211 return false; | 197 return false; |
| 212 | 198 |
| 213 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 199 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
| 214 return GetStringFromDictionary(dict, kAccessTokenKey, access_token); | 200 return dict->GetString(kAccessTokenKey, access_token); |
| 215 } | 201 } |
| OLD | NEW |