Chromium Code Reviews| 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/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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 } | 48 } |
| 49 | 49 |
| 50 HostScanCache::~HostScanCache() { | 50 HostScanCache::~HostScanCache() { |
| 51 tether_host_response_recorder_->RemoveObserver(this); | 51 tether_host_response_recorder_->RemoveObserver(this); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void HostScanCache::SetHostScanResult(const std::string& tether_network_guid, | 54 void HostScanCache::SetHostScanResult(const std::string& tether_network_guid, |
| 55 const std::string& device_name, | 55 const std::string& device_name, |
| 56 const std::string& carrier, | 56 const std::string& carrier, |
| 57 int battery_percentage, | 57 int battery_percentage, |
| 58 int signal_strength) { | 58 int signal_strength, |
| 59 bool setup_required) { | |
| 59 DCHECK(!tether_network_guid.empty()); | 60 DCHECK(!tether_network_guid.empty()); |
| 60 | 61 |
| 61 auto found_iter = tether_guid_to_timer_map_.find(tether_network_guid); | 62 auto found_iter = tether_guid_to_timer_map_.find(tether_network_guid); |
| 62 | 63 |
| 63 if (found_iter == tether_guid_to_timer_map_.end()) { | 64 if (found_iter == tether_guid_to_timer_map_.end()) { |
| 64 // Add the Tether network to NetworkStateHandler and create an associated | 65 // Add the Tether network to NetworkStateHandler and create an associated |
| 65 // Timer. | 66 // Timer. |
| 66 network_state_handler_->AddTetherNetworkState( | 67 network_state_handler_->AddTetherNetworkState( |
| 67 tether_network_guid, device_name, carrier, battery_percentage, | 68 tether_network_guid, device_name, carrier, battery_percentage, |
| 68 signal_strength, HasConnectedToHost(tether_network_guid)); | 69 signal_strength, HasConnectedToHost(tether_network_guid)); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 79 network_state_handler_->UpdateTetherNetworkProperties( | 80 network_state_handler_->UpdateTetherNetworkProperties( |
| 80 tether_network_guid, carrier, battery_percentage, signal_strength); | 81 tether_network_guid, carrier, battery_percentage, signal_strength); |
| 81 found_iter->second->Stop(); | 82 found_iter->second->Stop(); |
| 82 | 83 |
| 83 PA_LOG(INFO) << "Updated scan result for Tether network with GUID " | 84 PA_LOG(INFO) << "Updated scan result for Tether network with GUID " |
| 84 << tether_network_guid << ". New carrier: " << carrier << ", " | 85 << tether_network_guid << ". New carrier: " << carrier << ", " |
| 85 << "new battery percentage: " << battery_percentage << ", " | 86 << "new battery percentage: " << battery_percentage << ", " |
| 86 << "new signal strength: " << signal_strength; | 87 << "new signal strength: " << signal_strength; |
| 87 } | 88 } |
| 88 | 89 |
| 90 if (setup_required) | |
|
Kyle Horimoto
2017/05/31 23:01:19
Previously, you forgot to add this if(), but the t
Ryan Hansberry
2017/06/01 01:07:51
Mentioned this on the past commit: This was actual
| |
| 91 setup_required_tether_guids_.insert(tether_network_guid); | |
| 92 else | |
| 93 setup_required_tether_guids_.erase(tether_network_guid); | |
| 94 | |
| 89 StartTimer(tether_network_guid); | 95 StartTimer(tether_network_guid); |
| 90 } | 96 } |
| 91 | 97 |
| 92 bool HostScanCache::RemoveHostScanResult( | 98 bool HostScanCache::RemoveHostScanResult( |
| 93 const std::string& tether_network_guid) { | 99 const std::string& tether_network_guid) { |
| 94 DCHECK(!tether_network_guid.empty()); | 100 DCHECK(!tether_network_guid.empty()); |
| 95 | 101 |
| 96 auto it = tether_guid_to_timer_map_.find(tether_network_guid); | 102 auto it = tether_guid_to_timer_map_.find(tether_network_guid); |
| 97 if (it == tether_guid_to_timer_map_.end()) { | 103 if (it == tether_guid_to_timer_map_.end()) { |
| 98 PA_LOG(ERROR) << "Attempted to remove a host scan result which does not " | 104 PA_LOG(ERROR) << "Attempted to remove a host scan result which does not " |
| 99 << "exist in the cache. GUID: " << tether_network_guid; | 105 << "exist in the cache. GUID: " << tether_network_guid; |
| 100 return false; | 106 return false; |
| 101 } | 107 } |
| 102 | 108 |
| 103 if (active_host_->GetTetherNetworkGuid() == tether_network_guid) { | 109 if (active_host_->GetTetherNetworkGuid() == tether_network_guid) { |
| 104 PA_LOG(ERROR) << "RemoveHostScanResult() called for Tether network with " | 110 PA_LOG(ERROR) << "RemoveHostScanResult() called for Tether network with " |
| 105 << "GUID " << tether_network_guid << ", but the " | 111 << "GUID " << tether_network_guid << ", but the " |
| 106 << "corresponding device is the active host. Not removing " | 112 << "corresponding device is the active host. Not removing " |
| 107 << "this scan result from the cache."; | 113 << "this scan result from the cache."; |
| 108 return false; | 114 return false; |
| 109 } | 115 } |
| 110 | 116 |
| 111 tether_guid_to_timer_map_.erase(it); | 117 tether_guid_to_timer_map_.erase(it); |
| 118 setup_required_tether_guids_.erase(tether_network_guid); | |
| 112 return network_state_handler_->RemoveTetherNetworkState(tether_network_guid); | 119 return network_state_handler_->RemoveTetherNetworkState(tether_network_guid); |
| 113 } | 120 } |
| 114 | 121 |
| 115 void HostScanCache::ClearCacheExceptForActiveHost() { | 122 void HostScanCache::ClearCacheExceptForActiveHost() { |
| 116 // Create a list of all Tether network GUIDs serving as keys to | 123 // Create a list of all Tether network GUIDs serving as keys to |
| 117 // |tether_guid_to_timer_map_|. | 124 // |tether_guid_to_timer_map_|. |
| 118 std::vector<std::string> tether_network_guids; | 125 std::vector<std::string> tether_network_guids; |
| 119 tether_network_guids.reserve(tether_guid_to_timer_map_.size()); | 126 tether_network_guids.reserve(tether_guid_to_timer_map_.size()); |
| 120 for (auto& it : tether_guid_to_timer_map_) | 127 for (auto& it : tether_guid_to_timer_map_) |
| 121 tether_network_guids.push_back(it.first); | 128 tether_network_guids.push_back(it.first); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 140 for (auto& tether_network_guid : tether_network_guids) { | 147 for (auto& tether_network_guid : tether_network_guids) { |
| 141 if (active_host_->GetTetherNetworkGuid() == tether_network_guid) { | 148 if (active_host_->GetTetherNetworkGuid() == tether_network_guid) { |
| 142 // Do not remove the active host from the cache. | 149 // Do not remove the active host from the cache. |
| 143 continue; | 150 continue; |
| 144 } | 151 } |
| 145 | 152 |
| 146 RemoveHostScanResult(tether_network_guid); | 153 RemoveHostScanResult(tether_network_guid); |
| 147 } | 154 } |
| 148 } | 155 } |
| 149 | 156 |
| 157 bool HostScanCache::DoesHostRequireSetup( | |
| 158 const std::string& tether_network_guid) { | |
| 159 return setup_required_tether_guids_.find(tether_network_guid) != | |
| 160 setup_required_tether_guids_.end(); | |
| 161 } | |
| 162 | |
| 150 void HostScanCache::OnPreviouslyConnectedHostIdsChanged() { | 163 void HostScanCache::OnPreviouslyConnectedHostIdsChanged() { |
| 151 for (auto& map_entry : tether_guid_to_timer_map_) { | 164 for (auto& map_entry : tether_guid_to_timer_map_) { |
| 152 const std::string& tether_network_guid = map_entry.first; | 165 const std::string& tether_network_guid = map_entry.first; |
| 153 if (!HasConnectedToHost(tether_network_guid)) | 166 if (!HasConnectedToHost(tether_network_guid)) |
| 154 continue; | 167 continue; |
| 155 | 168 |
| 156 // If a the current device has connected to the Tether network with GUID | 169 // If a the current device has connected to the Tether network with GUID |
| 157 // |tether_network_guid|, alert |network_state_handler_|. Note that this | 170 // |tether_network_guid|, alert |network_state_handler_|. Note that this |
| 158 // function is a no-op if it is called on a network which already has its | 171 // function is a no-op if it is called on a network which already has its |
| 159 // HasConnectedToHost property set to true. | 172 // HasConnectedToHost property set to true. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 } | 231 } |
| 219 | 232 |
| 220 PA_LOG(INFO) << "Timer fired for Tether network GUID " << tether_network_guid | 233 PA_LOG(INFO) << "Timer fired for Tether network GUID " << tether_network_guid |
| 221 << ". Removing stale scan result."; | 234 << ". Removing stale scan result."; |
| 222 RemoveHostScanResult(tether_network_guid); | 235 RemoveHostScanResult(tether_network_guid); |
| 223 } | 236 } |
| 224 | 237 |
| 225 } // namespace tether | 238 } // namespace tether |
| 226 | 239 |
| 227 } // namespace chromeos | 240 } // namespace chromeos |
| OLD | NEW |