Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chromeos/components/tether/host_scanner.h

Issue 2870393003: Tether: only scan when asked to by NetworkStateHandler. (Closed)
Patch Set: Remove PowerManagerClient callbacks and implement all NetworkStateHandler callbacks. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/observer_list.h"
12 #include "base/time/clock.h"
13 #include "base/time/time.h"
11 #include "chromeos/components/tether/host_scanner_operation.h" 14 #include "chromeos/components/tether/host_scanner_operation.h"
12 #include "chromeos/components/tether/notification_presenter.h" 15 #include "chromeos/components/tether/notification_presenter.h"
13 #include "chromeos/network/network_state_handler.h" 16 #include "chromeos/network/network_state_handler.h"
14 #include "components/cryptauth/remote_device.h" 17 #include "components/cryptauth/remote_device.h"
15 18
16 namespace chromeos { 19 namespace chromeos {
17 20
18 namespace tether { 21 namespace tether {
19 22
20 class BleConnectionManager; 23 class BleConnectionManager;
21 class DeviceIdTetherNetworkGuidMap; 24 class DeviceIdTetherNetworkGuidMap;
22 class HostScanCache; 25 class HostScanCache;
23 class HostScanDevicePrioritizer; 26 class HostScanDevicePrioritizer;
24 class TetherHostFetcher; 27 class TetherHostFetcher;
25 class TetherHostResponseRecorder; 28 class TetherHostResponseRecorder;
26 29
27 // Scans for nearby tether hosts. When StartScan() is called, this class creates 30 // Scans for nearby tether hosts. When StartScan() is called, this class creates
28 // a new HostScannerOperation and uses it to contact nearby devices to query 31 // a new HostScannerOperation and uses it to contact nearby devices to query
29 // whether they can provide tether capabilities. Once the scan results are 32 // whether they can provide tether capabilities. Once the scan results are
30 // received, they are stored in the HostScanCache passed to the constructor. 33 // received, they are stored in the HostScanCache passed to the constructor,
34 // and observers are notified via HostScanner::Observer::ScanFinished().
31 class HostScanner : public HostScannerOperation::Observer { 35 class HostScanner : public HostScannerOperation::Observer {
32 public: 36 public:
37 class Observer {
38 public:
39 void virtual ScanFinished() = 0;
40 };
41
33 HostScanner(TetherHostFetcher* tether_host_fetcher, 42 HostScanner(TetherHostFetcher* tether_host_fetcher,
34 BleConnectionManager* connection_manager, 43 BleConnectionManager* connection_manager,
35 HostScanDevicePrioritizer* host_scan_device_prioritizer, 44 HostScanDevicePrioritizer* host_scan_device_prioritizer,
36 TetherHostResponseRecorder* tether_host_response_recorder, 45 TetherHostResponseRecorder* tether_host_response_recorder,
37 NotificationPresenter* notification_presenter, 46 NotificationPresenter* notification_presenter,
38 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map, 47 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map,
39 HostScanCache* host_scan_cache); 48 HostScanCache* host_scan_cache,
49 base::Clock* clock);
40 virtual ~HostScanner(); 50 virtual ~HostScanner();
41 51
42 // Starts a host scan if there is no current scan. If a scan is ongoing, this 52 // Returns true if a scan is currently in progress.
53 virtual bool IsScanActive();
54
55 // Returns true if a scan has occurred recently within a timespan, determined
56 // by HostScanCache::kNumMinutesBeforeCacheEntryExpires.
57 virtual bool HasRecentlyScanned();
58
59 // Starts a host scan if there is no current scan. If a scan is active, this
43 // function is a no-op. 60 // function is a no-op.
44 virtual void StartScan(); 61 virtual void StartScan();
45 62
46 bool IsScanActive();
47
48 // HostScannerOperation::Observer: 63 // HostScannerOperation::Observer:
49 void OnTetherAvailabilityResponse( 64 void OnTetherAvailabilityResponse(
50 std::vector<HostScannerOperation::ScannedDeviceInfo>& 65 std::vector<HostScannerOperation::ScannedDeviceInfo>&
51 scanned_device_list_so_far, 66 scanned_device_list_so_far,
52 bool is_final_scan_result) override; 67 bool is_final_scan_result) override;
53 68
69 void AddObserver(Observer* observer);
70 void RemoveObserver(Observer* observer);
71
54 private: 72 private:
55 friend class HostScannerTest; 73 friend class HostScannerTest;
56 friend class HostScanSchedulerTest; 74 friend class HostScanSchedulerTest;
57 75
76 void NotifyScanFinished();
77
58 void OnTetherHostsFetched(const cryptauth::RemoteDeviceList& tether_hosts); 78 void OnTetherHostsFetched(const cryptauth::RemoteDeviceList& tether_hosts);
59 void SetCacheEntry( 79 void SetCacheEntry(
60 const HostScannerOperation::ScannedDeviceInfo& scanned_device_info); 80 const HostScannerOperation::ScannedDeviceInfo& scanned_device_info);
61 81
62 TetherHostFetcher* tether_host_fetcher_; 82 TetherHostFetcher* tether_host_fetcher_;
63 BleConnectionManager* connection_manager_; 83 BleConnectionManager* connection_manager_;
64 HostScanDevicePrioritizer* host_scan_device_prioritizer_; 84 HostScanDevicePrioritizer* host_scan_device_prioritizer_;
65 TetherHostResponseRecorder* tether_host_response_recorder_; 85 TetherHostResponseRecorder* tether_host_response_recorder_;
66 NotificationPresenter* notification_presenter_; 86 NotificationPresenter* notification_presenter_;
67 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map_; 87 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map_;
68 HostScanCache* host_scan_cache_; 88 HostScanCache* host_scan_cache_;
89 base::Clock* clock_;
69 90
70 bool is_fetching_hosts_; 91 bool is_fetching_hosts_;
71 std::unique_ptr<HostScannerOperation> host_scanner_operation_; 92 std::unique_ptr<HostScannerOperation> host_scanner_operation_;
93 base::Time previous_scan_time_;
72 94
95 base::ObserverList<Observer> observer_list_;
73 base::WeakPtrFactory<HostScanner> weak_ptr_factory_; 96 base::WeakPtrFactory<HostScanner> weak_ptr_factory_;
74 97
75 DISALLOW_COPY_AND_ASSIGN(HostScanner); 98 DISALLOW_COPY_AND_ASSIGN(HostScanner);
76 }; 99 };
77 100
78 } // namespace tether 101 } // namespace tether
79 102
80 } // namespace chromeos 103 } // namespace chromeos
81 104
82 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_H_ 105 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCANNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698