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.
5 #ifndef REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_
6 #define REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_
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"
20 class SingleThreadTaskRunner
;
29 class ClientSessionControl
;
30 class DesktopSessionProxy
;
31 class GnubbyAuthHandler
;
32 class ScreenResolution
;
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
{
38 // |desktop_session_connector| is used to bind DesktopSessionProxy to
39 // a desktop session, to be notified every time the desktop process is
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();
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()
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
;
64 scoped_refptr
<DesktopSessionProxy
> desktop_session_proxy_
;
66 DISALLOW_COPY_AND_ASSIGN(IpcDesktopEnvironment
);
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
{
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();
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
;
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(
103 base::ProcessHandle desktop_process
,
104 IPC::PlatformFileForTransit desktop_pipe
) OVERRIDE
;
105 virtual void OnTerminalDisconnected(int terminal_id
) OVERRIDE
;
108 // Used to run the audio capturer.
109 scoped_refptr
<base::SingleThreadTaskRunner
> audio_task_runner_
;
111 // Task runner on which methods of DesktopEnvironmentFactory interface should
113 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner_
;
115 // Used to run the video capturer.
116 scoped_refptr
<base::SingleThreadTaskRunner
> capture_task_runner_
;
118 // Task runner used for running background I/O.
119 scoped_refptr
<base::SingleThreadTaskRunner
> io_task_runner_
;
121 // True if curtain mode is enabled.
122 bool curtain_enabled_
;
124 // IPC channel connected to the daemon process.
125 IPC::Sender
* daemon_channel_
;
127 // List of DesktopEnvironment instances we've told the daemon process about.
128 typedef std::map
<int, DesktopSessionProxy
*> ActiveConnectionsList
;
129 ActiveConnectionsList active_connections_
;
131 // Factory for weak pointers to DesktopSessionConnector interface.
132 base::WeakPtrFactory
<DesktopSessionConnector
> connector_factory_
;
134 // Next desktop session ID. IDs are allocated sequentially starting from 0.
135 // This gives us more than 67 years of unique IDs assuming a new ID is
136 // allocated every second.
139 DISALLOW_COPY_AND_ASSIGN(IpcDesktopEnvironmentFactory
);
142 } // namespace remoting
144 #endif // REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_