Migrate absl variant.h and utility.h in mojo
Since https://crrev.com/c/6330348, some utils in third_party/abseil-cpp/absl/types/variant.h and and third_party/abseil-cpp/absl/utility/utility.h are only aliases for their std counterparts. This CL migrates code to use std:: directly. Bug: 40242126 Change-Id: Ic08cd53bc4278d8af95891d6894cff3bc0ce9b52 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6343016 Reviewed-by: Oksana Zhuravlova <oksamyt@chromium.org> Commit-Queue: Victor Vianna <victorvianna@google.com> Cr-Commit-Position: refs/heads/main@{#1430887}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
4a6b423d12
commit
d3d7f3f397
mojo
@ -16,6 +16,7 @@
|
||||
#include <optional>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "base/android/binder.h"
|
||||
@ -42,7 +43,6 @@
|
||||
#include "mojo/core/ipcz_driver/envelope.h"
|
||||
#include "mojo/public/cpp/platform/binder_exchange.h"
|
||||
#include "mojo/public/cpp/platform/platform_handle.h"
|
||||
#include "third_party/abseil-cpp/absl/types/variant.h"
|
||||
|
||||
namespace mojo::core {
|
||||
|
||||
@ -162,7 +162,7 @@ struct PayloadBuffer {
|
||||
size_t size;
|
||||
};
|
||||
using ReceivedPayload =
|
||||
absl::variant<PayloadBuffer, base::ReadOnlySharedMemoryMapping>;
|
||||
std::variant<PayloadBuffer, base::ReadOnlySharedMemoryMapping>;
|
||||
base::android::BinderStatusOr<ReceivedPayload> ReadMessagePayload(
|
||||
const base::android::ParcelReader& in) {
|
||||
ASSIGN_OR_RETURN(const auto type, in.ReadInt32());
|
||||
@ -255,7 +255,7 @@ void ChannelBinder::Start() {
|
||||
std::optional<base::android::BinderRef> exchange;
|
||||
{
|
||||
base::AutoLock lock(lock_);
|
||||
exchange = absl::get<PendingExchange>(peer_).binder;
|
||||
exchange = std::get<PendingExchange>(peer_).binder;
|
||||
CHECK(exchange);
|
||||
peer_ = PendingConnection{};
|
||||
receiver_ = base::MakeRefCounted<Receiver>(this);
|
||||
@ -286,8 +286,8 @@ void ChannelBinder::ShutDownImpl() {
|
||||
receiver_.swap(receiver);
|
||||
outgoing_messages_.swap(outgoing_messages);
|
||||
peer_.swap(peer);
|
||||
if (leak_peer_ && absl::holds_alternative<Receiver::Proxy>(peer)) {
|
||||
std::ignore = absl::get<Receiver::Proxy>(peer).release();
|
||||
if (leak_peer_ && std::holds_alternative<Receiver::Proxy>(peer)) {
|
||||
std::ignore = std::get<Receiver::Proxy>(peer).release();
|
||||
}
|
||||
}
|
||||
receiver->ShutDown();
|
||||
@ -333,19 +333,19 @@ base::android::BinderStatusOr<void> ChannelBinder::WriteOrEnqueue(
|
||||
std::optional<Receiver::Proxy> receiver;
|
||||
{
|
||||
base::AutoLock lock(lock_);
|
||||
if (absl::holds_alternative<Disconnected>(peer_) || reject_writes_) {
|
||||
if (std::holds_alternative<Disconnected>(peer_) || reject_writes_) {
|
||||
return base::ok();
|
||||
}
|
||||
|
||||
if (absl::holds_alternative<PendingExchange>(peer_) ||
|
||||
absl::holds_alternative<PendingConnection>(peer_) ||
|
||||
if (std::holds_alternative<PendingExchange>(peer_) ||
|
||||
std::holds_alternative<PendingConnection>(peer_) ||
|
||||
!outgoing_messages_.empty() || is_writing_) {
|
||||
outgoing_messages_.push_back(std::move(message));
|
||||
return base::ok();
|
||||
}
|
||||
|
||||
is_writing_ = true;
|
||||
receiver = absl::get<Receiver::Proxy>(peer_);
|
||||
receiver = std::get<Receiver::Proxy>(peer_);
|
||||
}
|
||||
|
||||
// If this returns on error, `is_writing_` will remain true. This is fine
|
||||
@ -362,12 +362,12 @@ base::android::BinderStatusOr<void> ChannelBinder::WriteOrEnqueue(
|
||||
base::android::BinderStatusOr<void> ChannelBinder::FlushOutgoingMessages()
|
||||
EXCLUSIVE_LOCKS_REQUIRED(lock_) {
|
||||
DCHECK(is_writing_);
|
||||
if (absl::holds_alternative<Disconnected>(peer_)) {
|
||||
if (std::holds_alternative<Disconnected>(peer_)) {
|
||||
// If we're already disconnected we don't need to do any flushing.
|
||||
return base::ok();
|
||||
}
|
||||
|
||||
Receiver::Proxy receiver = absl::get<Receiver::Proxy>(peer_);
|
||||
Receiver::Proxy receiver = std::get<Receiver::Proxy>(peer_);
|
||||
while (!outgoing_messages_.empty()) {
|
||||
base::circular_deque<MessagePtr> messages;
|
||||
messages.swap(outgoing_messages_);
|
||||
@ -386,12 +386,12 @@ base::android::BinderStatusOr<void> ChannelBinder::FlushOutgoingMessages()
|
||||
|
||||
void ChannelBinder::SetPeerReceiver(base::android::BinderRef receiver) {
|
||||
base::AutoLock lock(lock_);
|
||||
if (absl::holds_alternative<Disconnected>(peer_)) {
|
||||
if (std::holds_alternative<Disconnected>(peer_)) {
|
||||
// Channel is already shutdown. Silently drop the peer endpoint.
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK(absl::holds_alternative<PendingConnection>(peer_));
|
||||
DCHECK(std::holds_alternative<PendingConnection>(peer_));
|
||||
if (!receiver) {
|
||||
// Connection failed.
|
||||
peer_ = Disconnected{};
|
||||
@ -489,7 +489,7 @@ ChannelBinder::Receiver::OnBinderTransaction(
|
||||
}
|
||||
|
||||
ASSIGN_OR_RETURN(const auto payload, ReadMessagePayload(in));
|
||||
const auto bytes = absl::visit(
|
||||
const auto bytes = std::visit(
|
||||
base::Overloaded{
|
||||
[](const PayloadBuffer& payload) {
|
||||
return base::span<const uint8_t>(payload.data.get(), payload.size);
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define MOJO_CORE_CHANNEL_BINDER_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "base/android/binder.h"
|
||||
@ -19,7 +20,6 @@
|
||||
#include "mojo/core/connection_params.h"
|
||||
#include "mojo/core/system_impl_export.h"
|
||||
#include "mojo/public/cpp/platform/platform_handle.h"
|
||||
#include "third_party/abseil-cpp/absl/types/variant.h"
|
||||
|
||||
namespace mojo::core {
|
||||
|
||||
@ -105,10 +105,10 @@ class MOJO_SYSTEM_IMPL_EXPORT ChannelBinder : public Channel {
|
||||
};
|
||||
struct PendingConnection {};
|
||||
enum class Disconnected {};
|
||||
using Peer = absl::variant<PendingExchange,
|
||||
PendingConnection,
|
||||
Receiver::Proxy,
|
||||
Disconnected>;
|
||||
using Peer = std::variant<PendingExchange,
|
||||
PendingConnection,
|
||||
Receiver::Proxy,
|
||||
Disconnected>;
|
||||
|
||||
const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/memory/read_only_shared_memory_region.h"
|
||||
@ -53,10 +54,10 @@ PlatformSharedMemoryMapping::PlatformSharedMemoryMapping(
|
||||
PlatformSharedMemoryMapping::~PlatformSharedMemoryMapping() = default;
|
||||
|
||||
bool PlatformSharedMemoryMapping::IsValid() const {
|
||||
return absl::visit(
|
||||
return std::visit(
|
||||
[](const auto& member) {
|
||||
using T = std::decay_t<decltype(member)>;
|
||||
if constexpr (std::is_same_v<T, absl::monostate>) {
|
||||
if constexpr (std::is_same_v<T, std::monostate>) {
|
||||
return false;
|
||||
} else {
|
||||
return member.IsValid();
|
||||
@ -66,10 +67,10 @@ bool PlatformSharedMemoryMapping::IsValid() const {
|
||||
}
|
||||
|
||||
void* PlatformSharedMemoryMapping::GetBase() const {
|
||||
return absl::visit(
|
||||
return std::visit(
|
||||
[](const auto& member) -> void* {
|
||||
using T = std::decay_t<decltype(member)>;
|
||||
if constexpr (std::is_same_v<T, absl::monostate>) {
|
||||
if constexpr (std::is_same_v<T, std::monostate>) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return const_cast<void*>(member.memory());
|
||||
@ -79,10 +80,10 @@ void* PlatformSharedMemoryMapping::GetBase() const {
|
||||
}
|
||||
|
||||
size_t PlatformSharedMemoryMapping::GetLength() const {
|
||||
return absl::visit(
|
||||
return std::visit(
|
||||
[](const auto& member) -> size_t {
|
||||
using T = std::decay_t<decltype(member)>;
|
||||
if constexpr (std::is_same_v<T, absl::monostate>) {
|
||||
if constexpr (std::is_same_v<T, std::monostate>) {
|
||||
return 0;
|
||||
} else {
|
||||
return member.size();
|
||||
|
@ -7,10 +7,11 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include "base/memory/platform_shared_memory_region.h"
|
||||
#include "base/memory/shared_memory_mapping.h"
|
||||
#include "mojo/core/system_impl_export.h"
|
||||
#include "third_party/abseil-cpp/absl/types/variant.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace core {
|
||||
@ -42,9 +43,9 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedMemoryMapping {
|
||||
size_t GetLength() const;
|
||||
|
||||
private:
|
||||
absl::variant<absl::monostate,
|
||||
base::ReadOnlySharedMemoryMapping,
|
||||
base::WritableSharedMemoryMapping>
|
||||
std::variant<std::monostate,
|
||||
base::ReadOnlySharedMemoryMapping,
|
||||
base::WritableSharedMemoryMapping>
|
||||
mapping_;
|
||||
};
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "base/barrier_closure.h"
|
||||
@ -57,7 +58,6 @@
|
||||
#include "mojo/public/cpp/system/wait.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "testing/multiprocess_func_list.h"
|
||||
#include "third_party/abseil-cpp/absl/types/variant.h"
|
||||
#include "third_party/ipcz/include/ipcz/ipcz.h"
|
||||
|
||||
namespace mojo_proxy::test {
|
||||
@ -223,8 +223,8 @@ class LegacyAppLauncher {
|
||||
mojom::TestService* AddInitialRemote() {
|
||||
CHECK(!app_process_.IsValid());
|
||||
CHECK(!exit_code_);
|
||||
CHECK(absl::holds_alternative<size_t>(attachment_info_));
|
||||
const uint64_t index = absl::get<size_t>(attachment_info_)++;
|
||||
CHECK(std::holds_alternative<size_t>(attachment_info_));
|
||||
const uint64_t index = std::get<size_t>(attachment_info_)++;
|
||||
auto remote = std::make_unique<mojo::Remote<mojom::TestService>>(
|
||||
mojo::PendingRemote<mojom::TestService>{
|
||||
invitation_.AttachMessagePipe(index), 0});
|
||||
@ -234,8 +234,8 @@ class LegacyAppLauncher {
|
||||
mojom::TestService* CreateNamedRemote(std::string_view name) {
|
||||
CHECK(!app_process_.IsValid());
|
||||
CHECK(!exit_code_);
|
||||
CHECK(absl::holds_alternative<size_t>(attachment_info_));
|
||||
CHECK_EQ(absl::get<size_t>(attachment_info_), 0u);
|
||||
CHECK(std::holds_alternative<size_t>(attachment_info_));
|
||||
CHECK_EQ(std::get<size_t>(attachment_info_), 0u);
|
||||
attachment_info_.emplace<std::string>(name);
|
||||
auto remote = std::make_unique<mojo::Remote<mojom::TestService>>(
|
||||
mojo::PendingRemote<mojom::TestService>{
|
||||
@ -289,16 +289,16 @@ class LegacyAppLauncher {
|
||||
proxy_command_line.AppendSwitchASCII(
|
||||
switches::kHostIpczTransportFd,
|
||||
base::NumberToString(kHostIpczTransportFdValue));
|
||||
absl::visit(base::Overloaded{[&](size_t num_attachments) {
|
||||
proxy_command_line.AppendSwitchASCII(
|
||||
switches::kNumAttachments,
|
||||
base::NumberToString(num_attachments));
|
||||
},
|
||||
[&](const std::string& name) {
|
||||
proxy_command_line.AppendSwitchASCII(
|
||||
switches::kAttachmentName, name);
|
||||
}},
|
||||
attachment_info_);
|
||||
std::visit(base::Overloaded{[&](size_t num_attachments) {
|
||||
proxy_command_line.AppendSwitchASCII(
|
||||
switches::kNumAttachments,
|
||||
base::NumberToString(num_attachments));
|
||||
},
|
||||
[&](const std::string& name) {
|
||||
proxy_command_line.AppendSwitchASCII(
|
||||
switches::kAttachmentName, name);
|
||||
}},
|
||||
attachment_info_);
|
||||
if (!mojo::core::GetIpczNodeOptions().is_broker) {
|
||||
// When connecting though the proxy from a non-broker subprocess, we need
|
||||
// to inform the proxy that it must inherit our broker.
|
||||
@ -335,7 +335,7 @@ class LegacyAppLauncher {
|
||||
|
||||
private:
|
||||
mojo::OutgoingInvitation invitation_;
|
||||
absl::variant<size_t, std::string> attachment_info_{0u};
|
||||
std::variant<size_t, std::string> attachment_info_{0u};
|
||||
base::Process app_process_;
|
||||
base::Process proxy_process_;
|
||||
std::optional<int> exit_code_;
|
||||
|
@ -9,11 +9,11 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <utility>
|
||||
|
||||
#include "base/check.h"
|
||||
#include "mojo/public/cpp/bindings/lib/hash_util.h"
|
||||
#include "mojo/public/cpp/bindings/type_converter.h"
|
||||
#include "third_party/abseil-cpp/absl/utility/utility.h"
|
||||
#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"
|
||||
|
||||
namespace mojo {
|
||||
|
@ -7,13 +7,13 @@
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
|
||||
#include "base/android/binder.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "base/types/expected.h"
|
||||
#include "base/types/expected_macros.h"
|
||||
#include "third_party/abseil-cpp/absl/types/variant.h"
|
||||
|
||||
namespace mojo {
|
||||
|
||||
@ -118,7 +118,7 @@ class Exchange : public base::RefCountedThreadSafe<Exchange> {
|
||||
{
|
||||
base::AutoLock lock(lock_);
|
||||
auto& ours = endpoints_[which];
|
||||
if (!absl::holds_alternative<NoEndpoint>(ours)) {
|
||||
if (!std::holds_alternative<NoEndpoint>(ours)) {
|
||||
// There's no situation where we expect to receive a binder for this
|
||||
// endpoint once its state has already changed in some way. Consider
|
||||
// this to be a validation failure.
|
||||
@ -127,14 +127,14 @@ class Exchange : public base::RefCountedThreadSafe<Exchange> {
|
||||
}
|
||||
|
||||
auto& theirs = endpoints_[1 - which];
|
||||
if (absl::holds_alternative<DeadEndpoint>(theirs)) {
|
||||
if (std::holds_alternative<DeadEndpoint>(theirs)) {
|
||||
// The peer is already gone. We can silently drop this endpoint too.
|
||||
ours = DeadEndpoint{};
|
||||
return base::ok();
|
||||
}
|
||||
|
||||
ours = std::move(ready_endpoint);
|
||||
if (absl::holds_alternative<NoEndpoint>(theirs)) {
|
||||
if (std::holds_alternative<NoEndpoint>(theirs)) {
|
||||
// Still waiting for the peer endpoint. The next time AcceptEndpoint()
|
||||
// is called it should be for the peer's endpoint, and at that point
|
||||
// they will discover that ours is ready too and proceed below.
|
||||
@ -142,10 +142,9 @@ class Exchange : public base::RefCountedThreadSafe<Exchange> {
|
||||
}
|
||||
|
||||
// If we're here, both endpoints are now ready to be exchanged.
|
||||
first =
|
||||
absl::get<ReadyEndpoint>(std::exchange(ours, ExchangedEndpoint()));
|
||||
first = std::get<ReadyEndpoint>(std::exchange(ours, ExchangedEndpoint()));
|
||||
second =
|
||||
absl::get<ReadyEndpoint>(std::exchange(theirs, ExchangedEndpoint()));
|
||||
std::get<ReadyEndpoint>(std::exchange(theirs, ExchangedEndpoint()));
|
||||
}
|
||||
|
||||
RETURN_IF_ERROR(PeerConnector::ConnectToPeer(first->connector,
|
||||
@ -160,14 +159,14 @@ class Exchange : public base::RefCountedThreadSafe<Exchange> {
|
||||
// binder for this endpoint.
|
||||
base::AutoLock lock(lock_);
|
||||
auto& ours = endpoints_[which];
|
||||
if (absl::holds_alternative<NoEndpoint>(ours)) {
|
||||
if (std::holds_alternative<NoEndpoint>(ours)) {
|
||||
ours = DeadEndpoint{};
|
||||
|
||||
// If the peer endpoint was ready, disconnect it too. Otherwise the peer's
|
||||
// state doesn't need to change: either it's already disconnected too or
|
||||
// it hasn't been received yet and will be dropped once it arrives.
|
||||
auto& theirs = endpoints_[1 - which];
|
||||
if (absl::holds_alternative<ReadyEndpoint>(theirs)) {
|
||||
if (std::holds_alternative<ReadyEndpoint>(theirs)) {
|
||||
theirs = DeadEndpoint{};
|
||||
}
|
||||
}
|
||||
@ -192,7 +191,7 @@ class Exchange : public base::RefCountedThreadSafe<Exchange> {
|
||||
struct ExchangedEndpoint {};
|
||||
|
||||
using Endpoint =
|
||||
absl::variant<NoEndpoint, ReadyEndpoint, DeadEndpoint, ExchangedEndpoint>;
|
||||
std::variant<NoEndpoint, ReadyEndpoint, DeadEndpoint, ExchangedEndpoint>;
|
||||
|
||||
~Exchange() = default;
|
||||
|
||||
|
Reference in New Issue
Block a user