Skip to content

Commit

Permalink
Change std::find() to use base:: functions: chromeos/
Browse files Browse the repository at this point in the history
Simplifies code slightly.

Bug: 1368812
Change-Id: I7af1e75eea6309a3ce1aa989e18fffdbd56beeca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3924292
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Maksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1052573}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Sep 28, 2022
1 parent d58e9a8 commit afce72a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/command_line.h"
#include "base/logging.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h"
Expand Down Expand Up @@ -36,8 +37,7 @@ bool PopPendingProfile(HermesEuiccClient::Properties* properties,
dbus::ObjectPath carrier_profile_path) {
std::vector<dbus::ObjectPath> pending_profiles =
properties->pending_carrier_profiles().value();
auto it = std::find(pending_profiles.begin(), pending_profiles.end(),
carrier_profile_path);
auto it = base::ranges::find(pending_profiles, carrier_profile_path);
if (it == pending_profiles.end()) {
return false;
}
Expand Down Expand Up @@ -214,8 +214,7 @@ bool FakeHermesEuiccClient::RemoveCarrierProfile(
std::vector<dbus::ObjectPath> installed_profiles =
euicc_properties->installed_carrier_profiles().value();
auto installed_carrier_profiles_iter =
std::find(installed_profiles.begin(), installed_profiles.end(),
carrier_profile_path);
base::ranges::find(installed_profiles, carrier_profile_path);
if (installed_carrier_profiles_iter == installed_profiles.end()) {
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions chromeos/ash/components/dbus/kerberos/fake_kerberos_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_split.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
Expand Down Expand Up @@ -117,8 +118,8 @@ FakeKerberosClient::~FakeKerberosClient() = default;
void FakeKerberosClient::AddAccount(const kerberos::AddAccountRequest& request,
AddAccountCallback callback) {
MaybeRecordFunctionCallForTesting(__FUNCTION__);
auto it = std::find(accounts_.begin(), accounts_.end(),
AccountData(request.principal_name()));
auto it =
base::ranges::find(accounts_, AccountData(request.principal_name()));
if (it != accounts_.end()) {
it->is_managed |= request.is_managed();
PostResponse(std::move(callback), kerberos::ERROR_DUPLICATE_PRINCIPAL_NAME,
Expand All @@ -137,8 +138,8 @@ void FakeKerberosClient::RemoveAccount(
RemoveAccountCallback callback) {
MaybeRecordFunctionCallForTesting(__FUNCTION__);
kerberos::RemoveAccountResponse response;
auto it = std::find(accounts_.begin(), accounts_.end(),
AccountData(request.principal_name()));
auto it =
base::ranges::find(accounts_, AccountData(request.principal_name()));
if (it == accounts_.end()) {
response.set_error(kerberos::ERROR_UNKNOWN_PRINCIPAL_NAME);
} else {
Expand Down Expand Up @@ -367,8 +368,7 @@ KerberosClient::TestInterface* FakeKerberosClient::GetTestInterface() {

FakeKerberosClient::AccountData* FakeKerberosClient::GetAccountData(
const std::string& principal_name) {
auto it = std::find(accounts_.begin(), accounts_.end(),
AccountData(principal_name));
auto it = base::ranges::find(accounts_, AccountData(principal_name));
return it != accounts_.end() ? &*it : nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <stdint.h>

#include <algorithm>
#include <string>
#include <vector>

Expand All @@ -16,6 +15,7 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
Expand Down Expand Up @@ -827,12 +827,8 @@ void UpdateEngineClient::Shutdown() {
bool UpdateEngineClient::IsTargetChannelMoreStable(
const std::string& current_channel,
const std::string& target_channel) {
const char** cix = std::find(
kReleaseChannelsList,
kReleaseChannelsList + std::size(kReleaseChannelsList), current_channel);
const char** tix = std::find(
kReleaseChannelsList,
kReleaseChannelsList + std::size(kReleaseChannelsList), target_channel);
const char** cix = base::ranges::find(kReleaseChannelsList, current_channel);
const char** tix = base::ranges::find(kReleaseChannelsList, target_channel);
return tix > cix;
}

Expand Down
15 changes: 5 additions & 10 deletions chromeos/ash/components/network/hotspot_state_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "chromeos/ash/components/network/hotspot_state_handler.h"

#include "base/containers/contains.h"
#include "chromeos/ash/components/dbus/shill/shill_manager_client.h"
#include "chromeos/ash/components/network/hotspot_util.h"
#include "chromeos/ash/components/network/network_event_log.h"
Expand All @@ -24,12 +25,6 @@ size_t GetActiveClientCount(const base::Value& status) {
return active_clients->GetList().size();
}

bool CanFindTechnoloyInList(const std::string& technology,
const base::Value::List& technology_list) {
return std::find(technology_list.begin(), technology_list.end(),
base::Value(technology)) != technology_list.end();
}

// Convert the base::Value::List type of |allowed_security_modes_in_shill| to
// the corresponding mojom enum and update the value to the
// |allowed_security_modes|.
Expand Down Expand Up @@ -346,8 +341,8 @@ void HotspotStateHandler::UpdateHotspotCapabilities(
return;
}

if (!CanFindTechnoloyInList(shill::kTypeCellular,
upstream_technologies->GetList())) {
if (!base::Contains(upstream_technologies->GetList(),
base::Value(shill::kTypeCellular))) {
SetHotspotCapablities(HotspotAllowStatus::kDisallowedNoCellularUpstream);
return;
}
Expand All @@ -362,8 +357,8 @@ void HotspotStateHandler::UpdateHotspotCapabilities(
return;
}

if (!CanFindTechnoloyInList(shill::kTypeWifi,
downstream_technologies->GetList())) {
if (!base::Contains(downstream_technologies->GetList(),
base::Value(shill::kTypeWifi))) {
SetHotspotCapablities(HotspotAllowStatus::kDisallowedNoWiFiDownstream);
return;
}
Expand Down
14 changes: 5 additions & 9 deletions chromeos/ash/components/network/network_metadata_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/stringprintf.h"
Expand Down Expand Up @@ -60,12 +61,6 @@ base::Value::List CreateOrCloneListValue(const base::Value::List* list) {
return base::Value::List();
}

bool ListContains(const base::Value::List* list, const std::string& value) {
if (!list)
return false;
return std::find(list->begin(), list->end(), value) != list->end();
}

bool IsApnListValid(const base::Value& list) {
if (!list.is_list())
return false;
Expand Down Expand Up @@ -313,14 +308,15 @@ void NetworkMetadataStore::UpdateExternalModifications(
const std::string& field) {
const base::Value::List* fields =
GetListPref(network_guid, kExternalModifications);
const bool contains_field = fields && base::Contains(*fields, field);
if (GetIsCreatedByUser(network_guid)) {
if (ListContains(fields, field)) {
if (contains_field) {
base::Value::List writeable_fields = CreateOrCloneListValue(fields);
writeable_fields.EraseValue(base::Value(field));
SetPref(network_guid, kExternalModifications,
base::Value(std::move(writeable_fields)));
}
} else if (!ListContains(fields, field)) {
} else if (!contains_field) {
base::Value::List writeable_fields = CreateOrCloneListValue(fields);
writeable_fields.Append(field);
SetPref(network_guid, kExternalModifications,
Expand Down Expand Up @@ -479,7 +475,7 @@ bool NetworkMetadataStore::GetIsFieldExternallyModified(
const std::string& field) {
const base::Value::List* fields =
GetListPref(network_guid, kExternalModifications);
return ListContains(fields, field);
return fields && base::Contains(*fields, field);
}

bool NetworkMetadataStore::GetHasBadPassword(const std::string& network_guid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <set>
#include <vector>

#include "base/containers/contains.h"
#include "base/ranges/algorithm.h"
#include "chromeos/ash/components/network/managed_network_configuration_handler.h"
#include "chromeos/ash/components/network/network_state_handler.h"
#include "chromeos/ash/components/network/network_util.h"
Expand Down Expand Up @@ -82,9 +84,7 @@ void ProhibitedTechnologiesHandler::EnforceProhibitedTechnologies() {
// ProhibitedTechnologies which may include ethernet, making users can
// not find Ethernet at next boot or logging out unless user log out first
// and then shutdown.
if (std::find(prohibited_technologies_.begin(),
prohibited_technologies_.end(),
shill::kTypeEthernet) != prohibited_technologies_.end()) {
if (base::Contains(prohibited_technologies_, shill::kTypeEthernet)) {
return;
}
if (network_state_handler_->IsTechnologyAvailable(
Expand Down Expand Up @@ -112,18 +112,15 @@ ProhibitedTechnologiesHandler::GetCurrentlyProhibitedTechnologies() {

void ProhibitedTechnologiesHandler::AddGloballyProhibitedTechnology(
const std::string& technology) {
if (std::find(globally_prohibited_technologies_.begin(),
globally_prohibited_technologies_.end(),
technology) == globally_prohibited_technologies_.end()) {
if (!base::Contains(globally_prohibited_technologies_, technology)) {
globally_prohibited_technologies_.push_back(technology);
}
EnforceProhibitedTechnologies();
}

void ProhibitedTechnologiesHandler::RemoveGloballyProhibitedTechnology(
const std::string& technology) {
auto it = std::find(globally_prohibited_technologies_.begin(),
globally_prohibited_technologies_.end(), technology);
auto it = base::ranges::find(globally_prohibited_technologies_, technology);
if (it != globally_prohibited_technologies_.end())
globally_prohibited_technologies_.erase(it);
EnforceProhibitedTechnologies();
Expand Down
4 changes: 2 additions & 2 deletions chromeos/ash/services/cellular_setup/esim_profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chromeos/ash/services/cellular_setup/esim_profile.h"

#include "ash/constants/ash_features.h"
#include "base/containers/contains.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -449,8 +450,7 @@ bool ESimProfile::ProfileExistsOnEuicc() {
? euicc_properties->installed_carrier_profiles().value()
: euicc_properties->pending_carrier_profiles().value();

auto iter = std::find(profile_paths.begin(), profile_paths.end(), path_);
return iter != profile_paths.end();
return base::Contains(profile_paths, path_);
}

bool ESimProfile::IsProfileInstalled() {
Expand Down

0 comments on commit afce72a

Please sign in to comment.