| Index: chromeos/components/tether/host_scanner.h
|
| diff --git a/chromeos/components/tether/host_scanner.h b/chromeos/components/tether/host_scanner.h
|
| index 85e1ef77c9fdaeaff8c6e99fa0a76c0a99b1cc38..7de4e1c37be615877cff704dba308139f8f7e15b 100644
|
| --- a/chromeos/components/tether/host_scanner.h
|
| +++ b/chromeos/components/tether/host_scanner.h
|
| @@ -8,6 +8,9 @@
|
| #include <vector>
|
|
|
| #include "base/memory/weak_ptr.h"
|
| +#include "base/observer_list.h"
|
| +#include "base/time/clock.h"
|
| +#include "base/time/time.h"
|
| #include "chromeos/components/tether/host_scanner_operation.h"
|
| #include "chromeos/components/tether/notification_presenter.h"
|
| #include "chromeos/network/network_state_handler.h"
|
| @@ -27,34 +30,51 @@ class TetherHostResponseRecorder;
|
| // Scans for nearby tether hosts. When StartScan() is called, this class creates
|
| // a new HostScannerOperation and uses it to contact nearby devices to query
|
| // whether they can provide tether capabilities. Once the scan results are
|
| -// received, they are stored in the HostScanCache passed to the constructor.
|
| +// received, they are stored in the HostScanCache passed to the constructor,
|
| +// and observers are notified via HostScanner::Observer::ScanFinished().
|
| class HostScanner : public HostScannerOperation::Observer {
|
| public:
|
| + class Observer {
|
| + public:
|
| + void virtual ScanFinished() = 0;
|
| + };
|
| +
|
| HostScanner(TetherHostFetcher* tether_host_fetcher,
|
| BleConnectionManager* connection_manager,
|
| HostScanDevicePrioritizer* host_scan_device_prioritizer,
|
| TetherHostResponseRecorder* tether_host_response_recorder,
|
| NotificationPresenter* notification_presenter,
|
| DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map,
|
| - HostScanCache* host_scan_cache);
|
| + HostScanCache* host_scan_cache,
|
| + base::Clock* clock);
|
| virtual ~HostScanner();
|
|
|
| - // Starts a host scan if there is no current scan. If a scan is ongoing, this
|
| + // Returns true if a scan is currently in progress.
|
| + virtual bool IsScanActive();
|
| +
|
| + // Returns true if a scan has occurred recently within a timespan, determined
|
| + // by HostScanCache::kNumMinutesBeforeCacheEntryExpires.
|
| + virtual bool HasRecentlyScanned();
|
| +
|
| + // Starts a host scan if there is no current scan. If a scan is active, this
|
| // function is a no-op.
|
| virtual void StartScan();
|
|
|
| - bool IsScanActive();
|
| -
|
| // HostScannerOperation::Observer:
|
| void OnTetherAvailabilityResponse(
|
| std::vector<HostScannerOperation::ScannedDeviceInfo>&
|
| scanned_device_list_so_far,
|
| bool is_final_scan_result) override;
|
|
|
| + void AddObserver(Observer* observer);
|
| + void RemoveObserver(Observer* observer);
|
| +
|
| private:
|
| friend class HostScannerTest;
|
| friend class HostScanSchedulerTest;
|
|
|
| + void NotifyScanFinished();
|
| +
|
| void OnTetherHostsFetched(const cryptauth::RemoteDeviceList& tether_hosts);
|
| void SetCacheEntry(
|
| const HostScannerOperation::ScannedDeviceInfo& scanned_device_info);
|
| @@ -66,10 +86,13 @@ class HostScanner : public HostScannerOperation::Observer {
|
| NotificationPresenter* notification_presenter_;
|
| DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map_;
|
| HostScanCache* host_scan_cache_;
|
| + base::Clock* clock_;
|
|
|
| bool is_fetching_hosts_;
|
| std::unique_ptr<HostScannerOperation> host_scanner_operation_;
|
| + base::Time previous_scan_time_;
|
|
|
| + base::ObserverList<Observer> observer_list_;
|
| base::WeakPtrFactory<HostScanner> weak_ptr_factory_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(HostScanner);
|
|
|