Skip to content

Commit 361ebe3

Browse files
gz83Chromium LUCI CQ
authored andcommitted
[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 <[email protected]> Reviewed-by: Ryo Hashimoto <[email protected]> Cr-Commit-Position: refs/heads/main@{#1184198}
1 parent 280c58a commit 361ebe3

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

dbus/bus.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <memory>
1010

11+
#include "base/containers/contains.h"
1112
#include "base/files/file_descriptor_watcher_posix.h"
1213
#include "base/functional/bind.h"
1314
#include "base/logging.h"
@@ -555,7 +556,7 @@ bool Bus::RequestOwnershipAndBlock(const std::string& service_name,
555556
AssertOnDBusThread();
556557

557558
// Check if we already own the service name.
558-
if (owned_service_names_.find(service_name) != owned_service_names_.end()) {
559+
if (base::Contains(owned_service_names_, service_name)) {
559560
return true;
560561
}
561562

@@ -694,8 +695,7 @@ void Bus::AddFilterFunction(DBusHandleMessageFunction filter_function,
694695

695696
std::pair<DBusHandleMessageFunction, void*> filter_data_pair =
696697
std::make_pair(filter_function, user_data);
697-
if (filter_functions_added_.find(filter_data_pair) !=
698-
filter_functions_added_.end()) {
698+
if (base::Contains(filter_functions_added_, filter_data_pair)) {
699699
VLOG(1) << "Filter function already exists: " << filter_function
700700
<< " with associated data: " << user_data;
701701
return;
@@ -716,8 +716,7 @@ void Bus::RemoveFilterFunction(DBusHandleMessageFunction filter_function,
716716

717717
std::pair<DBusHandleMessageFunction, void*> filter_data_pair =
718718
std::make_pair(filter_function, user_data);
719-
if (filter_functions_added_.find(filter_data_pair) ==
720-
filter_functions_added_.end()) {
719+
if (!base::Contains(filter_functions_added_, filter_data_pair)) {
721720
VLOG(1) << "Requested to remove an unknown filter function: "
722721
<< filter_function
723722
<< " with associated data: " << user_data;
@@ -812,8 +811,7 @@ bool Bus::TryRegisterObjectPathInternal(
812811
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
813812
base::BlockingType::MAY_BLOCK);
814813

815-
if (registered_object_paths_.find(object_path) !=
816-
registered_object_paths_.end()) {
814+
if (base::Contains(registered_object_paths_, object_path)) {
817815
LOG(ERROR) << "Object path already registered: " << object_path.value();
818816
return false;
819817
}
@@ -834,8 +832,7 @@ void Bus::UnregisterObjectPath(const ObjectPath& object_path) {
834832
DCHECK(connection_);
835833
AssertOnDBusThread();
836834

837-
if (registered_object_paths_.find(object_path) ==
838-
registered_object_paths_.end()) {
835+
if (!base::Contains(registered_object_paths_, object_path)) {
839836
LOG(ERROR) << "Requested to unregister an unknown object path: "
840837
<< object_path.value();
841838
return;

dbus/exported_object.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stdint.h>
88
#include <utility>
99

10+
#include "base/containers/contains.h"
1011
#include "base/functional/bind.h"
1112
#include "base/logging.h"
1213
#include "base/memory/ref_counted.h"
@@ -43,7 +44,7 @@ bool ExportedObject::ExportMethodAndBlock(
4344
// Check if the method is already exported.
4445
const std::string absolute_method_name =
4546
GetAbsoluteMemberName(interface_name, method_name);
46-
if (method_table_.find(absolute_method_name) != method_table_.end()) {
47+
if (base::Contains(method_table_, absolute_method_name)) {
4748
LOG(ERROR) << absolute_method_name << " is already exported";
4849
return false;
4950
}

dbus/object_proxy.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stddef.h>
88
#include <utility>
99

10+
#include "base/containers/contains.h"
1011
#include "base/debug/alias.h"
1112
#include "base/debug/leak_annotations.h"
1213
#include "base/functional/bind.h"
@@ -610,7 +611,7 @@ bool ObjectProxy::AddMatchRuleWithCallback(
610611
DCHECK(!absolute_signal_name.empty());
611612
bus_->AssertOnDBusThread();
612613

613-
if (match_rules_.find(match_rule) == match_rules_.end()) {
614+
if (!base::Contains(match_rules_, match_rule)) {
614615
dbus::Error error;
615616
bus_->AddMatch(match_rule, &error);
616617
if (error.IsValid()) {
@@ -638,8 +639,9 @@ bool ObjectProxy::AddMatchRuleWithoutCallback(
638639
DCHECK(!absolute_signal_name.empty());
639640
bus_->AssertOnDBusThread();
640641

641-
if (match_rules_.find(match_rule) != match_rules_.end())
642+
if (base::Contains(match_rules_, match_rule)) {
642643
return true;
644+
}
643645

644646
Error error;
645647
bus_->AddMatch(match_rule, &error);

0 commit comments

Comments
 (0)