Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / remoting / host / ipc_desktop_environment.h
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   ~IpcDesktopEnvironment() override;
50
51   // DesktopEnvironment implementation.
52   scoped_ptr<AudioCapturer> CreateAudioCapturer() override;
53   scoped_ptr<InputInjector> CreateInputInjector() override;
54   scoped_ptr<ScreenControls> CreateScreenControls() override;
55   scoped_ptr<webrtc::DesktopCapturer> CreateVideoCapturer() override;
56   scoped_ptr<webrtc::MouseCursorMonitor> CreateMouseCursorMonitor() override;
57   std::string GetCapabilities() const override;
58   void SetCapabilities(const std::string& capabilities) override;
59   scoped_ptr<GnubbyAuthHandler> CreateGnubbyAuthHandler(
60       protocol::ClientStub* client_stub) override;
61
62  private:
63   scoped_refptr<DesktopSessionProxy> desktop_session_proxy_;
64
65   DISALLOW_COPY_AND_ASSIGN(IpcDesktopEnvironment);
66 };
67
68 // Used to create IpcDesktopEnvironment objects integrating with the desktop via
69 // a helper process and talking to that process via IPC.
70 class IpcDesktopEnvironmentFactory
71     : public DesktopEnvironmentFactory,
72       public DesktopSessionConnector {
73  public:
74   // Passes a reference to the IPC channel connected to the daemon process and
75   // relevant task runners. |daemon_channel| must outlive this object.
76   IpcDesktopEnvironmentFactory(
77       scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
78       scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
79       scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
80       scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
81       IPC::Sender* daemon_channel);
82   ~IpcDesktopEnvironmentFactory() override;
83
84   // DesktopEnvironmentFactory implementation.
85   scoped_ptr<DesktopEnvironment> Create(
86       base::WeakPtr<ClientSessionControl> client_session_control) override;
87   void SetEnableCurtaining(bool enable) override;
88   bool SupportsAudioCapture() const override;
89
90   // DesktopSessionConnector implementation.
91   void ConnectTerminal(DesktopSessionProxy* desktop_session_proxy,
92                        const ScreenResolution& resolution,
93                        bool virtual_terminal) override;
94   void DisconnectTerminal(DesktopSessionProxy* desktop_session_proxy) override;
95   void SetScreenResolution(DesktopSessionProxy* desktop_session_proxy,
96                            const ScreenResolution& resolution) override;
97   void OnDesktopSessionAgentAttached(
98       int terminal_id,
99       base::ProcessHandle desktop_process,
100       IPC::PlatformFileForTransit desktop_pipe) override;
101   void OnTerminalDisconnected(int terminal_id) override;
102
103  private:
104   // Used to run the audio capturer.
105   scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
106
107   // Task runner on which methods of DesktopEnvironmentFactory interface should
108   // be called.
109   scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_;
110
111   // Used to run the video capturer.
112   scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
113
114   // Task runner used for running background I/O.
115   scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
116
117   // True if curtain mode is enabled.
118   bool curtain_enabled_;
119
120   // IPC channel connected to the daemon process.
121   IPC::Sender* daemon_channel_;
122
123   // List of DesktopEnvironment instances we've told the daemon process about.
124   typedef std::map<int, DesktopSessionProxy*> ActiveConnectionsList;
125   ActiveConnectionsList active_connections_;
126
127   // Next desktop session ID. IDs are allocated sequentially starting from 0.
128   // This gives us more than 67 years of unique IDs assuming a new ID is
129   // allocated every second.
130   int next_id_;
131
132   // Factory for weak pointers to DesktopSessionConnector interface.
133   base::WeakPtrFactory<DesktopSessionConnector> connector_factory_;
134
135   DISALLOW_COPY_AND_ASSIGN(IpcDesktopEnvironmentFactory);
136 };
137
138 }  // namespace remoting
139
140 #endif  // REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_