Skip to content

Commit

Permalink
Pass DesktopEnvironmentOptions form network to desktop process.
Browse files Browse the repository at this point in the history
Now DesktopEnvironmentOptions are passed to the desktop process in
StartSessionAgent IPC message. This will allow the network process
controll DesktopEnvironment configuration and particularly
DesktopCaptureOptions.

Review-Url: https://codereview.chromium.org/2529533003
Cr-Commit-Position: refs/heads/master@{#434754}
  • Loading branch information
SergeyUlanov authored and Commit bot committed Nov 28, 2016
1 parent f2f2146 commit c986f52
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 37 deletions.
3 changes: 2 additions & 1 deletion remoting/host/chromoting_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_platform_file.h"
#include "remoting/host/chromoting_param_traits.h"
#include "remoting/host/desktop_environment_options.h"
#include "remoting/host/screen_resolution.h"
#include "remoting/protocol/errors.h"
#include "remoting/protocol/transport.h"
Expand Down Expand Up @@ -205,7 +206,7 @@ IPC_MESSAGE_CONTROL1(ChromotingDesktopNetworkMsg_AudioPacket,
IPC_MESSAGE_CONTROL3(ChromotingNetworkDesktopMsg_StartSessionAgent,
std::string /* authenticated_jid */,
remoting::ScreenResolution /* resolution */,
bool /* virtual_terminal */)
remoting::DesktopEnvironmentOptions /* options */)

IPC_MESSAGE_CONTROL0(ChromotingNetworkDesktopMsg_CaptureFrame)

Expand Down
68 changes: 68 additions & 0 deletions remoting/host/chromoting_param_traits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,73 @@ void ParamTraits<remoting::ScreenResolution>::Log(
p.dpi().x(), p.dpi().y()));
}

// static
void ParamTraits<remoting::DesktopEnvironmentOptions>::Write(
base::Pickle* m,
const remoting::DesktopEnvironmentOptions& p) {
m->WriteBool(p.enable_curtaining());
m->WriteBool(p.enable_user_interface());
m->WriteBool(p.desktop_capture_options()->use_update_notifications());
m->WriteBool(p.desktop_capture_options()->disable_effects());
m->WriteBool(p.desktop_capture_options()->detect_updated_region());
#if defined(WEBRTC_WIN)
m->WriteBool(p.desktop_capture_options()->allow_use_magnification_api());
m->WriteBool(p.desktop_capture_options()->allow_directx_capturer());
#endif // defined(WEBRTC_WIN)
}

// static
bool ParamTraits<remoting::DesktopEnvironmentOptions>::Read(
const base::Pickle* m,
base::PickleIterator* iter,
remoting::DesktopEnvironmentOptions* r) {
*r = remoting::DesktopEnvironmentOptions::CreateDefault();
bool enable_curtaining;
bool enable_user_interface;
bool use_update_notifications;
bool disable_effects;
bool detect_updated_region;

if (!iter->ReadBool(&enable_curtaining) ||
!iter->ReadBool(&enable_user_interface) ||
!iter->ReadBool(&use_update_notifications) ||
!iter->ReadBool(&disable_effects) ||
!iter->ReadBool(&detect_updated_region)) {
return false;
}

r->set_enable_curtaining(enable_curtaining);
r->set_enable_user_interface(enable_user_interface);
r->desktop_capture_options()->set_use_update_notifications(
use_update_notifications);
r->desktop_capture_options()->set_detect_updated_region(
detect_updated_region);
r->desktop_capture_options()->set_disable_effects(disable_effects);

#if defined(WEBRTC_WIN)
bool allow_use_magnification_api;
bool allow_directx_capturer;

if (!iter->ReadBool(&allow_use_magnification_api) ||
!iter->ReadBool(&allow_directx_capturer)) {
return false;
}

r->desktop_capture_options()->set_allow_use_magnification_api(
allow_use_magnification_api);
r->desktop_capture_options()->set_allow_directx_capturer(
allow_directx_capturer);
#endif // defined(WEBRTC_WIN)

return true;
}

// static
void ParamTraits<remoting::DesktopEnvironmentOptions>::Log(
const remoting::DesktopEnvironmentOptions& p,
std::string* l) {
l->append("DesktopEnvironmentOptions()");
}

} // namespace IPC

11 changes: 11 additions & 0 deletions remoting/host/chromoting_param_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ipc/ipc_param_traits.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "remoting/host/desktop_environment_options.h"
#include "remoting/host/screen_resolution.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
Expand Down Expand Up @@ -80,6 +81,16 @@ struct ParamTraits<net::IPEndPoint> {
static void Log(const param_type& p, std::string* l);
};

template <>
struct ParamTraits<remoting::DesktopEnvironmentOptions> {
typedef remoting::DesktopEnvironmentOptions param_type;
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
param_type* p);
static void Log(const param_type& p, std::string* l);
};

} // namespace IPC

#endif // REMOTING_HOST_CHROMOTING_PARAM_TRAITS_H_
6 changes: 3 additions & 3 deletions remoting/host/desktop_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ bool DesktopProcess::Start(
#endif // !defined(OS_WIN)

// Create a desktop agent.
desktop_agent_ = new DesktopSessionAgent(
audio_task_runner, caller_task_runner_, input_task_runner_,
io_task_runner_, DesktopEnvironmentOptions::CreateDefault());
desktop_agent_ =
new DesktopSessionAgent(audio_task_runner, caller_task_runner_,
input_task_runner_, io_task_runner_);

// Start the agent and create an IPC channel to talk to it.
mojo::ScopedMessagePipeHandle desktop_pipe =
Expand Down
3 changes: 2 additions & 1 deletion remoting/host/desktop_process_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ void DesktopProcessTest::SendCrashRequest() {

void DesktopProcessTest::SendStartSessionAgent() {
network_channel_->Send(new ChromotingNetworkDesktopMsg_StartSessionAgent(
"user@domain/rest-of-jid", ScreenResolution(), false));
"user@domain/rest-of-jid", ScreenResolution(),
DesktopEnvironmentOptions()));
}

// Launches the desktop process and waits when it connects back.
Expand Down
10 changes: 2 additions & 8 deletions remoting/host/desktop_session_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,11 @@ DesktopSessionAgent::DesktopSessionAgent(
scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner,
scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
scoped_refptr<AutoThreadTaskRunner> input_task_runner,
scoped_refptr<AutoThreadTaskRunner> io_task_runner,
const DesktopEnvironmentOptions& desktop_environment_options)
scoped_refptr<AutoThreadTaskRunner> io_task_runner)
: audio_capture_task_runner_(audio_capture_task_runner),
caller_task_runner_(caller_task_runner),
input_task_runner_(input_task_runner),
io_task_runner_(io_task_runner),
desktop_environment_options_(desktop_environment_options),
weak_factory_(this) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());
}
Expand Down Expand Up @@ -255,7 +253,7 @@ void DesktopSessionAgent::SetDisableInputs(bool disable_inputs) {
void DesktopSessionAgent::OnStartSessionAgent(
const std::string& authenticated_jid,
const ScreenResolution& resolution,
bool virtual_terminal) {
const remoting::DesktopEnvironmentOptions& options) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());
DCHECK(!started_);
DCHECK(!audio_capturer_);
Expand All @@ -267,10 +265,6 @@ void DesktopSessionAgent::OnStartSessionAgent(
started_ = true;
client_jid_ = authenticated_jid;

DesktopEnvironmentOptions options = desktop_environment_options_;
// Enable the curtain mode.
options.set_enable_curtaining(virtual_terminal);

// Create a desktop environment for the new session.
desktop_environment_ = delegate_->desktop_environment_factory().Create(
weak_factory_.GetWeakPtr(), options);
Expand Down
7 changes: 2 additions & 5 deletions remoting/host/desktop_session_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ class DesktopSessionAgent
scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner,
scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
scoped_refptr<AutoThreadTaskRunner> input_task_runner,
scoped_refptr<AutoThreadTaskRunner> io_task_runner,
const DesktopEnvironmentOptions& options);
scoped_refptr<AutoThreadTaskRunner> io_task_runner);

// IPC::Listener implementation.
bool OnMessageReceived(const IPC::Message& message) override;
Expand Down Expand Up @@ -116,7 +115,7 @@ class DesktopSessionAgent
// Handles StartSessionAgent request from the client.
void OnStartSessionAgent(const std::string& authenticated_jid,
const ScreenResolution& resolution,
bool virtual_terminal);
const DesktopEnvironmentOptions& options);

// Handles CaptureFrame requests from the client.
void OnCaptureFrame();
Expand Down Expand Up @@ -192,8 +191,6 @@ class DesktopSessionAgent
// before it's received.
std::unique_ptr<webrtc::DesktopFrame> last_frame_;

DesktopEnvironmentOptions desktop_environment_options_;

// Used to disable callbacks to |this|.
base::WeakPtrFactory<DesktopSessionAgent> weak_factory_;

Expand Down
22 changes: 10 additions & 12 deletions remoting/host/desktop_session_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ DesktopSessionProxy::DesktopSessionProxy(
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
base::WeakPtr<ClientSessionControl> client_session_control,
base::WeakPtr<DesktopSessionConnector> desktop_session_connector,
bool virtual_terminal)
const DesktopEnvironmentOptions& options)
: audio_capture_task_runner_(audio_capture_task_runner),
caller_task_runner_(caller_task_runner),
io_task_runner_(io_task_runner),
client_session_control_(client_session_control),
desktop_session_connector_(desktop_session_connector),
pending_capture_frame_requests_(0),
is_desktop_session_connected_(false),
virtual_terminal_(virtual_terminal) {
options_(options) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());
}

Expand Down Expand Up @@ -138,7 +138,7 @@ DesktopSessionProxy::CreateMouseCursorMonitor() {
std::string DesktopSessionProxy::GetCapabilities() const {
std::string result = protocol::kRateLimitResizeRequests;
// Ask the client to send its resolution unconditionally.
if (virtual_terminal_) {
if (options_.enable_curtaining()) {
result += " ";
result += protocol::kSendInitialResolution;
}
Expand All @@ -154,10 +154,10 @@ std::string DesktopSessionProxy::GetCapabilities() const {
void DesktopSessionProxy::SetCapabilities(const std::string& capabilities) {
// Delay creation of the desktop session until the client screen resolution is
// received if the desktop session requires the initial screen resolution
// (when |virtual_terminal_| is true) and the client is expected to
// (when enable_curtaining() is true) and the client is expected to
// sent its screen resolution (the 'sendInitialResolution' capability is
// supported).
if (virtual_terminal_ &&
if (options_.enable_curtaining() &&
HasCapability(capabilities, protocol::kSendInitialResolution)) {
VLOG(1) << "Waiting for the client screen resolution.";
return;
Expand All @@ -167,8 +167,8 @@ void DesktopSessionProxy::SetCapabilities(const std::string& capabilities) {
if (!is_desktop_session_connected_) {
is_desktop_session_connected_ = true;
if (desktop_session_connector_.get()) {
desktop_session_connector_->ConnectTerminal(
this, screen_resolution_, virtual_terminal_);
desktop_session_connector_->ConnectTerminal(this, screen_resolution_,
options_.enable_curtaining());
}
}
}
Expand Down Expand Up @@ -229,9 +229,7 @@ bool DesktopSessionProxy::AttachToDesktop(
// Pass ID of the client (which is authenticated at this point) to the desktop
// session agent and start the agent.
SendToDesktop(new ChromotingNetworkDesktopMsg_StartSessionAgent(
client_session_control_->client_jid(),
screen_resolution_,
virtual_terminal_));
client_session_control_->client_jid(), screen_resolution_, options_));

desktop_session_id_ = session_id;

Expand Down Expand Up @@ -381,8 +379,8 @@ void DesktopSessionProxy::SetScreenResolution(
if (!is_desktop_session_connected_) {
is_desktop_session_connected_ = true;
if (desktop_session_connector_.get()) {
desktop_session_connector_->ConnectTerminal(
this, screen_resolution_, virtual_terminal_);
desktop_session_connector_->ConnectTerminal(this, screen_resolution_,
options_.enable_curtaining());
}
return;
}
Expand Down
4 changes: 2 additions & 2 deletions remoting/host/desktop_session_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DesktopSessionProxy
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
base::WeakPtr<ClientSessionControl> client_session_control,
base::WeakPtr<DesktopSessionConnector> desktop_session_connector,
bool virtual_terminal);
const DesktopEnvironmentOptions& options);

// Mirrors DesktopEnvironment.
std::unique_ptr<AudioCapturer> CreateAudioCapturer();
Expand Down Expand Up @@ -216,7 +216,7 @@ class DesktopSessionProxy
// True if |this| has been connected to the desktop session.
bool is_desktop_session_connected_;

bool virtual_terminal_;
DesktopEnvironmentOptions options_;

// Stores the session id for the proxied desktop process.
uint32_t desktop_session_id_ = UINT32_MAX;
Expand Down
7 changes: 3 additions & 4 deletions remoting/host/ipc_desktop_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ IpcDesktopEnvironment::IpcDesktopEnvironment(
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
base::WeakPtr<ClientSessionControl> client_session_control,
base::WeakPtr<DesktopSessionConnector> desktop_session_connector,
bool virtual_terminal) {
const DesktopEnvironmentOptions& options) {
DCHECK(caller_task_runner->BelongsToCurrentThread());

desktop_session_proxy_ = new DesktopSessionProxy(
audio_task_runner, caller_task_runner, io_task_runner,
client_session_control, desktop_session_connector, virtual_terminal);
client_session_control, desktop_session_connector, options);
}

IpcDesktopEnvironment::~IpcDesktopEnvironment() {}
Expand Down Expand Up @@ -96,8 +96,7 @@ std::unique_ptr<DesktopEnvironment> IpcDesktopEnvironmentFactory::Create(

return base::MakeUnique<IpcDesktopEnvironment>(
audio_task_runner_, caller_task_runner_, io_task_runner_,
client_session_control, connector_factory_.GetWeakPtr(),
options.enable_curtaining());
client_session_control, connector_factory_.GetWeakPtr(), options);
}

bool IpcDesktopEnvironmentFactory::SupportsAudioCapture() const {
Expand Down
2 changes: 1 addition & 1 deletion remoting/host/ipc_desktop_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class IpcDesktopEnvironment : public DesktopEnvironment {
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
base::WeakPtr<ClientSessionControl> client_session_control,
base::WeakPtr<DesktopSessionConnector> desktop_session_connector,
bool virtual_terminal);
const DesktopEnvironmentOptions& options);
~IpcDesktopEnvironment() override;

// DesktopEnvironment implementation.
Expand Down

0 comments on commit c986f52

Please sign in to comment.