#include "mojo/public/cpp/bindings/interface_endpoint_client.h"
#include <stdint.h>
#include <optional>
#include <string_view>
#include <tuple>
#include <vector>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/debug/alias.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/bind_post_task.h"
#include "base/task/common/task_annotator.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/threading/thread_local.h"
#include "base/trace_event/interned_args_helper.h"
#include "base/trace_event/typed_macros.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/associated_group.h"
#include "mojo/public/cpp/bindings/associated_group_controller.h"
#include "mojo/public/cpp/bindings/interface_endpoint_controller.h"
#include "mojo/public/cpp/bindings/lib/task_runner_helper.h"
#include "mojo/public/cpp/bindings/lib/validation_util.h"
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
#include "mojo/public/cpp/bindings/sync_event_watcher.h"
#include "mojo/public/cpp/bindings/thread_safe_proxy.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/chrome_mojo_event_info.pbzero.h"
namespace mojo {
namespace {
ABSL_CONST_INIT thread_local base::HistogramBase* g_end_to_end_metric = …;
class ThreadSafeInterfaceEndpointClientProxy : public ThreadSafeProxy { … };
void DetermineIfEndpointIsConnected(
const base::WeakPtr<InterfaceEndpointClient>& client,
base::OnceCallback<void(bool)> callback) { … }
class ResponderThunk : public MessageReceiverWithStatus { … };
}
InterfaceEndpointClient::PendingAsyncResponse::PendingAsyncResponse(
uint32_t request_message_name,
std::unique_ptr<MessageReceiver> responder)
: … { … }
InterfaceEndpointClient::PendingAsyncResponse::PendingAsyncResponse(
PendingAsyncResponse&&) = default;
InterfaceEndpointClient::PendingAsyncResponse&
InterfaceEndpointClient::PendingAsyncResponse::operator=(
PendingAsyncResponse&&) = default;
InterfaceEndpointClient::PendingAsyncResponse::~PendingAsyncResponse() =
default;
InterfaceEndpointClient::SyncResponseInfo::SyncResponseInfo(
uint32_t request_message_name,
bool* in_response_received)
: … { … }
InterfaceEndpointClient::SyncResponseInfo::~SyncResponseInfo() { … }
InterfaceEndpointClient::HandleIncomingMessageThunk::HandleIncomingMessageThunk(
InterfaceEndpointClient* owner)
: … { … }
InterfaceEndpointClient::HandleIncomingMessageThunk::
~HandleIncomingMessageThunk() { … }
bool InterfaceEndpointClient::HandleIncomingMessageThunk::Accept(
Message* message) { … }
void ThreadSafeInterfaceEndpointClientProxy::SendMessageWithResponder(
Message& message,
std::unique_ptr<MessageReceiver> responder) { … }
InterfaceEndpointClient::InterfaceEndpointClient(
ScopedInterfaceEndpointHandle handle,
MessageReceiverWithResponderStatus* receiver,
std::unique_ptr<MessageReceiver> payload_validator,
base::span<const uint32_t> sync_method_ordinals,
scoped_refptr<base::SequencedTaskRunner> task_runner,
uint32_t interface_version,
const char* interface_name,
MessageToMethodInfoCallback method_info_callback,
MessageToMethodNameCallback method_name_callback)
: … { … }
InterfaceEndpointClient::~InterfaceEndpointClient() { … }
AssociatedGroup* InterfaceEndpointClient::associated_group() { … }
scoped_refptr<ThreadSafeProxy> InterfaceEndpointClient::CreateThreadSafeProxy(
scoped_refptr<ThreadSafeProxy::Target> target) { … }
ScopedInterfaceEndpointHandle InterfaceEndpointClient::PassHandle() { … }
void InterfaceEndpointClient::SetFilter(std::unique_ptr<MessageFilter> filter) { … }
void InterfaceEndpointClient::RaiseError() { … }
void InterfaceEndpointClient::CloseWithReason(uint32_t custom_reason,
std::string_view description) { … }
bool InterfaceEndpointClient::PrefersSerializedMessages() { … }
void InterfaceEndpointClient::SendControlMessage(Message* message) { … }
void InterfaceEndpointClient::SendControlMessageWithResponder(
Message* message,
std::unique_ptr<MessageReceiver> responder) { … }
bool InterfaceEndpointClient::Accept(Message* message) { … }
bool InterfaceEndpointClient::AcceptWithResponder(
Message* message,
std::unique_ptr<MessageReceiver> responder) { … }
bool InterfaceEndpointClient::SendMessage(Message* message,
bool is_control_message) { … }
bool InterfaceEndpointClient::SendMessageWithResponder(
Message* message,
bool is_control_message,
SyncSendMode sync_send_mode,
std::unique_ptr<MessageReceiver> responder) { … }
bool InterfaceEndpointClient::HandleIncomingMessage(Message* message) { … }
void InterfaceEndpointClient::NotifyError(
const std::optional<DisconnectReason>& reason) { … }
void InterfaceEndpointClient::QueryVersion(
base::OnceCallback<void(uint32_t)> callback) { … }
void InterfaceEndpointClient::RequireVersion(uint32_t version) { … }
void InterfaceEndpointClient::FlushForTesting() { … }
void InterfaceEndpointClient::FlushAsyncForTesting(base::OnceClosure callback) { … }
void InterfaceEndpointClient::SetIdleHandler(base::TimeDelta timeout,
base::RepeatingClosure handler) { … }
void InterfaceEndpointClient::SetIdleTrackingEnabledCallback(
IdleTrackingEnabledCallback callback) { … }
bool InterfaceEndpointClient::AcceptEnableIdleTracking(
base::TimeDelta timeout) { … }
bool InterfaceEndpointClient::AcceptMessageAck() { … }
bool InterfaceEndpointClient::AcceptNotifyIdle() { … }
void InterfaceEndpointClient::MaybeStartIdleTimer() { … }
void InterfaceEndpointClient::MaybeSendNotifyIdle() { … }
void InterfaceEndpointClient::ResetFromAnotherSequenceUnsafe() { … }
void InterfaceEndpointClient::ForgetAsyncRequest(uint64_t request_id) { … }
void InterfaceEndpointClient::InitControllerIfNecessary() { … }
void InterfaceEndpointClient::OnAssociationEvent(
ScopedInterfaceEndpointHandle::AssociationEvent event) { … }
bool InterfaceEndpointClient::HandleValidatedMessage(Message* message) { … }
void InterfaceEndpointClient::SetThreadNameSuffixForMetrics(
std::string thread_name) { … }
}