1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_HOST_CHROMOTING_HOST_SERVICES_SERVER_H_
#define REMOTING_HOST_CHROMOTING_HOST_SERVICES_SERVER_H_
#include <memory>
#include "base/functional/callback.h"
#include "base/process/process_handle.h"
#include "components/named_mojo_ipc_server/connection_info.h"
#include "components/named_mojo_ipc_server/endpoint_options.h"
#include "components/named_mojo_ipc_server/named_mojo_ipc_server.h"
#include "components/named_mojo_ipc_server/named_mojo_message_pipe_server.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/platform/named_platform_channel.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "remoting/host/mojom/chromoting_host_services.mojom.h"
namespace remoting {
// Class to run a mojo server on a named pipe for the ChromotingHostServices
// interface. Client processes must connect using ChromotingHostServicesClient.
class ChromotingHostServicesServer {
public:
using BindChromotingHostServicesCallback = base::RepeatingCallback<void(
mojo::PendingReceiver<mojom::ChromotingHostServices>,
base::ProcessId /* peer_pid */)>;
using Validator = base::RepeatingCallback<bool(
const named_mojo_ipc_server::ConnectionInfo&)>;
explicit ChromotingHostServicesServer(
BindChromotingHostServicesCallback bind_chromoting_host_services);
ChromotingHostServicesServer(
const mojo::NamedPlatformChannel::ServerName& server_name,
Validator validator,
BindChromotingHostServicesCallback bind_chromoting_host_services);
~ChromotingHostServicesServer();
void StartServer();
void StopServer();
private:
friend class ChromotingHostServicesServerTest;
void OnMessagePipeReady(
mojo::ScopedMessagePipeHandle message_pipe,
std::unique_ptr<named_mojo_ipc_server::ConnectionInfo> connection_info,
void* context,
std::unique_ptr<mojo::IsolatedConnection> connection);
named_mojo_ipc_server::NamedMojoMessagePipeServer message_pipe_server_;
BindChromotingHostServicesCallback bind_chromoting_host_services_;
};
} // namespace remoting
#endif // REMOTING_HOST_CHROMOTING_HOST_SERVICES_SERVER_H_
|