diff options
26 files changed, 269 insertions, 127 deletions
diff --git a/remoting/host/basic_desktop_environment.cc b/remoting/host/basic_desktop_environment.cc index d49de5c..99ddca0 100644 --- a/remoting/host/basic_desktop_environment.cc +++ b/remoting/host/basic_desktop_environment.cc @@ -7,7 +7,9 @@ #include "base/logging.h" #include "media/video/capture/screen/screen_capturer.h" #include "remoting/host/audio_capturer.h" +#include "remoting/host/desktop_resizer.h" #include "remoting/host/event_executor.h" +#include "remoting/host/resizing_host_observer.h" namespace remoting { @@ -34,6 +36,15 @@ scoped_ptr<EventExecutor> BasicDesktopEnvironment::CreateEventExecutor( return EventExecutor::Create(input_task_runner, ui_task_runner); } +scoped_ptr<SessionController> +BasicDesktopEnvironment::CreateSessionController() { + DCHECK(CalledOnValidThread()); + + scoped_ptr<SessionController> session_controller( + new ResizingHostObserver(DesktopResizer::Create())); + return session_controller.Pass(); +} + scoped_ptr<media::ScreenCapturer> BasicDesktopEnvironment::CreateVideoCapturer( scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) { diff --git a/remoting/host/basic_desktop_environment.h b/remoting/host/basic_desktop_environment.h index a71ed1e..6544bdd 100644 --- a/remoting/host/basic_desktop_environment.h +++ b/remoting/host/basic_desktop_environment.h @@ -29,6 +29,7 @@ class BasicDesktopEnvironment virtual scoped_ptr<EventExecutor> CreateEventExecutor( scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) OVERRIDE; + virtual scoped_ptr<SessionController> CreateSessionController() OVERRIDE; virtual scoped_ptr<media::ScreenCapturer> CreateVideoCapturer( scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) OVERRIDE; diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index 68009d4..fc642e2 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -267,15 +267,6 @@ void ChromotingHost::OnSessionRouteChange( route)); } -void ChromotingHost::OnClientResolutionChanged(ClientSession* session, - const SkISize& size, - const SkIPoint& dpi) { - DCHECK(network_task_runner_->BelongsToCurrentThread()); - FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, - OnClientResolutionChanged(session->client_jid(), - size, dpi)); -} - void ChromotingHost::OnSessionManagerReady() { DCHECK(network_task_runner_->BelongsToCurrentThread()); // Don't need to do anything here, just wait for incoming diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h index 5d9d236..9aa9afd 100644 --- a/remoting/host/chromoting_host.h +++ b/remoting/host/chromoting_host.h @@ -126,9 +126,6 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, ClientSession* session, const std::string& channel_name, const protocol::TransportRoute& route) OVERRIDE; - virtual void OnClientResolutionChanged(ClientSession* session, - const SkISize& size, - const SkIPoint& dpi) OVERRIDE; // SessionManager::Listener implementation. virtual void OnSessionManagerReady() OVERRIDE; diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc index 97c490a..80b3fa0 100644 --- a/remoting/host/chromoting_host_unittest.cc +++ b/remoting/host/chromoting_host_unittest.cc @@ -294,6 +294,10 @@ class ChromotingHostTest : public testing::Test { EXPECT_CALL(*desktop_environment, CreateEventExecutorPtr(_, _)) .Times(AnyNumber()) .WillRepeatedly(Invoke(this, &ChromotingHostTest::CreateEventExecutor)); + EXPECT_CALL(*desktop_environment, CreateSessionControllerPtr()) + .Times(AnyNumber()) + .WillRepeatedly(Invoke(this, + &ChromotingHostTest::CreateSessionController)); EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _)) .Times(AnyNumber()) .WillRepeatedly(Invoke(this, &ChromotingHostTest::CreateVideoCapturer)); @@ -311,6 +315,12 @@ class ChromotingHostTest : public testing::Test { return event_executor; } + // Creates a dummy SessionController, to mock + // DesktopEnvironment::CreateSessionController(). + SessionController* CreateSessionController() { + return new MockSessionController(); + } + // Creates a fake media::ScreenCapturer, to mock // DesktopEnvironment::CreateVideoCapturer(). media::ScreenCapturer* CreateVideoCapturer( diff --git a/remoting/host/client_session.cc b/remoting/host/client_session.cc index 46bb5c5..a150066 100644 --- a/remoting/host/client_session.cc +++ b/remoting/host/client_session.cc @@ -19,6 +19,7 @@ #include "remoting/host/audio_scheduler.h" #include "remoting/host/desktop_environment.h" #include "remoting/host/event_executor.h" +#include "remoting/host/session_controller.h" #include "remoting/host/video_scheduler.h" #include "remoting/proto/control.pb.h" #include "remoting/proto/event.pb.h" @@ -94,10 +95,9 @@ void ClientSession::NotifyClientResolution( VLOG(1) << "Received ClientResolution (dips_width=" << resolution.dips_width() << ", dips_height=" << resolution.dips_height() << ")"; - event_handler_->OnClientResolutionChanged( - this, - SkISize::Make(resolution.dips_width(), resolution.dips_height()), - SkIPoint::Make(kDefaultDPI, kDefaultDPI)); + session_controller_->OnClientResolutionChanged( + SkIPoint::Make(kDefaultDPI, kDefaultDPI), + SkISize::Make(resolution.dips_width(), resolution.dips_height())); } } @@ -146,8 +146,12 @@ void ClientSession::OnConnectionChannelsConnected( DCHECK_EQ(connection_.get(), connection); DCHECK(!audio_scheduler_); DCHECK(!event_executor_); + DCHECK(!session_controller_); DCHECK(!video_scheduler_); + // Create the session controller. + session_controller_ = desktop_environment_->CreateSessionController(); + // Create and start the event executor. event_executor_ = desktop_environment_->CreateEventExecutor( input_task_runner_, ui_task_runner_); @@ -225,6 +229,7 @@ void ClientSession::OnConnectionClosed( client_clipboard_factory_.InvalidateWeakPtrs(); event_executor_.reset(); + session_controller_.reset(); // Notify the ChromotingHost that this client is disconnected. // TODO(sergeyu): Log failure reason? @@ -266,6 +271,7 @@ void ClientSession::Stop() { DCHECK(CalledOnValidThread()); DCHECK(!audio_scheduler_); DCHECK(!event_executor_); + DCHECK(!session_controller_); DCHECK(!video_scheduler_); connection_.reset(); @@ -290,6 +296,7 @@ ClientSession::~ClientSession() { DCHECK(CalledOnValidThread()); DCHECK(!audio_scheduler_); DCHECK(!event_executor_); + DCHECK(!session_controller_); DCHECK(!video_scheduler_); } diff --git a/remoting/host/client_session.h b/remoting/host/client_session.h index 5ed34f3..b6d3a6a 100644 --- a/remoting/host/client_session.h +++ b/remoting/host/client_session.h @@ -38,6 +38,7 @@ struct ClientSessionTraits; class DesktopEnvironment; class DesktopEnvironmentFactory; class EventExecutor; +class SessionController; class VideoEncoder; class VideoScheduler; @@ -78,12 +79,6 @@ class ClientSession const std::string& channel_name, const protocol::TransportRoute& route) = 0; - // Called when the initial client resolution is received, and when it - // changes. - virtual void OnClientResolutionChanged(ClientSession* client, - const SkISize& size, - const SkIPoint& dpi) = 0; - protected: virtual ~EventHandler() {} }; @@ -230,6 +225,8 @@ class ClientSession scoped_ptr<EventExecutor> event_executor_; + scoped_ptr<SessionController> session_controller_; + DISALLOW_COPY_AND_ASSIGN(ClientSession); }; diff --git a/remoting/host/client_session_unittest.cc b/remoting/host/client_session_unittest.cc index 9eb6348..a7893a4 100644 --- a/remoting/host/client_session_unittest.cc +++ b/remoting/host/client_session_unittest.cc @@ -77,6 +77,10 @@ class ClientSessionTest : public testing::Test { scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); + // Creates a dummy SessionController, to mock + // DesktopEnvironment::CreateSessionController(). + SessionController* CreateSessionController(); + // Creates a fake media::ScreenCapturer, to mock // DesktopEnvironment::CreateVideoCapturer(). media::ScreenCapturer* CreateVideoCapturer( @@ -195,6 +199,8 @@ DesktopEnvironment* ClientSessionTest::CreateDesktopEnvironment() { .Times(0); EXPECT_CALL(*desktop_environment, CreateEventExecutorPtr(_, _)) .WillOnce(Invoke(this, &ClientSessionTest::CreateEventExecutor)); + EXPECT_CALL(*desktop_environment, CreateSessionControllerPtr()) + .WillOnce(Invoke(this, &ClientSessionTest::CreateSessionController)); EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _)) .WillOnce(Invoke(this, &ClientSessionTest::CreateVideoCapturer)); @@ -208,6 +214,10 @@ EventExecutor* ClientSessionTest::CreateEventExecutor( return event_executor_.release(); } +SessionController* ClientSessionTest::CreateSessionController() { + return new MockSessionController(); +} + media::ScreenCapturer* ClientSessionTest::CreateVideoCapturer( scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) { diff --git a/remoting/host/desktop_environment.h b/remoting/host/desktop_environment.h index f91fb85..6a6a82c 100644 --- a/remoting/host/desktop_environment.h +++ b/remoting/host/desktop_environment.h @@ -24,6 +24,7 @@ namespace remoting { class AudioCapturer; class EventExecutor; +class SessionController; // Provides factory methods for creation of audio/video capturers and event // executor for a given desktop environment. @@ -31,13 +32,14 @@ class DesktopEnvironment { public: virtual ~DesktopEnvironment() {} - // Factory methods used to create audio/video capturers and event executor for - // a particular desktop environment. + // Factory methods used to create audio/video capturers, event executor, and + // session controller for a particular desktop environment. virtual scoped_ptr<AudioCapturer> CreateAudioCapturer( scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner) = 0; virtual scoped_ptr<EventExecutor> CreateEventExecutor( scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) = 0; + virtual scoped_ptr<SessionController> CreateSessionController() = 0; virtual scoped_ptr<media::ScreenCapturer> CreateVideoCapturer( scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) = 0; diff --git a/remoting/host/desktop_process_unittest.cc b/remoting/host/desktop_process_unittest.cc index a299e47..026c9bc 100644 --- a/remoting/host/desktop_process_unittest.cc +++ b/remoting/host/desktop_process_unittest.cc @@ -111,6 +111,10 @@ class DesktopProcessTest : public testing::Test { // DesktopEnvironment::CreateEventExecutor(). EventExecutor* CreateEventExecutor(); + // Creates a dummy SessionController, to mock + // DesktopEnvironment::CreateSessionController(). + SessionController* CreateSessionController(); + // Creates a fake media::ScreenCapturer, to mock // DesktopEnvironment::CreateVideoCapturer(). media::ScreenCapturer* CreateVideoCapturer(); @@ -200,6 +204,11 @@ DesktopEnvironment* DesktopProcessTest::CreateDesktopEnvironment() { .Times(AnyNumber()) .WillRepeatedly( InvokeWithoutArgs(this, &DesktopProcessTest::CreateEventExecutor)); + EXPECT_CALL(*desktop_environment, CreateSessionControllerPtr()) + .Times(AnyNumber()) + .WillRepeatedly( + InvokeWithoutArgs(this, + &DesktopProcessTest::CreateSessionController)); EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _)) .Times(AnyNumber()) .WillRepeatedly( @@ -216,6 +225,10 @@ EventExecutor* DesktopProcessTest::CreateEventExecutor() { return event_executor; } +SessionController* DesktopProcessTest::CreateSessionController() { + return new MockSessionController(); +} + media::ScreenCapturer* DesktopProcessTest::CreateVideoCapturer() { return new media::ScreenCapturerFake(); } diff --git a/remoting/host/desktop_session_proxy.cc b/remoting/host/desktop_session_proxy.cc index abd3ef2..1e3ec99 100644 --- a/remoting/host/desktop_session_proxy.cc +++ b/remoting/host/desktop_session_proxy.cc @@ -17,7 +17,9 @@ #include "remoting/host/desktop_session_connector.h" #include "remoting/host/ipc_audio_capturer.h" #include "remoting/host/ipc_event_executor.h" +#include "remoting/host/ipc_session_controller.h" #include "remoting/host/ipc_video_frame_capturer.h" +#include "remoting/host/session_controller.h" #include "remoting/proto/audio.pb.h" #include "remoting/proto/control.pb.h" #include "remoting/proto/event.pb.h" @@ -61,6 +63,10 @@ scoped_ptr<EventExecutor> DesktopSessionProxy::CreateEventExecutor( return scoped_ptr<EventExecutor>(new IpcEventExecutor(this)); } +scoped_ptr<SessionController> DesktopSessionProxy::CreateSessionController() { + return scoped_ptr<SessionController>(new IpcSessionController(this)); +} + scoped_ptr<media::ScreenCapturer> DesktopSessionProxy::CreateVideoCapturer( scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) { diff --git a/remoting/host/desktop_session_proxy.h b/remoting/host/desktop_session_proxy.h index 927fb4d..e484e44 100644 --- a/remoting/host/desktop_session_proxy.h +++ b/remoting/host/desktop_session_proxy.h @@ -43,6 +43,7 @@ struct DesktopSessionParams; struct DesktopSessionProxyTraits; class IpcAudioCapturer; class IpcVideoFrameCapturer; +class SessionController; // DesktopSessionProxy is created by an owning DesktopEnvironment to route // requests from stubs to the DesktopSessionAgent instance through @@ -75,6 +76,7 @@ class DesktopSessionProxy scoped_ptr<EventExecutor> CreateEventExecutor( scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); + scoped_ptr<SessionController> CreateSessionController(); scoped_ptr<media::ScreenCapturer> CreateVideoCapturer( scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner); diff --git a/remoting/host/host_mock_objects.cc b/remoting/host/host_mock_objects.cc index f8f1062..0dd33e9 100644 --- a/remoting/host/host_mock_objects.cc +++ b/remoting/host/host_mock_objects.cc @@ -34,6 +34,11 @@ scoped_ptr<EventExecutor> MockDesktopEnvironment::CreateEventExecutor( ui_task_runner)); } +scoped_ptr<SessionController> +MockDesktopEnvironment::CreateSessionController() { + return scoped_ptr<SessionController>(CreateSessionControllerPtr()); +} + scoped_ptr<media::ScreenCapturer> MockDesktopEnvironment::CreateVideoCapturer( scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) { @@ -89,4 +94,8 @@ MockHostStatusObserver::MockHostStatusObserver() {} MockHostStatusObserver::~MockHostStatusObserver() {} +MockSessionController::MockSessionController() {} + +MockSessionController::~MockSessionController() {} + } // namespace remoting diff --git a/remoting/host/host_mock_objects.h b/remoting/host/host_mock_objects.h index 1c4e88e..d9d57a9 100644 --- a/remoting/host/host_mock_objects.h +++ b/remoting/host/host_mock_objects.h @@ -14,6 +14,7 @@ #include "remoting/host/event_executor.h" #include "remoting/host/host_status_observer.h" #include "remoting/host/local_input_monitor.h" +#include "remoting/host/session_controller.h" #include "remoting/proto/control.pb.h" #include "testing/gmock/include/gmock/gmock.h" @@ -33,6 +34,7 @@ class MockDesktopEnvironment : public DesktopEnvironment { MOCK_METHOD2(CreateEventExecutorPtr, EventExecutor*(scoped_refptr<base::SingleThreadTaskRunner>, scoped_refptr<base::SingleThreadTaskRunner>)); + MOCK_METHOD0(CreateSessionControllerPtr, SessionController*()); MOCK_METHOD2( CreateVideoCapturerPtr, media::ScreenCapturer*(scoped_refptr<base::SingleThreadTaskRunner>, @@ -44,6 +46,7 @@ class MockDesktopEnvironment : public DesktopEnvironment { virtual scoped_ptr<EventExecutor> CreateEventExecutor( scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) OVERRIDE; + virtual scoped_ptr<SessionController> CreateSessionController() OVERRIDE; virtual scoped_ptr<media::ScreenCapturer> CreateVideoCapturer( scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) OVERRIDE; @@ -94,9 +97,6 @@ class MockClientSessionEventHandler : public ClientSession::EventHandler { ClientSession* client, const std::string& channel_name, const protocol::TransportRoute& route)); - MOCK_METHOD3(OnClientResolutionChanged, void(ClientSession* client, - const SkISize& size, - const SkIPoint& dpi)); private: DISALLOW_COPY_AND_ASSIGN(MockClientSessionEventHandler); @@ -153,6 +153,18 @@ class MockHostStatusObserver : public HostStatusObserver { MOCK_METHOD0(OnShutdown, void()); }; +class MockSessionController : public SessionController { + public: + MockSessionController(); + virtual ~MockSessionController(); + + MOCK_METHOD2(OnClientResolutionChanged, + void(const SkIPoint&, const SkISize&)); + + private: + DISALLOW_COPY_AND_ASSIGN(MockSessionController); +}; + } // namespace remoting #endif // REMOTING_HOST_HOST_MOCK_OBJECTS_H_ diff --git a/remoting/host/host_status_observer.h b/remoting/host/host_status_observer.h index f2e2198..c43097f 100644 --- a/remoting/host/host_status_observer.h +++ b/remoting/host/host_status_observer.h @@ -46,11 +46,6 @@ class HostStatusObserver { const std::string& channel_name, const protocol::TransportRoute& route) {} - // Called when the client view size or pixel density change. - virtual void OnClientResolutionChanged(const std::string& jid, - const SkISize& size, - const SkIPoint& dpi) {} - // Called when hosting is started for an account. virtual void OnStart(const std::string& xmpp_login) {} diff --git a/remoting/host/ipc_desktop_environment.cc b/remoting/host/ipc_desktop_environment.cc index 51ca9b1..53f90e1 100644 --- a/remoting/host/ipc_desktop_environment.cc +++ b/remoting/host/ipc_desktop_environment.cc @@ -18,6 +18,7 @@ #include "remoting/host/desktop_session.h" #include "remoting/host/desktop_session_proxy.h" #include "remoting/host/event_executor.h" +#include "remoting/host/session_controller.h" namespace remoting { @@ -59,6 +60,12 @@ scoped_ptr<EventExecutor> IpcDesktopEnvironment::CreateEventExecutor( ui_task_runner); } +scoped_ptr<SessionController> IpcDesktopEnvironment::CreateSessionController() { + DCHECK(caller_task_runner_->BelongsToCurrentThread()); + + return desktop_session_proxy_->CreateSessionController(); +} + scoped_ptr<media::ScreenCapturer> IpcDesktopEnvironment::CreateVideoCapturer( scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) { diff --git a/remoting/host/ipc_desktop_environment.h b/remoting/host/ipc_desktop_environment.h index 2e918e6..99a0a28 100644 --- a/remoting/host/ipc_desktop_environment.h +++ b/remoting/host/ipc_desktop_environment.h @@ -52,6 +52,7 @@ class IpcDesktopEnvironment : public DesktopEnvironment { virtual scoped_ptr<EventExecutor> CreateEventExecutor( scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) OVERRIDE; + virtual scoped_ptr<SessionController> CreateSessionController() OVERRIDE; virtual scoped_ptr<media::ScreenCapturer> CreateVideoCapturer( scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) OVERRIDE; diff --git a/remoting/host/ipc_desktop_environment_unittest.cc b/remoting/host/ipc_desktop_environment_unittest.cc index 17d29c6..f93e164 100644 --- a/remoting/host/ipc_desktop_environment_unittest.cc +++ b/remoting/host/ipc_desktop_environment_unittest.cc @@ -129,6 +129,10 @@ class IpcDesktopEnvironmentTest : public testing::Test { // DesktopEnvironment::CreateEventExecutor(). EventExecutor* CreateEventExecutor(); + // Creates a dummy SessionController, to mock + // DesktopEnvironment::CreateSessionController(). + SessionController* CreateSessionController(); + // Creates a fake media::ScreenCapturer, to mock // DesktopEnvironment::CreateVideoCapturer(). media::ScreenCapturer* CreateVideoCapturer(); @@ -285,6 +289,10 @@ DesktopEnvironment* IpcDesktopEnvironmentTest::CreateDesktopEnvironment() { .WillRepeatedly( InvokeWithoutArgs(this, &IpcDesktopEnvironmentTest::CreateEventExecutor)); + EXPECT_CALL(*desktop_environment, CreateSessionControllerPtr()) + .Times(AnyNumber()) + .WillRepeatedly(InvokeWithoutArgs( + this, &IpcDesktopEnvironmentTest::CreateSessionController)); EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _)) .Times(AnyNumber()) .WillRepeatedly( @@ -305,6 +313,10 @@ EventExecutor* IpcDesktopEnvironmentTest::CreateEventExecutor() { return remote_event_executor_; } +SessionController* IpcDesktopEnvironmentTest::CreateSessionController() { + return new MockSessionController(); +} + media::ScreenCapturer* IpcDesktopEnvironmentTest::CreateVideoCapturer() { return new media::ScreenCapturerFake(); } diff --git a/remoting/host/ipc_session_controller.cc b/remoting/host/ipc_session_controller.cc new file mode 100644 index 0000000..e925038 --- /dev/null +++ b/remoting/host/ipc_session_controller.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "remoting/host/ipc_session_controller.h" + +#include "base/logging.h" +#include "remoting/host/desktop_session_proxy.h" + +namespace remoting { + +IpcSessionController::IpcSessionController( + scoped_refptr<DesktopSessionProxy> desktop_session_proxy) + : desktop_session_proxy_(desktop_session_proxy) { +} + +IpcSessionController::~IpcSessionController() { +} + +void IpcSessionController::OnClientResolutionChanged( + const SkIPoint& client_dpi, + const SkISize& client_size) { + NOTIMPLEMENTED(); +} + +} // namespace remoting diff --git a/remoting/host/ipc_session_controller.h b/remoting/host/ipc_session_controller.h new file mode 100644 index 0000000..fc39299 --- /dev/null +++ b/remoting/host/ipc_session_controller.h @@ -0,0 +1,35 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef REMOTING_HOST_IPC_SESSION_CONTROLLER_H_ +#define REMOTING_HOST_IPC_SESSION_CONTROLLER_H_ + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "remoting/host/session_controller.h" + +namespace remoting { + +class DesktopSessionProxy; + +class IpcSessionController : public SessionController { + public: + explicit IpcSessionController( + scoped_refptr<DesktopSessionProxy> desktop_session_proxy); + virtual ~IpcSessionController(); + + // SessionController interface. + virtual void OnClientResolutionChanged(const SkIPoint& client_dpi, + const SkISize& client_size) OVERRIDE; + + private: + // Wraps the IPC channel to the desktop session agent. + scoped_refptr<DesktopSessionProxy> desktop_session_proxy_; + + DISALLOW_COPY_AND_ASSIGN(IpcSessionController); +}; + +} // namespace remoting + +#endif // REMOTING_HOST_IPC_SESSION_CONTROLLER_H_ diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index d243839..35823b3 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -43,7 +43,6 @@ #include "remoting/host/curtain_mode.h" #include "remoting/host/curtaining_host_observer.h" #include "remoting/host/desktop_environment.h" -#include "remoting/host/desktop_resizer.h" #include "remoting/host/desktop_session_connector.h" #include "remoting/host/dns_blackhole_checker.h" #include "remoting/host/event_executor.h" @@ -62,7 +61,6 @@ #include "remoting/host/logging.h" #include "remoting/host/network_settings.h" #include "remoting/host/policy_hack/policy_watcher.h" -#include "remoting/host/resizing_host_observer.h" #include "remoting/host/service_urls.h" #include "remoting/host/session_manager_factory.h" #include "remoting/host/signaling_connector.h" @@ -301,8 +299,6 @@ class HostProcess scoped_ptr<CurtainingHostObserver> curtaining_host_observer_; bool curtain_required_; - scoped_ptr<DesktopResizer> desktop_resizer_; - scoped_ptr<ResizingHostObserver> resizing_host_observer_; scoped_ptr<XmppSignalStrategy> signal_strategy_; scoped_ptr<SignalingConnector> signaling_connector_; scoped_ptr<HeartbeatSender> heartbeat_sender_; @@ -331,7 +327,6 @@ HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, state_(HOST_INITIALIZING), allow_nat_traversal_(true), curtain_required_(false), - desktop_resizer_(DesktopResizer::Create()), #if defined(REMOTING_MULTI_PROCESS) desktop_session_connector_(NULL), #endif // defined(REMOTING_MULTI_PROCESS) @@ -970,9 +965,6 @@ void HostProcess::StartHost() { HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); #endif // !defined(REMOTING_MULTI_PROCESS) - resizing_host_observer_.reset( - new ResizingHostObserver(desktop_resizer_.get(), host_->AsWeakPtr())); - #if defined(REMOTING_RDP_SESSION) // TODO(alexeypa): do not create |curtain_| in this case. CurtainMode* curtain = static_cast<IpcDesktopEnvironmentFactory*>( @@ -1073,7 +1065,6 @@ void HostProcess::ShutdownOnNetworkThread() { host_change_notification_listener_.reset(); signaling_connector_.reset(); signal_strategy_.reset(); - resizing_host_observer_.reset(); if (state_ == HOST_STOPPING_TO_RESTART) { StartHost(); diff --git a/remoting/host/resizing_host_observer.cc b/remoting/host/resizing_host_observer.cc index e1c96b5..7491eea 100644 --- a/remoting/host/resizing_host_observer.cc +++ b/remoting/host/resizing_host_observer.cc @@ -4,42 +4,12 @@ #include "remoting/host/resizing_host_observer.h" -#include <set> +#include <list> #include "base/logging.h" #include "remoting/host/desktop_resizer.h" -#include "remoting/host/host_status_monitor.h" -namespace remoting { - -ResizingHostObserver::ResizingHostObserver( - DesktopResizer* desktop_resizer, - base::WeakPtr<HostStatusMonitor> monitor) - : desktop_resizer_(desktop_resizer), - monitor_(monitor), - original_size_(SkISize::Make(0, 0)) { - monitor_->AddStatusObserver(this); -} - -ResizingHostObserver::~ResizingHostObserver() { - if (monitor_) - monitor_->RemoveStatusObserver(this); -} - -void ResizingHostObserver::OnClientAuthenticated(const std::string& jid) { - // This implementation assumes a single connected client, which is what the - // host currently supports - DCHECK(client_jid_.empty()); - original_size_ = desktop_resizer_->GetCurrentSize(); -} - -void ResizingHostObserver::OnClientDisconnected(const std::string& jid) { - if (!original_size_.isZero()) { - desktop_resizer_->RestoreSize(original_size_); - original_size_.set(0, 0); - } - client_jid_.clear(); -} +namespace { class CandidateSize { public: @@ -123,25 +93,39 @@ class CandidateSize { SkISize size_; }; +} // namespace + +namespace remoting { + +ResizingHostObserver::ResizingHostObserver( + scoped_ptr<DesktopResizer> desktop_resizer) + : desktop_resizer_(desktop_resizer.Pass()), + original_size_(desktop_resizer_->GetCurrentSize()) { +} + +ResizingHostObserver::~ResizingHostObserver() { + if (!original_size_.isZero()) + desktop_resizer_->RestoreSize(original_size_); +} + void ResizingHostObserver::OnClientResolutionChanged( - const std::string& jid, - const SkISize& preferred_size, - const SkIPoint& dpi) { - if (preferred_size.isEmpty()) { + const SkIPoint& client_dpi, + const SkISize& client_size) { + if (client_size.isEmpty()) { return; } // If the implementation returns any sizes, pick the best one according to // the algorithm described in CandidateSize::IsBetterThen. std::list<SkISize> sizes = - desktop_resizer_->GetSupportedSizes(preferred_size); + desktop_resizer_->GetSupportedSizes(client_size); if (sizes.empty()) { return; } - CandidateSize best_size(sizes.front(), preferred_size); + CandidateSize best_size(sizes.front(), client_size); for (std::list<SkISize>::const_iterator i = ++sizes.begin(); i != sizes.end(); ++i) { - CandidateSize candidate_size(*i, preferred_size); + CandidateSize candidate_size(*i, client_size); if (candidate_size.IsBetterThan(best_size)) { best_size = candidate_size; } diff --git a/remoting/host/resizing_host_observer.h b/remoting/host/resizing_host_observer.h index 85c23f1..ded8fc8 100644 --- a/remoting/host/resizing_host_observer.h +++ b/remoting/host/resizing_host_observer.h @@ -5,40 +5,34 @@ #ifndef REMOTING_HOST_RESIZING_HOST_OBSERVER_H_ #define REMOTING_HOST_RESIZING_HOST_OBSERVER_H_ -#include <string> - #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/memory/weak_ptr.h" -#include "remoting/host/host_status_observer.h" +#include "base/memory/scoped_ptr.h" +#include "remoting/host/session_controller.h" #include "third_party/skia/include/core/SkSize.h" namespace remoting { class DesktopResizer; -class HostStatusMonitor; + +// TODO(alexeypa): Rename this class to reflect that it is not +// HostStatusObserver any more. // Use the specified DesktopResizer to match host desktop size to the client // view size as closely as is possible. When the connection closes, restore // the original desktop size. -class ResizingHostObserver : public HostStatusObserver { +class ResizingHostObserver : public SessionController { public: - ResizingHostObserver(DesktopResizer* desktop_resizer, - base::WeakPtr<HostStatusMonitor> monitor); + explicit ResizingHostObserver(scoped_ptr<DesktopResizer> desktop_resizer); virtual ~ResizingHostObserver(); - // HostStatusObserver interface - virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; - virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; - virtual void OnClientResolutionChanged(const std::string& jid, - const SkISize& size, - const SkIPoint& dpi) OVERRIDE; + // SessionController interface. + virtual void OnClientResolutionChanged(const SkIPoint& client_dpi, + const SkISize& client_size) OVERRIDE; private: - DesktopResizer* const desktop_resizer_; - base::WeakPtr<HostStatusMonitor> monitor_; + scoped_ptr<DesktopResizer> desktop_resizer_; SkISize original_size_; - std::string client_jid_; DISALLOW_COPY_AND_ASSIGN(ResizingHostObserver); }; diff --git a/remoting/host/resizing_host_observer_unittest.cc b/remoting/host/resizing_host_observer_unittest.cc index ec0ae10..d54b542 100644 --- a/remoting/host/resizing_host_observer_unittest.cc +++ b/remoting/host/resizing_host_observer_unittest.cc @@ -7,7 +7,6 @@ #include "base/compiler_specific.h" #include "base/logging.h" #include "remoting/host/desktop_resizer.h" -#include "remoting/host/host_status_monitor_fake.h" #include "remoting/host/resizing_host_observer.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkSize.h" @@ -31,7 +30,10 @@ class FakeDesktopResizer : public DesktopResizer { } } - const SkISize& initial_size() { return initial_size_; } + ~FakeDesktopResizer() { + EXPECT_EQ(initial_size_, GetCurrentSize()); + } + int set_size_call_count() { return set_size_call_count_; } // remoting::DesktopResizer interface @@ -65,18 +67,19 @@ class FakeDesktopResizer : public DesktopResizer { class ResizingHostObserverTest : public testing::Test { public: - void SetDesktopResizer(FakeDesktopResizer* desktop_resizer) { - CHECK(!desktop_resizer_.get()) << "Call SetDeskopResizer once per test"; + ResizingHostObserverTest() : desktop_resizer_(NULL) { + } + + void SetDesktopResizer(scoped_ptr<FakeDesktopResizer> desktop_resizer) { + CHECK(!desktop_resizer_) << "Call SetDeskopResizer once per test"; + desktop_resizer_ = desktop_resizer.get(); + resizing_host_observer_.reset( - new ResizingHostObserver(desktop_resizer, - host_status_monitor_.AsWeakPtr())); - desktop_resizer_.reset(desktop_resizer); - resizing_host_observer_->OnClientAuthenticated(""); + new ResizingHostObserver(desktop_resizer.PassAs<DesktopResizer>())); } SkISize GetBestSize(const SkISize& client_size) { - resizing_host_observer_->OnClientResolutionChanged( - "", client_size, SkIPoint()); + resizing_host_observer_->OnClientResolutionChanged(SkIPoint(), client_size); return desktop_resizer_->GetCurrentSize(); } @@ -89,30 +92,19 @@ class ResizingHostObserverTest : public testing::Test { } } - void Reconnect() { - resizing_host_observer_->OnClientDisconnected(""); - resizing_host_observer_->OnClientAuthenticated(""); - } - - // testing::Test interface - virtual void TearDown() OVERRIDE { - resizing_host_observer_->OnClientDisconnected(""); - EXPECT_EQ(desktop_resizer_->initial_size(), - desktop_resizer_->GetCurrentSize()); - } - private: scoped_ptr<ResizingHostObserver> resizing_host_observer_; - scoped_ptr<FakeDesktopResizer> desktop_resizer_; - HostStatusMonitorFake host_status_monitor_; + FakeDesktopResizer* desktop_resizer_; }; // Check that the host is not resized if GetSupportedSizes returns an empty // list (even if GetCurrentSize is supported). TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { SkISize initial = { 640, 480 }; - SetDesktopResizer( + scoped_ptr<FakeDesktopResizer> desktop_resizer( new FakeDesktopResizer(initial, false, NULL, 0)); + SetDesktopResizer(desktop_resizer.Pass()); + SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } }; SkISize expected_sizes[] = { initial, initial }; VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); @@ -120,8 +112,10 @@ TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { // Check that if the implementation supports exact size matching, it is used. TEST_F(ResizingHostObserverTest, SelectExactSize) { - SetDesktopResizer( + scoped_ptr<FakeDesktopResizer> desktop_resizer( new FakeDesktopResizer(SkISize::Make(640, 480), true, NULL, 0)); + SetDesktopResizer(desktop_resizer.Pass()); + SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } , { 640, 480 }, { 480, 640 }, { 1280, 1024 } }; VerifySizes(client_sizes, client_sizes, arraysize(client_sizes)); @@ -132,9 +126,11 @@ TEST_F(ResizingHostObserverTest, SelectExactSize) { TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) { SkISize supported_sizes[] = { SkISize::Make(639, 479), SkISize::Make(640, 480) }; - SetDesktopResizer( + scoped_ptr<FakeDesktopResizer> desktop_resizer( new FakeDesktopResizer(SkISize::Make(640, 480), false, supported_sizes, arraysize(supported_sizes))); + SetDesktopResizer(desktop_resizer.Pass()); + SkISize client_sizes[] = { { 639, 479 }, { 640, 480 }, { 641, 481 }, { 999, 999 } }; SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[1], @@ -146,9 +142,11 @@ TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) { // the requested size, then the one that requires the least down-scaling. TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { SkISize supported_sizes[] = { { 100, 100 }, { 200, 100 } }; - SetDesktopResizer( + scoped_ptr<FakeDesktopResizer> desktop_resizer( new FakeDesktopResizer(SkISize::Make(200, 100), false, supported_sizes, arraysize(supported_sizes))); + SetDesktopResizer(desktop_resizer.Pass()); + SkISize client_sizes[] = { { 1, 1 }, { 99, 99 }, { 199, 99 } }; SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0], supported_sizes[1] }; @@ -159,9 +157,11 @@ TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { // resultant scale factor, then the widest one is selected. TEST_F(ResizingHostObserverTest, SelectWidest) { SkISize supported_sizes[] = { { 640, 480 }, { 480, 640 } }; - SetDesktopResizer( + scoped_ptr<FakeDesktopResizer> desktop_resizer( new FakeDesktopResizer(SkISize::Make(480, 640), false, supported_sizes, arraysize(supported_sizes))); + SetDesktopResizer(desktop_resizer.Pass()); + SkISize client_sizes[] = { { 100, 100 }, { 480, 480 }, { 500, 500 }, { 640, 640 }, { 1000, 1000 } }; SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0], @@ -177,7 +177,8 @@ TEST_F(ResizingHostObserverTest, NoSetSizeForSameSize) { FakeDesktopResizer* desktop_resizer = new FakeDesktopResizer(SkISize::Make(640, 480), false, supported_sizes, arraysize(supported_sizes)); - SetDesktopResizer(desktop_resizer); + SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer)); + SkISize client_sizes[] = { { 640, 640 }, { 1024, 768 }, { 640, 480 } }; SkISize expected_sizes[] = { { 640, 480 }, { 640, 480 }, { 640, 480 } }; VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); diff --git a/remoting/host/session_controller.h b/remoting/host/session_controller.h new file mode 100644 index 0000000..46fff8d --- /dev/null +++ b/remoting/host/session_controller.h @@ -0,0 +1,25 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef REMOTING_HOST_SESSION_CONTROLLER_H_ +#define REMOTING_HOST_SESSION_CONTROLLER_H_ + +#include "base/basictypes.h" +#include "third_party/skia/include/core/SkPoint.h" +#include "third_party/skia/include/core/SkSize.h" + +namespace remoting { + +class SessionController { + public: + virtual ~SessionController() {} + + // Called when the client view size or pixel density change. + virtual void OnClientResolutionChanged(const SkIPoint& client_dpi, + const SkISize& client_size) = 0; +}; + +} // namespace remoting + +#endif // REMOTING_HOST_SESSION_CONTROLLER_H_ diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index 712dddd..1f26013 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -380,6 +380,8 @@ 'host/ipc_event_executor.h', 'host/ipc_host_event_logger.cc', 'host/ipc_host_event_logger.h', + 'host/ipc_session_controller.cc', + 'host/ipc_session_controller.h', 'host/ipc_video_frame_capturer.cc', 'host/ipc_video_frame_capturer.h', 'host/it2me_host_user_interface.cc', @@ -427,6 +429,7 @@ 'host/service_client.h', 'host/service_urls.cc', 'host/service_urls.h', + 'host/session_controller.h', 'host/session_manager_factory.cc', 'host/session_manager_factory.h', 'host/signaling_connector.cc', |