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 #ifndef CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_DEVICE_PRIORITIZER_H_ | 5 #ifndef CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_DEVICE_PRIORITIZER_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_DEVICE_PRIORITIZER_H_ | 6 #define CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_DEVICE_PRIORITIZER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "chromeos/network/network_state_handler.h" | |
| 9 #include "components/cryptauth/remote_device.h" | 10 #include "components/cryptauth/remote_device.h" |
| 10 | 11 |
| 11 namespace chromeos { | 12 namespace chromeos { |
| 12 | 13 |
| 14 class NetworkStateHandler; | |
| 15 | |
| 13 namespace tether { | 16 namespace tether { |
| 14 | 17 |
| 15 class TetherHostResponseRecorder; | 18 class TetherHostResponseRecorder; |
| 19 class DeviceIdTetherNetworkGuidMap; | |
| 16 | 20 |
| 17 // Prioritizes the order of devices when performing a host scan. To optimize for | 21 // Prioritizes the order of devices when performing a host scan. To optimize for |
| 18 // the most common tethering operations, this class uses the following rules: | 22 // the most common tethering operations, this class uses the following rules: |
| 19 // * The device which has most recently sent a successful | 23 // * The device which has most recently sent a successful |
| 20 // ConnectTetheringResponse is always at the front of the queue. | 24 // ConnectTetheringResponse is always at the front of the queue. |
| 21 // * Devices which have most recently sent a successful | 25 // * Devices which have most recently sent a successful |
| 22 // TetherAvailabilityResponse are next in the order, as long as they do not | 26 // TetherAvailabilityResponse are next in the order, as long as they do not |
| 23 // violate the first rule. | 27 // violate the first rule. |
| 24 // * All other devices are left in the order they are passed. | 28 // * All other devices are left in the order they are passed. |
| 25 class HostScanDevicePrioritizer { | 29 class HostScanDevicePrioritizer |
| 30 : public NetworkStateHandler::TetherNetworkListSorter { | |
| 26 public: | 31 public: |
| 27 HostScanDevicePrioritizer( | 32 HostScanDevicePrioritizer( |
| 28 TetherHostResponseRecorder* tether_host_response_recorder); | 33 NetworkStateHandler* network_state_handler, |
| 34 TetherHostResponseRecorder* tether_host_response_recorder, | |
| 35 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map); | |
| 29 virtual ~HostScanDevicePrioritizer(); | 36 virtual ~HostScanDevicePrioritizer(); |
| 30 | 37 |
| 31 // Prioritizes |remote_devices| using the rules described above. | 38 // Prioritizes |remote_devices| using the rules described above. |
| 32 virtual void SortByHostScanOrder( | 39 virtual void SortByHostScanOrder( |
| 33 std::vector<cryptauth::RemoteDevice>* remote_devices) const; | 40 std::vector<cryptauth::RemoteDevice>* remote_devices) const; |
| 34 | 41 |
| 42 // NetworkStateHandler::TetherNetworkListSorter: | |
| 43 void SortTetherNetworkList( | |
| 44 NetworkStateHandler::ManagedStateList* tether_networks) const override; | |
| 45 | |
| 35 private: | 46 private: |
| 47 // Performs sorting for both SortByHostScanOrder() and | |
| 48 // SortTetherNetworkList(). | |
| 49 template <typename T> | |
| 50 void SortNetworks(std::vector<T>* list_to_sort) const; | |
| 51 | |
| 52 // GetDeviceId() and Move() are used internally by SortNetworks() to sort | |
| 53 // lists of both cryptauth::RemoteDevice and std::unique_ptr<ManagedState>. | |
| 54 std::string GetDeviceId(const cryptauth::RemoteDevice& remote_device) const; | |
| 55 std::string GetDeviceId( | |
| 56 const std::unique_ptr<ManagedState>& tether_network_state) const; | |
| 57 cryptauth::RemoteDevice Move( | |
| 58 const cryptauth::RemoteDevice& remote_device) const; | |
| 59 std::unique_ptr<ManagedState> Move( | |
|
Ryan Hansberry
2017/06/19 19:17:48
Why ManagedState instead of NetworkState?
Kyle Horimoto
2017/06/20 23:44:54
The vector stored in NetworkStateHandler is a Mana
| |
| 60 std::unique_ptr<ManagedState>& tether_network_state) const; | |
| 61 | |
| 62 NetworkStateHandler* network_state_handler_; | |
| 36 TetherHostResponseRecorder* tether_host_response_recorder_; | 63 TetherHostResponseRecorder* tether_host_response_recorder_; |
| 64 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map_; | |
| 37 | 65 |
| 38 DISALLOW_COPY_AND_ASSIGN(HostScanDevicePrioritizer); | 66 DISALLOW_COPY_AND_ASSIGN(HostScanDevicePrioritizer); |
| 39 }; | 67 }; |
| 40 | 68 |
| 41 } // namespace tether | 69 } // namespace tether |
| 42 | 70 |
| 43 } // namespace chromeos | 71 } // namespace chromeos |
| 44 | 72 |
| 45 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_DEVICE_PRIORITIZER_H_ | 73 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_DEVICE_PRIORITIZER_H_ |
| OLD | NEW |