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 "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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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() { |
| 64 } | 64 } |
| 65 | 65 |
| 66 void CryptAuthClientImpl::GetMyDevices( | 66 void CryptAuthClientImpl::GetMyDevices( |
| 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 const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { |
| 71 MakeApiCall(kGetMyDevicesPath, request, callback, error_callback, | |
| 72 partial_traffic_annotation); | |
| 71 } | 73 } |
| 72 | 74 |
| 73 void CryptAuthClientImpl::FindEligibleUnlockDevices( | 75 void CryptAuthClientImpl::FindEligibleUnlockDevices( |
| 74 const FindEligibleUnlockDevicesRequest& request, | 76 const FindEligibleUnlockDevicesRequest& request, |
| 75 const FindEligibleUnlockDevicesCallback& callback, | 77 const FindEligibleUnlockDevicesCallback& callback, |
| 76 const ErrorCallback& error_callback) { | 78 const ErrorCallback& error_callback) { |
| 77 MakeApiCall(kFindEligibleUnlockDevicesPath, request, callback, | 79 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation = |
| 78 error_callback); | 80 net::DefinePartialNetworkTrafficAnnotation( |
| 81 "cryptauth_find_eligible_unlock_devices", "oauth2_api_call_flow", | |
| 82 R"( | |
| 83 semantics { | |
| 84 sender: "CryptAuth Device Manager" | |
| 85 description: | |
| 86 "Gets the list of mobile devices that can be used by Smart Lock to " | |
| 87 "unlock the current device." | |
| 88 trigger: | |
| 89 "This request is sent when the user starts the Smart Lock setup flow." | |
| 90 data: "OAuth 2.0 token and the device's public key." | |
| 91 destination: GOOGLE_OWNED_SERVICE | |
| 92 } | |
| 93 policy { | |
| 94 setting: | |
| 95 "This feature cannot be disabled in settings, but the request will " | |
| 96 "only be send if the user explicitly tries to enable Smart Lock " | |
|
msramek
2017/06/28 08:40:55
typo: sent
Ramin Halavati
2017/06/28 09:21:29
Done.
| |
| 97 "(EasyUnlock), i.e. starts the setup flow." | |
| 98 chrome_policy { | |
| 99 EasyUnlockAllowed { | |
| 100 EasyUnlockAllowed: false | |
| 101 } | |
| 102 } | |
| 103 })"); | |
| 104 MakeApiCall(kFindEligibleUnlockDevicesPath, request, callback, error_callback, | |
| 105 partial_traffic_annotation); | |
| 79 } | 106 } |
| 80 | 107 |
| 81 void CryptAuthClientImpl::SendDeviceSyncTickle( | 108 void CryptAuthClientImpl::SendDeviceSyncTickle( |
| 82 const SendDeviceSyncTickleRequest& request, | 109 const SendDeviceSyncTickleRequest& request, |
| 83 const SendDeviceSyncTickleCallback& callback, | 110 const SendDeviceSyncTickleCallback& callback, |
| 84 const ErrorCallback& error_callback) { | 111 const ErrorCallback& error_callback, |
| 85 MakeApiCall(kSendDeviceSyncTicklePath, request, callback, error_callback); | 112 const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { |
| 113 MakeApiCall(kSendDeviceSyncTicklePath, request, callback, error_callback, | |
| 114 partial_traffic_annotation); | |
| 86 } | 115 } |
| 87 | 116 |
| 88 void CryptAuthClientImpl::ToggleEasyUnlock( | 117 void CryptAuthClientImpl::ToggleEasyUnlock( |
| 89 const ToggleEasyUnlockRequest& request, | 118 const ToggleEasyUnlockRequest& request, |
| 90 const ToggleEasyUnlockCallback& callback, | 119 const ToggleEasyUnlockCallback& callback, |
| 91 const ErrorCallback& error_callback) { | 120 const ErrorCallback& error_callback) { |
| 92 MakeApiCall(kToggleEasyUnlockPath, request, callback, error_callback); | 121 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation = |
| 122 net::DefinePartialNetworkTrafficAnnotation("cryptauth_toggle_easyunlock", | |
| 123 "oauth2_api_call_flow", R"( | |
| 124 semantics { | |
| 125 sender: "CryptAuth Device Manager" | |
| 126 description: "Enables Smart Lock (EasyUnlock) for the current device." | |
| 127 trigger: | |
| 128 "This request is send after the user goes through the EasyUnlock " | |
| 129 "setup flow." | |
| 130 data: "OAuth 2.0 token and the device public key." | |
| 131 destination: GOOGLE_OWNED_SERVICE | |
| 132 } | |
| 133 policy { | |
| 134 setting: | |
| 135 "This feature cannot be disabled in settings, but the request will " | |
| 136 "only be send if the user explicitly enables Smart Lock " | |
| 137 "(EasyUnlock), i.e. uccessfully complete the setup flow." | |
| 138 chrome_policy { | |
| 139 EasyUnlockAllowed { | |
| 140 EasyUnlockAllowed: false | |
| 141 } | |
| 142 } | |
| 143 })"); | |
| 144 MakeApiCall(kToggleEasyUnlockPath, request, callback, error_callback, | |
| 145 partial_traffic_annotation); | |
| 93 } | 146 } |
| 94 | 147 |
| 95 void CryptAuthClientImpl::SetupEnrollment( | 148 void CryptAuthClientImpl::SetupEnrollment( |
| 96 const SetupEnrollmentRequest& request, | 149 const SetupEnrollmentRequest& request, |
| 97 const SetupEnrollmentCallback& callback, | 150 const SetupEnrollmentCallback& callback, |
| 98 const ErrorCallback& error_callback) { | 151 const ErrorCallback& error_callback) { |
| 99 MakeApiCall(kSetupEnrollmentPath, request, callback, error_callback); | 152 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation = |
| 153 net::DefinePartialNetworkTrafficAnnotation( | |
| 154 "cryptauth_enrollment_flow_setup", "oauth2_api_call_flow", R"( | |
| 155 semantics { | |
| 156 sender: "CryptAuth Device Manager" | |
| 157 description: "Starts the CryptAuth registration flow." | |
|
msramek
2017/06/28 08:40:55
Since this cannot be disabled, could you expand th
sacomoto
2017/06/30 10:09:54
The periodic re-enrollments are part of the CryptA
Ramin Halavati
2017/06/30 11:51:36
Done.
| |
| 158 trigger: "Occurs periodically, at least once a month." | |
| 159 data: | |
| 160 "Various device information (public key, bluetooth MAC address, " | |
| 161 "model, OS version, screen size, manufacturer, has screen lock " | |
| 162 "enabled), and OAuth 2.0 token." | |
| 163 destination: GOOGLE_OWNED_SERVICE | |
| 164 } | |
| 165 policy { | |
| 166 setting: | |
| 167 "This feature cannot be disabled by settings. However, this request " | |
| 168 "is made only for signed-in users." | |
| 169 chrome_policy { | |
| 170 SigninAllowed { | |
| 171 SigninAllowed: false | |
| 172 } | |
| 173 } | |
| 174 })"); | |
| 175 MakeApiCall(kSetupEnrollmentPath, request, callback, error_callback, | |
| 176 partial_traffic_annotation); | |
| 100 } | 177 } |
| 101 | 178 |
| 102 void CryptAuthClientImpl::FinishEnrollment( | 179 void CryptAuthClientImpl::FinishEnrollment( |
| 103 const FinishEnrollmentRequest& request, | 180 const FinishEnrollmentRequest& request, |
| 104 const FinishEnrollmentCallback& callback, | 181 const FinishEnrollmentCallback& callback, |
| 105 const ErrorCallback& error_callback) { | 182 const ErrorCallback& error_callback) { |
| 106 MakeApiCall(kFinishEnrollmentPath, request, callback, error_callback); | 183 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation = |
| 184 net::DefinePartialNetworkTrafficAnnotation( | |
| 185 "cryptauth_enrollment_flow_finish", "oauth2_api_call_flow", R"( | |
| 186 semantics { | |
| 187 sender: "CryptAuth Device Manager" | |
| 188 description: "Finishes the CryptAuth registration flow." | |
|
msramek
2017/06/28 08:40:55
Ditto here (I understand that this is related to t
sacomoto
2017/06/30 10:09:54
See the previous comment.
Ramin Halavati
2017/06/30 11:51:36
Done.
| |
| 189 trigger: "Occurs periodically, at least once a month." | |
| 190 data: "OAuth 2.0 token." | |
| 191 destination: GOOGLE_OWNED_SERVICE | |
| 192 } | |
| 193 policy { | |
| 194 setting: | |
| 195 "This feature cannot be disabled by settings. However, this request " | |
| 196 "is made only for signed-in users." | |
| 197 chrome_policy { | |
| 198 SigninAllowed { | |
| 199 SigninAllowed: false | |
| 200 } | |
| 201 } | |
| 202 })"); | |
| 203 MakeApiCall(kFinishEnrollmentPath, request, callback, error_callback, | |
| 204 partial_traffic_annotation); | |
| 107 } | 205 } |
| 108 | 206 |
| 109 std::string CryptAuthClientImpl::GetAccessTokenUsed() { | 207 std::string CryptAuthClientImpl::GetAccessTokenUsed() { |
| 110 return access_token_used_; | 208 return access_token_used_; |
| 111 } | 209 } |
| 112 | 210 |
| 113 template <class RequestProto, class ResponseProto> | 211 template <class RequestProto, class ResponseProto> |
| 114 void CryptAuthClientImpl::MakeApiCall( | 212 void CryptAuthClientImpl::MakeApiCall( |
| 115 const std::string& request_path, | 213 const std::string& request_path, |
| 116 const RequestProto& request_proto, | 214 const RequestProto& request_proto, |
| 117 const base::Callback<void(const ResponseProto&)>& response_callback, | 215 const base::Callback<void(const ResponseProto&)>& response_callback, |
| 118 const ErrorCallback& error_callback) { | 216 const ErrorCallback& error_callback, |
| 217 const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { | |
| 119 if (has_call_started_) { | 218 if (has_call_started_) { |
| 120 error_callback.Run( | 219 error_callback.Run( |
| 121 "Client has been used for another request. Do not reuse."); | 220 "Client has been used for another request. Do not reuse."); |
| 122 return; | 221 return; |
| 123 } | 222 } |
| 124 has_call_started_ = true; | 223 has_call_started_ = true; |
| 125 | 224 |
| 225 api_call_flow_->SetPartialNetworkTrafficAnnotation( | |
| 226 partial_traffic_annotation); | |
| 227 | |
| 126 // The |device_classifier| field must be present for all CryptAuth requests. | 228 // The |device_classifier| field must be present for all CryptAuth requests. |
| 127 RequestProto request_copy(request_proto); | 229 RequestProto request_copy(request_proto); |
| 128 request_copy.mutable_device_classifier()->CopyFrom(device_classifier_); | 230 request_copy.mutable_device_classifier()->CopyFrom(device_classifier_); |
| 129 | 231 |
| 130 std::string serialized_request; | 232 std::string serialized_request; |
| 131 if (!request_copy.SerializeToString(&serialized_request)) { | 233 if (!request_copy.SerializeToString(&serialized_request)) { |
| 132 error_callback.Run(std::string("Failed to serialize ") + | 234 error_callback.Run(std::string("Failed to serialize ") + |
| 133 request_proto.GetTypeName() + " proto."); | 235 request_proto.GetTypeName() + " proto."); |
| 134 return; | 236 return; |
| 135 } | 237 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 | 296 |
| 195 std::unique_ptr<CryptAuthClient> CryptAuthClientFactoryImpl::CreateInstance() { | 297 std::unique_ptr<CryptAuthClient> CryptAuthClientFactoryImpl::CreateInstance() { |
| 196 return base::MakeUnique<CryptAuthClientImpl>( | 298 return base::MakeUnique<CryptAuthClientImpl>( |
| 197 base::WrapUnique(new CryptAuthApiCallFlow()), | 299 base::WrapUnique(new CryptAuthApiCallFlow()), |
| 198 base::WrapUnique( | 300 base::WrapUnique( |
| 199 new CryptAuthAccessTokenFetcherImpl(token_service_, account_id_)), | 301 new CryptAuthAccessTokenFetcherImpl(token_service_, account_id_)), |
| 200 url_request_context_, device_classifier_); | 302 url_request_context_, device_classifier_); |
| 201 } | 303 } |
| 202 | 304 |
| 203 } // namespace cryptauth | 305 } // namespace cryptauth |
| OLD | NEW |