Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: google_apis/gaia/gaia_oauth_client.cc

Issue 2796293003: Network traffic annotation added to google_apis/gaia. (Closed)
Patch Set: Annotation moved to input argument. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | google_apis/gaia/oauth2_access_token_fetcher_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gaia_oauth_client.h" 5 #include "google_apis/gaia/gaia_oauth_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "google_apis/gaia/gaia_auth_util.h" 14 #include "google_apis/gaia/gaia_auth_util.h"
15 #include "google_apis/gaia/gaia_urls.h" 15 #include "google_apis/gaia/gaia_urls.h"
16 #include "net/base/escape.h" 16 #include "net/base/escape.h"
17 #include "net/base/load_flags.h" 17 #include "net/base/load_flags.h"
18 #include "net/http/http_status_code.h" 18 #include "net/http/http_status_code.h"
19 #include "net/traffic_annotation/network_traffic_annotation.h"
19 #include "net/url_request/url_fetcher.h" 20 #include "net/url_request/url_fetcher.h"
20 #include "net/url_request/url_fetcher_delegate.h" 21 #include "net/url_request/url_fetcher_delegate.h"
21 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 namespace { 25 namespace {
25 const char kAccessTokenValue[] = "access_token"; 26 const char kAccessTokenValue[] = "access_token";
26 const char kRefreshTokenValue[] = "refresh_token"; 27 const char kRefreshTokenValue[] = "refresh_token";
27 const char kExpiresInValue[] = "expires_in"; 28 const char kExpiresInValue[] = "expires_in";
28 } 29 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 void GaiaOAuthClient::Core::GetUserInfoImpl( 170 void GaiaOAuthClient::Core::GetUserInfoImpl(
170 RequestType type, 171 RequestType type,
171 const std::string& oauth_access_token, 172 const std::string& oauth_access_token,
172 int max_retries, 173 int max_retries,
173 Delegate* delegate) { 174 Delegate* delegate) {
174 DCHECK_EQ(request_type_, NO_PENDING_REQUEST); 175 DCHECK_EQ(request_type_, NO_PENDING_REQUEST);
175 DCHECK(!request_.get()); 176 DCHECK(!request_.get());
176 request_type_ = type; 177 request_type_ = type;
177 delegate_ = delegate; 178 delegate_ = delegate;
178 num_retries_ = 0; 179 num_retries_ = 0;
180 net::NetworkTrafficAnnotationTag traffic_annotation =
181 net::DefineNetworkTrafficAnnotation("gaia_core_get_user_info", R"(
182 semantics {
183 sender: "OAuth2 Client"
184 description: "This request is used to fetch user information."
185 trigger:
186 "The main trigger for this request in the AccountTrackerService "
187 "that fetches the user info soon after the user signs in."
188 data:
189 "The OAUth2 access token of the account."
190 destination: GOOGLE_OWNED_SERVICE
191 }
192 policy {
193 cookies_allowed: false
194 setting: "This feature cannot be disabled in settings."
195 policy_exception_justification:
196 "Not implemented. Disabling this fetcher would break features that "
197 "require user information about of the account that is signed in ("
198 "e.g. the profile switcher UI, the settings UI etc)."
199 })");
179 request_ = net::URLFetcher::Create( 200 request_ = net::URLFetcher::Create(
180 kUrlFetcherId, GURL(GaiaUrls::GetInstance()->oauth_user_info_url()), 201 kUrlFetcherId, GURL(GaiaUrls::GetInstance()->oauth_user_info_url()),
181 net::URLFetcher::GET, this); 202 net::URLFetcher::GET, this, traffic_annotation);
182 request_->SetRequestContext(request_context_getter_.get()); 203 request_->SetRequestContext(request_context_getter_.get());
183 request_->AddExtraRequestHeader("Authorization: OAuth " + oauth_access_token); 204 request_->AddExtraRequestHeader("Authorization: OAuth " + oauth_access_token);
184 request_->SetMaxRetriesOn5xx(max_retries); 205 request_->SetMaxRetriesOn5xx(max_retries);
185 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 206 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
186 net::LOAD_DO_NOT_SAVE_COOKIES); 207 net::LOAD_DO_NOT_SAVE_COOKIES);
187 MarkURLFetcherAsGaia(request_.get()); 208 MarkURLFetcherAsGaia(request_.get());
188 209
189 // Fetchers are sometimes cancelled because a network change was detected, 210 // Fetchers are sometimes cancelled because a network change was detected,
190 // especially at startup and after sign-in on ChromeOS. Retrying once should 211 // especially at startup and after sign-in on ChromeOS. Retrying once should
191 // be enough in those cases; let the fetcher retry up to 3 times just in case. 212 // be enough in those cases; let the fetcher retry up to 3 times just in case.
(...skipping 18 matching lines...) Expand all
210 } 231 }
211 232
212 void GaiaOAuthClient::Core::MakeGaiaRequest( 233 void GaiaOAuthClient::Core::MakeGaiaRequest(
213 const GURL& url, 234 const GURL& url,
214 const std::string& post_body, 235 const std::string& post_body,
215 int max_retries, 236 int max_retries,
216 GaiaOAuthClient::Delegate* delegate) { 237 GaiaOAuthClient::Delegate* delegate) {
217 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; 238 DCHECK(!request_.get()) << "Tried to fetch two things at once!";
218 delegate_ = delegate; 239 delegate_ = delegate;
219 num_retries_ = 0; 240 num_retries_ = 0;
220 request_ = 241 net::NetworkTrafficAnnotationTag traffic_annotation =
msarda 2017/05/16 13:38:29 This is again one of these cases when this is a ge
221 net::URLFetcher::Create(kUrlFetcherId, url, net::URLFetcher::POST, this); 242 net::DefineNetworkTrafficAnnotation("...", R"(
243 semantics {
244 sender: "..."
245 description: "..."
246 trigger: "..."
247 data: "..."
248 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER
249 }
250 policy {
251 cookies_allowed: false
252 setting: "..."
253 chrome_policy {
254 [POLICY_NAME] {
255 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
256 [POLICY_NAME]: ... //(value to disable it)
257 }
258 }
259 policy_exception_justification: "..."
260 })");
261 request_ = net::URLFetcher::Create(kUrlFetcherId, url, net::URLFetcher::POST,
262 this, traffic_annotation);
222 request_->SetRequestContext(request_context_getter_.get()); 263 request_->SetRequestContext(request_context_getter_.get());
223 request_->SetUploadData("application/x-www-form-urlencoded", post_body); 264 request_->SetUploadData("application/x-www-form-urlencoded", post_body);
224 request_->SetMaxRetriesOn5xx(max_retries); 265 request_->SetMaxRetriesOn5xx(max_retries);
225 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 266 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
226 net::LOAD_DO_NOT_SAVE_COOKIES); 267 net::LOAD_DO_NOT_SAVE_COOKIES);
227 MarkURLFetcherAsGaia(request_.get()); 268 MarkURLFetcherAsGaia(request_.get());
228 // See comment on SetAutomaticallyRetryOnNetworkChanges() above. 269 // See comment on SetAutomaticallyRetryOnNetworkChanges() above.
229 request_->SetAutomaticallyRetryOnNetworkChanges(3); 270 request_->SetAutomaticallyRetryOnNetworkChanges(3);
230 request_->Start(); 271 request_->Start();
231 } 272 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 450 }
410 451
411 void GaiaOAuthClient::GetTokenHandleInfo(const std::string& token_handle, 452 void GaiaOAuthClient::GetTokenHandleInfo(const std::string& token_handle,
412 int max_retries, 453 int max_retries,
413 Delegate* delegate) { 454 Delegate* delegate) {
414 return core_->GetTokenInfo("token_handle", token_handle, max_retries, 455 return core_->GetTokenInfo("token_handle", token_handle, max_retries,
415 delegate); 456 delegate);
416 } 457 }
417 458
418 } // namespace gaia 459 } // namespace gaia
OLDNEW
« no previous file with comments | « no previous file | google_apis/gaia/oauth2_access_token_fetcher_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698