Skip to content

Commit

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

Bug: 1368812
Change-Id: Iecb3c9ce7d8da507ef4bc6cfce8233385c3ba5bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3926100
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1055935}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Oct 6, 2022
1 parent b0d38cb commit ff5db66
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/check.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/escape.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -876,12 +877,8 @@ IN_PROC_BROWSER_TEST_F(AccessibilityActionBrowserTest,
target->GetIntListAttribute(ax::mojom::IntListAttribute::kControlsIds);
EXPECT_EQ(2u, control_list.size());

auto find_radio1 =
std::find(control_list.cbegin(), control_list.cend(), radio1->GetId());
auto find_radio2 =
std::find(control_list.cbegin(), control_list.cend(), radio2->GetId());
EXPECT_NE(find_radio1, control_list.cend());
EXPECT_NE(find_radio2, control_list.cend());
EXPECT_TRUE(base::Contains(control_list, radio1->GetId()));
EXPECT_TRUE(base::Contains(control_list, radio2->GetId()));
}

IN_PROC_BROWSER_TEST_F(AccessibilityActionBrowserTest, FocusLostOnDeletedNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// found in the LICENSE file.

#include <Cocoa/Cocoa.h>

#include <algorithm>

#include "base/strings/sys_string_conversions.h"
#include "content/browser/devtools/protocol/native_input_event_builder.h"
#include "third_party/blink/public/common/input/web_input_event.h"
Expand Down
6 changes: 3 additions & 3 deletions content/browser/devtools/protocol/network_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

#include <stddef.h>
#include <stdint.h>

#include <memory>

#include "base/barrier_closure.h"
#include "base/base64.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/containers/queue.h"
#include "base/feature_list.h"
#include "base/i18n/i18n_constants.h"
Expand Down Expand Up @@ -1315,9 +1317,7 @@ NetworkHandler::BuildProtocolReport(const net::ReportingReport& report) {
return nullptr;
}
std::vector<GURL> reporting_filter_urls = ComputeReportingURLs(host_);
auto iter = std::find(reporting_filter_urls.begin(),
reporting_filter_urls.end(), report.url);
if (iter != reporting_filter_urls.end()) {
if (base::Contains(reporting_filter_urls, report.url)) {
return protocol::Network::ReportingApiReport::Create()
.SetId(report.id.ToString())
.SetInitiatorUrl(report.url.spec())
Expand Down
6 changes: 3 additions & 3 deletions content/browser/find_request_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

#include "content/browser/find_request_manager.h"

#include <algorithm>
#include <utility>

#include "base/bind.h"
#include "base/containers/contains.h"
#include "base/containers/queue.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "content/browser/find_in_page_client.h"
Expand Down Expand Up @@ -99,7 +99,7 @@ RenderFrameHostImpl* GetPreviousSibling(RenderFrameHostImpl* rfh) {
// The previous sibling may be in another WebContents.
if (RenderFrameHostImpl* parent = GetAncestor(rfh)) {
auto children = GetChildren(parent);
auto it = std::find(children.begin(), children.end(), rfh);
auto it = base::ranges::find(children, rfh);
// It is odd that this rfh may not be a child of its parent, but this is
// actually possible during teardown, hence the need for the check for
// "it != children.end()".
Expand All @@ -119,7 +119,7 @@ RenderFrameHostImpl* GetNextSibling(RenderFrameHostImpl* rfh) {
// The next sibling may be in another WebContents.
if (RenderFrameHostImpl* parent = GetAncestor(rfh)) {
auto children = GetChildren(parent);
auto it = std::find(children.begin(), children.end(), rfh);
auto it = base::ranges::find(children, rfh);
// It is odd that this RenderFrameHost may not be a child of its parent, but
// this is actually possible during teardown, hence the need for the check
// for "it != children.end()".
Expand Down
5 changes: 2 additions & 3 deletions content/browser/indexed_db/list_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

#include <stddef.h>

#include <algorithm>
#include <iterator>
#include <list>
#include <memory>
#include <set>

#include "base/check_op.h"
#include "base/ranges/algorithm.h"

//
// A container class that provides fast containment test (like a set)
Expand Down Expand Up @@ -51,8 +51,7 @@ class list_set {
if (set_.find(elem) == set_.end())
return;
set_.erase(elem);
typename std::list<T>::iterator it =
std::find(list_.begin(), list_.end(), elem);
typename std::list<T>::iterator it = base::ranges::find(list_, elem);
DCHECK(it != list_.end());
list_.erase(it);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "base/barrier_closure.h"
#include "base/bind.h"
#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/feature_list.h"
#include "base/memory/raw_ptr.h"
Expand Down Expand Up @@ -251,8 +252,7 @@ class NetworkResponder {
// Returns true if the network request for path received a response.
bool ReportSent(const std::string& path) const {
base::AutoLock auto_lock(lock_);
return std::find(sent_reports_.begin(), sent_reports_.end(), path) !=
sent_reports_.end();
return base::Contains(sent_reports_, path);
}

// Indicates whether `stored_url_loader_client_` is connected to a receiver.
Expand Down
4 changes: 1 addition & 3 deletions content/browser/interest_group/interest_group_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8149,9 +8149,7 @@ IN_PROC_BROWSER_TEST_F(InterestGroupBrowserTest,
same_origin_iframe_in_cross_origin_iframe};
#endif // BUILDFLAG(IS_ANDROID)

if (std::find(std::begin(execution_targets_with_message),
std::end(execution_targets_with_message), execution_target) !=
std::end(execution_targets_with_message)) {
if (base::Contains(execution_targets_with_message, execution_target)) {
EXPECT_EQ(WarningPermissionsPolicy("join-ad-interest-group",
"joinAdInterestGroup"),
console_observer.GetMessageAt(0));
Expand Down
3 changes: 1 addition & 2 deletions content/browser/media/active_media_session_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "content/browser/media/active_media_session_controller.h"

#include <algorithm>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -65,7 +64,7 @@ void ActiveMediaSessionController::MediaSessionActionsChanged(
MediaSessionActionToKeyCode(action);
if (!action_key_code.has_value())
continue;
if (std::find(actions.begin(), actions.end(), action) == actions.end())
if (!base::Contains(actions, action))
media_keys_listener_manager->StopWatchingMediaKey(*action_key_code, this);
}

Expand Down
7 changes: 3 additions & 4 deletions content/browser/plugin_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

#include <stddef.h>

#include <algorithm>

#include "base/check.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/lazy_instance.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
Expand Down Expand Up @@ -283,8 +282,8 @@ bool PluginList::GetPluginInfoArray(
void PluginList::RemoveExtraPluginPathLocked(
const base::FilePath& plugin_path) {
lock_.AssertAcquired();
std::vector<base::FilePath>::iterator it = std::find(
extra_plugin_paths_.begin(), extra_plugin_paths_.end(), plugin_path);
std::vector<base::FilePath>::iterator it =
base::ranges::find(extra_plugin_paths_, plugin_path);
if (it != extra_plugin_paths_.end())
extra_plugin_paths_.erase(it);
}
Expand Down
4 changes: 2 additions & 2 deletions content/browser/posix_file_descriptor_info_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <utility>

#include "base/containers/contains.h"
#include "base/ranges/algorithm.h"

namespace content {

Expand Down Expand Up @@ -73,8 +74,7 @@ base::ScopedFD PosixFileDescriptorInfoImpl::ReleaseFD(base::PlatformFile file) {
DCHECK(OwnsFD(file));

base::ScopedFD fd;
auto found =
std::find(owned_descriptors_.begin(), owned_descriptors_.end(), file);
auto found = base::ranges::find(owned_descriptors_, file);

std::swap(*found, fd);
owned_descriptors_.erase(found);
Expand Down
5 changes: 2 additions & 3 deletions content/browser/renderer_host/delegated_frame_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

#include "content/browser/renderer_host/delegated_frame_host.h"

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

#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/metrics/histogram_macros.h"
#include "base/observer_list.h"
#include "base/trace_event/trace_event.h"
Expand Down Expand Up @@ -470,8 +470,7 @@ void DelegatedFrameHost::ContinueDelegatedFrameEviction() {
// during navigation, construction, destruction, or in unit tests).
if (!surface_ids.empty()) {
DCHECK(!GetCurrentSurfaceId().is_valid() ||
std::find(surface_ids.begin(), surface_ids.end(),
GetCurrentSurfaceId()) != surface_ids.end());
base::Contains(surface_ids, GetCurrentSurfaceId()));
DCHECK(host_frame_sink_manager_);
host_frame_sink_manager_->EvictSurfaces(surface_ids);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <memory>

#include "base/containers/contains.h"
#include "base/file_version_info.h"
#include "base/files/file.h"
#include "base/files/scoped_temp_dir.h"
Expand Down Expand Up @@ -281,12 +282,8 @@ TEST_F(DWriteFontProxyImplUnitTest, FallbackFamily) {
"Times New Roman", fallback_request.language_tag, codepoint,
&fallback_family_and_style);

auto find_result_it =
std::find(fallback_request.fallback_fonts.begin(),
fallback_request.fallback_fonts.end(),
fallback_family_and_style->fallback_family_name);

EXPECT_TRUE(find_result_it != fallback_request.fallback_fonts.end())
EXPECT_TRUE(base::Contains(fallback_request.fallback_fonts,
fallback_family_and_style->fallback_family_name))
<< "Did not find expected fallback font for language: "
<< fallback_request.language_tag << ", codepoint U+" << std::hex
<< codepoint << " DWrite returned font name: \""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <stdint.h>

#include <algorithm>
#include <memory>
#include <string>
#include <vector>
Expand All @@ -17,6 +16,7 @@
#include "base/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/threading/thread_task_runner_handle.h"
Expand Down Expand Up @@ -144,7 +144,7 @@ class WrappedDeviceFactory final : public media::FakeVideoCaptureDeviceFactory {
void OnDeviceCreated(WrappedDevice* device) { devices_.push_back(device); }

void OnDeviceDestroyed(WrappedDevice* device) {
const auto it = std::find(devices_.begin(), devices_.end(), device);
const auto it = base::ranges::find(devices_, device);
CHECK(it != devices_.end());
devices_.erase(it);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
Expand Down Expand Up @@ -5031,10 +5032,7 @@ ObjectData kInnerObject{10, {"getInnerId"}};
class MockInnerObject : public blink::mojom::RemoteObject {
public:
void HasMethod(const std::string& name, HasMethodCallback callback) override {
bool has_method =
std::find(kInnerObject.methods.begin(), kInnerObject.methods.end(),
name) != kInnerObject.methods.end();
std::move(callback).Run(has_method);
std::move(callback).Run(base::Contains(kInnerObject.methods, name));
}
void GetMethods(GetMethodsCallback callback) override {
std::move(callback).Run(kInnerObject.methods);
Expand All @@ -5060,10 +5058,7 @@ class MockObject : public blink::mojom::RemoteObject {
mojo::PendingReceiver<blink::mojom::RemoteObject> receiver)
: receiver_(this, std::move(receiver)) {}
void HasMethod(const std::string& name, HasMethodCallback callback) override {
bool has_method =
std::find(kMainObject.methods.begin(), kMainObject.methods.end(),
name) != kMainObject.methods.end();
std::move(callback).Run(has_method);
std::move(callback).Run(base::Contains(kMainObject.methods, name));
}

void GetMethods(GetMethodsCallback callback) override {
Expand Down
6 changes: 3 additions & 3 deletions content/browser/renderer_host/render_frame_host_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <stddef.h>

#include <algorithm>
#include <string>
#include <unordered_set>
#include <utility>
Expand All @@ -21,6 +20,7 @@
#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/trace_event/base_tracing.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/typed_macros.h"
Expand Down Expand Up @@ -3951,8 +3951,8 @@ void RenderFrameHostManager::CollectOpenerFrameTrees(
continue;

FrameTree* opener_tree = node->opener()->frame_tree();
const auto& existing_tree_it = std::find(
opener_frame_trees->begin(), opener_frame_trees->end(), opener_tree);
const auto& existing_tree_it =
base::ranges::find(*opener_frame_trees, opener_tree);

if (existing_tree_it == opener_frame_trees->end()) {
// This is a new opener tree that we will need to process.
Expand Down
5 changes: 2 additions & 3 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "content/browser/renderer_host/render_process_host_impl.h"

#include <algorithm>
#include <limits>
#include <map>
#include <memory>
Expand Down Expand Up @@ -51,6 +50,7 @@
#include "base/observer_list.h"
#include "base/process/process_handle.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/supports_user_data.h"
#include "base/system/sys_info.h"
Expand Down Expand Up @@ -4115,8 +4115,7 @@ void RenderProcessHostImpl::RegisterCreationObserver(
void RenderProcessHostImpl::UnregisterCreationObserver(
RenderProcessHostCreationObserver* observer) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto iter = std::find(GetAllCreationObservers().begin(),
GetAllCreationObservers().end(), observer);
auto iter = base::ranges::find(GetAllCreationObservers(), observer);
DCHECK(iter != GetAllCreationObservers().end());
GetAllCreationObservers().erase(iter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vector>

#include "base/bind.h"
#include "base/containers/contains.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
Expand Down Expand Up @@ -275,9 +276,8 @@ IN_PROC_BROWSER_TEST_F(RenderWidgetHostTouchEmulatorBrowserTest,
// that we generated a GestureScrollEnd and routed it without crashing.
TestInputEventObserver::EventTypeVector dispatched_events =
observer.GetAndResetDispatchedEventTypes();
auto it_gse = std::find(dispatched_events.begin(), dispatched_events.end(),
blink::WebInputEvent::Type::kGestureScrollEnd);
EXPECT_NE(dispatched_events.end(), it_gse);
EXPECT_TRUE(base::Contains(dispatched_events,
blink::WebInputEvent::Type::kGestureScrollEnd));
} while (!touch_emulator->suppress_next_fling_cancel_for_testing());
}
#endif // !BUILDFLAG(IS_ANDROID)
Expand Down
Loading

0 comments on commit ff5db66

Please sign in to comment.