| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_H_ | 5 #ifndef CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_H_ | 6 #define CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "chromeos/components/tether/host_scanner_operation.h" | 11 #include "chromeos/components/tether/host_scanner_operation.h" |
| 12 #include "chromeos/components/tether/notification_presenter.h" | 12 #include "chromeos/components/tether/notification_presenter.h" |
| 13 #include "chromeos/network/network_state_handler.h" | 13 #include "chromeos/network/network_state_handler.h" |
| 14 #include "components/cryptauth/remote_device.h" | 14 #include "components/cryptauth/remote_device.h" |
| 15 | 15 |
| 16 namespace chromeos { | 16 namespace chromeos { |
| 17 | 17 |
| 18 namespace tether { | 18 namespace tether { |
| 19 | 19 |
| 20 class BleConnectionManager; | 20 class BleConnectionManager; |
| 21 class DeviceIdTetherNetworkGuidMap; | 21 class DeviceIdTetherNetworkGuidMap; |
| 22 class HostScanCache; |
| 22 class HostScanDevicePrioritizer; | 23 class HostScanDevicePrioritizer; |
| 23 class TetherHostFetcher; | 24 class TetherHostFetcher; |
| 24 class TetherHostResponseRecorder; | 25 class TetherHostResponseRecorder; |
| 25 | 26 |
| 26 // Scans for nearby tether hosts. | 27 // Scans for nearby tether hosts. When StartScan() is called, this class creates |
| 27 // TODO(khorimoto): Add some sort of "staleness" timeout which removes scan | 28 // a new HostScannerOperation and uses it to contact nearby devices to query |
| 28 // results which occurred long enough ago that they are no | 29 // whether they can provide tether capabilities. Once the scan results are |
| 29 // longer valid. | 30 // received, they are stored in the HostScanCache passed to the constructor. |
| 30 class HostScanner : public HostScannerOperation::Observer { | 31 class HostScanner : public HostScannerOperation::Observer { |
| 31 public: | 32 public: |
| 32 HostScanner(TetherHostFetcher* tether_host_fetcher, | 33 HostScanner(TetherHostFetcher* tether_host_fetcher, |
| 33 BleConnectionManager* connection_manager, | 34 BleConnectionManager* connection_manager, |
| 34 HostScanDevicePrioritizer* host_scan_device_prioritizer, | 35 HostScanDevicePrioritizer* host_scan_device_prioritizer, |
| 35 TetherHostResponseRecorder* tether_host_response_recorder, | 36 TetherHostResponseRecorder* tether_host_response_recorder, |
| 36 NetworkStateHandler* network_state_handler, | |
| 37 NotificationPresenter* notification_presenter, | 37 NotificationPresenter* notification_presenter, |
| 38 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map); | 38 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map, |
| 39 HostScanCache* host_scan_cache); |
| 39 virtual ~HostScanner(); | 40 virtual ~HostScanner(); |
| 40 | 41 |
| 41 // Starts a host scan if there is no current scan. If a scan is ongoing, this | 42 // Starts a host scan if there is no current scan. If a scan is ongoing, this |
| 42 // function is a no-op. | 43 // function is a no-op. |
| 43 virtual void StartScan(); | 44 virtual void StartScan(); |
| 44 | 45 |
| 45 bool IsScanActive(); | 46 bool IsScanActive(); |
| 46 | 47 |
| 47 std::vector<HostScannerOperation::ScannedDeviceInfo> | |
| 48 most_recent_scan_results() { | |
| 49 return most_recent_scan_results_; | |
| 50 } | |
| 51 | |
| 52 // HostScannerOperation::Observer: | 48 // HostScannerOperation::Observer: |
| 53 void OnTetherAvailabilityResponse( | 49 void OnTetherAvailabilityResponse( |
| 54 std::vector<HostScannerOperation::ScannedDeviceInfo>& | 50 std::vector<HostScannerOperation::ScannedDeviceInfo>& |
| 55 scanned_device_list_so_far, | 51 scanned_device_list_so_far, |
| 56 bool is_final_scan_result) override; | 52 bool is_final_scan_result) override; |
| 57 | 53 |
| 58 private: | 54 private: |
| 59 friend class HostScannerTest; | 55 friend class HostScannerTest; |
| 60 friend class HostScanSchedulerTest; | 56 friend class HostScanSchedulerTest; |
| 61 | 57 |
| 62 void OnTetherHostsFetched(const cryptauth::RemoteDeviceList& tether_hosts); | 58 void OnTetherHostsFetched(const cryptauth::RemoteDeviceList& tether_hosts); |
| 59 void SetCacheEntry( |
| 60 const HostScannerOperation::ScannedDeviceInfo& scanned_device_info); |
| 63 | 61 |
| 64 TetherHostFetcher* tether_host_fetcher_; | 62 TetherHostFetcher* tether_host_fetcher_; |
| 65 BleConnectionManager* connection_manager_; | 63 BleConnectionManager* connection_manager_; |
| 66 HostScanDevicePrioritizer* host_scan_device_prioritizer_; | 64 HostScanDevicePrioritizer* host_scan_device_prioritizer_; |
| 67 TetherHostResponseRecorder* tether_host_response_recorder_; | 65 TetherHostResponseRecorder* tether_host_response_recorder_; |
| 68 NetworkStateHandler* network_state_handler_; | |
| 69 NotificationPresenter* notification_presenter_; | 66 NotificationPresenter* notification_presenter_; |
| 70 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map_; | 67 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map_; |
| 68 HostScanCache* host_scan_cache_; |
| 71 | 69 |
| 72 bool is_fetching_hosts_; | 70 bool is_fetching_hosts_; |
| 73 std::unique_ptr<HostScannerOperation> host_scanner_operation_; | 71 std::unique_ptr<HostScannerOperation> host_scanner_operation_; |
| 74 std::vector<HostScannerOperation::ScannedDeviceInfo> | |
| 75 most_recent_scan_results_; | |
| 76 | 72 |
| 77 base::WeakPtrFactory<HostScanner> weak_ptr_factory_; | 73 base::WeakPtrFactory<HostScanner> weak_ptr_factory_; |
| 78 | 74 |
| 79 DISALLOW_COPY_AND_ASSIGN(HostScanner); | 75 DISALLOW_COPY_AND_ASSIGN(HostScanner); |
| 80 }; | 76 }; |
| 81 | 77 |
| 82 } // namespace tether | 78 } // namespace tether |
| 83 | 79 |
| 84 } // namespace chromeos | 80 } // namespace chromeos |
| 85 | 81 |
| 86 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_H_ | 82 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_H_ |
| OLD | NEW |