#ifndef REMOTING_HOST_CHROMOTING_HOST_H_
#define REMOTING_HOST_CHROMOTING_HOST_H_
#include <memory>
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "net/base/backoff_entry.h"
#include "remoting/host/base/desktop_environment_options.h"
#include "remoting/host/client_session.h"
#include "remoting/host/host_extension.h"
#include "remoting/host/host_status_monitor.h"
#include "remoting/host/host_status_observer.h"
#include "remoting/host/mojom/chromoting_host_services.mojom.h"
#include "remoting/protocol/authenticator.h"
#include "remoting/protocol/connection_to_client.h"
#include "remoting/protocol/pairing_registry.h"
#include "remoting/protocol/session_manager.h"
#include "remoting/protocol/transport_context.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace named_mojo_ipc_server {
class IpcServer;
}
namespace remoting {
namespace protocol {
class InputStub;
}
class DesktopEnvironmentFactory;
class ChromotingHost : public ClientSession::EventHandler,
public mojom::ChromotingHostServices {
public:
typedef std::vector<std::unique_ptr<ClientSession>> ClientSessions;
ChromotingHost(
DesktopEnvironmentFactory* desktop_environment_factory,
std::unique_ptr<protocol::SessionManager> session_manager,
scoped_refptr<protocol::TransportContext> transport_context,
scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner,
const DesktopEnvironmentOptions& options);
ChromotingHost(const ChromotingHost&) = delete;
ChromotingHost& operator=(const ChromotingHost&) = delete;
~ChromotingHost() override;
void Start(const std::string& host_owner);
void StartChromotingHostServices();
scoped_refptr<HostStatusMonitor> status_monitor() { return status_monitor_; }
const DesktopEnvironmentOptions& desktop_environment_options() const {
return desktop_environment_options_;
}
void AddExtension(std::unique_ptr<HostExtension> extension);
void SetAuthenticatorFactory(
std::unique_ptr<protocol::AuthenticatorFactory> authenticator_factory);
void SetMaximumSessionDuration(const base::TimeDelta& max_session_duration);
void OnSessionAuthenticating(ClientSession* client) override;
void OnSessionAuthenticated(ClientSession* client) override;
void OnSessionChannelsConnected(ClientSession* client) override;
void OnSessionAuthenticationFailed(ClientSession* client) override;
void OnSessionClosed(ClientSession* session) override;
void OnSessionRouteChange(ClientSession* session,
const std::string& channel_name,
const protocol::TransportRoute& route) override;
void BindSessionServices(
mojo::PendingReceiver<mojom::ChromotingSessionServices> receiver)
override;
void OnIncomingSession(
protocol::Session* session,
protocol::SessionManager::IncomingSessionResponse* response);
scoped_refptr<protocol::PairingRegistry> pairing_registry() const {
return pairing_registry_;
}
void set_pairing_registry(
scoped_refptr<protocol::PairingRegistry> pairing_registry) {
pairing_registry_ = pairing_registry;
}
const ClientSessions& client_sessions_for_tests() { return clients_; }
scoped_refptr<protocol::TransportContext> transport_context_for_tests() {
return transport_context_;
}
private:
ClientSession* GetConnectedClientSession() const;
friend class ChromotingHostTest;
raw_ptr<DesktopEnvironmentFactory> desktop_environment_factory_;
std::unique_ptr<protocol::SessionManager> session_manager_;
scoped_refptr<protocol::TransportContext> transport_context_;
scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_;
scoped_refptr<HostStatusMonitor> status_monitor_;
ClientSessions clients_;
bool started_ = false;
net::BackoffEntry login_backoff_;
const DesktopEnvironmentOptions desktop_environment_options_;
base::TimeDelta max_session_duration_;
scoped_refptr<protocol::PairingRegistry> pairing_registry_;
std::vector<std::unique_ptr<HostExtension>> extensions_;
std::unique_ptr<named_mojo_ipc_server::IpcServer> ipc_server_;
SEQUENCE_CHECKER(sequence_checker_);
base::WeakPtrFactory<ChromotingHost> weak_factory_{this};
};
}
#endif