| 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 #ifndef CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_OPERATION_H_ | 5 #ifndef CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_OPERATION_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_OPERATION_H_ | 6 #define CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_OPERATION_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "chromeos/components/tether/ble_connection_manager.h" | 13 #include "chromeos/components/tether/ble_connection_manager.h" |
| 14 #include "chromeos/components/tether/message_transfer_operation.h" | 14 #include "chromeos/components/tether/message_transfer_operation.h" |
| 15 #include "components/cryptauth/remote_device.h" | 15 #include "components/cryptauth/remote_device.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 | 18 |
| 19 namespace tether { | 19 namespace tether { |
| 20 | 20 |
| 21 class HostScanDevicePrioritizer; | 21 class HostScanDevicePrioritizer; |
| 22 class MessageWrapper; | 22 class MessageWrapper; |
| 23 class TetherHostResponseRecorder; |
| 23 | 24 |
| 24 // Operation used to perform a host scan. Attempts to connect to each of the | 25 // Operation used to perform a host scan. Attempts to connect to each of the |
| 25 // devices passed and sends a TetherAvailabilityRequest to each connected device | 26 // devices passed and sends a TetherAvailabilityRequest to each connected device |
| 26 // once an authenticated channel has been established; once a response has been | 27 // once an authenticated channel has been established; once a response has been |
| 27 // received, HostScannerOperation alerts observers of devices which can provide | 28 // received, HostScannerOperation alerts observers of devices which can provide |
| 28 // a tethering connection. | 29 // a tethering connection. |
| 29 // TODO(khorimoto): Add a timeout which gives up if no response is received in | 30 // TODO(khorimoto): Add a timeout which gives up if no response is received in |
| 30 // a reasonable amount of time. | 31 // a reasonable amount of time. |
| 31 class HostScannerOperation : public MessageTransferOperation { | 32 class HostScannerOperation : public MessageTransferOperation { |
| 32 public: | 33 public: |
| 33 class Factory { | 34 class Factory { |
| 34 public: | 35 public: |
| 35 static std::unique_ptr<HostScannerOperation> NewInstance( | 36 static std::unique_ptr<HostScannerOperation> NewInstance( |
| 36 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, | 37 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, |
| 37 BleConnectionManager* connection_manager, | 38 BleConnectionManager* connection_manager, |
| 38 HostScanDevicePrioritizer* host_scan_device_prioritizer); | 39 HostScanDevicePrioritizer* host_scan_device_prioritizer, |
| 40 TetherHostResponseRecorder* tether_host_response_recorder); |
| 39 | 41 |
| 40 static void SetInstanceForTesting(Factory* factory); | 42 static void SetInstanceForTesting(Factory* factory); |
| 41 | 43 |
| 42 protected: | 44 protected: |
| 43 virtual std::unique_ptr<HostScannerOperation> BuildInstance( | 45 virtual std::unique_ptr<HostScannerOperation> BuildInstance( |
| 44 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, | 46 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, |
| 45 BleConnectionManager* connection_manager, | 47 BleConnectionManager* connection_manager, |
| 46 HostScanDevicePrioritizer* host_scan_device_prioritizer); | 48 HostScanDevicePrioritizer* host_scan_device_prioritizer, |
| 49 TetherHostResponseRecorder* tether_host_response_recorder); |
| 47 | 50 |
| 48 private: | 51 private: |
| 49 static Factory* factory_instance_; | 52 static Factory* factory_instance_; |
| 50 }; | 53 }; |
| 51 | 54 |
| 52 struct ScannedDeviceInfo { | 55 struct ScannedDeviceInfo { |
| 53 ScannedDeviceInfo(const cryptauth::RemoteDevice& remote_device, | 56 ScannedDeviceInfo(const cryptauth::RemoteDevice& remote_device, |
| 54 const DeviceStatus& device_status, | 57 const DeviceStatus& device_status, |
| 55 bool set_up_required); | 58 bool set_up_required); |
| 56 ~ScannedDeviceInfo(); | 59 ~ScannedDeviceInfo(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 70 // processed, the callback is invoked one final time with | 73 // processed, the callback is invoked one final time with |
| 71 // |is_final_scan_result| = true. | 74 // |is_final_scan_result| = true. |
| 72 virtual void OnTetherAvailabilityResponse( | 75 virtual void OnTetherAvailabilityResponse( |
| 73 std::vector<ScannedDeviceInfo>& scanned_device_list_so_far, | 76 std::vector<ScannedDeviceInfo>& scanned_device_list_so_far, |
| 74 bool is_final_scan_result) = 0; | 77 bool is_final_scan_result) = 0; |
| 75 }; | 78 }; |
| 76 | 79 |
| 77 HostScannerOperation( | 80 HostScannerOperation( |
| 78 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, | 81 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, |
| 79 BleConnectionManager* connection_manager, | 82 BleConnectionManager* connection_manager, |
| 80 HostScanDevicePrioritizer* host_scan_device_prioritizer); | 83 HostScanDevicePrioritizer* host_scan_device_prioritizer, |
| 84 TetherHostResponseRecorder* tether_host_response_recorder); |
| 81 ~HostScannerOperation() override; | 85 ~HostScannerOperation() override; |
| 82 | 86 |
| 83 void AddObserver(Observer* observer); | 87 void AddObserver(Observer* observer); |
| 84 void RemoveObserver(Observer* observer); | 88 void RemoveObserver(Observer* observer); |
| 85 | 89 |
| 86 protected: | 90 protected: |
| 87 void NotifyObserversOfScannedDeviceList(bool is_final_scan_result); | 91 void NotifyObserversOfScannedDeviceList(bool is_final_scan_result); |
| 88 | 92 |
| 89 // MessageTransferOperation: | 93 // MessageTransferOperation: |
| 90 void OnDeviceAuthenticated( | 94 void OnDeviceAuthenticated( |
| 91 const cryptauth::RemoteDevice& remote_device) override; | 95 const cryptauth::RemoteDevice& remote_device) override; |
| 92 void OnMessageReceived(std::unique_ptr<MessageWrapper> message_wrapper, | 96 void OnMessageReceived(std::unique_ptr<MessageWrapper> message_wrapper, |
| 93 const cryptauth::RemoteDevice& remote_device) override; | 97 const cryptauth::RemoteDevice& remote_device) override; |
| 94 void OnOperationStarted() override; | 98 void OnOperationStarted() override; |
| 95 void OnOperationFinished() override; | 99 void OnOperationFinished() override; |
| 96 MessageType GetMessageTypeForConnection() override; | 100 MessageType GetMessageTypeForConnection() override; |
| 97 | 101 |
| 98 std::vector<ScannedDeviceInfo> scanned_device_list_so_far_; | 102 std::vector<ScannedDeviceInfo> scanned_device_list_so_far_; |
| 99 | 103 |
| 100 private: | 104 private: |
| 101 friend class HostScannerOperationTest; | 105 friend class HostScannerOperationTest; |
| 102 | 106 |
| 103 HostScanDevicePrioritizer* host_scan_device_prioritizer_; | 107 TetherHostResponseRecorder* tether_host_response_recorder_; |
| 104 base::ObserverList<Observer> observer_list_; | 108 base::ObserverList<Observer> observer_list_; |
| 105 | 109 |
| 106 DISALLOW_COPY_AND_ASSIGN(HostScannerOperation); | 110 DISALLOW_COPY_AND_ASSIGN(HostScannerOperation); |
| 107 }; | 111 }; |
| 108 | 112 |
| 109 } // namespace tether | 113 } // namespace tether |
| 110 | 114 |
| 111 } // namespace chromeos | 115 } // namespace chromeos |
| 112 | 116 |
| 113 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_OPERATION_H_ | 117 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_OPERATION_H_ |
| OLD | NEW |