Skip to content

Commit

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

Bug: 1368812
Change-Id: I5bdb03618e9937d88ab6ec27923d88a0b9bb933a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3923591
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: Marc Treib <treib@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1052501}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Sep 28, 2022
1 parent 181de62 commit 627d796
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <utility>

#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_refptr.h"
Expand Down Expand Up @@ -75,8 +76,7 @@ class CapturingScannerControllerImpl : public ScannerControllerImpl {
void TestFoundUwSIds(const std::vector<UwSId>& expected_pup_ids) const {
EXPECT_EQ(pup_ids_.size(), expected_pup_ids.size());
for (auto id : expected_pup_ids) {
EXPECT_NE(std::find(pup_ids_.begin(), pup_ids_.end(), id),
pup_ids_.end());
EXPECT_TRUE(base::Contains(pup_ids_, id));
}
}

Expand Down
3 changes: 2 additions & 1 deletion chrome/chrome_cleaner/logging/registry_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
Expand Down Expand Up @@ -238,7 +239,7 @@ bool RegistryLogger::RemoveLogFilePath(const base::FilePath& log_file) {
}

std::vector<std::wstring>::const_iterator iter =
std::find(log_files.begin(), log_files.end(), log_file.value());
base::ranges::find(log_files, log_file.value());
if (iter == log_files.end()) {
PLOG(WARNING) << "Requested log file '" << SanitizePath(log_file)
<< "', not found in registered log files '"
Expand Down
4 changes: 2 additions & 2 deletions chrome/chrome_cleaner/os/disk_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <stdint.h>

#include <algorithm>
#include <memory>
#include <string>
#include <utility>
Expand All @@ -21,6 +20,7 @@
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
Expand Down Expand Up @@ -947,7 +947,7 @@ void TruncateLogFileToTail(const base::FilePath& path,
// Find first newline character within the tail bytes. That will guarantee
// not only that the log file with start with a full line, but also that it
// won't start with a middle byte of a multi-byte UTF8 character.
auto newline_it = std::find(file_tail.begin(), file_tail.end(), '\n');
auto newline_it = base::ranges::find(file_tail, '\n');
int64_t newline_offset = newline_it - file_tail.begin();

file.Initialize(path,
Expand Down
7 changes: 3 additions & 4 deletions chrome/credential_provider/gaiacp/gaia_credential_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
Expand Down Expand Up @@ -2530,8 +2531,7 @@ HRESULT CGaiaCredentialBase::OnUserAuthenticated(BSTR authentication_info,
const std::wstring email_domain = email.substr(email.find(L"@") + 1);
const std::vector<std::wstring> allowed_domains = GetEmailDomainsList();

if (std::find(allowed_domains.begin(), allowed_domains.end(),
email_domain) == allowed_domains.end()) {
if (!base::Contains(allowed_domains, email_domain)) {
LOGFN(VERBOSE) << "Account " << email
<< " isn't in a domain from allowed domains.";
*status_text =
Expand All @@ -2541,8 +2541,7 @@ HRESULT CGaiaCredentialBase::OnUserAuthenticated(BSTR authentication_info,

std::vector<std::wstring> permitted_accounts = GetPermittedAccounts();
if (!permitted_accounts.empty() &&
std::find(permitted_accounts.begin(), permitted_accounts.end(),
email) == permitted_accounts.end()) {
!base::Contains(permitted_accounts, email)) {
*status_text = AllocErrorString(IDS_EMAIL_MISMATCH_BASE);
return E_FAIL;
}
Expand Down
5 changes: 2 additions & 3 deletions chrome/credential_provider/gaiacp/gaia_credential_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <utility>

#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/json/json_reader.h"
#include "base/memory/raw_ptr.h"
Expand Down Expand Up @@ -174,9 +175,7 @@ bool BackgroundTokenHandleUpdater::IsAuthEnforcedOnAssociatedUsers() {
const std::wstring& sid = sid_to_association.first;
// Checks if the login UI was already refreshed due to
// auth enforcements on this sid.
if (reauth_sids_ != nullptr &&
(std::find(reauth_sids_->begin(), reauth_sids_->end(), sid) !=
reauth_sids_->end()))
if (reauth_sids_ != nullptr && base::Contains(*reauth_sids_, sid))
continue;

// Return true if the associated user sid has auth enforced.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "base/bind.h"
#include "base/path_service.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_discardable_memory_allocator.h"
Expand Down Expand Up @@ -93,7 +94,7 @@ class PhishingClassifierTest
std::vector<int> indices_map_from_original;
for (const auto& original_hash : original_hashes_vector) {
indices_map_from_original.push_back(
std::find(hashes_vector.begin(), hashes_vector.end(), original_hash) -
base::ranges::find(hashes_vector, original_hash) -
hashes_vector.begin());
}
for (std::string& feature : hashes_vector) {
Expand Down
4 changes: 2 additions & 2 deletions chrome/test/chromedriver/session_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "base/json/json_writer.h"
#include "base/logging.h" // For CHECK macros.
#include "base/memory/ref_counted.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/lock.h"
Expand Down Expand Up @@ -850,8 +851,7 @@ Status ExecuteGetWindowHandles(Session* session,
// the mapper?
status = session->chrome->GetWebViewIdForFirstTab(&mapper_view_id,
session->w3c_compliant);
auto it =
std::find(web_view_ids.begin(), web_view_ids.end(), mapper_view_id);
auto it = base::ranges::find(web_view_ids, mapper_view_id);
if (it != web_view_ids.end()) {
web_view_ids.erase(it);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/auto_reset.h"
#include "base/memory/ptr_util.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/gmock_callback_support.h"
Expand Down Expand Up @@ -128,8 +129,7 @@ void AccessCodeCastIntegrationBrowserTest::OnWillCreateBrowserContextServices(
// this to occur).
ON_CALL(*media_router_, UnregisterMediaSinksObserver(_))
.WillByDefault([this](MediaSinksObserver* observer) {
auto it = std::find(media_sinks_observers_.begin(),
media_sinks_observers_.end(), observer);
auto it = base::ranges::find(media_sinks_observers_, observer);
if (it != media_sinks_observers_.end()) {
media_sinks_observers_.erase(it);
}
Expand All @@ -145,8 +145,7 @@ void AccessCodeCastIntegrationBrowserTest::OnWillCreateBrowserContextServices(
// this to occur).
ON_CALL(*media_router_, UnregisterMediaRoutesObserver(_))
.WillByDefault([this](MediaRoutesObserver* observer) {
auto it = std::find(media_routes_observers_.begin(),
media_routes_observers_.end(), observer);
auto it = base::ranges::find(media_routes_observers_, observer);
if (it != media_routes_observers_.end()) {
media_routes_observers_.erase(it);
}
Expand Down

0 comments on commit 627d796

Please sign in to comment.