[dbus] Use base::Contains() instead of std::find() in //dbus
Use base::Contains() instead of std::find() where appropriate in //dbus. Bug: 561800 Change-Id: Id31974ee5e7c559e5d1df6836586fda52ee228af Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4783169 Commit-Queue: Ho Cheung <uioptt24@gmail.com> Reviewed-by: Ryo Hashimoto <hashimoto@chromium.org> Cr-Commit-Position: refs/heads/main@{#1184198}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
280c58a0e1
commit
361ebe3b56
15
dbus/bus.cc
15
dbus/bus.cc
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "base/containers/contains.h"
|
||||||
#include "base/files/file_descriptor_watcher_posix.h"
|
#include "base/files/file_descriptor_watcher_posix.h"
|
||||||
#include "base/functional/bind.h"
|
#include "base/functional/bind.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
@@ -555,7 +556,7 @@ bool Bus::RequestOwnershipAndBlock(const std::string& service_name,
|
|||||||
AssertOnDBusThread();
|
AssertOnDBusThread();
|
||||||
|
|
||||||
// Check if we already own the service name.
|
// Check if we already own the service name.
|
||||||
if (owned_service_names_.find(service_name) != owned_service_names_.end()) {
|
if (base::Contains(owned_service_names_, service_name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -694,8 +695,7 @@ void Bus::AddFilterFunction(DBusHandleMessageFunction filter_function,
|
|||||||
|
|
||||||
std::pair<DBusHandleMessageFunction, void*> filter_data_pair =
|
std::pair<DBusHandleMessageFunction, void*> filter_data_pair =
|
||||||
std::make_pair(filter_function, user_data);
|
std::make_pair(filter_function, user_data);
|
||||||
if (filter_functions_added_.find(filter_data_pair) !=
|
if (base::Contains(filter_functions_added_, filter_data_pair)) {
|
||||||
filter_functions_added_.end()) {
|
|
||||||
VLOG(1) << "Filter function already exists: " << filter_function
|
VLOG(1) << "Filter function already exists: " << filter_function
|
||||||
<< " with associated data: " << user_data;
|
<< " with associated data: " << user_data;
|
||||||
return;
|
return;
|
||||||
@@ -716,8 +716,7 @@ void Bus::RemoveFilterFunction(DBusHandleMessageFunction filter_function,
|
|||||||
|
|
||||||
std::pair<DBusHandleMessageFunction, void*> filter_data_pair =
|
std::pair<DBusHandleMessageFunction, void*> filter_data_pair =
|
||||||
std::make_pair(filter_function, user_data);
|
std::make_pair(filter_function, user_data);
|
||||||
if (filter_functions_added_.find(filter_data_pair) ==
|
if (!base::Contains(filter_functions_added_, filter_data_pair)) {
|
||||||
filter_functions_added_.end()) {
|
|
||||||
VLOG(1) << "Requested to remove an unknown filter function: "
|
VLOG(1) << "Requested to remove an unknown filter function: "
|
||||||
<< filter_function
|
<< filter_function
|
||||||
<< " with associated data: " << user_data;
|
<< " with associated data: " << user_data;
|
||||||
@@ -812,8 +811,7 @@ bool Bus::TryRegisterObjectPathInternal(
|
|||||||
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
|
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
|
||||||
base::BlockingType::MAY_BLOCK);
|
base::BlockingType::MAY_BLOCK);
|
||||||
|
|
||||||
if (registered_object_paths_.find(object_path) !=
|
if (base::Contains(registered_object_paths_, object_path)) {
|
||||||
registered_object_paths_.end()) {
|
|
||||||
LOG(ERROR) << "Object path already registered: " << object_path.value();
|
LOG(ERROR) << "Object path already registered: " << object_path.value();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -834,8 +832,7 @@ void Bus::UnregisterObjectPath(const ObjectPath& object_path) {
|
|||||||
DCHECK(connection_);
|
DCHECK(connection_);
|
||||||
AssertOnDBusThread();
|
AssertOnDBusThread();
|
||||||
|
|
||||||
if (registered_object_paths_.find(object_path) ==
|
if (!base::Contains(registered_object_paths_, object_path)) {
|
||||||
registered_object_paths_.end()) {
|
|
||||||
LOG(ERROR) << "Requested to unregister an unknown object path: "
|
LOG(ERROR) << "Requested to unregister an unknown object path: "
|
||||||
<< object_path.value();
|
<< object_path.value();
|
||||||
return;
|
return;
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "base/containers/contains.h"
|
||||||
#include "base/functional/bind.h"
|
#include "base/functional/bind.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/memory/ref_counted.h"
|
#include "base/memory/ref_counted.h"
|
||||||
@@ -43,7 +44,7 @@ bool ExportedObject::ExportMethodAndBlock(
|
|||||||
// Check if the method is already exported.
|
// Check if the method is already exported.
|
||||||
const std::string absolute_method_name =
|
const std::string absolute_method_name =
|
||||||
GetAbsoluteMemberName(interface_name, method_name);
|
GetAbsoluteMemberName(interface_name, method_name);
|
||||||
if (method_table_.find(absolute_method_name) != method_table_.end()) {
|
if (base::Contains(method_table_, absolute_method_name)) {
|
||||||
LOG(ERROR) << absolute_method_name << " is already exported";
|
LOG(ERROR) << absolute_method_name << " is already exported";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "base/containers/contains.h"
|
||||||
#include "base/debug/alias.h"
|
#include "base/debug/alias.h"
|
||||||
#include "base/debug/leak_annotations.h"
|
#include "base/debug/leak_annotations.h"
|
||||||
#include "base/functional/bind.h"
|
#include "base/functional/bind.h"
|
||||||
@@ -610,7 +611,7 @@ bool ObjectProxy::AddMatchRuleWithCallback(
|
|||||||
DCHECK(!absolute_signal_name.empty());
|
DCHECK(!absolute_signal_name.empty());
|
||||||
bus_->AssertOnDBusThread();
|
bus_->AssertOnDBusThread();
|
||||||
|
|
||||||
if (match_rules_.find(match_rule) == match_rules_.end()) {
|
if (!base::Contains(match_rules_, match_rule)) {
|
||||||
dbus::Error error;
|
dbus::Error error;
|
||||||
bus_->AddMatch(match_rule, &error);
|
bus_->AddMatch(match_rule, &error);
|
||||||
if (error.IsValid()) {
|
if (error.IsValid()) {
|
||||||
@@ -638,8 +639,9 @@ bool ObjectProxy::AddMatchRuleWithoutCallback(
|
|||||||
DCHECK(!absolute_signal_name.empty());
|
DCHECK(!absolute_signal_name.empty());
|
||||||
bus_->AssertOnDBusThread();
|
bus_->AssertOnDBusThread();
|
||||||
|
|
||||||
if (match_rules_.find(match_rule) != match_rules_.end())
|
if (base::Contains(match_rules_, match_rule)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Error error;
|
Error error;
|
||||||
bus_->AddMatch(match_rule, &error);
|
bus_->AddMatch(match_rule, &error);
|
||||||
|
Reference in New Issue
Block a user