[chromecast] Use base::Contains() instead of std::find() in chromecast
Use base::Contains() instead of std::find() where appropriate in //chromecast. Bug: 561800 Change-Id: I8142266ba07d8fde1becafd2f47e425ec33e7724 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4787008 Reviewed-by: Vigen Issahhanjan <vigeni@google.com> Commit-Queue: Ho Cheung <uioptt24@gmail.com> Cr-Commit-Position: refs/heads/main@{#1184545}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
02fbd3f5ac
commit
9b2ff9e70d
chromecast
base
browser
cast_core
grpc
crash
device
external_mojo
public
media
cma
backend
renderer
@ -8,6 +8,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/functional/callback_helpers.h"
|
||||
#include "base/json/json_writer.h"
|
||||
@ -26,7 +27,7 @@ const char kPathSeparator = '.';
|
||||
// Determines if a key passed to Register() is valid. No path separators can
|
||||
// be present in the key and it must not be empty.
|
||||
bool IsValidRegisterKey(const std::string& key) {
|
||||
return !key.empty() && key.find(kPathSeparator) == std::string::npos;
|
||||
return !key.empty() && !base::Contains(key, kPathSeparator);
|
||||
}
|
||||
|
||||
// Determines if a path is valid. This is true if there are no empty keys
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/functional/callback_helpers.h"
|
||||
#include "base/json/json_writer.h"
|
||||
@ -55,8 +56,10 @@ bool CastMetricsHelper::DecodeAppInfoFromMetricsName(
|
||||
DCHECK(app_id);
|
||||
DCHECK(session_id);
|
||||
DCHECK(sdk_version);
|
||||
if (metrics_name.find(kMetricsNameAppInfoDelimiter) == std::string::npos)
|
||||
|
||||
if (!base::Contains(metrics_name, kMetricsNameAppInfoDelimiter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> tokens = base::SplitString(
|
||||
metrics_name, std::string(1, kMetricsNameAppInfoDelimiter),
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "chromecast/browser/bluetooth/cast_bluetooth_chooser.h"
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/logging.h"
|
||||
#include "mojo/public/cpp/bindings/remote.h"
|
||||
@ -32,7 +33,7 @@ void CastBluetoothChooser::GrantAccess(const std::string& address) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (available_devices_.find(address) != available_devices_.end()) {
|
||||
if (base::Contains(available_devices_, address)) {
|
||||
RunEventHandlerAndResetReceiver(content::BluetoothChooserEvent::SELECTED,
|
||||
address);
|
||||
return;
|
||||
@ -59,8 +60,7 @@ void CastBluetoothChooser::AddOrUpdateDevice(const std::string& device_id,
|
||||
DCHECK(event_handler_);
|
||||
|
||||
// Note: |device_id| is just a canonical Bluetooth address.
|
||||
if (all_devices_approved_ ||
|
||||
approved_devices_.find(device_id) != approved_devices_.end()) {
|
||||
if (all_devices_approved_ || base::Contains(approved_devices_, device_id)) {
|
||||
RunEventHandlerAndResetReceiver(content::BluetoothChooserEvent::SELECTED,
|
||||
device_id);
|
||||
return;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "content/public/browser/devtools_agent_host.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
@ -46,8 +47,8 @@ class CastDevToolsManagerDelegateTest
|
||||
EXPECT_EQ(enabled_web_contents.size(), targets.size());
|
||||
|
||||
for (const auto& target : targets) {
|
||||
EXPECT_TRUE(enabled_web_contents.find(target->GetWebContents()) !=
|
||||
enabled_web_contents.end())
|
||||
EXPECT_TRUE(
|
||||
base::Contains(enabled_web_contents, target->GetWebContents()))
|
||||
<< "Discovered target not found in enabled WebContents.";
|
||||
}
|
||||
}
|
||||
@ -63,17 +64,17 @@ TEST_F(CastDevToolsManagerDelegateTest, TestSingletonGetter) {
|
||||
}
|
||||
|
||||
TEST_F(CastDevToolsManagerDelegateTest, DisabledWebContents) {
|
||||
TestDiscoveredTargets(WebContentsSet(),
|
||||
devtools_manager_delegate_->RemoteDebuggingTargets(
|
||||
content::DevToolsManagerDelegate::kFrame));
|
||||
TestDiscoveredTargets(WebContentsSet(),
|
||||
devtools_manager_delegate_->RemoteDebuggingTargets(
|
||||
content::DevToolsManagerDelegate::kFrame));
|
||||
}
|
||||
|
||||
TEST_F(CastDevToolsManagerDelegateTest, EnabledWebContents) {
|
||||
devtools_manager_delegate_->EnableWebContentsForDebugging(web_contents());
|
||||
WebContentsSet enabled_web_contents({web_contents()});
|
||||
TestDiscoveredTargets(enabled_web_contents,
|
||||
devtools_manager_delegate_->RemoteDebuggingTargets(
|
||||
content::DevToolsManagerDelegate::kFrame));
|
||||
TestDiscoveredTargets(enabled_web_contents,
|
||||
devtools_manager_delegate_->RemoteDebuggingTargets(
|
||||
content::DevToolsManagerDelegate::kFrame));
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/logging.h"
|
||||
#include "chromecast/cast_core/grpc/grpc_handler.h"
|
||||
@ -76,8 +77,7 @@ class GrpcServer : public grpc::CallbackGenericService {
|
||||
void SetHandler(typename THandler::OnRequestCallback on_request_callback) {
|
||||
// The full rpc name is /<fully-qualified-service-type>/method, ie
|
||||
// /cast.core.CastCoreService/RegisterRuntime.
|
||||
DCHECK(registered_handlers_.find(THandler::rpc_name()) ==
|
||||
registered_handlers_.end())
|
||||
DCHECK(!base::Contains(registered_handlers_, THandler::rpc_name()))
|
||||
<< "Duplicate handler: " << THandler::rpc_name();
|
||||
registered_handlers_.emplace(
|
||||
THandler::rpc_name(),
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "chromecast/base/version.h"
|
||||
namespace chromecast {
|
||||
@ -43,8 +44,8 @@ const std::string GetVersionString(const std::string& cast_release_number,
|
||||
}
|
||||
|
||||
const std::string VersionToVariant(const std::string& cast_build_revision) {
|
||||
for (std::string variant : {kEngVariant, kUserVariant}) {
|
||||
if (cast_build_revision.find(variant) != std::string::npos) {
|
||||
for (const std::string& variant : {kEngVariant, kUserVariant}) {
|
||||
if (base::Contains(cast_build_revision, variant)) {
|
||||
return variant;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/containers/cxx20_erase.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/logging.h"
|
||||
@ -239,7 +240,7 @@ void GattClientManagerImpl::DisconnectAll(StatusCallback cb) {
|
||||
bool GattClientManagerImpl::IsConnectedLeDevice(
|
||||
const bluetooth_v2_shlib::Addr& addr) {
|
||||
DCHECK(io_task_runner_->BelongsToCurrentThread());
|
||||
return connected_devices_.find(addr) != connected_devices_.end();
|
||||
return base::Contains(connected_devices_, addr);
|
||||
}
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner>
|
||||
@ -570,7 +571,7 @@ void GattClientManagerImpl::OnConnectTimeout(
|
||||
LOG(ERROR) << "Connect (" << addr_str << ")"
|
||||
<< " timed out. Disconnecting";
|
||||
|
||||
if (connected_devices_.find(addr) != connected_devices_.end()) {
|
||||
if (base::Contains(connected_devices_, addr)) {
|
||||
// Connect times out before OnGetServices is received.
|
||||
gatt_client_->Disconnect(addr);
|
||||
} else {
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "chromecast/device/bluetooth/le/remote_characteristic_impl.h"
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
@ -122,7 +123,7 @@ RemoteCharacteristicImpl::CreateDescriptorMap() {
|
||||
}
|
||||
|
||||
if (fake_cccd_) {
|
||||
DCHECK(ret.find(RemoteDescriptor::kCccdUuid) == ret.end());
|
||||
DCHECK(!base::Contains(ret, RemoteDescriptor::kCccdUuid));
|
||||
ret[fake_cccd_->uuid] = new RemoteDescriptorImpl(
|
||||
device_, gatt_client_manager_, fake_cccd_.get(), io_task_runner_);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <set>
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "build/build_config.h"
|
||||
|
||||
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
||||
@ -236,7 +237,7 @@ class ExternalMojoBroker::ConnectorImpl : public mojom::ExternalConnector {
|
||||
void RegisterServiceInstance(
|
||||
const std::string& service_name,
|
||||
mojo::PendingRemote<mojom::ExternalService> service_remote) {
|
||||
if (services_.find(service_name) != services_.end()) {
|
||||
if (base::Contains(services_, service_name)) {
|
||||
LOG(ERROR) << "Duplicate service " << service_name;
|
||||
return;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
@ -245,7 +246,7 @@ class VolumeControlInternal : public SystemVolumeControl::Delegate {
|
||||
DCHECK(thread_.task_runner()->BelongsToCurrentThread());
|
||||
DCHECK_NE(AudioContentType::kOther, type);
|
||||
DCHECK(!from_system || type == AudioContentType::kMedia);
|
||||
DCHECK(volume_multipliers_.find(type) != volume_multipliers_.end());
|
||||
DCHECK(base::Contains(volume_multipliers_, type));
|
||||
|
||||
{
|
||||
base::AutoLock lock(volume_lock_);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/values.h"
|
||||
#include "chromecast/base/cast_features.h"
|
||||
@ -135,7 +136,7 @@ void FeatureManager::OnFeatureManagerRequest(
|
||||
}
|
||||
|
||||
bool FeatureManager::FeatureEnabled(const std::string& feature) const {
|
||||
return features_map_.find(feature) != features_map_.end();
|
||||
return base::Contains(features_map_, feature);
|
||||
}
|
||||
|
||||
const chromecast::shell::mojom::FeaturePtr& FeatureManager::GetFeature(
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "chromecast/renderer/feature_manager_on_associated_interface.h"
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/values.h"
|
||||
#include "chromecast/base/cast_features.h"
|
||||
@ -78,7 +79,7 @@ void FeatureManagerOnAssociatedInterface::OnFeatureManagerAssociatedRequest(
|
||||
|
||||
bool FeatureManagerOnAssociatedInterface::FeatureEnabled(
|
||||
const std::string& feature) const {
|
||||
return features_map_.find(feature) != features_map_.end();
|
||||
return base::Contains(features_map_, feature);
|
||||
}
|
||||
|
||||
const chromecast::shell::mojom::FeaturePtr&
|
||||
|
Reference in New Issue
Block a user