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 #include "chromeos/components/tether/fake_host_scan_cache.h" | 5 #include "chromeos/components/tether/fake_host_scan_cache.h" |
6 | 6 |
7 #include "chromeos/components/tether/tether_host_response_recorder.h" | 7 #include "chromeos/components/tether/tether_host_response_recorder.h" |
8 | 8 |
9 namespace chromeos { | 9 namespace chromeos { |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return nullptr; | 44 return nullptr; |
45 | 45 |
46 return &it->second; | 46 return &it->second; |
47 } | 47 } |
48 | 48 |
49 void FakeHostScanCache::SetHostScanResult( | 49 void FakeHostScanCache::SetHostScanResult( |
50 const std::string& tether_network_guid, | 50 const std::string& tether_network_guid, |
51 const std::string& device_name, | 51 const std::string& device_name, |
52 const std::string& carrier, | 52 const std::string& carrier, |
53 int battery_percentage, | 53 int battery_percentage, |
54 int signal_strength) { | 54 int signal_strength, |
| 55 bool setup_required) { |
55 auto it = cache_.find(tether_network_guid); | 56 auto it = cache_.find(tether_network_guid); |
56 if (it != cache_.end()) { | 57 if (it != cache_.end()) { |
57 // If already in the cache, update the cache with new values. | 58 // If already in the cache, update the cache with new values. |
58 it->second.device_name = device_name; | 59 it->second.device_name = device_name; |
59 it->second.carrier = carrier; | 60 it->second.carrier = carrier; |
60 it->second.battery_percentage = battery_percentage; | 61 it->second.battery_percentage = battery_percentage; |
61 it->second.signal_strength = signal_strength; | 62 it->second.signal_strength = signal_strength; |
| 63 it->second.setup_required = setup_required; |
62 return; | 64 return; |
63 } | 65 } |
64 | 66 |
65 // Otherwise, add a new entry. | 67 // Otherwise, add a new entry. |
66 cache_.emplace( | 68 cache_.emplace(tether_network_guid, |
67 tether_network_guid, | 69 CacheEntry{device_name, carrier, battery_percentage, |
68 CacheEntry{device_name, carrier, battery_percentage, signal_strength}); | 70 signal_strength, setup_required}); |
69 } | 71 } |
70 | 72 |
71 bool FakeHostScanCache::RemoveHostScanResult( | 73 bool FakeHostScanCache::RemoveHostScanResult( |
72 const std::string& tether_network_guid) { | 74 const std::string& tether_network_guid) { |
73 if (tether_network_guid == active_host_tether_network_guid()) | 75 if (tether_network_guid == active_host_tether_network_guid()) |
74 return false; | 76 return false; |
75 | 77 |
76 return cache_.erase(tether_network_guid) > 0; | 78 return cache_.erase(tether_network_guid) > 0; |
77 } | 79 } |
78 | 80 |
79 void FakeHostScanCache::ClearCacheExceptForActiveHost() { | 81 void FakeHostScanCache::ClearCacheExceptForActiveHost() { |
80 auto it = cache_.begin(); | 82 auto it = cache_.begin(); |
81 while (it != cache_.end()) { | 83 while (it != cache_.end()) { |
82 if (it->first == active_host_tether_network_guid_) | 84 if (it->first == active_host_tether_network_guid_) |
83 it++; | 85 it++; |
84 else | 86 else |
85 it = cache_.erase(it); | 87 it = cache_.erase(it); |
86 } | 88 } |
87 } | 89 } |
88 | 90 |
| 91 bool FakeHostScanCache::DoesHostRequireSetup( |
| 92 const std::string& tether_network_guid) { |
| 93 auto it = cache_.find(tether_network_guid); |
| 94 if (it != cache_.end()) |
| 95 return it->second.setup_required; |
| 96 |
| 97 return false; |
| 98 } |
| 99 |
89 void FakeHostScanCache::OnPreviouslyConnectedHostIdsChanged() {} | 100 void FakeHostScanCache::OnPreviouslyConnectedHostIdsChanged() {} |
90 | 101 |
91 } // namespace tether | 102 } // namespace tether |
92 | 103 |
93 } // namespace chromeos | 104 } // namespace chromeos |
OLD | NEW |