| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 DLOG(WARNING) << "Could not reach Google Accounts servers: errno " | 53 DLOG(WARNING) << "Could not reach Google Accounts servers: errno " |
| 54 << status.error(); | 54 << status.error(); |
| 55 return GoogleServiceAuthError::FromConnectionError(status.error()); | 55 return GoogleServiceAuthError::FromConnectionError(status.error()); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 static URLFetcher* CreateFetcher(URLRequestContextGetter* getter, | 59 static URLFetcher* CreateFetcher(URLRequestContextGetter* getter, |
| 60 const GURL& url, | 60 const GURL& url, |
| 61 const std::string& body, | 61 const std::string& body, |
| 62 URLFetcherDelegate* delegate) { | 62 URLFetcherDelegate* delegate) { |
| 63 static int fetcher_index = 0; |
| 63 bool empty_body = body.empty(); | 64 bool empty_body = body.empty(); |
| 64 URLFetcher* result = net::URLFetcher::Create( | 65 URLFetcher* result = net::URLFetcher::Create( |
| 65 0, url, | 66 fetcher_index++, url, |
| 66 empty_body ? URLFetcher::GET : URLFetcher::POST, | 67 empty_body ? URLFetcher::GET : URLFetcher::POST, |
| 67 delegate); | 68 delegate); |
| 68 | 69 |
| 69 result->SetRequestContext(getter); | 70 result->SetRequestContext(getter); |
| 70 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 71 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 71 net::LOAD_DO_NOT_SAVE_COOKIES); | 72 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 72 // Fetchers are sometimes cancelled because a network change was detected, | 73 // Fetchers are sometimes cancelled because a network change was detected, |
| 73 // especially at startup and after sign-in on ChromeOS. Retrying once should | 74 // especially at startup and after sign-in on ChromeOS. Retrying once should |
| 74 // be enough in those cases; let the fetcher retry up to 3 times just in case. | 75 // be enough in those cases; let the fetcher retry up to 3 times just in case. |
| 75 // http://crbug.com/163710 | 76 // http://crbug.com/163710 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 source->GetResponseAsString(&data); | 225 source->GetResponseAsString(&data); |
| 225 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | 226 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); |
| 226 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) | 227 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) |
| 227 return false; | 228 return false; |
| 228 | 229 |
| 229 base::DictionaryValue* dict = | 230 base::DictionaryValue* dict = |
| 230 static_cast<base::DictionaryValue*>(value.get()); | 231 static_cast<base::DictionaryValue*>(value.get()); |
| 231 return dict->GetString(kAccessTokenKey, access_token) && | 232 return dict->GetString(kAccessTokenKey, access_token) && |
| 232 dict->GetInteger(kExpiresInKey, expires_in); | 233 dict->GetInteger(kExpiresInKey, expires_in); |
| 233 } | 234 } |
| OLD | NEW |