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_CACHE_H_ | 5 #ifndef CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_CACHE_H_ |
6 #define CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_CACHE_H_ | 6 #define CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_CACHE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
14 #include "chromeos/components/tether/tether_host_response_recorder.h" | 14 #include "chromeos/components/tether/tether_host_response_recorder.h" |
15 | 15 |
16 namespace chromeos { | 16 namespace chromeos { |
17 | 17 |
18 class NetworkStateHandler; | 18 class NetworkStateHandler; |
19 | 19 |
20 namespace tether { | 20 namespace tether { |
21 | 21 |
22 class ActiveHost; | 22 class ActiveHost; |
23 class DeviceIdTetherNetworkGuidMap; | 23 class DeviceIdTetherNetworkGuidMap; |
24 class TetherHostResponseRecorder; | 24 class TetherHostResponseRecorder; |
| 25 class TimerFactory; |
25 | 26 |
26 // Caches scan results and inserts them into the network stack. | 27 // Caches scan results and inserts them into the network stack. |
27 class HostScanCache : public TetherHostResponseRecorder::Observer { | 28 class HostScanCache : public TetherHostResponseRecorder::Observer { |
28 public: | 29 public: |
29 // The number of minutes that a cache entry is considered to be valid before | 30 // The number of minutes that a cache entry is considered to be valid before |
30 // it becomes stale. Once a cache entry is inserted, it will be automatically | 31 // it becomes stale. Once a cache entry is inserted, it will be automatically |
31 // removed after this amount of time passes unless it corresponds to the | 32 // removed after this amount of time passes unless it corresponds to the |
32 // active host. This value was chosen for two reasons: | 33 // active host. This value was chosen for two reasons: |
33 // (1) Tether properties such as battery percentage and signal strength | 34 // (1) Tether properties such as battery percentage and signal strength |
34 // are ephemeral in nature, so keeping these values cached for more | 35 // are ephemeral in nature, so keeping these values cached for more |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 virtual bool RemoveHostScanResult(const std::string& tether_network_guid); | 70 virtual bool RemoveHostScanResult(const std::string& tether_network_guid); |
70 | 71 |
71 // Removes all scan results from the cache unless they correspond to the | 72 // Removes all scan results from the cache unless they correspond to the |
72 // active host; the active host must always remain in the cache while | 73 // active host; the active host must always remain in the cache while |
73 // connecting/connected to ensure the UI is up to date. | 74 // connecting/connected to ensure the UI is up to date. |
74 virtual void ClearCacheExceptForActiveHost(); | 75 virtual void ClearCacheExceptForActiveHost(); |
75 | 76 |
76 // TetherHostResponseRecorder::Observer: | 77 // TetherHostResponseRecorder::Observer: |
77 void OnPreviouslyConnectedHostIdsChanged() override; | 78 void OnPreviouslyConnectedHostIdsChanged() override; |
78 | 79 |
79 class TimerFactory { | |
80 public: | |
81 virtual std::unique_ptr<base::Timer> CreateOneShotTimer() = 0; | |
82 }; | |
83 | |
84 private: | 80 private: |
85 friend class HostScanCacheTest; | 81 friend class HostScanCacheTest; |
86 | 82 |
87 void SetTimerFactoryForTest( | 83 void SetTimerFactoryForTest( |
88 std::unique_ptr<TimerFactory> timer_factory_for_test); | 84 std::unique_ptr<TimerFactory> timer_factory_for_test); |
89 | 85 |
90 bool HasConnectedToHost(const std::string& tether_network_guid); | 86 bool HasConnectedToHost(const std::string& tether_network_guid); |
91 void StartTimer(const std::string& tether_network_guid); | 87 void StartTimer(const std::string& tether_network_guid); |
92 void OnTimerFired(const std::string& tether_network_guid); | 88 void OnTimerFired(const std::string& tether_network_guid); |
93 | 89 |
(...skipping 12 matching lines...) Expand all Loading... |
106 base::WeakPtrFactory<HostScanCache> weak_ptr_factory_; | 102 base::WeakPtrFactory<HostScanCache> weak_ptr_factory_; |
107 | 103 |
108 DISALLOW_COPY_AND_ASSIGN(HostScanCache); | 104 DISALLOW_COPY_AND_ASSIGN(HostScanCache); |
109 }; | 105 }; |
110 | 106 |
111 } // namespace tether | 107 } // namespace tether |
112 | 108 |
113 } // namespace chromeos | 109 } // namespace chromeos |
114 | 110 |
115 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_CACHE_H_ | 111 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_CACHE_H_ |
OLD | NEW |