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

Side by Side Diff: chromeos/components/tether/host_scan_cache.cc

Issue 2913313002: Tether: Persist if first-time setup is required to HostScanCache. (Closed)
Patch Set: khorimoto@ comments. Created 3 years, 6 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 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/host_scan_cache.h" 5 #include "chromeos/components/tether/host_scan_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 23 matching lines...) Expand all
34 } 34 }
35 35
36 HostScanCache::~HostScanCache() { 36 HostScanCache::~HostScanCache() {
37 tether_host_response_recorder_->RemoveObserver(this); 37 tether_host_response_recorder_->RemoveObserver(this);
38 } 38 }
39 39
40 void HostScanCache::SetHostScanResult(const std::string& tether_network_guid, 40 void HostScanCache::SetHostScanResult(const std::string& tether_network_guid,
41 const std::string& device_name, 41 const std::string& device_name,
42 const std::string& carrier, 42 const std::string& carrier,
43 int battery_percentage, 43 int battery_percentage,
44 int signal_strength) { 44 int signal_strength,
45 bool setup_required) {
45 DCHECK(!tether_network_guid.empty()); 46 DCHECK(!tether_network_guid.empty());
46 47
47 auto found_iter = tether_guid_to_timer_map_.find(tether_network_guid); 48 auto found_iter = tether_guid_to_timer_map_.find(tether_network_guid);
48 49
49 if (found_iter == tether_guid_to_timer_map_.end()) { 50 if (found_iter == tether_guid_to_timer_map_.end()) {
50 // Add the Tether network to NetworkStateHandler and create an associated 51 // Add the Tether network to NetworkStateHandler and create an associated
51 // Timer. 52 // Timer.
52 network_state_handler_->AddTetherNetworkState( 53 network_state_handler_->AddTetherNetworkState(
53 tether_network_guid, device_name, carrier, battery_percentage, 54 tether_network_guid, device_name, carrier, battery_percentage,
54 signal_strength, HasConnectedToHost(tether_network_guid)); 55 signal_strength, HasConnectedToHost(tether_network_guid));
(...skipping 10 matching lines...) Expand all
65 network_state_handler_->UpdateTetherNetworkProperties( 66 network_state_handler_->UpdateTetherNetworkProperties(
66 tether_network_guid, carrier, battery_percentage, signal_strength); 67 tether_network_guid, carrier, battery_percentage, signal_strength);
67 found_iter->second->Stop(); 68 found_iter->second->Stop();
68 69
69 PA_LOG(INFO) << "Updated scan result for Tether network with GUID " 70 PA_LOG(INFO) << "Updated scan result for Tether network with GUID "
70 << tether_network_guid << ". New carrier: " << carrier << ", " 71 << tether_network_guid << ". New carrier: " << carrier << ", "
71 << "new battery percentage: " << battery_percentage << ", " 72 << "new battery percentage: " << battery_percentage << ", "
72 << "new signal strength: " << signal_strength; 73 << "new signal strength: " << signal_strength;
73 } 74 }
74 75
76 if (setup_required)
77 setup_required_tether_guids_.insert(tether_network_guid);
78 else
79 setup_required_tether_guids_.erase(tether_network_guid);
80
75 StartTimer(tether_network_guid); 81 StartTimer(tether_network_guid);
76 } 82 }
77 83
78 bool HostScanCache::RemoveHostScanResult( 84 bool HostScanCache::RemoveHostScanResult(
79 const std::string& tether_network_guid) { 85 const std::string& tether_network_guid) {
80 DCHECK(!tether_network_guid.empty()); 86 DCHECK(!tether_network_guid.empty());
81 87
82 auto it = tether_guid_to_timer_map_.find(tether_network_guid); 88 auto it = tether_guid_to_timer_map_.find(tether_network_guid);
83 if (it == tether_guid_to_timer_map_.end()) { 89 if (it == tether_guid_to_timer_map_.end()) {
84 PA_LOG(ERROR) << "Attempted to remove a host scan result which does not " 90 PA_LOG(ERROR) << "Attempted to remove a host scan result which does not "
85 << "exist in the cache. GUID: " << tether_network_guid; 91 << "exist in the cache. GUID: " << tether_network_guid;
86 return false; 92 return false;
87 } 93 }
88 94
89 if (active_host_->GetTetherNetworkGuid() == tether_network_guid) { 95 if (active_host_->GetTetherNetworkGuid() == tether_network_guid) {
90 PA_LOG(ERROR) << "RemoveHostScanResult() called for Tether network with " 96 PA_LOG(ERROR) << "RemoveHostScanResult() called for Tether network with "
91 << "GUID " << tether_network_guid << ", but the " 97 << "GUID " << tether_network_guid << ", but the "
92 << "corresponding device is the active host. Not removing " 98 << "corresponding device is the active host. Not removing "
93 << "this scan result from the cache."; 99 << "this scan result from the cache.";
94 return false; 100 return false;
95 } 101 }
96 102
97 tether_guid_to_timer_map_.erase(it); 103 tether_guid_to_timer_map_.erase(it);
104 setup_required_tether_guids_.erase(tether_network_guid);
98 return network_state_handler_->RemoveTetherNetworkState(tether_network_guid); 105 return network_state_handler_->RemoveTetherNetworkState(tether_network_guid);
99 } 106 }
100 107
101 void HostScanCache::ClearCacheExceptForActiveHost() { 108 void HostScanCache::ClearCacheExceptForActiveHost() {
102 // Create a list of all Tether network GUIDs serving as keys to 109 // Create a list of all Tether network GUIDs serving as keys to
103 // |tether_guid_to_timer_map_|. 110 // |tether_guid_to_timer_map_|.
104 std::vector<std::string> tether_network_guids; 111 std::vector<std::string> tether_network_guids;
105 tether_network_guids.reserve(tether_guid_to_timer_map_.size()); 112 tether_network_guids.reserve(tether_guid_to_timer_map_.size());
106 for (auto& it : tether_guid_to_timer_map_) 113 for (auto& it : tether_guid_to_timer_map_)
107 tether_network_guids.push_back(it.first); 114 tether_network_guids.push_back(it.first);
(...skipping 18 matching lines...) Expand all
126 for (auto& tether_network_guid : tether_network_guids) { 133 for (auto& tether_network_guid : tether_network_guids) {
127 if (active_host_->GetTetherNetworkGuid() == tether_network_guid) { 134 if (active_host_->GetTetherNetworkGuid() == tether_network_guid) {
128 // Do not remove the active host from the cache. 135 // Do not remove the active host from the cache.
129 continue; 136 continue;
130 } 137 }
131 138
132 RemoveHostScanResult(tether_network_guid); 139 RemoveHostScanResult(tether_network_guid);
133 } 140 }
134 } 141 }
135 142
143 bool HostScanCache::DoesHostRequireSetup(
144 const std::string& tether_network_guid) {
145 return setup_required_tether_guids_.find(tether_network_guid) !=
146 setup_required_tether_guids_.end();
147 }
148
136 void HostScanCache::OnPreviouslyConnectedHostIdsChanged() { 149 void HostScanCache::OnPreviouslyConnectedHostIdsChanged() {
137 for (auto& map_entry : tether_guid_to_timer_map_) { 150 for (auto& map_entry : tether_guid_to_timer_map_) {
138 const std::string& tether_network_guid = map_entry.first; 151 const std::string& tether_network_guid = map_entry.first;
139 if (!HasConnectedToHost(tether_network_guid)) 152 if (!HasConnectedToHost(tether_network_guid))
140 continue; 153 continue;
141 154
142 // If a the current device has connected to the Tether network with GUID 155 // If a the current device has connected to the Tether network with GUID
143 // |tether_network_guid|, alert |network_state_handler_|. Note that this 156 // |tether_network_guid|, alert |network_state_handler_|. Note that this
144 // function is a no-op if it is called on a network which already has its 157 // function is a no-op if it is called on a network which already has its
145 // HasConnectedToHost property set to true. 158 // HasConnectedToHost property set to true.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 217 }
205 218
206 PA_LOG(INFO) << "Timer fired for Tether network GUID " << tether_network_guid 219 PA_LOG(INFO) << "Timer fired for Tether network GUID " << tether_network_guid
207 << ". Removing stale scan result."; 220 << ". Removing stale scan result.";
208 RemoveHostScanResult(tether_network_guid); 221 RemoveHostScanResult(tether_network_guid);
209 } 222 }
210 223
211 } // namespace tether 224 } // namespace tether
212 225
213 } // namespace chromeos 226 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/components/tether/host_scan_cache.h ('k') | chromeos/components/tether/host_scan_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698