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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 URLFetcherDelegate* delegate) { | 62 URLFetcherDelegate* delegate) { |
63 bool empty_body = body.empty(); | 63 bool empty_body = body.empty(); |
64 URLFetcher* result = net::URLFetcher::Create( | 64 URLFetcher* result = net::URLFetcher::Create( |
65 0, url, | 65 0, url, |
66 empty_body ? URLFetcher::GET : URLFetcher::POST, | 66 empty_body ? URLFetcher::GET : URLFetcher::POST, |
67 delegate); | 67 delegate); |
68 | 68 |
69 result->SetRequestContext(getter); | 69 result->SetRequestContext(getter); |
70 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 70 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
71 net::LOAD_DO_NOT_SAVE_COOKIES); | 71 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 72 // Fetchers are sometimes cancelled because a network change was detected, |
| 73 // 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 // http://crbug.com/163710 |
| 76 result->SetAutomaticallyRetryOnNetworkChanges(3); |
72 | 77 |
73 if (!empty_body) | 78 if (!empty_body) |
74 result->SetUploadData("application/x-www-form-urlencoded", body); | 79 result->SetUploadData("application/x-www-form-urlencoded", body); |
75 | 80 |
76 return result; | 81 return result; |
77 } | 82 } |
78 } // namespace | 83 } // namespace |
79 | 84 |
80 OAuth2AccessTokenFetcher::OAuth2AccessTokenFetcher( | 85 OAuth2AccessTokenFetcher::OAuth2AccessTokenFetcher( |
81 OAuth2AccessTokenConsumer* consumer, | 86 OAuth2AccessTokenConsumer* consumer, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 std::string data; | 214 std::string data; |
210 source->GetResponseAsString(&data); | 215 source->GetResponseAsString(&data); |
211 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | 216 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); |
212 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) | 217 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) |
213 return false; | 218 return false; |
214 | 219 |
215 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 220 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
216 return dict->GetString(kAccessTokenKey, access_token) && | 221 return dict->GetString(kAccessTokenKey, access_token) && |
217 dict->GetInteger(kExpiresInKey, expires_in); | 222 dict->GetInteger(kExpiresInKey, expires_in); |
218 } | 223 } |
OLD | NEW |