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 sent if the user explicitly tries to enable Smart Lock " |
| 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." |
| 158 trigger: |
| 159 "Occurs periodically, at least once a month, because if the device " |
| 160 "does not re-enroll for more than a specific number of days " |
| 161 "(currently 45) it will be removed from the server." |
| 162 data: |
| 163 "Various device information (public key, bluetooth MAC address, " |
| 164 "model, OS version, screen size, manufacturer, has screen lock " |
| 165 "enabled), and OAuth 2.0 token." |
| 166 destination: GOOGLE_OWNED_SERVICE |
| 167 } |
| 168 policy { |
| 169 setting: |
| 170 "This feature cannot be disabled by settings. However, this request " |
| 171 "is made only for signed-in users." |
| 172 chrome_policy { |
| 173 SigninAllowed { |
| 174 SigninAllowed: false |
| 175 } |
| 176 } |
| 177 })"); |
| 178 MakeApiCall(kSetupEnrollmentPath, request, callback, error_callback, |
| 179 partial_traffic_annotation); |
100 } | 180 } |
101 | 181 |
102 void CryptAuthClientImpl::FinishEnrollment( | 182 void CryptAuthClientImpl::FinishEnrollment( |
103 const FinishEnrollmentRequest& request, | 183 const FinishEnrollmentRequest& request, |
104 const FinishEnrollmentCallback& callback, | 184 const FinishEnrollmentCallback& callback, |
105 const ErrorCallback& error_callback) { | 185 const ErrorCallback& error_callback) { |
106 MakeApiCall(kFinishEnrollmentPath, request, callback, error_callback); | 186 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation = |
| 187 net::DefinePartialNetworkTrafficAnnotation( |
| 188 "cryptauth_enrollment_flow_finish", "oauth2_api_call_flow", R"( |
| 189 semantics { |
| 190 sender: "CryptAuth Device Manager" |
| 191 description: "Finishes the CryptAuth registration flow." |
| 192 trigger: |
| 193 "Occurs periodically, at least once a month, because if the device " |
| 194 "does not re-enroll for more than a specific number of days " |
| 195 "(currently 45) it will be removed from the server." |
| 196 data: "OAuth 2.0 token." |
| 197 destination: GOOGLE_OWNED_SERVICE |
| 198 } |
| 199 policy { |
| 200 setting: |
| 201 "This feature cannot be disabled by settings. However, this request " |
| 202 "is made only for signed-in users." |
| 203 chrome_policy { |
| 204 SigninAllowed { |
| 205 SigninAllowed: false |
| 206 } |
| 207 } |
| 208 })"); |
| 209 MakeApiCall(kFinishEnrollmentPath, request, callback, error_callback, |
| 210 partial_traffic_annotation); |
107 } | 211 } |
108 | 212 |
109 std::string CryptAuthClientImpl::GetAccessTokenUsed() { | 213 std::string CryptAuthClientImpl::GetAccessTokenUsed() { |
110 return access_token_used_; | 214 return access_token_used_; |
111 } | 215 } |
112 | 216 |
113 template <class RequestProto, class ResponseProto> | 217 template <class RequestProto, class ResponseProto> |
114 void CryptAuthClientImpl::MakeApiCall( | 218 void CryptAuthClientImpl::MakeApiCall( |
115 const std::string& request_path, | 219 const std::string& request_path, |
116 const RequestProto& request_proto, | 220 const RequestProto& request_proto, |
117 const base::Callback<void(const ResponseProto&)>& response_callback, | 221 const base::Callback<void(const ResponseProto&)>& response_callback, |
118 const ErrorCallback& error_callback) { | 222 const ErrorCallback& error_callback, |
| 223 const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { |
119 if (has_call_started_) { | 224 if (has_call_started_) { |
120 error_callback.Run( | 225 error_callback.Run( |
121 "Client has been used for another request. Do not reuse."); | 226 "Client has been used for another request. Do not reuse."); |
122 return; | 227 return; |
123 } | 228 } |
124 has_call_started_ = true; | 229 has_call_started_ = true; |
125 | 230 |
| 231 api_call_flow_->SetPartialNetworkTrafficAnnotation( |
| 232 partial_traffic_annotation); |
| 233 |
126 // The |device_classifier| field must be present for all CryptAuth requests. | 234 // The |device_classifier| field must be present for all CryptAuth requests. |
127 RequestProto request_copy(request_proto); | 235 RequestProto request_copy(request_proto); |
128 request_copy.mutable_device_classifier()->CopyFrom(device_classifier_); | 236 request_copy.mutable_device_classifier()->CopyFrom(device_classifier_); |
129 | 237 |
130 std::string serialized_request; | 238 std::string serialized_request; |
131 if (!request_copy.SerializeToString(&serialized_request)) { | 239 if (!request_copy.SerializeToString(&serialized_request)) { |
132 error_callback.Run(std::string("Failed to serialize ") + | 240 error_callback.Run(std::string("Failed to serialize ") + |
133 request_proto.GetTypeName() + " proto."); | 241 request_proto.GetTypeName() + " proto."); |
134 return; | 242 return; |
135 } | 243 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 302 |
195 std::unique_ptr<CryptAuthClient> CryptAuthClientFactoryImpl::CreateInstance() { | 303 std::unique_ptr<CryptAuthClient> CryptAuthClientFactoryImpl::CreateInstance() { |
196 return base::MakeUnique<CryptAuthClientImpl>( | 304 return base::MakeUnique<CryptAuthClientImpl>( |
197 base::WrapUnique(new CryptAuthApiCallFlow()), | 305 base::WrapUnique(new CryptAuthApiCallFlow()), |
198 base::WrapUnique( | 306 base::WrapUnique( |
199 new CryptAuthAccessTokenFetcherImpl(token_service_, account_id_)), | 307 new CryptAuthAccessTokenFetcherImpl(token_service_, account_id_)), |
200 url_request_context_, device_classifier_); | 308 url_request_context_, device_classifier_); |
201 } | 309 } |
202 | 310 |
203 } // namespace cryptauth | 311 } // namespace cryptauth |
OLD | NEW |