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