#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "mojo/core/broker_host.h"
#include <string_view>
#include <utility>
#include "base/logging.h"
#include "base/memory/platform_shared_memory_region.h"
#include "base/memory/ref_counted.h"
#include "base/ranges/algorithm.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "mojo/buildflags.h"
#include "mojo/core/broker_messages.h"
#include "mojo/core/platform_handle_utils.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#endif
namespace mojo {
namespace core {
BrokerHost::BrokerHost(base::Process client_process,
ConnectionParams connection_params,
const ProcessErrorCallback& process_error_callback)
: … { … }
BrokerHost::~BrokerHost() { … }
bool BrokerHost::PrepareHandlesForClient(
std::vector<PlatformHandleInTransit>* handles) { … }
bool BrokerHost::SendChannel(PlatformHandle handle) { … }
#if BUILDFLAG(IS_WIN)
void BrokerHost::SendNamedChannel(std::wstring_view pipe_name) {
InitData* data;
wchar_t* name_data;
Channel::MessagePtr message = CreateBrokerMessage(
BrokerMessageType::INIT, 0, sizeof(*name_data) * pipe_name.length(),
&data, reinterpret_cast<void**>(&name_data));
data->pipe_name_length = static_cast<uint32_t>(pipe_name.length());
base::ranges::copy(pipe_name, name_data);
channel_->Write(std::move(message));
}
#endif
void BrokerHost::OnBufferRequest(uint32_t num_bytes) { … }
void BrokerHost::OnChannelMessage(const void* payload,
size_t payload_size,
std::vector<PlatformHandle> handles) { … }
void BrokerHost::OnChannelError(Channel::Error error) { … }
void BrokerHost::WillDestroyCurrentMessageLoop() { … }
}
}