Skip to content

Commit

Permalink
Show the disconnect window and monitor the local mouse input when run…
Browse files Browse the repository at this point in the history
…ning the multiprocess host.

Supporting changes in this CL:
  - Desktop session agent now start only after receiving JID of the authenticated client.
  - The desktop process terminates if an unknown or unexpected message is received.

BUG=134694


Review URL: https://chromiumcodereview.appspot.com/11512005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174694 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
alexeypa@chromium.org committed Dec 27, 2012
1 parent 399ed42 commit a031c97
Show file tree
Hide file tree
Showing 25 changed files with 300 additions and 149 deletions.
11 changes: 0 additions & 11 deletions remoting/host/chromoting_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,6 @@ void ChromotingHost::DisconnectAllClients() {
}
}

void ChromotingHost::DisconnectClient(DesktopEnvironment* desktop_environment) {
DCHECK(network_task_runner_->BelongsToCurrentThread());

for (ClientList::iterator i = clients_.begin(); i != clients_.end(); ++i) {
if ((*i)->desktop_environment() == desktop_environment) {
(*i)->Disconnect();
break;
}
}
}

void ChromotingHost::SetUiStrings(const UiStrings& ui_strings) {
DCHECK(network_task_runner_->BelongsToCurrentThread());
DCHECK_EQ(state_, kInitial);
Expand Down
3 changes: 0 additions & 3 deletions remoting/host/chromoting_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
// clients that were not connected when this method is called.
void DisconnectAllClients();

// Disconnects the client that is using |desktop_environment|, if any.
void DisconnectClient(DesktopEnvironment* desktop_environment);

const UiStrings& ui_strings() { return ui_strings_; }

// Set localized strings. Must be called before host is started.
Expand Down
4 changes: 2 additions & 2 deletions remoting/host/chromoting_host_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class ChromotingHostTest : public testing::Test {
base::Unretained(this)));

desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory());
EXPECT_CALL(*desktop_environment_factory_, CreatePtr(_))
EXPECT_CALL(*desktop_environment_factory_, CreatePtr())
.Times(AnyNumber())
.WillRepeatedly(Invoke(this,
&ChromotingHostTest::CreateDesktopEnvironment));
Expand Down Expand Up @@ -282,7 +282,7 @@ class ChromotingHostTest : public testing::Test {
host_->OnSessionRouteChange(get_client(0), channel_name, route);
}

DesktopEnvironment* CreateDesktopEnvironment(ClientSession* client) {
DesktopEnvironment* CreateDesktopEnvironment() {
scoped_ptr<EventExecutor> event_executor(new EventExecutorFake());
scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake());
return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL),
Expand Down
8 changes: 8 additions & 0 deletions remoting/host/chromoting_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,17 @@ IPC_MESSAGE_CONTROL1(ChromotingDesktopNetworkMsg_CursorShapeChanged,
IPC_MESSAGE_CONTROL1(ChromotingDesktopNetworkMsg_InjectClipboardEvent,
std::string /* serialized_event */ )

// Requests the network process to terminate the client session.
IPC_MESSAGE_CONTROL0(ChromotingDesktopNetworkMsg_DisconnectSession)

//-----------------------------------------------------------------------------
// Chromoting messages sent from the network to the desktop process.

// Passes the client session data to the desktop session agent and starts it.
// This must be the first message received from the host.
IPC_MESSAGE_CONTROL1(ChromotingNetworkDesktopMsg_StartSessionAgent,
std::string /* authenticated_jid */ )

// Notifies the desktop process that the shared memory buffer has been mapped to
// the memory of the network process and so it can be safely dropped by
// the network process at any time.
Expand Down
17 changes: 12 additions & 5 deletions remoting/host/client_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ ClientSession::ClientSession(
const base::TimeDelta& max_duration)
: event_handler_(event_handler),
connection_(connection.Pass()),
desktop_environment_(desktop_environment_factory->Create(
ALLOW_THIS_IN_INITIALIZER_LIST(this))),
connection_factory_(connection_.get()),
desktop_environment_(desktop_environment_factory->Create()),
client_jid_(connection_->session()->jid()),
host_clipboard_stub_(desktop_environment_->event_executor()),
host_input_stub_(desktop_environment_->event_executor()),
Expand Down Expand Up @@ -129,6 +129,13 @@ void ClientSession::OnConnectionChannelsConnected(
DCHECK_EQ(connection_.get(), connection);
SetDisableInputs(false);

// Let the desktop environment notify us of local clipboard changes.
desktop_environment_->Start(
CreateClipboardProxy(),
client_jid(),
base::Bind(&protocol::ConnectionToClient::Disconnect,
connection_factory_.GetWeakPtr()));

// Create a VideoEncoder based on the session's video channel configuration.
scoped_ptr<VideoEncoder> video_encoder =
CreateVideoEncoder(connection_->session()->config());
Expand Down Expand Up @@ -157,9 +164,6 @@ void ClientSession::OnConnectionChannelsConnected(
++active_recorders_;
}

// Let the desktop environment notify us of local clipboard changes.
desktop_environment_->Start(CreateClipboardProxy());

// Notify the event handler that all our channels are now connected.
event_handler_->OnSessionChannelsConnected(this);
}
Expand All @@ -170,6 +174,9 @@ void ClientSession::OnConnectionClosed(
DCHECK(CalledOnValidThread());
DCHECK_EQ(connection_.get(), connection);

// Ignore any further callbacks from the DesktopEnvironment.
connection_factory_.InvalidateWeakPtrs();

// If the client never authenticated then the session failed.
if (!auth_input_filter_.enabled())
event_handler_->OnSessionAuthenticationFailed(this);
Expand Down
3 changes: 3 additions & 0 deletions remoting/host/client_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class ClientSession
// The connection to the client.
scoped_ptr<protocol::ConnectionToClient> connection_;

// Used to disable callbacks to |connection_| once it is disconnected.
base::WeakPtrFactory<protocol::ConnectionToClient> connection_factory_;

// The desktop environment used by this session.
scoped_ptr<DesktopEnvironment> desktop_environment_;

Expand Down
4 changes: 2 additions & 2 deletions remoting/host/client_session_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ClientSessionTest : public testing::Test {
client_jid_ = "user@domain/rest-of-jid";

desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory());
EXPECT_CALL(*desktop_environment_factory_, CreatePtr(_))
EXPECT_CALL(*desktop_environment_factory_, CreatePtr())
.Times(AnyNumber())
.WillRepeatedly(Invoke(this,
&ClientSessionTest::CreateDesktopEnvironment));
Expand Down Expand Up @@ -97,7 +97,7 @@ class ClientSessionTest : public testing::Test {
}

protected:
DesktopEnvironment* CreateDesktopEnvironment(ClientSession* client) {
DesktopEnvironment* CreateDesktopEnvironment() {
MockVideoFrameCapturer* capturer = new MockVideoFrameCapturer();
EXPECT_CALL(*capturer, Start(_));
EXPECT_CALL(*capturer, Stop());
Expand Down
5 changes: 4 additions & 1 deletion remoting/host/desktop_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "remoting/host/desktop_environment.h"

#include "base/callback.h"
#include "base/compiler_specific.h"
#include "remoting/capturer/video_frame_capturer.h"
#include "remoting/host/audio_capturer.h"
Expand All @@ -25,7 +26,9 @@ DesktopEnvironment::~DesktopEnvironment() {
}

void DesktopEnvironment::Start(
scoped_ptr<protocol::ClipboardStub> client_clipboard) {
scoped_ptr<protocol::ClipboardStub> client_clipboard,
const std::string& client_jid,
const base::Closure& disconnect_callback) {
event_executor_->Start(client_clipboard.Pass());
}

Expand Down
13 changes: 12 additions & 1 deletion remoting/host/desktop_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#ifndef REMOTING_HOST_DESKTOP_ENVIRONMENT_H_
#define REMOTING_HOST_DESKTOP_ENVIRONMENT_H_

#include <string>

#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"

namespace remoting {
Expand All @@ -29,8 +32,16 @@ class DesktopEnvironment {
EventExecutor* event_executor() const { return event_executor_.get(); }
VideoFrameCapturer* video_capturer() const { return video_capturer_.get(); }

// Starts the desktop environment passing |client_jid| of the attached
// authenticated session. Registers |client_clipboard| to receive
// notifications about local clipboard changes. |disconnect_callback| can be
// invoked by the DesktopEnvironment to request the client session to be
// disconnected. |disconnect_callback| is invoked on the same thread Start()
// has been called on.
virtual void Start(
scoped_ptr<protocol::ClipboardStub> client_clipboard);
scoped_ptr<protocol::ClipboardStub> client_clipboard,
const std::string& client_jid,
const base::Closure& disconnect_callback);

private:
// Used to capture audio to deliver to clients.
Expand Down
4 changes: 1 addition & 3 deletions remoting/host/desktop_environment_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "remoting/capturer/video_frame_capturer.h"
#include "remoting/host/audio_capturer.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/client_session.h"
#include "remoting/host/desktop_environment.h"
#include "remoting/host/event_executor.h"

Expand All @@ -24,8 +23,7 @@ DesktopEnvironmentFactory::DesktopEnvironmentFactory(
DesktopEnvironmentFactory::~DesktopEnvironmentFactory() {
}

scoped_ptr<DesktopEnvironment> DesktopEnvironmentFactory::Create(
ClientSession* client) {
scoped_ptr<DesktopEnvironment> DesktopEnvironmentFactory::Create() {
scoped_ptr<DesktopEnvironment> environment(new DesktopEnvironment(
AudioCapturer::Create(),
EventExecutor::Create(input_task_runner_, ui_task_runner_),
Expand Down
5 changes: 2 additions & 3 deletions remoting/host/desktop_environment_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class SingleThreadTaskRunner;

namespace remoting {

class ClientSession;
class DesktopEnvironment;

class DesktopEnvironmentFactory {
Expand All @@ -25,8 +24,8 @@ class DesktopEnvironmentFactory {
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
virtual ~DesktopEnvironmentFactory();

// Creates an instance of |DesktopEnvironment| to be used by |client|.
virtual scoped_ptr<DesktopEnvironment> Create(ClientSession* client);
// Creates an instance of |DesktopEnvironment|.
virtual scoped_ptr<DesktopEnvironment> Create();

// Returns |true| if created |DesktopEnvironment| instances support audio
// capture.
Expand Down
Loading

0 comments on commit a031c97

Please sign in to comment.