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("...", R"( | |
| 102 semantics { | |
| 103 sender: "..." | |
|
msarda
2017/05/03 09:03:53
OAuth2 Access Token Fetcher
Ramin Halavati
2017/05/03 09:45:07
Done.
| |
| 104 description: "..." | |
|
msarda
2017/05/03 09:03:53
This request is used by the Token Service to fetch
Ramin Halavati
2017/05/03 09:45:07
Done.
| |
| 105 trigger: "..." | |
|
msarda
2017/05/03 09:03:53
This request can be triggered at any moment when a
Ramin Halavati
2017/05/03 09:45:07
Done.
| |
| 106 data: "..." | |
|
msarda
2017/05/03 09:03:54
The body of the request includes the following inf
Ramin Halavati
2017/05/03 09:45:07
Done.
| |
| 107 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER | |
|
msarda
2017/05/03 09:03:53
GOOGLE_OWNED_SERVICE
Ramin Halavati
2017/05/03 09:45:07
Done.
| |
| 108 } | |
| 109 policy { | |
| 110 cookies_allowed: false | |
| 111 setting: "..." | |
|
msarda
2017/05/03 09:03:53
This feature cannot be disabled in settings.
Ramin Halavati
2017/05/03 09:45:07
Done.
| |
| 112 chrome_policy { | |
|
msarda
2017/05/03 09:03:54
Remove block.
Ramin Halavati
2017/05/03 09:45:07
Done.
| |
| 113 [POLICY_NAME] { | |
| 114 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
| 115 [POLICY_NAME]: ... //(value to disable it) | |
| 116 } | |
| 117 } | |
| 118 policy_exception_justification: "..." | |
|
msarda
2017/05/03 09:03:54
"Not implemented. Disabling Oauth2 Access Token Fe
Ramin Halavati
2017/05/03 09:45:07
Done.
| |
| 119 })"); | |
| 99 std::unique_ptr<URLFetcher> result = net::URLFetcher::Create( | 120 std::unique_ptr<URLFetcher> result = net::URLFetcher::Create( |
| 100 0, url, empty_body ? URLFetcher::GET : URLFetcher::POST, delegate); | 121 0, url, empty_body ? URLFetcher::GET : URLFetcher::POST, delegate, |
| 122 traffic_annotation); | |
| 101 | 123 |
| 102 gaia::MarkURLFetcherAsGaia(result.get()); | 124 gaia::MarkURLFetcherAsGaia(result.get()); |
| 103 result->SetRequestContext(getter); | 125 result->SetRequestContext(getter); |
| 104 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 126 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 105 net::LOAD_DO_NOT_SAVE_COOKIES); | 127 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 106 // Fetchers are sometimes cancelled because a network change was detected, | 128 // Fetchers are sometimes cancelled because a network change was detected, |
| 107 // especially at startup and after sign-in on ChromeOS. Retrying once should | 129 // 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. | 130 // be enough in those cases; let the fetcher retry up to 3 times just in case. |
| 109 // http://crbug.com/163710 | 131 // http://crbug.com/163710 |
| 110 result->SetAutomaticallyRetryOnNetworkChanges(3); | 132 result->SetAutomaticallyRetryOnNetworkChanges(3); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 bool OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse( | 336 bool OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse( |
| 315 const net::URLFetcher* source, | 337 const net::URLFetcher* source, |
| 316 std::string* error) { | 338 std::string* error) { |
| 317 CHECK(error); | 339 CHECK(error); |
| 318 std::unique_ptr<base::DictionaryValue> value = | 340 std::unique_ptr<base::DictionaryValue> value = |
| 319 ParseGetAccessTokenResponse(source); | 341 ParseGetAccessTokenResponse(source); |
| 320 if (value.get() == NULL) | 342 if (value.get() == NULL) |
| 321 return false; | 343 return false; |
| 322 return value->GetString(kErrorKey, error); | 344 return value->GetString(kErrorKey, error); |
| 323 } | 345 } |
| OLD | NEW |