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() {
if (map_entry.second->GetStatus() ==
cryptauth::SecureChannel::Status::CONNECTING &&
!map_entry.second->HasEstablishedConnection() &&
std::find(should_advertise_to.begin(), should_advertise_to.end(),
map_entry.first) == should_advertise_to.end()) {
!base::ContainsValue(should_advertise_to, map_entry.first)) {
device_ids_to_stop.push_back(map_entry.first);
}
}
......
......@@ -160,9 +160,7 @@ void BleScannerImpl::SetTestDoubles(
}
bool BleScannerImpl::IsDeviceRegistered(const std::string& device_id) {
return std::find(registered_remote_device_ids_.begin(),
registered_remote_device_ids_.end(),
device_id) != registered_remote_device_ids_.end();
return base::ContainsValue(registered_remote_device_ids_, device_id);
}
void BleScannerImpl::DeviceAdded(device::BluetoothAdapter* adapter,
......
......@@ -27,10 +27,8 @@ bool FakeBleAdvertiser::StartAdvertisingToDevice(const std::string& device_id) {
if (should_fail_to_start_advertising_)
return false;
if (std::find(registered_device_ids_.begin(), registered_device_ids_.end(),
device_id) != registered_device_ids_.end()) {
if (base::ContainsValue(registered_device_ids_, device_id))
return false;
}
registered_device_ids_.push_back(device_id);
......@@ -41,10 +39,8 @@ bool FakeBleAdvertiser::StartAdvertisingToDevice(const std::string& device_id) {
}
bool FakeBleAdvertiser::StopAdvertisingToDevice(const std::string& device_id) {
if (std::find(registered_device_ids_.begin(), registered_device_ids_.end(),
device_id) == registered_device_ids_.end()) {
if (!base::ContainsValue(registered_device_ids_, device_id))
return false;
}
base::Erase(registered_device_ids_, device_id);
if (automatically_update_active_advertisements_ &&
......
......@@ -35,10 +35,8 @@ bool FakeBleScanner::RegisterScanFilterForDevice(const std::string& device_id) {
if (should_fail_to_register_)
return false;
if (std::find(registered_device_ids_.begin(), registered_device_ids_.end(),
device_id) != registered_device_ids_.end()) {
if (base::ContainsValue(registered_device_ids_, device_id))
return false;
}
bool was_empty = registered_device_ids_.empty();
registered_device_ids_.push_back(device_id);
......@@ -53,10 +51,8 @@ bool FakeBleScanner::RegisterScanFilterForDevice(const std::string& device_id) {
bool FakeBleScanner::UnregisterScanFilterForDevice(
const std::string& device_id) {
if (std::find(registered_device_ids_.begin(), registered_device_ids_.end(),
device_id) == registered_device_ids_.end()) {
if (!base::ContainsValue(registered_device_ids_, device_id))
return false;
}
base::Erase(registered_device_ids_, device_id);
......
......@@ -117,8 +117,7 @@ bool NetworkHostScanCache::HasConnectedToHost(
tether_network_guid);
std::vector<std::string> connected_device_ids =
tether_host_response_recorder_->GetPreviouslyConnectedHostIds();
return std::find(connected_device_ids.begin(), connected_device_ids.end(),
device_id) != connected_device_ids.end();
return base::ContainsValue(connected_device_ids, device_id);
}
} // namespace tether
......
......@@ -88,10 +88,8 @@ class NetworkHostScanCacheTest : public NetworkStateTest {
}
bool HasConnectedToHost(const std::string& tether_network_guid) {
auto it =
std::find(has_connected_to_host_device_ids_.begin(),
has_connected_to_host_device_ids_.end(), tether_network_guid);
return it != has_connected_to_host_device_ids_.end();
return base::ContainsValue(has_connected_to_host_device_ids_,
tether_network_guid);
}
// 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