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

Side by Side Diff: components/cryptauth/cryptauth_client_impl.cc

Issue 2888053003: Network traffic annotation added to OAuth2ApiCallFlow and its subclasses. (Closed)
Patch Set: Comments addressed. Created 3 years, 6 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 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 "components/cryptauth/cryptauth_client_impl.h" 5 #include "components/cryptauth/cryptauth_client_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 std::unique_ptr<CryptAuthAccessTokenFetcher> access_token_fetcher, 53 std::unique_ptr<CryptAuthAccessTokenFetcher> access_token_fetcher,
54 scoped_refptr<net::URLRequestContextGetter> url_request_context, 54 scoped_refptr<net::URLRequestContextGetter> url_request_context,
55 const DeviceClassifier& device_classifier) 55 const DeviceClassifier& device_classifier)
56 : api_call_flow_(std::move(api_call_flow)), 56 : api_call_flow_(std::move(api_call_flow)),
57 access_token_fetcher_(std::move(access_token_fetcher)), 57 access_token_fetcher_(std::move(access_token_fetcher)),
58 url_request_context_(url_request_context), 58 url_request_context_(url_request_context),
59 device_classifier_(device_classifier), 59 device_classifier_(device_classifier),
60 has_call_started_(false), 60 has_call_started_(false),
61 weak_ptr_factory_(this) {} 61 weak_ptr_factory_(this) {}
62 62
63 CryptAuthClientImpl::~CryptAuthClientImpl() { 63 CryptAuthClientImpl::~CryptAuthClientImpl() {
sacomoto 2017/06/15 06:13:23 For all requests: destination: GOOGLE_OWNED_SERVI
Ramin Halavati 2017/06/16 09:48:18 Done.
64 } 64 }
65 65
66 void CryptAuthClientImpl::GetMyDevices( 66 void CryptAuthClientImpl::GetMyDevices(
sacomoto 2017/06/15 06:13:19 Currently, this request (and the SendDeviceSyncTic
Ramin Halavati 2017/06/16 09:48:17 I moved the annotation to the caller function so t
67 const GetMyDevicesRequest& request, 67 const GetMyDevicesRequest& request,
68 const GetMyDevicesCallback& callback, 68 const GetMyDevicesCallback& callback,
69 const ErrorCallback& error_callback) { 69 const ErrorCallback& error_callback) {
70 MakeApiCall(kGetMyDevicesPath, request, callback, error_callback); 70 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
71 net::DefinePartialNetworkTrafficAnnotation("...", "oauth2_api_call_flow",
sacomoto 2017/06/15 06:13:23 cryptauth_get_my_devices
Ramin Halavati 2017/06/16 09:48:18 Acknowledged.
72 R"(
73 semantics {
74 sender: "..."
75 description: "..."
76 trigger: "..."
77 data: "..."
78 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER/LOCAL
79 }
80 policy {
81 setting: "..."
82 chrome_policy {
83 [POLICY_NAME] {
84 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
85 [POLICY_NAME]: ... //(value to disable it)
86 }
87 }
88 policy_exception_justification: "..."
89 })");
90 MakeApiCall(kGetMyDevicesPath, request, callback, error_callback,
91 partial_traffic_annotation);
71 } 92 }
72 93
73 void CryptAuthClientImpl::FindEligibleUnlockDevices( 94 void CryptAuthClientImpl::FindEligibleUnlockDevices(
74 const FindEligibleUnlockDevicesRequest& request, 95 const FindEligibleUnlockDevicesRequest& request,
75 const FindEligibleUnlockDevicesCallback& callback, 96 const FindEligibleUnlockDevicesCallback& callback,
76 const ErrorCallback& error_callback) { 97 const ErrorCallback& error_callback) {
77 MakeApiCall(kFindEligibleUnlockDevicesPath, request, callback, 98 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
78 error_callback); 99 net::DefinePartialNetworkTrafficAnnotation("...", "oauth2_api_call_flow",
sacomoto 2017/06/15 06:13:15 cryptauth_find_eligible_unlock_devices
Ramin Halavati 2017/06/16 09:48:17 Done.
100 R"(
101 semantics {
102 sender: "..."
sacomoto 2017/06/15 06:13:11 CryptAuth Device Manager.
Ramin Halavati 2017/06/16 09:48:16 Done.
103 description: "..."
sacomoto 2017/06/15 06:13:12 Gets the list of mobile devices that can be used b
Ramin Halavati 2017/06/16 09:48:16 Done.
104 trigger: "..."
sacomoto 2017/06/15 06:13:11 This request is sent when the user starts the Smar
Ramin Halavati 2017/06/16 09:48:17 Done.
105 data: "..."
sacomoto 2017/06/15 06:13:11 The device's public key.
Ramin Halavati 2017/06/16 09:48:18 Done.
106 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER/LOCAL
107 }
108 policy {
109 setting: "..."
sacomoto 2017/06/15 06:13:10 This request will only be send if the user explici
Ramin Halavati 2017/06/16 09:48:16 Done.
110 chrome_policy {
111 [POLICY_NAME] {
sacomoto 2017/06/15 06:13:23 EasyUnlockAllowed
Ramin Halavati 2017/06/16 09:48:17 Done.
112 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
sacomoto 2017/06/15 06:13:11 MANDATORY.
Ramin Halavati 2017/06/16 09:48:17 We are removing this field as it's always MANDATOR
113 [POLICY_NAME]: ... //(value to disable it)
sacomoto 2017/06/15 06:13:17 EasyUnlockAllowed: false
Ramin Halavati 2017/06/16 09:48:17 Done.
114 }
115 }
116 policy_exception_justification: "..."
117 })");
118 MakeApiCall(kFindEligibleUnlockDevicesPath, request, callback, error_callback,
119 partial_traffic_annotation);
79 } 120 }
80 121
81 void CryptAuthClientImpl::SendDeviceSyncTickle( 122 void CryptAuthClientImpl::SendDeviceSyncTickle(
82 const SendDeviceSyncTickleRequest& request, 123 const SendDeviceSyncTickleRequest& request,
83 const SendDeviceSyncTickleCallback& callback, 124 const SendDeviceSyncTickleCallback& callback,
84 const ErrorCallback& error_callback) { 125 const ErrorCallback& error_callback) {
85 MakeApiCall(kSendDeviceSyncTicklePath, request, callback, error_callback); 126 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
127 net::DefinePartialNetworkTrafficAnnotation("...", "oauth2_api_call_flow",
sacomoto 2017/06/15 06:13:11 cryptauth_device_sync_tickle
Ramin Halavati 2017/06/16 09:48:17 Acknowledged.
128 R"(
129 semantics {
130 sender: "..."
131 description: "..."
132 trigger: "..."
133 data: "..."
134 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER/LOCAL
135 }
136 policy {
137 setting: "..."
138 chrome_policy {
139 [POLICY_NAME] {
140 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
141 [POLICY_NAME]: ... //(value to disable it)
142 }
143 }
144 policy_exception_justification: "..."
145 })");
146 MakeApiCall(kSendDeviceSyncTicklePath, request, callback, error_callback,
147 partial_traffic_annotation);
86 } 148 }
87 149
88 void CryptAuthClientImpl::ToggleEasyUnlock( 150 void CryptAuthClientImpl::ToggleEasyUnlock(
89 const ToggleEasyUnlockRequest& request, 151 const ToggleEasyUnlockRequest& request,
90 const ToggleEasyUnlockCallback& callback, 152 const ToggleEasyUnlockCallback& callback,
91 const ErrorCallback& error_callback) { 153 const ErrorCallback& error_callback) {
92 MakeApiCall(kToggleEasyUnlockPath, request, callback, error_callback); 154 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
155 net::DefinePartialNetworkTrafficAnnotation("...", "oauth2_api_call_flow",
sacomoto 2017/06/15 06:13:14 cryptauth_toggle_easyunlock
Ramin Halavati 2017/06/16 09:48:17 Done.
156 R"(
157 semantics {
158 sender: "..."
sacomoto 2017/06/15 06:13:11 CryptAuth Device Manager
Ramin Halavati 2017/06/16 09:48:17 Done.
159 description: "..."
sacomoto 2017/06/15 06:13:11 Enables Smart Lock (EasyUnlock) for the current de
Ramin Halavati 2017/06/16 09:48:16 Done.
160 trigger: "..."
sacomoto 2017/06/15 06:13:16 This request is send after the user goes through t
Ramin Halavati 2017/06/16 09:48:17 Done.
161 data: "..."
sacomoto 2017/06/15 06:13:11 The device public key.
Ramin Halavati 2017/06/16 09:48:16 Done.
162 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER/LOCAL
163 }
164 policy {
165 setting: "..."
sacomoto 2017/06/15 06:13:15 This will only be send if the user explicitly enab
Ramin Halavati 2017/06/16 09:48:18 Done.
166 chrome_policy {
167 [POLICY_NAME] {
sacomoto 2017/06/15 06:13:10 EasyUnlockAllowed
Ramin Halavati 2017/06/16 09:48:17 Done.
168 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
sacomoto 2017/06/15 06:13:21 MANDATORY
Ramin Halavati 2017/06/16 09:48:16 Acknowledged.
169 [POLICY_NAME]: ... //(value to disable it)
sacomoto 2017/06/15 06:13:10 EasyUnlockAllowed: false
Ramin Halavati 2017/06/16 09:48:16 Done.
170 }
171 }
172 policy_exception_justification: "..."
173 })");
174 MakeApiCall(kToggleEasyUnlockPath, request, callback, error_callback,
175 partial_traffic_annotation);
93 } 176 }
94 177
95 void CryptAuthClientImpl::SetupEnrollment( 178 void CryptAuthClientImpl::SetupEnrollment(
96 const SetupEnrollmentRequest& request, 179 const SetupEnrollmentRequest& request,
97 const SetupEnrollmentCallback& callback, 180 const SetupEnrollmentCallback& callback,
98 const ErrorCallback& error_callback) { 181 const ErrorCallback& error_callback) {
99 MakeApiCall(kSetupEnrollmentPath, request, callback, error_callback); 182 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
183 net::DefinePartialNetworkTrafficAnnotation("...", "oauth2_api_call_flow",
sacomoto 2017/06/15 06:13:11 cryptauth_enrollment_flow_setup
Ramin Halavati 2017/06/16 09:48:17 Done.
184 R"(
185 semantics {
186 sender: "..."
sacomoto 2017/06/15 06:13:23 CryptAuth Enrollment Manager
Ramin Halavati 2017/06/16 09:48:16 Done.
187 description: "..."
sacomoto 2017/06/15 06:13:20 Starts the CryptAuth registration flow.
Ramin Halavati 2017/06/16 09:48:18 Done.
188 trigger: "..."
sacomoto 2017/06/15 06:13:10 Occurs periodically, at least once a month.
Ramin Halavati 2017/06/16 09:48:16 Done.
189 data: "..."
sacomoto 2017/06/15 06:13:23 Various device information (public key, bluetooth
Ramin Halavati 2017/06/16 09:48:17 Done.
190 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER/LOCAL
191 }
192 policy {
193 setting: "..."
sacomoto 2017/06/15 06:13:18 This feature cannot be disabled by settings. Howev
Ramin Halavati 2017/06/16 09:48:18 Done.
194 chrome_policy {
sacomoto 2017/06/15 06:13:10 There is no policy covering this request.
Ramin Halavati 2017/06/16 09:48:17 How about 'SigninAllowed'?
sacomoto 2017/06/19 18:25:38 Yes, you are right. This policy would disable all
Ramin Halavati 2017/06/20 05:35:33 Acknowledged.
195 [POLICY_NAME] {
196 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
197 [POLICY_NAME]: ... //(value to disable it)
198 }
199 }
200 policy_exception_justification: "..."
201 })");
202 MakeApiCall(kSetupEnrollmentPath, request, callback, error_callback,
203 partial_traffic_annotation);
100 } 204 }
101 205
102 void CryptAuthClientImpl::FinishEnrollment( 206 void CryptAuthClientImpl::FinishEnrollment(
103 const FinishEnrollmentRequest& request, 207 const FinishEnrollmentRequest& request,
104 const FinishEnrollmentCallback& callback, 208 const FinishEnrollmentCallback& callback,
105 const ErrorCallback& error_callback) { 209 const ErrorCallback& error_callback) {
106 MakeApiCall(kFinishEnrollmentPath, request, callback, error_callback); 210 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
211 net::DefinePartialNetworkTrafficAnnotation("...", "oauth2_api_call_flow",
sacomoto 2017/06/15 06:13:23 cryptauth_enrollment_flow_finish
Ramin Halavati 2017/06/16 09:48:16 Done.
212 R"(
213 semantics {
214 sender: "..."
sacomoto 2017/06/15 06:13:11 CryptAuth Enrollment Manager
Ramin Halavati 2017/06/16 09:48:17 Done.
215 description: "..."
sacomoto 2017/06/15 06:13:23 Finishes the CryptAuth registration flow.
Ramin Halavati 2017/06/16 09:48:18 Done.
216 trigger: "..."
sacomoto 2017/06/15 06:13:22 Occurs periodically, at least once a month.
Ramin Halavati 2017/06/16 09:48:17 Done.
217 data: "..."
Ramin Halavati 2017/06/16 09:48:17 None?
218 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER/LOCAL
219 }
220 policy {
221 setting: "..."
sacomoto 2017/06/15 06:13:10 This feature cannot be disabled by settings. Howev
Ramin Halavati 2017/06/16 09:48:17 Done.
222 chrome_policy {
sacomoto 2017/06/15 06:13:23 There is no policy covering this request.
Ramin Halavati 2017/06/16 09:48:16 Acknowledged.
223 [POLICY_NAME] {
224 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
225 [POLICY_NAME]: ... //(value to disable it)
226 }
227 }
228 policy_exception_justification: "..."
229 })");
230 MakeApiCall(kFinishEnrollmentPath, request, callback, error_callback,
231 partial_traffic_annotation);
107 } 232 }
108 233
109 std::string CryptAuthClientImpl::GetAccessTokenUsed() { 234 std::string CryptAuthClientImpl::GetAccessTokenUsed() {
110 return access_token_used_; 235 return access_token_used_;
111 } 236 }
112 237
113 template <class RequestProto, class ResponseProto> 238 template <class RequestProto, class ResponseProto>
114 void CryptAuthClientImpl::MakeApiCall( 239 void CryptAuthClientImpl::MakeApiCall(
115 const std::string& request_path, 240 const std::string& request_path,
116 const RequestProto& request_proto, 241 const RequestProto& request_proto,
117 const base::Callback<void(const ResponseProto&)>& response_callback, 242 const base::Callback<void(const ResponseProto&)>& response_callback,
118 const ErrorCallback& error_callback) { 243 const ErrorCallback& error_callback,
244 const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) {
119 if (has_call_started_) { 245 if (has_call_started_) {
120 error_callback.Run( 246 error_callback.Run(
121 "Client has been used for another request. Do not reuse."); 247 "Client has been used for another request. Do not reuse.");
122 return; 248 return;
123 } 249 }
124 has_call_started_ = true; 250 has_call_started_ = true;
125 251
252 api_call_flow_->SetPartialNetworkTrafficAnnotation(
253 partial_traffic_annotation);
254
126 // The |device_classifier| field must be present for all CryptAuth requests. 255 // The |device_classifier| field must be present for all CryptAuth requests.
127 RequestProto request_copy(request_proto); 256 RequestProto request_copy(request_proto);
128 request_copy.mutable_device_classifier()->CopyFrom(device_classifier_); 257 request_copy.mutable_device_classifier()->CopyFrom(device_classifier_);
129 258
130 std::string serialized_request; 259 std::string serialized_request;
131 if (!request_copy.SerializeToString(&serialized_request)) { 260 if (!request_copy.SerializeToString(&serialized_request)) {
132 error_callback.Run(std::string("Failed to serialize ") + 261 error_callback.Run(std::string("Failed to serialize ") +
133 request_proto.GetTypeName() + " proto."); 262 request_proto.GetTypeName() + " proto.");
134 return; 263 return;
135 } 264 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 323
195 std::unique_ptr<CryptAuthClient> CryptAuthClientFactoryImpl::CreateInstance() { 324 std::unique_ptr<CryptAuthClient> CryptAuthClientFactoryImpl::CreateInstance() {
196 return base::MakeUnique<CryptAuthClientImpl>( 325 return base::MakeUnique<CryptAuthClientImpl>(
197 base::WrapUnique(new CryptAuthApiCallFlow()), 326 base::WrapUnique(new CryptAuthApiCallFlow()),
198 base::WrapUnique( 327 base::WrapUnique(
199 new CryptAuthAccessTokenFetcherImpl(token_service_, account_id_)), 328 new CryptAuthAccessTokenFetcherImpl(token_service_, account_id_)),
200 url_request_context_, device_classifier_); 329 url_request_context_, device_classifier_);
201 } 330 }
202 331
203 } // namespace cryptauth 332 } // namespace cryptauth
OLDNEW
« no previous file with comments | « components/cryptauth/cryptauth_client_impl.h ('k') | components/cryptauth/cryptauth_client_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698