Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_impl.h" | 5 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.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/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "google_apis/gaia/gaia_auth_util.h" | 18 #include "google_apis/gaia/gaia_auth_util.h" |
| 19 #include "google_apis/gaia/gaia_urls.h" | 19 #include "google_apis/gaia/gaia_urls.h" |
| 20 #include "google_apis/gaia/google_service_auth_error.h" | 20 #include "google_apis/gaia/google_service_auth_error.h" |
| 21 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
| 22 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 23 #include "net/http/http_status_code.h" | 23 #include "net/http/http_status_code.h" |
| 24 #include "net/traffic_annotation/network_traffic_annotation.h" | |
| 24 #include "net/url_request/url_fetcher.h" | 25 #include "net/url_request/url_fetcher.h" |
| 25 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
| 26 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
| 27 | 28 |
| 28 using net::URLFetcher; | 29 using net::URLFetcher; |
| 29 using net::URLFetcherDelegate; | 30 using net::URLFetcherDelegate; |
| 30 using net::URLRequestContextGetter; | 31 using net::URLRequestContextGetter; |
| 31 using net::URLRequestStatus; | 32 using net::URLRequestStatus; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 return GoogleServiceAuthError::FromConnectionError(status.error()); | 90 return GoogleServiceAuthError::FromConnectionError(status.error()); |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
| 93 static std::unique_ptr<URLFetcher> CreateFetcher( | 94 static std::unique_ptr<URLFetcher> CreateFetcher( |
| 94 URLRequestContextGetter* getter, | 95 URLRequestContextGetter* getter, |
| 95 const GURL& url, | 96 const GURL& url, |
| 96 const std::string& body, | 97 const std::string& body, |
| 97 URLFetcherDelegate* delegate) { | 98 URLFetcherDelegate* delegate) { |
| 98 bool empty_body = body.empty(); | 99 bool empty_body = body.empty(); |
| 100 net::NetworkTrafficAnnotationTag traffic_annotation = | |
| 101 net::DefineNetworkTrafficAnnotation("oauth2_access_token_fetcher", R"( | |
| 102 semantics { | |
| 103 sender: "OAuth2 Access Token Fetcher" | |
|
msarda
2017/05/22 11:49:36
Here and below:
s/OAuth2/Oauth 2.0
Ramin Halavati
2017/05/22 12:42:17
Done.
| |
| 104 description: | |
| 105 "This request is used by the Token Service to fetch an OAuth2 " | |
| 106 "access token for a known Google account." | |
| 107 trigger: | |
| 108 "This request can be triggered at any moment when any service " | |
| 109 "requests an OAuth2 access token from the Token Service." | |
| 110 data: | |
| 111 "Chrome OAuth2 client id and secret, the set of OAuth2 scopes and " | |
| 112 "the OAuth2 refresh token." | |
| 113 destination: GOOGLE_OWNED_SERVICE | |
| 114 } | |
| 115 policy { | |
| 116 cookies_allowed: false | |
| 117 setting: "This feature cannot be disabled in settings." | |
| 118 policy_exception_justification: | |
| 119 "Not implemented. Disabling Oauth2 Access Token Fetcher would " | |
|
msarda
2017/05/22 11:49:36
Not sure about this policy statement. See comment
msarda
2017/05/22 11:49:36
s/Oauth2/OAuth 2.0
Ramin Halavati
2017/05/22 12:42:17
Done.
| |
| 120 "break features need access tokens (e.g. sync, chrome identity " | |
| 121 "API, etc)." | |
| 122 })"); | |
| 99 std::unique_ptr<URLFetcher> result = net::URLFetcher::Create( | 123 std::unique_ptr<URLFetcher> result = net::URLFetcher::Create( |
| 100 0, url, empty_body ? URLFetcher::GET : URLFetcher::POST, delegate); | 124 0, url, empty_body ? URLFetcher::GET : URLFetcher::POST, delegate, |
| 125 traffic_annotation); | |
| 101 | 126 |
| 102 gaia::MarkURLFetcherAsGaia(result.get()); | 127 gaia::MarkURLFetcherAsGaia(result.get()); |
| 103 result->SetRequestContext(getter); | 128 result->SetRequestContext(getter); |
| 104 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 129 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 105 net::LOAD_DO_NOT_SAVE_COOKIES); | 130 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 106 // Fetchers are sometimes cancelled because a network change was detected, | 131 // Fetchers are sometimes cancelled because a network change was detected, |
| 107 // especially at startup and after sign-in on ChromeOS. Retrying once should | 132 // especially at startup and after sign-in on ChromeOS. Retrying once should |
| 108 // be enough in those cases; let the fetcher retry up to 3 times just in case. | 133 // be enough in those cases; let the fetcher retry up to 3 times just in case. |
| 109 // http://crbug.com/163710 | 134 // http://crbug.com/163710 |
| 110 result->SetAutomaticallyRetryOnNetworkChanges(3); | 135 result->SetAutomaticallyRetryOnNetworkChanges(3); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 bool OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse( | 339 bool OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse( |
| 315 const net::URLFetcher* source, | 340 const net::URLFetcher* source, |
| 316 std::string* error) { | 341 std::string* error) { |
| 317 CHECK(error); | 342 CHECK(error); |
| 318 std::unique_ptr<base::DictionaryValue> value = | 343 std::unique_ptr<base::DictionaryValue> value = |
| 319 ParseGetAccessTokenResponse(source); | 344 ParseGetAccessTokenResponse(source); |
| 320 if (value.get() == NULL) | 345 if (value.get() == NULL) |
| 321 return false; | 346 return false; |
| 322 return value->GetString(kErrorKey, error); | 347 return value->GetString(kErrorKey, error); |
| 323 } | 348 } |
| OLD | NEW |