1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_ 6 #define REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_ 7 8 #include <map> 9 #include <string> 10 11 #include "base/basictypes.h" 12 #include "base/callback_forward.h" 13 #include "base/memory/ref_counted.h" 14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/weak_ptr.h" 16 #include "remoting/host/desktop_environment.h" 17 #include "remoting/host/desktop_session_connector.h" 18 19 namespace base { 20 class SingleThreadTaskRunner; 21 } // base 22 23 namespace IPC { 24 class Sender; 25 } // namespace IPC 26 27 namespace remoting { 28 29 class ClientSessionControl; 30 class DesktopSessionProxy; 31 class GnubbyAuthHandler; 32 class ScreenResolution; 33 34 // A variant of desktop environment integrating with the desktop by means of 35 // a helper process and talking to that process via IPC. 36 class IpcDesktopEnvironment : public DesktopEnvironment { 37 public: 38 // |desktop_session_connector| is used to bind DesktopSessionProxy to 39 // a desktop session, to be notified every time the desktop process is 40 // restarted. 41 IpcDesktopEnvironment( 42 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, 43 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, 44 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 45 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 46 base::WeakPtr<ClientSessionControl> client_session_control, 47 base::WeakPtr<DesktopSessionConnector> desktop_session_connector, 48 bool virtual_terminal); 49 virtual ~IpcDesktopEnvironment(); 50 51 // DesktopEnvironment implementation. 52 virtual scoped_ptr<AudioCapturer> CreateAudioCapturer() OVERRIDE; 53 virtual scoped_ptr<InputInjector> CreateInputInjector() OVERRIDE; 54 virtual scoped_ptr<ScreenControls> CreateScreenControls() OVERRIDE; 55 virtual scoped_ptr<webrtc::DesktopCapturer> CreateVideoCapturer() OVERRIDE; 56 virtual scoped_ptr<webrtc::MouseCursorMonitor> CreateMouseCursorMonitor() 57 OVERRIDE; 58 virtual std::string GetCapabilities() const OVERRIDE; 59 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; 60 virtual scoped_ptr<GnubbyAuthHandler> CreateGnubbyAuthHandler( 61 protocol::ClientStub* client_stub) OVERRIDE; 62 63 private: 64 scoped_refptr<DesktopSessionProxy> desktop_session_proxy_; 65 66 DISALLOW_COPY_AND_ASSIGN(IpcDesktopEnvironment); 67 }; 68 69 // Used to create IpcDesktopEnvironment objects integrating with the desktop via 70 // a helper process and talking to that process via IPC. 71 class IpcDesktopEnvironmentFactory 72 : public DesktopEnvironmentFactory, 73 public DesktopSessionConnector { 74 public: 75 // Passes a reference to the IPC channel connected to the daemon process and 76 // relevant task runners. |daemon_channel| must outlive this object. 77 IpcDesktopEnvironmentFactory( 78 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, 79 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, 80 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 81 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 82 IPC::Sender* daemon_channel); 83 virtual ~IpcDesktopEnvironmentFactory(); 84 85 // DesktopEnvironmentFactory implementation. 86 virtual scoped_ptr<DesktopEnvironment> Create( 87 base::WeakPtr<ClientSessionControl> client_session_control) OVERRIDE; 88 virtual void SetEnableCurtaining(bool enable) OVERRIDE; 89 virtual bool SupportsAudioCapture() const OVERRIDE; 90 91 // DesktopSessionConnector implementation. 92 virtual void ConnectTerminal( 93 DesktopSessionProxy* desktop_session_proxy, 94 const ScreenResolution& resolution, 95 bool virtual_terminal) OVERRIDE; 96 virtual void DisconnectTerminal( 97 DesktopSessionProxy* desktop_session_proxy) OVERRIDE; 98 virtual void SetScreenResolution( 99 DesktopSessionProxy* desktop_session_proxy, 100 const ScreenResolution& resolution) OVERRIDE; 101 virtual void OnDesktopSessionAgentAttached( 102 int terminal_id, 103 base::ProcessHandle desktop_process, 104 IPC::PlatformFileForTransit desktop_pipe) OVERRIDE; 105 virtual void OnTerminalDisconnected(int terminal_id) OVERRIDE; 106 107 private: 108 // Used to run the audio capturer. 109 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; 110 111 // Task runner on which methods of DesktopEnvironmentFactory interface should 112 // be called. 113 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; 114 115 // Used to run the video capturer. 116 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; 117 118 // Task runner used for running background I/O. 119 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 120 121 // True if curtain mode is enabled. 122 bool curtain_enabled_; 123 124 // IPC channel connected to the daemon process. 125 IPC::Sender* daemon_channel_; 126 127 // List of DesktopEnvironment instances we've told the daemon process about. 128 typedef std::map<int, DesktopSessionProxy*> ActiveConnectionsList; 129 ActiveConnectionsList active_connections_; 130 131 // Next desktop session ID. IDs are allocated sequentially starting from 0. 132 // This gives us more than 67 years of unique IDs assuming a new ID is 133 // allocated every second. 134 int next_id_; 135 136 // Factory for weak pointers to DesktopSessionConnector interface. 137 base::WeakPtrFactory<DesktopSessionConnector> connector_factory_; 138 139 DISALLOW_COPY_AND_ASSIGN(IpcDesktopEnvironmentFactory); 140 }; 141 142 } // namespace remoting 143 144 #endif // REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_ 145