refactor: prefer base::Contains() over find() + end() (#38443)
* refactor: use base::Contains() in KeyWeakMap::Has() * refactor: use base::Contains() in WebRequest::RequestFilter::MatchesType() * refactor: use base::Contains() in BaseWindow::AddBrowserView() * refactor: use base::Contains() in DeepFreeze() * refactor: use base::Contains() in Clipboard::Read() * Revert "refactor: use base::Contains() in BaseWindow::AddBrowserView()" This reverts commit 60152359d3978451ebdd7c8eed602c2fb8a9cafa. * refactor: use base::Contains() in BaseWindow::AddBrowserView() * refactor: use base::Contains() in IsDevToolsFileSystemAdded() * refactor: use base::Contains() in MessagePort::DisentanglePorts() * refactor: use base::Contains() in PowerSaveBlocker::IsStarted() * refactor: use base::Contains() in SpellCheckClient::OnSpellCheckDone() * refactor: use base::Contains() in ShowTaskDialogWstr() * refactor: use base::Contains() in PrintViewManagerElectron::ScriptedPrint() * refactor: use base::Contains() in PrintViewManagerElectron::DidGetPrintedPagesCount() * refactor: use base::Contains() in NativeWindow::AddDraggableRegionProvider() * refactor: use base::Contains() in ElectronBindings::ActivateUVLoop() * refactor: use base::Contains() in NativeWindowViews::IsVisibleOnAllWorkspaces() * refactor: use base::Contains() in HidChooserController::OnDeviceAdded() * refactor: use base::Contains() in ElectronSandboxedRendererClient::WillReleaseScriptContext() * refactor: use base::Contains() in ElectronRendererClient::WillDestroyWorkerContextOnWorkerThread() * refactor: use base::Contains() in GlobalShortcut::OnKeyPressed()
This commit is contained in:
parent
9640ac441d
commit
0203bd3305
19 changed files with 39 additions and 36 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "gin/dictionary.h"
|
||||
|
@ -757,8 +758,7 @@ void BaseWindow::SetBrowserView(
|
|||
}
|
||||
|
||||
void BaseWindow::AddBrowserView(gin::Handle<BrowserView> browser_view) {
|
||||
auto iter = browser_views_.find(browser_view->ID());
|
||||
if (iter == browser_views_.end()) {
|
||||
if (!base::Contains(browser_views_, browser_view->ID())) {
|
||||
// If we're reparenting a BrowserView, ensure that it's detached from
|
||||
// its previous owner window.
|
||||
BaseWindow* owner_window = browser_view->owner_window();
|
||||
|
|
|
@ -62,8 +62,7 @@ GlobalShortcut::~GlobalShortcut() {
|
|||
}
|
||||
|
||||
void GlobalShortcut::OnKeyPressed(const ui::Accelerator& accelerator) {
|
||||
if (accelerator_callback_map_.find(accelerator) ==
|
||||
accelerator_callback_map_.end()) {
|
||||
if (!base::Contains(accelerator_callback_map_, accelerator)) {
|
||||
// This should never occur, because if it does, GlobalShortcutListener
|
||||
// notifies us with wrong accelerator.
|
||||
NOTREACHED();
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/callback_helpers.h"
|
||||
#include "content/public/browser/device_service.h"
|
||||
#include "gin/dictionary.h"
|
||||
|
@ -106,8 +107,8 @@ bool PowerSaveBlocker::Stop(int id) {
|
|||
return success;
|
||||
}
|
||||
|
||||
bool PowerSaveBlocker::IsStarted(int id) {
|
||||
return wake_lock_types_.find(id) != wake_lock_types_.end();
|
||||
bool PowerSaveBlocker::IsStarted(int id) const {
|
||||
return base::Contains(wake_lock_types_, id);
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -37,7 +37,7 @@ class PowerSaveBlocker : public gin::Wrappable<PowerSaveBlocker> {
|
|||
void UpdatePowerSaveBlocker();
|
||||
int Start(device::mojom::WakeLockType type);
|
||||
bool Stop(int id);
|
||||
bool IsStarted(int id);
|
||||
bool IsStarted(int id) const;
|
||||
|
||||
device::mojom::WakeLock* GetWakeLock();
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/containers/id_map.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/json/json_reader.h"
|
||||
|
@ -729,8 +730,8 @@ std::map<std::string, std::string> GetAddedFileSystemPaths(
|
|||
|
||||
bool IsDevToolsFileSystemAdded(content::WebContents* web_contents,
|
||||
const std::string& file_system_path) {
|
||||
auto file_system_paths = GetAddedFileSystemPaths(web_contents);
|
||||
return file_system_paths.find(file_system_path) != file_system_paths.end();
|
||||
return base::Contains(GetAddedFileSystemPaths(web_contents),
|
||||
file_system_path);
|
||||
}
|
||||
|
||||
void SetBackgroundColor(content::RenderWidgetHostView* rwhv, SkColor color) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
|
@ -294,7 +295,7 @@ bool WebRequest::RequestFilter::MatchesURL(const GURL& url) const {
|
|||
|
||||
bool WebRequest::RequestFilter::MatchesType(
|
||||
extensions::WebRequestResourceType type) const {
|
||||
return types_.empty() || types_.find(type) != types_.end();
|
||||
return types_.empty() || base::Contains(types_, type);
|
||||
}
|
||||
|
||||
bool WebRequest::RequestFilter::MatchesRequest(
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
#include "gin/arguments.h"
|
||||
|
@ -221,7 +222,7 @@ std::vector<blink::MessagePortChannel> MessagePort::DisentanglePorts(
|
|||
// or cloned ports, throw an error (per section 8.3.3 of the HTML5 spec).
|
||||
for (unsigned i = 0; i < ports.size(); ++i) {
|
||||
auto* port = ports[i].get();
|
||||
if (!port || port->IsNeutered() || visited.find(port) != visited.end()) {
|
||||
if (!port || port->IsNeutered() || base::Contains(visited, port)) {
|
||||
std::string type;
|
||||
if (!port)
|
||||
type = "null";
|
||||
|
|
|
@ -149,8 +149,7 @@ void HidChooserController::OnDeviceAdded(
|
|||
void HidChooserController::OnDeviceRemoved(
|
||||
const device::mojom::HidDeviceInfo& device) {
|
||||
auto id = PhysicalDeviceIdFromDeviceInfo(device);
|
||||
auto items_it = std::find(items_.begin(), items_.end(), id);
|
||||
if (items_it == items_.end())
|
||||
if (!base::Contains(items_, id))
|
||||
return;
|
||||
api::Session* session = GetSession();
|
||||
if (session) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/values.h"
|
||||
|
@ -725,9 +726,7 @@ int NativeWindow::NonClientHitTest(const gfx::Point& point) {
|
|||
|
||||
void NativeWindow::AddDraggableRegionProvider(
|
||||
DraggableRegionProvider* provider) {
|
||||
if (std::find(draggable_region_providers_.begin(),
|
||||
draggable_region_providers_.end(),
|
||||
provider) == draggable_region_providers_.end()) {
|
||||
if (!base::Contains(draggable_region_providers_, provider)) {
|
||||
draggable_region_providers_.push_back(provider);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
|
@ -1438,8 +1439,7 @@ bool NativeWindowViews::IsVisibleOnAllWorkspaces() {
|
|||
std::vector<x11::Atom> wm_states;
|
||||
GetArrayProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
|
||||
x11::GetAtom("_NET_WM_STATE"), &wm_states);
|
||||
return std::find(wm_states.begin(), wm_states.end(), sticky_atom) !=
|
||||
wm_states.end();
|
||||
return base::Contains(wm_states, sticky_atom);
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "build/build_config.h"
|
||||
#include "components/printing/browser/print_to_pdf/pdf_print_utils.h"
|
||||
|
@ -98,8 +99,7 @@ void PrintViewManagerElectron::GetDefaultPrintSettings(
|
|||
void PrintViewManagerElectron::ScriptedPrint(
|
||||
printing::mojom::ScriptedPrintParamsPtr params,
|
||||
ScriptedPrintCallback callback) {
|
||||
auto entry = std::find(pdf_jobs_.begin(), pdf_jobs_.end(), params->cookie);
|
||||
if (entry == pdf_jobs_.end()) {
|
||||
if (!base::Contains(pdf_jobs_, params->cookie)) {
|
||||
PrintViewManagerBase::ScriptedPrint(std::move(params), std::move(callback));
|
||||
return;
|
||||
}
|
||||
|
@ -135,8 +135,7 @@ void PrintViewManagerElectron::CheckForCancel(int32_t preview_ui_id,
|
|||
|
||||
void PrintViewManagerElectron::DidGetPrintedPagesCount(int32_t cookie,
|
||||
uint32_t number_pages) {
|
||||
auto entry = std::find(pdf_jobs_.begin(), pdf_jobs_.end(), cookie);
|
||||
if (entry == pdf_jobs_.end()) {
|
||||
if (!base::Contains(pdf_jobs_, cookie)) {
|
||||
PrintViewManagerBase::DidGetPrintedPagesCount(cookie, number_pages);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ DialogResult ShowTaskDialogWstr(gfx::AcceleratedWidget parent,
|
|||
TaskDialogIndirect(&config, &id, nullptr, &verification_flag_checked);
|
||||
|
||||
int button_id;
|
||||
if (id_map.find(id) != id_map.end()) // common button.
|
||||
if (base::Contains(id_map, id)) // common button.
|
||||
button_id = id_map[id];
|
||||
else if (id >= kIDStart) // custom button.
|
||||
button_id = id - kIDStart;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue