Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 | 95 |
| 93 tether_host_fetcher_->FetchTetherHost( | 96 tether_host_fetcher_->FetchTetherHost( |
| 94 device_id_pending_connection_, | 97 device_id_pending_connection_, |
| 95 base::Bind(&TetherConnector::OnTetherHostToConnectFetched, | 98 base::Bind(&TetherConnector::OnTetherHostToConnectFetched, |
| 96 weak_ptr_factory_.GetWeakPtr(), | 99 weak_ptr_factory_.GetWeakPtr(), |
| 97 device_id_pending_connection_)); | 100 device_id_pending_connection_)); |
| 98 } | 101 } |
| 99 | 102 |
| 100 bool TetherConnector::CancelConnectionAttempt( | 103 bool TetherConnector::CancelConnectionAttempt( |
| 101 const std::string& tether_network_guid) { | 104 const std::string& tether_network_guid) { |
| 105 host_connection_metrics_logger_->RecordConnectionToHostResult( | |
|
Kyle Horimoto
2017/07/07 17:06:33
Move this down to after the device ID check. This
Ryan Hansberry
2017/07/12 16:37:06
Done.
| |
| 106 HostConnectionMetricsLogger::ConnectionToHostResult:: | |
| 107 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER); | |
| 108 | |
| 102 const std::string device_id = | 109 const std::string device_id = |
| 103 device_id_tether_network_guid_map_->GetDeviceIdForTetherNetworkGuid( | 110 device_id_tether_network_guid_map_->GetDeviceIdForTetherNetworkGuid( |
| 104 tether_network_guid); | 111 tether_network_guid); |
| 105 | 112 |
| 106 if (device_id != device_id_pending_connection_) { | 113 if (device_id != device_id_pending_connection_) { |
| 107 PA_LOG(ERROR) << "CancelConnectionAttempt(): Cancel requested for Tether " | 114 PA_LOG(ERROR) << "CancelConnectionAttempt(): Cancel requested for Tether " |
| 108 << "network with GUID " << tether_network_guid << ", but " | 115 << "network with GUID " << tether_network_guid << ", but " |
| 109 << "there was no active connection to that network."; | 116 << "there was no active connection to that network."; |
| 110 return false; | 117 return false; |
| 111 } | 118 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 PA_LOG(INFO) << "Received failed ConnectTetheringResponse from device with " | 174 PA_LOG(INFO) << "Received failed ConnectTetheringResponse from device with " |
| 168 << "ID " << remote_device.GetTruncatedDeviceIdForLogs() | 175 << "ID " << remote_device.GetTruncatedDeviceIdForLogs() |
| 169 << ", but a connection to another device has already started."; | 176 << ", but a connection to another device has already started."; |
| 170 return; | 177 return; |
| 171 } | 178 } |
| 172 | 179 |
| 173 PA_LOG(WARNING) << "Connection to device with ID " | 180 PA_LOG(WARNING) << "Connection to device with ID " |
| 174 << remote_device.GetTruncatedDeviceIdForLogs() | 181 << remote_device.GetTruncatedDeviceIdForLogs() |
| 175 << " could not complete. Error code: " << error_code; | 182 << " could not complete. Error code: " << error_code; |
| 176 | 183 |
| 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 } else if (error_code == | |
| 191 ConnectTetheringResponse_ResponseCode:: | |
| 192 ConnectTetheringResponse_ResponseCode_TETHERING_TIMEOUT) { | |
| 193 const std::string tether_network_guid = | |
| 194 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( | |
| 195 remote_device.GetDeviceId()); | |
| 196 bool setup_was_required = | |
| 197 host_scan_cache_->DoesHostRequireSetup(tether_network_guid); | |
| 198 host_connection_metrics_logger_->RecordConnectionToHostResult( | |
| 199 setup_was_required | |
| 200 ? HostConnectionMetricsLogger::ConnectionToHostResult:: | |
| 201 CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP _WAS_REQUIRED | |
| 202 : HostConnectionMetricsLogger::ConnectionToHostResult:: | |
| 203 CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP _WAS_NOT_REQUIRED); | |
| 204 } else { | |
| 205 host_connection_metrics_logger_->RecordConnectionToHostResult( | |
| 206 HostConnectionMetricsLogger::ConnectionToHostResult:: | |
| 207 CONNECTION_RESULT_FAILURE_UNKNOWN_ERROR); | |
| 208 } | |
| 209 | |
| 177 connect_tethering_operation_->RemoveObserver(this); | 210 connect_tethering_operation_->RemoveObserver(this); |
| 178 connect_tethering_operation_.reset(); | 211 connect_tethering_operation_.reset(); |
| 179 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); | 212 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); |
| 180 } | 213 } |
| 181 | 214 |
| 182 void TetherConnector::OnTetherHostToConnectFetched( | 215 void TetherConnector::OnTetherHostToConnectFetched( |
| 183 const std::string& device_id, | 216 const std::string& device_id, |
| 184 std::unique_ptr<cryptauth::RemoteDevice> tether_host_to_connect) { | 217 std::unique_ptr<cryptauth::RemoteDevice> tether_host_to_connect) { |
| 185 if (device_id_pending_connection_ != device_id) { | 218 if (device_id_pending_connection_ != device_id) { |
| 186 PA_LOG(INFO) << "Device to connect to has changed while device with ID " | 219 PA_LOG(INFO) << "Device to connect to has changed while device with ID " |
| 187 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) | 220 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) |
| 188 << " was being fetched."; | 221 << " was being fetched."; |
| 189 return; | 222 return; |
| 190 } | 223 } |
| 191 | 224 |
| 192 if (!tether_host_to_connect) { | 225 if (!tether_host_to_connect) { |
| 193 PA_LOG(ERROR) << "Could not fetch tether host with device ID " | 226 PA_LOG(ERROR) << "Could not fetch tether host with device ID " |
| 194 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) | 227 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) |
| 195 << ". Cannot connect."; | 228 << ". Cannot connect."; |
| 196 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); | 229 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); |
| 230 host_connection_metrics_logger_->RecordConnectionToHostResult( | |
|
Kyle Horimoto
2017/07/07 17:06:33
See comment on other CL - I think this should just
Ryan Hansberry
2017/07/12 16:37:06
Done.
| |
| 231 HostConnectionMetricsLogger::ConnectionToHostResult:: | |
| 232 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_HOST_FETCH_FAILURE); | |
| 197 return; | 233 return; |
| 198 } | 234 } |
| 199 | 235 |
| 200 DCHECK(device_id == tether_host_to_connect->GetDeviceId()); | 236 DCHECK(device_id == tether_host_to_connect->GetDeviceId()); |
| 201 | 237 |
| 202 const std::string& tether_network_guid = | 238 const std::string tether_network_guid = |
| 203 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( | 239 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( |
| 204 device_id); | 240 device_id); |
| 205 connect_tethering_operation_ = | 241 connect_tethering_operation_ = |
| 206 ConnectTetheringOperation::Factory::NewInstance( | 242 ConnectTetheringOperation::Factory::NewInstance( |
| 207 *tether_host_to_connect, connection_manager_, | 243 *tether_host_to_connect, connection_manager_, |
| 208 tether_host_response_recorder_, | 244 tether_host_response_recorder_, |
| 209 host_scan_cache_->DoesHostRequireSetup(tether_network_guid)); | 245 host_scan_cache_->DoesHostRequireSetup(tether_network_guid)); |
| 210 connect_tethering_operation_->AddObserver(this); | 246 connect_tethering_operation_->AddObserver(this); |
| 211 connect_tethering_operation_->Initialize(); | 247 connect_tethering_operation_->Initialize(); |
| 212 } | 248 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 228 active_host_->SetActiveHostDisconnected(); | 264 active_host_->SetActiveHostDisconnected(); |
| 229 } | 265 } |
| 230 | 266 |
| 231 void TetherConnector::SetConnectionSucceeded( | 267 void TetherConnector::SetConnectionSucceeded( |
| 232 const std::string& device_id, | 268 const std::string& device_id, |
| 233 const std::string& wifi_network_guid) { | 269 const std::string& wifi_network_guid) { |
| 234 DCHECK(!device_id_pending_connection_.empty()); | 270 DCHECK(!device_id_pending_connection_.empty()); |
| 235 DCHECK(device_id_pending_connection_ == device_id); | 271 DCHECK(device_id_pending_connection_ == device_id); |
| 236 DCHECK(!success_callback_.is_null()); | 272 DCHECK(!success_callback_.is_null()); |
| 237 | 273 |
| 274 host_connection_metrics_logger_->RecordConnectionToHostResult( | |
| 275 HostConnectionMetricsLogger::ConnectionToHostResult:: | |
| 276 CONNECTION_RESULT_SUCCESS); | |
| 277 | |
| 238 notification_presenter_->RemoveSetupRequiredNotification(); | 278 notification_presenter_->RemoveSetupRequiredNotification(); |
| 239 | 279 |
| 240 // Save a copy of the callback before resetting it below. | 280 // Save a copy of the callback before resetting it below. |
| 241 base::Closure success_callback = success_callback_; | 281 base::Closure success_callback = success_callback_; |
| 242 | 282 |
| 243 device_id_pending_connection_.clear(); | 283 device_id_pending_connection_.clear(); |
| 244 success_callback_.Reset(); | 284 success_callback_.Reset(); |
| 245 error_callback_.Reset(); | 285 error_callback_.Reset(); |
| 246 | 286 |
| 247 success_callback.Run(); | 287 success_callback.Run(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 266 return; | 306 return; |
| 267 } | 307 } |
| 268 | 308 |
| 269 if (wifi_network_guid.empty()) { | 309 if (wifi_network_guid.empty()) { |
| 270 // If the Wi-Fi network ID is empty, then the connection did not succeed. | 310 // 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 " | 311 PA_LOG(ERROR) << "Failed to connect to the hotspot belonging to the device " |
| 272 << "with ID " | 312 << "with ID " |
| 273 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) | 313 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) |
| 274 << "."; | 314 << "."; |
| 275 | 315 |
| 316 host_connection_metrics_logger_->RecordConnectionToHostResult( | |
|
Kyle Horimoto
2017/07/07 17:06:33
Same thing - think you should move to SetConnectio
Ryan Hansberry
2017/07/12 16:37:06
Done.
| |
| 317 HostConnectionMetricsLogger::ConnectionToHostResult:: | |
| 318 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_TIMEOUT); | |
| 319 | |
| 276 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); | 320 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); |
| 277 return; | 321 return; |
| 278 } | 322 } |
| 279 | 323 |
| 280 SetConnectionSucceeded(device_id, wifi_network_guid); | 324 SetConnectionSucceeded(device_id, wifi_network_guid); |
| 281 } | 325 } |
| 282 | 326 |
| 283 } // namespace tether | 327 } // namespace tether |
| 284 | 328 |
| 285 } // namespace chromeos | 329 } // namespace chromeos |
| OLD | NEW |