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

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

Issue 2796293003: Network traffic annotation added to google_apis/gaia. (Closed)
Patch Set: Created 3 years, 8 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
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/oauth2_api_call_flow.h" 5 #include "google_apis/gaia/oauth2_api_call_flow.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "google_apis/gaia/gaia_auth_util.h" 11 #include "google_apis/gaia/gaia_auth_util.h"
12 #include "google_apis/gaia/gaia_urls.h" 12 #include "google_apis/gaia/gaia_urls.h"
13 #include "net/base/escape.h" 13 #include "net/base/escape.h"
14 #include "net/base/load_flags.h" 14 #include "net/base/load_flags.h"
15 #include "net/http/http_status_code.h" 15 #include "net/http/http_status_code.h"
16 #include "net/traffic_annotation/network_traffic_annotation.h"
16 #include "net/url_request/url_request_context_getter.h" 17 #include "net/url_request/url_request_context_getter.h"
17 #include "net/url_request/url_request_status.h" 18 #include "net/url_request/url_request_status.h"
18 19
19 using net::URLFetcher; 20 using net::URLFetcher;
20 using net::URLFetcherDelegate; 21 using net::URLFetcherDelegate;
21 using net::URLRequestContextGetter; 22 using net::URLRequestContextGetter;
22 using net::URLRequestStatus; 23 using net::URLRequestStatus;
23 24
24 namespace { 25 namespace {
25 static const char kAuthorizationHeaderFormat[] = 26 static const char kAuthorizationHeaderFormat[] =
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 CHECK(source); 73 CHECK(source);
73 CHECK_EQ(API_CALL_STARTED, state_); 74 CHECK_EQ(API_CALL_STARTED, state_);
74 EndApiCall(source); 75 EndApiCall(source);
75 } 76 }
76 77
77 std::unique_ptr<URLFetcher> OAuth2ApiCallFlow::CreateURLFetcher( 78 std::unique_ptr<URLFetcher> OAuth2ApiCallFlow::CreateURLFetcher(
78 net::URLRequestContextGetter* context, 79 net::URLRequestContextGetter* context,
79 const std::string& access_token) { 80 const std::string& access_token) {
80 std::string body = CreateApiCallBody(); 81 std::string body = CreateApiCallBody();
81 net::URLFetcher::RequestType request_type = GetRequestTypeForBody(body); 82 net::URLFetcher::RequestType request_type = GetRequestTypeForBody(body);
82 std::unique_ptr<URLFetcher> result = 83 net::NetworkTrafficAnnotationTag traffic_annotation =
msarda 2017/05/03 09:03:54 I do not know what this fetcher is supposed to do.
Roger Tawa OOO till Jul 10th 2017/05/15 15:14:18 OAuth2ApiCallFlow helps write code to call google
Ramin Halavati 2017/05/16 05:26:02 What about adding NetworkTrafficAnnotation as an i
83 net::URLFetcher::Create(0, CreateApiCallUrl(), request_type, this); 84 net::DefineNetworkTrafficAnnotation("...", R"(
85 semantics {
86 sender: "..."
87 description: "..."
88 trigger: "..."
89 data: "..."
90 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER
91 }
92 policy {
93 cookies_allowed: false
94 setting: "..."
95 chrome_policy {
96 [POLICY_NAME] {
97 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
98 [POLICY_NAME]: ... //(value to disable it)
99 }
100 }
101 policy_exception_justification: "..."
102 })");
103 std::unique_ptr<URLFetcher> result = net::URLFetcher::Create(
104 0, CreateApiCallUrl(), request_type, this, traffic_annotation);
84 105
85 gaia::MarkURLFetcherAsGaia(result.get()); 106 gaia::MarkURLFetcherAsGaia(result.get());
86 result->SetRequestContext(context); 107 result->SetRequestContext(context);
87 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 108 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
88 net::LOAD_DO_NOT_SAVE_COOKIES); 109 net::LOAD_DO_NOT_SAVE_COOKIES);
89 result->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); 110 result->AddExtraRequestHeader(MakeAuthorizationHeader(access_token));
90 // Fetchers are sometimes cancelled because a network change was detected, 111 // Fetchers are sometimes cancelled because a network change was detected,
91 // especially at startup and after sign-in on ChromeOS. Retrying once should 112 // especially at startup and after sign-in on ChromeOS. Retrying once should
92 // be enough in those cases; let the fetcher retry up to 3 times just in case. 113 // be enough in those cases; let the fetcher retry up to 3 times just in case.
93 // http://crbug.com/163710 114 // http://crbug.com/163710
94 result->SetAutomaticallyRetryOnNetworkChanges(3); 115 result->SetAutomaticallyRetryOnNetworkChanges(3);
95 116
96 // Even if the the body is empty, we still set the Content-Type because an 117 // Even if the the body is empty, we still set the Content-Type because an
97 // empty string may be a meaningful value. For example, a Protocol Buffer 118 // empty string may be a meaningful value. For example, a Protocol Buffer
98 // message with only default values will be serialized as an empty string. 119 // message with only default values will be serialized as an empty string.
99 if (request_type != net::URLFetcher::GET) 120 if (request_type != net::URLFetcher::GET)
100 result->SetUploadData(CreateApiCallBodyContentType(), body); 121 result->SetUploadData(CreateApiCallBodyContentType(), body);
101 122
102 return result; 123 return result;
103 } 124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698