| 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 |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/common/net/gaia/gaia_urls.h" | 15 #include "chrome/common/net/gaia/gaia_urls.h" |
| 16 #include "chrome/common/net/gaia/google_service_auth_error.h" | 16 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 17 #include "content/public/common/url_fetcher.h" | |
| 18 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
| 19 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| 20 #include "net/http/http_status_code.h" | 19 #include "net/http/http_status_code.h" |
| 20 #include "net/url_request/url_fetcher.h" |
| 21 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
| 22 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
| 23 | 23 |
| 24 using net::ResponseCookies; | 24 using net::ResponseCookies; |
| 25 using net::URLFetcher; | 25 using net::URLFetcher; |
| 26 using net::URLFetcherDelegate; | 26 using net::URLFetcherDelegate; |
| 27 using net::URLRequestContextGetter; | 27 using net::URLRequestContextGetter; |
| 28 using net::URLRequestStatus; | 28 using net::URLRequestStatus; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 52 << status.error(); | 52 << status.error(); |
| 53 return GoogleServiceAuthError::FromConnectionError(status.error()); | 53 return GoogleServiceAuthError::FromConnectionError(status.error()); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 static URLFetcher* CreateFetcher(URLRequestContextGetter* getter, | 57 static URLFetcher* CreateFetcher(URLRequestContextGetter* getter, |
| 58 const GURL& url, | 58 const GURL& url, |
| 59 const std::string& body, | 59 const std::string& body, |
| 60 URLFetcherDelegate* delegate) { | 60 URLFetcherDelegate* delegate) { |
| 61 bool empty_body = body.empty(); | 61 bool empty_body = body.empty(); |
| 62 URLFetcher* result = content::URLFetcher::Create( | 62 URLFetcher* result = net::URLFetcher::Create( |
| 63 0, url, | 63 0, url, |
| 64 empty_body ? URLFetcher::GET : URLFetcher::POST, | 64 empty_body ? URLFetcher::GET : URLFetcher::POST, |
| 65 delegate); | 65 delegate); |
| 66 | 66 |
| 67 result->SetRequestContext(getter); | 67 result->SetRequestContext(getter); |
| 68 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 68 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 69 net::LOAD_DO_NOT_SAVE_COOKIES); | 69 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 70 | 70 |
| 71 if (!empty_body) | 71 if (!empty_body) |
| 72 result->SetUploadData("application/x-www-form-urlencoded", body); | 72 result->SetUploadData("application/x-www-form-urlencoded", body); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 CHECK(access_token); | 194 CHECK(access_token); |
| 195 std::string data; | 195 std::string data; |
| 196 source->GetResponseAsString(&data); | 196 source->GetResponseAsString(&data); |
| 197 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | 197 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); |
| 198 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) | 198 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) |
| 199 return false; | 199 return false; |
| 200 | 200 |
| 201 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 201 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
| 202 return dict->GetString(kAccessTokenKey, access_token); | 202 return dict->GetString(kAccessTokenKey, access_token); |
| 203 } | 203 } |
| OLD | NEW |