Commit ef4a7dd5 authored by DongJun Kim's avatar DongJun Kim Committed by Commit Bot

Use ContainsValue() instead of std::find() in chromeos/components/tether/

This simplifies many conditions around the code in
chromeos/components/tether.

Bug: 561800
Change-Id: I69c25666ae1b1362df6df67889a9a45226961387
Reviewed-on: https://chromium-review.googlesource.com/1188060Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: DongJun Kim <djmix.kim@samsung.com>
Cr-Commit-Position: refs/heads/master@{#586084}
parent 4fb96ed6
...@@ -447,8 +447,7 @@ void BleConnectionManager::UpdateConnectionAttempts() { ...@@ -447,8 +447,7 @@ void BleConnectionManager::UpdateConnectionAttempts() {
if (map_entry.second->GetStatus() == if (map_entry.second->GetStatus() ==
cryptauth::SecureChannel::Status::CONNECTING && cryptauth::SecureChannel::Status::CONNECTING &&
!map_entry.second->HasEstablishedConnection() && !map_entry.second->HasEstablishedConnection() &&
std::find(should_advertise_to.begin(), should_advertise_to.end(), !base::ContainsValue(should_advertise_to, map_entry.first)) {
map_entry.first) == should_advertise_to.end()) {
device_ids_to_stop.push_back(map_entry.first); device_ids_to_stop.push_back(map_entry.first);
} }
} }
......
...@@ -160,9 +160,7 @@ void BleScannerImpl::SetTestDoubles( ...@@ -160,9 +160,7 @@ void BleScannerImpl::SetTestDoubles(
} }
bool BleScannerImpl::IsDeviceRegistered(const std::string& device_id) { bool BleScannerImpl::IsDeviceRegistered(const std::string& device_id) {
return std::find(registered_remote_device_ids_.begin(), return base::ContainsValue(registered_remote_device_ids_, device_id);
registered_remote_device_ids_.end(),
device_id) != registered_remote_device_ids_.end();
} }
void BleScannerImpl::DeviceAdded(device::BluetoothAdapter* adapter, void BleScannerImpl::DeviceAdded(device::BluetoothAdapter* adapter,
......
...@@ -27,10 +27,8 @@ bool FakeBleAdvertiser::StartAdvertisingToDevice(const std::string& device_id) { ...@@ -27,10 +27,8 @@ bool FakeBleAdvertiser::StartAdvertisingToDevice(const std::string& device_id) {
if (should_fail_to_start_advertising_) if (should_fail_to_start_advertising_)
return false; return false;
if (std::find(registered_device_ids_.begin(), registered_device_ids_.end(), if (base::ContainsValue(registered_device_ids_, device_id))
device_id) != registered_device_ids_.end()) {
return false; return false;
}
registered_device_ids_.push_back(device_id); registered_device_ids_.push_back(device_id);
...@@ -41,10 +39,8 @@ bool FakeBleAdvertiser::StartAdvertisingToDevice(const std::string& device_id) { ...@@ -41,10 +39,8 @@ bool FakeBleAdvertiser::StartAdvertisingToDevice(const std::string& device_id) {
} }
bool FakeBleAdvertiser::StopAdvertisingToDevice(const std::string& device_id) { bool FakeBleAdvertiser::StopAdvertisingToDevice(const std::string& device_id) {
if (std::find(registered_device_ids_.begin(), registered_device_ids_.end(), if (!base::ContainsValue(registered_device_ids_, device_id))
device_id) == registered_device_ids_.end()) {
return false; return false;
}
base::Erase(registered_device_ids_, device_id); base::Erase(registered_device_ids_, device_id);
if (automatically_update_active_advertisements_ && if (automatically_update_active_advertisements_ &&
......
...@@ -35,10 +35,8 @@ bool FakeBleScanner::RegisterScanFilterForDevice(const std::string& device_id) { ...@@ -35,10 +35,8 @@ bool FakeBleScanner::RegisterScanFilterForDevice(const std::string& device_id) {
if (should_fail_to_register_) if (should_fail_to_register_)
return false; return false;
if (std::find(registered_device_ids_.begin(), registered_device_ids_.end(), if (base::ContainsValue(registered_device_ids_, device_id))
device_id) != registered_device_ids_.end()) {
return false; return false;
}
bool was_empty = registered_device_ids_.empty(); bool was_empty = registered_device_ids_.empty();
registered_device_ids_.push_back(device_id); registered_device_ids_.push_back(device_id);
...@@ -53,10 +51,8 @@ bool FakeBleScanner::RegisterScanFilterForDevice(const std::string& device_id) { ...@@ -53,10 +51,8 @@ bool FakeBleScanner::RegisterScanFilterForDevice(const std::string& device_id) {
bool FakeBleScanner::UnregisterScanFilterForDevice( bool FakeBleScanner::UnregisterScanFilterForDevice(
const std::string& device_id) { const std::string& device_id) {
if (std::find(registered_device_ids_.begin(), registered_device_ids_.end(), if (!base::ContainsValue(registered_device_ids_, device_id))
device_id) == registered_device_ids_.end()) {
return false; return false;
}
base::Erase(registered_device_ids_, device_id); base::Erase(registered_device_ids_, device_id);
......
...@@ -117,8 +117,7 @@ bool NetworkHostScanCache::HasConnectedToHost( ...@@ -117,8 +117,7 @@ bool NetworkHostScanCache::HasConnectedToHost(
tether_network_guid); tether_network_guid);
std::vector<std::string> connected_device_ids = std::vector<std::string> connected_device_ids =
tether_host_response_recorder_->GetPreviouslyConnectedHostIds(); tether_host_response_recorder_->GetPreviouslyConnectedHostIds();
return std::find(connected_device_ids.begin(), connected_device_ids.end(), return base::ContainsValue(connected_device_ids, device_id);
device_id) != connected_device_ids.end();
} }
} // namespace tether } // namespace tether
......
...@@ -88,10 +88,8 @@ class NetworkHostScanCacheTest : public NetworkStateTest { ...@@ -88,10 +88,8 @@ class NetworkHostScanCacheTest : public NetworkStateTest {
} }
bool HasConnectedToHost(const std::string& tether_network_guid) { bool HasConnectedToHost(const std::string& tether_network_guid) {
auto it = return base::ContainsValue(has_connected_to_host_device_ids_,
std::find(has_connected_to_host_device_ids_.begin(), tether_network_guid);
has_connected_to_host_device_ids_.end(), tether_network_guid);
return it != has_connected_to_host_device_ids_.end();
} }
// Verifies that the information present in |expected_cache_| and // Verifies that the information present in |expected_cache_| and
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment