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

Side by Side Diff: chromeos/components/tether/tether_connector.cc

Issue 2949343002: Tether: record each type of host connection result. (Closed)
Patch Set: Remove commented out code. Created 3 years, 5 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chromeos/components/tether/tether_connector.h" 5 #include "chromeos/components/tether/tether_connector.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chromeos/components/tether/active_host.h" 8 #include "chromeos/components/tether/active_host.h"
9 #include "chromeos/components/tether/device_id_tether_network_guid_map.h" 9 #include "chromeos/components/tether/device_id_tether_network_guid_map.h"
10 #include "chromeos/components/tether/host_connection_metrics_logger.h"
10 #include "chromeos/components/tether/host_scan_cache.h" 11 #include "chromeos/components/tether/host_scan_cache.h"
11 #include "chromeos/components/tether/notification_presenter.h" 12 #include "chromeos/components/tether/notification_presenter.h"
12 #include "chromeos/components/tether/tether_host_fetcher.h" 13 #include "chromeos/components/tether/tether_host_fetcher.h"
13 #include "chromeos/components/tether/wifi_hotspot_connector.h" 14 #include "chromeos/components/tether/wifi_hotspot_connector.h"
14 #include "chromeos/network/network_handler.h" 15 #include "chromeos/network/network_handler.h"
15 #include "chromeos/network/network_state.h" 16 #include "chromeos/network/network_state.h"
16 #include "chromeos/network/network_state_handler.h" 17 #include "chromeos/network/network_state_handler.h"
17 #include "components/proximity_auth/logging/logging.h" 18 #include "components/proximity_auth/logging/logging.h"
18 19
19 namespace chromeos { 20 namespace chromeos {
20 21
21 namespace tether { 22 namespace tether {
22 23
23 TetherConnector::TetherConnector( 24 TetherConnector::TetherConnector(
24 NetworkStateHandler* network_state_handler, 25 NetworkStateHandler* network_state_handler,
25 WifiHotspotConnector* wifi_hotspot_connector, 26 WifiHotspotConnector* wifi_hotspot_connector,
26 ActiveHost* active_host, 27 ActiveHost* active_host,
27 TetherHostFetcher* tether_host_fetcher, 28 TetherHostFetcher* tether_host_fetcher,
28 BleConnectionManager* connection_manager, 29 BleConnectionManager* connection_manager,
29 TetherHostResponseRecorder* tether_host_response_recorder, 30 TetherHostResponseRecorder* tether_host_response_recorder,
30 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map, 31 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map,
31 HostScanCache* host_scan_cache, 32 HostScanCache* host_scan_cache,
32 NotificationPresenter* notification_presenter) 33 NotificationPresenter* notification_presenter,
34 HostConnectionMetricsLogger* host_connection_metrics_logger)
33 : network_state_handler_(network_state_handler), 35 : network_state_handler_(network_state_handler),
34 wifi_hotspot_connector_(wifi_hotspot_connector), 36 wifi_hotspot_connector_(wifi_hotspot_connector),
35 active_host_(active_host), 37 active_host_(active_host),
36 tether_host_fetcher_(tether_host_fetcher), 38 tether_host_fetcher_(tether_host_fetcher),
37 connection_manager_(connection_manager), 39 connection_manager_(connection_manager),
38 tether_host_response_recorder_(tether_host_response_recorder), 40 tether_host_response_recorder_(tether_host_response_recorder),
39 device_id_tether_network_guid_map_(device_id_tether_network_guid_map), 41 device_id_tether_network_guid_map_(device_id_tether_network_guid_map),
40 host_scan_cache_(host_scan_cache), 42 host_scan_cache_(host_scan_cache),
41 notification_presenter_(notification_presenter), 43 notification_presenter_(notification_presenter),
44 host_connection_metrics_logger_(host_connection_metrics_logger),
42 weak_ptr_factory_(this) {} 45 weak_ptr_factory_(this) {}
43 46
44 TetherConnector::~TetherConnector() { 47 TetherConnector::~TetherConnector() {
45 if (connect_tethering_operation_) { 48 if (connect_tethering_operation_) {
46 connect_tethering_operation_->RemoveObserver(this); 49 connect_tethering_operation_->RemoveObserver(this);
47 } 50 }
48 } 51 }
49 52
50 void TetherConnector::ConnectToNetwork( 53 void TetherConnector::ConnectToNetwork(
51 const std::string& tether_network_guid, 54 const std::string& tether_network_guid,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 115
113 PA_LOG(INFO) << "Canceling connection attempt to Tether network with GUID " 116 PA_LOG(INFO) << "Canceling connection attempt to Tether network with GUID "
114 << tether_network_guid; 117 << tether_network_guid;
115 118
116 if (connect_tethering_operation_) { 119 if (connect_tethering_operation_) {
117 // If a ConnectTetheringOperation is in progress, stop it. 120 // If a ConnectTetheringOperation is in progress, stop it.
118 connect_tethering_operation_->RemoveObserver(this); 121 connect_tethering_operation_->RemoveObserver(this);
119 connect_tethering_operation_.reset(); 122 connect_tethering_operation_.reset();
120 } 123 }
121 124
122 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectCanceled); 125 SetConnectionFailed(
126 NetworkConnectionHandler::kErrorConnectCanceled,
127 HostConnectionMetricsLogger::ConnectionToHostResult::
128 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER);
123 return true; 129 return true;
124 } 130 }
125 131
126 void TetherConnector::OnSuccessfulConnectTetheringResponse( 132 void TetherConnector::OnSuccessfulConnectTetheringResponse(
127 const cryptauth::RemoteDevice& remote_device, 133 const cryptauth::RemoteDevice& remote_device,
128 const std::string& ssid, 134 const std::string& ssid,
129 const std::string& password) { 135 const std::string& password) {
130 if (device_id_pending_connection_ != remote_device.GetDeviceId()) { 136 if (device_id_pending_connection_ != remote_device.GetDeviceId()) {
131 // If the success was part of a previous attempt for a different device, 137 // If the success was part of a previous attempt for a different device,
132 // ignore it. 138 // ignore it.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 << ", but a connection to another device has already started."; 175 << ", but a connection to another device has already started.";
170 return; 176 return;
171 } 177 }
172 178
173 PA_LOG(WARNING) << "Connection to device with ID " 179 PA_LOG(WARNING) << "Connection to device with ID "
174 << remote_device.GetTruncatedDeviceIdForLogs() 180 << remote_device.GetTruncatedDeviceIdForLogs()
175 << " could not complete. Error code: " << error_code; 181 << " could not complete. Error code: " << error_code;
176 182
177 connect_tethering_operation_->RemoveObserver(this); 183 connect_tethering_operation_->RemoveObserver(this);
178 connect_tethering_operation_.reset(); 184 connect_tethering_operation_.reset();
179 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); 185 SetConnectionFailed(
186 NetworkConnectionHandler::kErrorConnectFailed,
187 GetConnectionToHostResultFromErrorCode(remote_device, error_code));
180 } 188 }
181 189
182 void TetherConnector::OnTetherHostToConnectFetched( 190 void TetherConnector::OnTetherHostToConnectFetched(
183 const std::string& device_id, 191 const std::string& device_id,
184 std::unique_ptr<cryptauth::RemoteDevice> tether_host_to_connect) { 192 std::unique_ptr<cryptauth::RemoteDevice> tether_host_to_connect) {
185 if (device_id_pending_connection_ != device_id) { 193 if (device_id_pending_connection_ != device_id) {
186 PA_LOG(INFO) << "Device to connect to has changed while device with ID " 194 PA_LOG(INFO) << "Device to connect to has changed while device with ID "
187 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) 195 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id)
188 << " was being fetched."; 196 << " was being fetched.";
189 return; 197 return;
190 } 198 }
191 199
192 if (!tether_host_to_connect) { 200 if (!tether_host_to_connect) {
193 PA_LOG(ERROR) << "Could not fetch tether host with device ID " 201 PA_LOG(ERROR) << "Could not fetch tether host with device ID "
194 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) 202 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id)
195 << ". Cannot connect."; 203 << ". Cannot connect.";
196 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); 204 SetConnectionFailed(
205 NetworkConnectionHandler::kErrorConnectFailed,
206 HostConnectionMetricsLogger::ConnectionToHostResult::
207 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_INTERNAL_ERROR);
197 return; 208 return;
198 } 209 }
199 210
200 DCHECK(device_id == tether_host_to_connect->GetDeviceId()); 211 DCHECK(device_id == tether_host_to_connect->GetDeviceId());
201 212
202 const std::string& tether_network_guid = 213 const std::string tether_network_guid =
203 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( 214 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId(
204 device_id); 215 device_id);
205 connect_tethering_operation_ = 216 connect_tethering_operation_ =
206 ConnectTetheringOperation::Factory::NewInstance( 217 ConnectTetheringOperation::Factory::NewInstance(
207 *tether_host_to_connect, connection_manager_, 218 *tether_host_to_connect, connection_manager_,
208 tether_host_response_recorder_, 219 tether_host_response_recorder_,
209 host_scan_cache_->DoesHostRequireSetup(tether_network_guid)); 220 host_scan_cache_->DoesHostRequireSetup(tether_network_guid));
210 connect_tethering_operation_->AddObserver(this); 221 connect_tethering_operation_->AddObserver(this);
211 connect_tethering_operation_->Initialize(); 222 connect_tethering_operation_->Initialize();
212 } 223 }
213 224
214 void TetherConnector::SetConnectionFailed(const std::string& error_name) { 225 void TetherConnector::SetConnectionFailed(
226 const std::string& error_name,
227 HostConnectionMetricsLogger::ConnectionToHostResult
228 connection_to_host_result) {
215 DCHECK(!device_id_pending_connection_.empty()); 229 DCHECK(!device_id_pending_connection_.empty());
216 DCHECK(!error_callback_.is_null()); 230 DCHECK(!error_callback_.is_null());
217 231
218 notification_presenter_->RemoveSetupRequiredNotification(); 232 notification_presenter_->RemoveSetupRequiredNotification();
219 233
220 // Save a copy of the callback before resetting it below. 234 // Save a copy of the callback before resetting it below.
221 network_handler::StringResultCallback error_callback = error_callback_; 235 network_handler::StringResultCallback error_callback = error_callback_;
222 236
223 device_id_pending_connection_.clear(); 237 device_id_pending_connection_.clear();
224 success_callback_.Reset(); 238 success_callback_.Reset();
225 error_callback_.Reset(); 239 error_callback_.Reset();
226 240
227 error_callback.Run(error_name); 241 error_callback.Run(error_name);
228 active_host_->SetActiveHostDisconnected(); 242 active_host_->SetActiveHostDisconnected();
243
244 host_connection_metrics_logger_->RecordConnectionToHostResult(
245 connection_to_host_result);
229 } 246 }
230 247
231 void TetherConnector::SetConnectionSucceeded( 248 void TetherConnector::SetConnectionSucceeded(
232 const std::string& device_id, 249 const std::string& device_id,
233 const std::string& wifi_network_guid) { 250 const std::string& wifi_network_guid) {
234 DCHECK(!device_id_pending_connection_.empty()); 251 DCHECK(!device_id_pending_connection_.empty());
235 DCHECK(device_id_pending_connection_ == device_id); 252 DCHECK(device_id_pending_connection_ == device_id);
236 DCHECK(!success_callback_.is_null()); 253 DCHECK(!success_callback_.is_null());
237 254
255 host_connection_metrics_logger_->RecordConnectionToHostResult(
256 HostConnectionMetricsLogger::ConnectionToHostResult::
257 CONNECTION_RESULT_SUCCESS);
258
238 notification_presenter_->RemoveSetupRequiredNotification(); 259 notification_presenter_->RemoveSetupRequiredNotification();
239 260
240 // Save a copy of the callback before resetting it below. 261 // Save a copy of the callback before resetting it below.
241 base::Closure success_callback = success_callback_; 262 base::Closure success_callback = success_callback_;
242 263
243 device_id_pending_connection_.clear(); 264 device_id_pending_connection_.clear();
244 success_callback_.Reset(); 265 success_callback_.Reset();
245 error_callback_.Reset(); 266 error_callback_.Reset();
246 267
247 success_callback.Run(); 268 success_callback.Run();
(...skipping 18 matching lines...) Expand all
266 return; 287 return;
267 } 288 }
268 289
269 if (wifi_network_guid.empty()) { 290 if (wifi_network_guid.empty()) {
270 // If the Wi-Fi network ID is empty, then the connection did not succeed. 291 // If the Wi-Fi network ID is empty, then the connection did not succeed.
271 PA_LOG(ERROR) << "Failed to connect to the hotspot belonging to the device " 292 PA_LOG(ERROR) << "Failed to connect to the hotspot belonging to the device "
272 << "with ID " 293 << "with ID "
273 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) 294 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id)
274 << "."; 295 << ".";
275 296
276 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); 297 SetConnectionFailed(
298 NetworkConnectionHandler::kErrorConnectFailed,
299 HostConnectionMetricsLogger::ConnectionToHostResult::
300 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_TIMEOUT);
277 return; 301 return;
278 } 302 }
279 303
280 SetConnectionSucceeded(device_id, wifi_network_guid); 304 SetConnectionSucceeded(device_id, wifi_network_guid);
281 } 305 }
282 306
307 HostConnectionMetricsLogger::ConnectionToHostResult
308 TetherConnector::GetConnectionToHostResultFromErrorCode(
309 const cryptauth::RemoteDevice& remote_device,
310 ConnectTetheringResponse_ResponseCode error_code) {
311 if (error_code ==
312 ConnectTetheringResponse_ResponseCode::
313 ConnectTetheringResponse_ResponseCode_PROVISIONING_FAILED) {
314 return HostConnectionMetricsLogger::ConnectionToHostResult::
315 CONNECTION_RESULT_PROVISIONING_FAILED;
316 } else if (error_code ==
Kyle Horimoto 2017/07/12 17:55:32 You return in the above if(), so don't do an else.
Ryan Hansberry 2017/07/12 18:06:25 Done.
317 ConnectTetheringResponse_ResponseCode::
318 ConnectTetheringResponse_ResponseCode_TETHERING_TIMEOUT) {
319 const std::string tether_network_guid =
320 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId(
321 remote_device.GetDeviceId());
322 bool setup_was_required =
Kyle Horimoto 2017/07/12 17:55:32 Just use: if (cache->RequiresSetup(guid)) retur
Ryan Hansberry 2017/07/12 18:06:25 Done.
323 host_scan_cache_->DoesHostRequireSetup(tether_network_guid);
324 return setup_was_required
325 ? HostConnectionMetricsLogger::ConnectionToHostResult::
326 CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SE TUP_WAS_REQUIRED
327 : HostConnectionMetricsLogger::ConnectionToHostResult::
328 CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SE TUP_WAS_NOT_REQUIRED;
329 }
330
331 return HostConnectionMetricsLogger::ConnectionToHostResult::
332 CONNECTION_RESULT_FAILURE_UNKNOWN_ERROR;
333 }
334
283 } // namespace tether 335 } // namespace tether
284 336
285 } // namespace chromeos 337 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/components/tether/tether_connector.h ('k') | chromeos/components/tether/tether_connector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698