OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROMEOS_COMPONENTS_TETHER_FAKE_HOST_SCAN_CACHE_H_ | |
6 #define CHROMEOS_COMPONENTS_TETHER_FAKE_HOST_SCAN_CACHE_H_ | |
7 | |
8 #include <string> | |
9 #include <unordered_map> | |
10 | |
11 #include "base/macros.h" | |
12 #include "chromeos/components/tether/host_scan_cache.h" | |
13 | |
14 namespace chromeos { | |
15 | |
16 namespace tether { | |
17 | |
18 // Test double for HostScanCache which stores cache results in memory. | |
19 class FakeHostScanCache : public HostScanCache { | |
20 public: | |
21 struct CacheEntry { | |
22 std::string device_name; | |
23 std::string carrier; | |
24 int battery_percentage; | |
25 int signal_strength; | |
26 }; | |
27 | |
28 FakeHostScanCache(); | |
29 ~FakeHostScanCache() override; | |
30 | |
31 // Getter and setter for the active host Tether network GUID. This value is | |
32 // used to implement the ClearCacheExceptForActiveHost() function. | |
33 std::string& active_host_tether_network_guid() { | |
34 return active_host_tether_network_guid_; | |
35 } | |
36 void set_active_host_tether_network_guid( | |
37 const std::string& active_host_tether_network_guid) { | |
38 active_host_tether_network_guid_ = active_host_tether_network_guid; | |
39 } | |
40 | |
41 // Getters for contents of the cache. | |
42 FakeHostScanCache::CacheEntry* GetCacheEntry( | |
stevenjb
2017/04/28 23:00:22
The cache probably shouldn't be directly editable,
Kyle Horimoto
2017/04/29 00:16:55
Done.
| |
43 const std::string& tether_network_guid); | |
44 size_t size() { return cache_.size(); } | |
45 bool empty() { return cache_.empty(); } | |
46 std::unordered_map<std::string, FakeHostScanCache::CacheEntry> cache() { | |
47 return cache_; | |
48 } | |
49 | |
50 // HostScanCache: | |
51 void SetHostScanResult(const std::string& tether_network_guid, | |
52 const std::string& device_name, | |
53 const std::string& carrier, | |
54 int battery_percentage, | |
55 int signal_strength) override; | |
56 bool RemoveHostScanResult(const std::string& tether_network_guid) override; | |
57 void ClearCacheExceptForActiveHost() override; | |
58 void OnPreviouslyConnectedHostIdsChanged() override; | |
59 | |
60 private: | |
61 std::string active_host_tether_network_guid_; | |
62 std::unordered_map<std::string, CacheEntry> cache_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(FakeHostScanCache); | |
65 }; | |
66 | |
67 } // namespace tether | |
68 | |
69 } // namespace chromeos | |
70 | |
71 #endif // CHROMEOS_COMPONENTS_TETHER_FAKE_HOST_SCAN_CACHE_H_ | |
OLD | NEW |