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/tether_host_fetcher.h" | 10 #include "chromeos/components/tether/tether_host_fetcher.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // Make a copy of the device ID, SSID, and password to pass below before | 132 // Make a copy of the device ID, SSID, and password to pass below before |
133 // destroying |connect_tethering_operation_|. | 133 // destroying |connect_tethering_operation_|. |
134 std::string remote_device_id = remote_device.GetDeviceId(); | 134 std::string remote_device_id = remote_device.GetDeviceId(); |
135 std::string ssid_copy = ssid; | 135 std::string ssid_copy = ssid; |
136 std::string password_copy = password; | 136 std::string password_copy = password; |
137 | 137 |
138 connect_tethering_operation_->RemoveObserver(this); | 138 connect_tethering_operation_->RemoveObserver(this); |
139 connect_tethering_operation_.reset(); | 139 connect_tethering_operation_.reset(); |
140 | 140 |
141 wifi_hotspot_connector_->ConnectToWifiHotspot( | 141 wifi_hotspot_connector_->ConnectToWifiHotspot( |
142 ssid_copy, password_copy, | 142 ssid_copy, password_copy, active_host_->GetTetherNetworkGuid(), |
143 base::Bind(&TetherConnector::OnWifiConnection, | 143 base::Bind(&TetherConnector::OnWifiConnection, |
144 weak_ptr_factory_.GetWeakPtr(), remote_device_id)); | 144 weak_ptr_factory_.GetWeakPtr(), remote_device_id)); |
145 } | 145 } |
146 | 146 |
147 void TetherConnector::OnConnectTetheringFailure( | 147 void TetherConnector::OnConnectTetheringFailure( |
148 const cryptauth::RemoteDevice& remote_device, | 148 const cryptauth::RemoteDevice& remote_device, |
149 ConnectTetheringResponse_ResponseCode error_code) { | 149 ConnectTetheringResponse_ResponseCode error_code) { |
150 if (device_id_pending_connection_ != remote_device.GetDeviceId()) { | 150 if (device_id_pending_connection_ != remote_device.GetDeviceId()) { |
151 // If the failure was part of a previous attempt for a different device, | 151 // If the failure was part of a previous attempt for a different device, |
152 // ignore it. | 152 // ignore it. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 // If the Wi-Fi network ID is empty, then the connection did not succeed. | 248 // If the Wi-Fi network ID is empty, then the connection did not succeed. |
249 PA_LOG(ERROR) << "Failed to connect to the hotspot belonging to the device " | 249 PA_LOG(ERROR) << "Failed to connect to the hotspot belonging to the device " |
250 << "with ID " | 250 << "with ID " |
251 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) | 251 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) |
252 << "."; | 252 << "."; |
253 | 253 |
254 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); | 254 SetConnectionFailed(NetworkConnectionHandler::kErrorConnectFailed); |
255 return; | 255 return; |
256 } | 256 } |
257 | 257 |
258 bool successful_association = | |
259 network_state_handler_->AssociateTetherNetworkStateWithWifiNetwork( | |
260 device_id, wifi_network_guid); | |
261 if (successful_association) { | |
262 PA_LOG(INFO) << "Successfully connected to host device with ID " | |
263 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) | |
264 << ". Tether network ID: \"" << device_id | |
265 << "\", Wi-Fi network ID: \"" << wifi_network_guid << "\""; | |
266 } else { | |
267 PA_LOG(WARNING) << "Successfully connected to host device with ID " | |
268 << cryptauth::RemoteDevice::TruncateDeviceIdForLogs( | |
269 device_id) | |
270 << ", but failed to associate tether network with ID \"" | |
271 << device_id << "\" to Wi-Fi network with ID \"" | |
272 << wifi_network_guid << "\"."; | |
273 } | |
274 | |
275 SetConnectionSucceeded(device_id, wifi_network_guid); | 258 SetConnectionSucceeded(device_id, wifi_network_guid); |
276 } | 259 } |
277 | 260 |
278 } // namespace tether | 261 } // namespace tether |
279 | 262 |
280 } // namespace chromeos | 263 } // namespace chromeos |
OLD | NEW |