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";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue