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

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

Issue 2949343002: Tether: record each type of host connection result. (Closed)
Patch Set: Remove incorrect metric recording call. 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 PA_LOG(INFO) << "Received failed ConnectTetheringResponse from device with " 173 PA_LOG(INFO) << "Received failed ConnectTetheringResponse from device with "
168 << "ID " << remote_device.GetTruncatedDeviceIdForLogs() 174 << "ID " << remote_device.GetTruncatedDeviceIdForLogs()
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
183 HostConnectionMetricsLogger::ConnectionToHostResult connection_to_host_result;
Kyle Horimoto 2017/07/12 17:23:21 Move this to a helper function, and remove the com
Ryan Hansberry 2017/07/12 17:51:17 Oops :) Done.
184 if (error_code ==
185 ConnectTetheringResponse_ResponseCode::
186 ConnectTetheringResponse_ResponseCode_PROVISIONING_FAILED) {
187 // host_connection_metrics_logger_->RecordConnectionToHostResult(
188 // HostConnectionMetricsLogger::ConnectionToHostResult::
189 // CONNECTION_RESULT_PROVISIONING_FAILED);
190 connection_to_host_result = HostConnectionMetricsLogger::
191 ConnectionToHostResult::CONNECTION_RESULT_PROVISIONING_FAILED;
192 } else if (error_code ==
193 ConnectTetheringResponse_ResponseCode::
194 ConnectTetheringResponse_ResponseCode_TETHERING_TIMEOUT) {
195 const std::string tether_network_guid =
196 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId(
197 remote_device.GetDeviceId());
198 bool setup_was_required =
199 host_scan_cache_->DoesHostRequireSetup(tether_network_guid);
200 // host_connection_metrics_logger_->RecordConnectionToHostResult(
201 // setup_was_required
202 // ? HostConnectionMetricsLogger::ConnectionToHostResult::
203 // CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SE TUP_WAS_REQUIRED
204 // : HostConnectionMetricsLogger::ConnectionToHostResult::
205 // CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SE TUP_WAS_NOT_REQUIRED);
206
207 connection_to_host_result =
208 setup_was_required
209 ? HostConnectionMetricsLogger::ConnectionToHostResult::
210 CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP _WAS_REQUIRED
211 : HostConnectionMetricsLogger::ConnectionToHostResult::
212 CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP _WAS_NOT_REQUIRED;
213 } else {
214 // host_connection_metrics_logger_->RecordConnectionToHostResult(
215 // HostConnectionMetricsLogger::ConnectionToHostResult::
216 // CONNECTION_RESULT_FAILURE_UNKNOWN_ERROR);
217 connection_to_host_result = HostConnectionMetricsLogger::
218 ConnectionToHostResult::CONNECTION_RESULT_FAILURE_UNKNOWN_ERROR;
219 }
220
177 connect_tethering_operation_->RemoveObserver(this); 221 connect_tethering_operation_->RemoveObserver(this);
178 connect_tethering_operation_.reset(); 222 connect_tethering_operation_.reset();
179 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); 223 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed,
224 connection_to_host_result);
180 } 225 }
181 226
182 void TetherConnector::OnTetherHostToConnectFetched( 227 void TetherConnector::OnTetherHostToConnectFetched(
183 const std::string& device_id, 228 const std::string& device_id,
184 std::unique_ptr<cryptauth::RemoteDevice> tether_host_to_connect) { 229 std::unique_ptr<cryptauth::RemoteDevice> tether_host_to_connect) {
185 if (device_id_pending_connection_ != device_id) { 230 if (device_id_pending_connection_ != device_id) {
186 PA_LOG(INFO) << "Device to connect to has changed while device with ID " 231 PA_LOG(INFO) << "Device to connect to has changed while device with ID "
187 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) 232 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id)
188 << " was being fetched."; 233 << " was being fetched.";
189 return; 234 return;
190 } 235 }
191 236
192 if (!tether_host_to_connect) { 237 if (!tether_host_to_connect) {
193 PA_LOG(ERROR) << "Could not fetch tether host with device ID " 238 PA_LOG(ERROR) << "Could not fetch tether host with device ID "
194 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) 239 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id)
195 << ". Cannot connect."; 240 << ". Cannot connect.";
196 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); 241 SetConnectionFailed(
242 NetworkConnectionHandler::kErrorConnectFailed,
243 HostConnectionMetricsLogger::ConnectionToHostResult::
244 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_INTERNAL_ERROR);
245 // host_connection_metrics_logger_->RecordConnectionToHostResult(
Kyle Horimoto 2017/07/12 17:23:21 Remove.
Ryan Hansberry 2017/07/12 17:51:17 Done.
246 // HostConnectionMetricsLogger::ConnectionToHostResult::
247 // CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_INTERNAL_ERROR);
197 return; 248 return;
198 } 249 }
199 250
200 DCHECK(device_id == tether_host_to_connect->GetDeviceId()); 251 DCHECK(device_id == tether_host_to_connect->GetDeviceId());
201 252
202 const std::string& tether_network_guid = 253 const std::string tether_network_guid =
203 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( 254 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId(
204 device_id); 255 device_id);
205 connect_tethering_operation_ = 256 connect_tethering_operation_ =
206 ConnectTetheringOperation::Factory::NewInstance( 257 ConnectTetheringOperation::Factory::NewInstance(
207 *tether_host_to_connect, connection_manager_, 258 *tether_host_to_connect, connection_manager_,
208 tether_host_response_recorder_, 259 tether_host_response_recorder_,
209 host_scan_cache_->DoesHostRequireSetup(tether_network_guid)); 260 host_scan_cache_->DoesHostRequireSetup(tether_network_guid));
210 connect_tethering_operation_->AddObserver(this); 261 connect_tethering_operation_->AddObserver(this);
211 connect_tethering_operation_->Initialize(); 262 connect_tethering_operation_->Initialize();
212 } 263 }
213 264
214 void TetherConnector::SetConnectionFailed(const std::string& error_name) { 265 void TetherConnector::SetConnectionFailed(
266 const std::string& error_name,
267 HostConnectionMetricsLogger::ConnectionToHostResult
268 connection_to_host_result) {
215 DCHECK(!device_id_pending_connection_.empty()); 269 DCHECK(!device_id_pending_connection_.empty());
216 DCHECK(!error_callback_.is_null()); 270 DCHECK(!error_callback_.is_null());
217 271
218 notification_presenter_->RemoveSetupRequiredNotification(); 272 notification_presenter_->RemoveSetupRequiredNotification();
219 273
220 // Save a copy of the callback before resetting it below. 274 // Save a copy of the callback before resetting it below.
221 network_handler::StringResultCallback error_callback = error_callback_; 275 network_handler::StringResultCallback error_callback = error_callback_;
222 276
223 device_id_pending_connection_.clear(); 277 device_id_pending_connection_.clear();
224 success_callback_.Reset(); 278 success_callback_.Reset();
225 error_callback_.Reset(); 279 error_callback_.Reset();
226 280
227 error_callback.Run(error_name); 281 error_callback.Run(error_name);
228 active_host_->SetActiveHostDisconnected(); 282 active_host_->SetActiveHostDisconnected();
283
284 host_connection_metrics_logger_->RecordConnectionToHostResult(
285 connection_to_host_result);
229 } 286 }
230 287
231 void TetherConnector::SetConnectionSucceeded( 288 void TetherConnector::SetConnectionSucceeded(
232 const std::string& device_id, 289 const std::string& device_id,
233 const std::string& wifi_network_guid) { 290 const std::string& wifi_network_guid) {
234 DCHECK(!device_id_pending_connection_.empty()); 291 DCHECK(!device_id_pending_connection_.empty());
235 DCHECK(device_id_pending_connection_ == device_id); 292 DCHECK(device_id_pending_connection_ == device_id);
236 DCHECK(!success_callback_.is_null()); 293 DCHECK(!success_callback_.is_null());
237 294
295 host_connection_metrics_logger_->RecordConnectionToHostResult(
296 HostConnectionMetricsLogger::ConnectionToHostResult::
297 CONNECTION_RESULT_SUCCESS);
298
238 notification_presenter_->RemoveSetupRequiredNotification(); 299 notification_presenter_->RemoveSetupRequiredNotification();
239 300
240 // Save a copy of the callback before resetting it below. 301 // Save a copy of the callback before resetting it below.
241 base::Closure success_callback = success_callback_; 302 base::Closure success_callback = success_callback_;
242 303
243 device_id_pending_connection_.clear(); 304 device_id_pending_connection_.clear();
244 success_callback_.Reset(); 305 success_callback_.Reset();
245 error_callback_.Reset(); 306 error_callback_.Reset();
246 307
247 success_callback.Run(); 308 success_callback.Run();
(...skipping 18 matching lines...) Expand all
266 return; 327 return;
267 } 328 }
268 329
269 if (wifi_network_guid.empty()) { 330 if (wifi_network_guid.empty()) {
270 // If the Wi-Fi network ID is empty, then the connection did not succeed. 331 // 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 " 332 PA_LOG(ERROR) << "Failed to connect to the hotspot belonging to the device "
272 << "with ID " 333 << "with ID "
273 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) 334 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id)
274 << "."; 335 << ".";
275 336
276 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); 337 // host_connection_metrics_logger_->RecordConnectionToHostResult(
Kyle Horimoto 2017/07/12 17:23:21 Remove.
Ryan Hansberry 2017/07/12 17:51:17 Done.
338 // HostConnectionMetricsLogger::ConnectionToHostResult::
339 // CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_TIMEOUT);
340
341 SetConnectionFailed(
342 NetworkConnectionHandler::kErrorConnectFailed,
343 HostConnectionMetricsLogger::ConnectionToHostResult::
344 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_TIMEOUT);
277 return; 345 return;
278 } 346 }
279 347
280 SetConnectionSucceeded(device_id, wifi_network_guid); 348 SetConnectionSucceeded(device_id, wifi_network_guid);
281 } 349 }
282 350
283 } // namespace tether 351 } // namespace tether
284 352
285 } // namespace chromeos 353 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698