| 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/connect_tethering_operation.h" | 5 #include "chromeos/components/tether/connect_tethering_operation.h" |
| 6 | 6 |
| 7 #include "chromeos/components/tether/host_scan_device_prioritizer.h" | |
| 8 #include "chromeos/components/tether/message_wrapper.h" | 7 #include "chromeos/components/tether/message_wrapper.h" |
| 9 #include "chromeos/components/tether/proto/tether.pb.h" | 8 #include "chromeos/components/tether/proto/tether.pb.h" |
| 9 #include "chromeos/components/tether/tether_host_response_recorder.h" |
| 10 #include "components/proximity_auth/logging/logging.h" | 10 #include "components/proximity_auth/logging/logging.h" |
| 11 | 11 |
| 12 namespace chromeos { | 12 namespace chromeos { |
| 13 | 13 |
| 14 namespace tether { | 14 namespace tether { |
| 15 | 15 |
| 16 // static | 16 // static |
| 17 ConnectTetheringOperation::Factory* | 17 ConnectTetheringOperation::Factory* |
| 18 ConnectTetheringOperation::Factory::factory_instance_ = nullptr; | 18 ConnectTetheringOperation::Factory::factory_instance_ = nullptr; |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 std::unique_ptr<ConnectTetheringOperation> | 21 std::unique_ptr<ConnectTetheringOperation> |
| 22 ConnectTetheringOperation::Factory::NewInstance( | 22 ConnectTetheringOperation::Factory::NewInstance( |
| 23 const cryptauth::RemoteDevice& device_to_connect, | 23 const cryptauth::RemoteDevice& device_to_connect, |
| 24 BleConnectionManager* connection_manager, | 24 BleConnectionManager* connection_manager, |
| 25 HostScanDevicePrioritizer* host_scan_device_prioritizer) { | 25 TetherHostResponseRecorder* tether_host_response_recorder) { |
| 26 if (!factory_instance_) { | 26 if (!factory_instance_) { |
| 27 factory_instance_ = new Factory(); | 27 factory_instance_ = new Factory(); |
| 28 } | 28 } |
| 29 return factory_instance_->BuildInstance(device_to_connect, connection_manager, | 29 return factory_instance_->BuildInstance(device_to_connect, connection_manager, |
| 30 host_scan_device_prioritizer); | 30 tether_host_response_recorder); |
| 31 } | 31 } |
| 32 | 32 |
| 33 // static | 33 // static |
| 34 void ConnectTetheringOperation::Factory::SetInstanceForTesting( | 34 void ConnectTetheringOperation::Factory::SetInstanceForTesting( |
| 35 Factory* factory) { | 35 Factory* factory) { |
| 36 factory_instance_ = factory; | 36 factory_instance_ = factory; |
| 37 } | 37 } |
| 38 | 38 |
| 39 std::unique_ptr<ConnectTetheringOperation> | 39 std::unique_ptr<ConnectTetheringOperation> |
| 40 ConnectTetheringOperation::Factory::BuildInstance( | 40 ConnectTetheringOperation::Factory::BuildInstance( |
| 41 const cryptauth::RemoteDevice& device_to_connect, | 41 const cryptauth::RemoteDevice& device_to_connect, |
| 42 BleConnectionManager* connection_manager, | 42 BleConnectionManager* connection_manager, |
| 43 HostScanDevicePrioritizer* host_scan_device_prioritizer) { | 43 TetherHostResponseRecorder* tether_host_response_recorder) { |
| 44 return base::MakeUnique<ConnectTetheringOperation>( | 44 return base::MakeUnique<ConnectTetheringOperation>( |
| 45 device_to_connect, connection_manager, host_scan_device_prioritizer); | 45 device_to_connect, connection_manager, tether_host_response_recorder); |
| 46 } | 46 } |
| 47 | 47 |
| 48 ConnectTetheringOperation::ConnectTetheringOperation( | 48 ConnectTetheringOperation::ConnectTetheringOperation( |
| 49 const cryptauth::RemoteDevice& device_to_connect, | 49 const cryptauth::RemoteDevice& device_to_connect, |
| 50 BleConnectionManager* connection_manager, | 50 BleConnectionManager* connection_manager, |
| 51 HostScanDevicePrioritizer* host_scan_device_prioritizer) | 51 TetherHostResponseRecorder* tether_host_response_recorder) |
| 52 : MessageTransferOperation( | 52 : MessageTransferOperation( |
| 53 std::vector<cryptauth::RemoteDevice>{device_to_connect}, | 53 std::vector<cryptauth::RemoteDevice>{device_to_connect}, |
| 54 connection_manager), | 54 connection_manager), |
| 55 remote_device_(device_to_connect), | 55 remote_device_(device_to_connect), |
| 56 host_scan_device_prioritizer_(host_scan_device_prioritizer), | 56 tether_host_response_recorder_(tether_host_response_recorder), |
| 57 error_code_to_return_( | 57 error_code_to_return_( |
| 58 ConnectTetheringResponse_ResponseCode:: | 58 ConnectTetheringResponse_ResponseCode:: |
| 59 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR) {} | 59 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR) {} |
| 60 | 60 |
| 61 ConnectTetheringOperation::~ConnectTetheringOperation() {} | 61 ConnectTetheringOperation::~ConnectTetheringOperation() {} |
| 62 | 62 |
| 63 void ConnectTetheringOperation::AddObserver(Observer* observer) { | 63 void ConnectTetheringOperation::AddObserver(Observer* observer) { |
| 64 observer_list_.AddObserver(observer); | 64 observer_list_.AddObserver(observer); |
| 65 } | 65 } |
| 66 | 66 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 94 if (response->response_code() == | 94 if (response->response_code() == |
| 95 ConnectTetheringResponse_ResponseCode:: | 95 ConnectTetheringResponse_ResponseCode:: |
| 96 ConnectTetheringResponse_ResponseCode_SUCCESS) { | 96 ConnectTetheringResponse_ResponseCode_SUCCESS) { |
| 97 if (response->has_ssid() && response->has_password()) { | 97 if (response->has_ssid() && response->has_password()) { |
| 98 PA_LOG(INFO) << "Received ConnectTetheringResponse from device with ID " | 98 PA_LOG(INFO) << "Received ConnectTetheringResponse from device with ID " |
| 99 << remote_device.GetTruncatedDeviceIdForLogs() << " and " | 99 << remote_device.GetTruncatedDeviceIdForLogs() << " and " |
| 100 << "response_code == SUCCESS. Config: {ssid: \"" | 100 << "response_code == SUCCESS. Config: {ssid: \"" |
| 101 << response->ssid() << "\", password: \"" | 101 << response->ssid() << "\", password: \"" |
| 102 << response->password() << "\"}"; | 102 << response->password() << "\"}"; |
| 103 | 103 |
| 104 host_scan_device_prioritizer_->RecordSuccessfulConnectTetheringResponse( | 104 tether_host_response_recorder_->RecordSuccessfulConnectTetheringResponse( |
| 105 remote_device); | 105 remote_device); |
| 106 | 106 |
| 107 ssid_to_return_ = response->ssid(); | 107 ssid_to_return_ = response->ssid(); |
| 108 password_to_return_ = response->password(); | 108 password_to_return_ = response->password(); |
| 109 } else { | 109 } else { |
| 110 PA_LOG(ERROR) << "Received ConnectTetheringResponse from device with ID " | 110 PA_LOG(ERROR) << "Received ConnectTetheringResponse from device with ID " |
| 111 << remote_device.GetTruncatedDeviceIdForLogs() << " and " | 111 << remote_device.GetTruncatedDeviceIdForLogs() << " and " |
| 112 << "response_code == SUCCESS, but the response did not " | 112 << "response_code == SUCCESS, but the response did not " |
| 113 << "contain a Wi-Fi SSID and/or password."; | 113 << "contain a Wi-Fi SSID and/or password."; |
| 114 } | 114 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 void ConnectTetheringOperation::NotifyObserversOfConnectionFailure( | 155 void ConnectTetheringOperation::NotifyObserversOfConnectionFailure( |
| 156 ConnectTetheringResponse_ResponseCode error_code) { | 156 ConnectTetheringResponse_ResponseCode error_code) { |
| 157 for (auto& observer : observer_list_) { | 157 for (auto& observer : observer_list_) { |
| 158 observer.OnConnectTetheringFailure(remote_device_, error_code); | 158 observer.OnConnectTetheringFailure(remote_device_, error_code); |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace tether | 162 } // namespace tether |
| 163 | 163 |
| 164 } // namespace chromeos | 164 } // namespace chromeos |
| OLD | NEW |