| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_ | 5 #ifndef REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_ |
| 6 #define REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_ | 6 #define REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_ |
| 7 | 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 8 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 9 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 10 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 12 #include "ipc/ipc_platform_file.h" | 15 #include "base/memory/weak_ptr.h" |
| 13 #include "remoting/host/desktop_environment.h" | 16 #include "remoting/host/desktop_environment.h" |
| 17 #include "remoting/host/desktop_session_connector.h" |
| 14 | 18 |
| 15 namespace base { | 19 namespace base { |
| 16 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
| 17 } // base | 21 } // base |
| 18 | 22 |
| 23 namespace IPC { |
| 24 class ChannelProxy; |
| 25 } // namespace IPC |
| 26 |
| 19 namespace remoting { | 27 namespace remoting { |
| 20 | 28 |
| 21 class DesktopSessionConnector; | |
| 22 class DesktopSessionProxy; | 29 class DesktopSessionProxy; |
| 23 | 30 |
| 24 // A variant of desktop environment integrating with the desktop by means of | 31 // A variant of desktop environment integrating with the desktop by means of |
| 25 // a helper process and talking to that process via IPC. | 32 // a helper process and talking to that process via IPC. |
| 26 class IpcDesktopEnvironment : public DesktopEnvironment { | 33 class IpcDesktopEnvironment : public DesktopEnvironment { |
| 27 public: | 34 public: |
| 28 // |desktop_session_connector| is used to bind the IpcDesktopEnvironment to | 35 // |desktop_session_connector| is used to bind DesktopSessionProxy to |
| 29 // a desktop session, to be notified with a new IPC channel every time | 36 // a desktop session, to be notified every time the desktop process is |
| 30 // the desktop process is changed. |desktop_session_connector| must outlive | 37 // restarted. |
| 31 // |this|. |client| specifies the client session owning |this|. | |
| 32 IpcDesktopEnvironment( | 38 IpcDesktopEnvironment( |
| 33 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 39 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 34 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 40 const std::string& client_jid, |
| 35 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 41 const base::Closure& disconnect_callback, |
| 36 DesktopSessionConnector* desktop_session_connector, | 42 base::WeakPtr<DesktopSessionConnector> desktop_session_connector); |
| 37 scoped_refptr<DesktopSessionProxy> desktop_session_proxy); | |
| 38 virtual ~IpcDesktopEnvironment(); | 43 virtual ~IpcDesktopEnvironment(); |
| 39 | 44 |
| 40 virtual void Start( | 45 // DesktopEnvironment implementation. |
| 41 scoped_ptr<protocol::ClipboardStub> client_clipboard, | 46 virtual scoped_ptr<AudioCapturer> CreateAudioCapturer( |
| 42 const std::string& client_jid, | 47 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner) OVERRIDE; |
| 43 const base::Closure& disconnect_callback) OVERRIDE; | 48 virtual scoped_ptr<EventExecutor> CreateEventExecutor( |
| 49 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 50 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) OVERRIDE; |
| 51 virtual scoped_ptr<VideoFrameCapturer> CreateVideoCapturer( |
| 52 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
| 53 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) OVERRIDE; |
| 44 | 54 |
| 45 private: | 55 private: |
| 46 // Used for IPC I/O. | 56 // Binds DesktopSessionProxy to a desktop session if it is not bound already. |
| 47 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 57 void ConnectToDesktopSession(); |
| 48 | 58 |
| 49 DesktopSessionConnector* desktop_session_connector_; | 59 // Task runner on which public methods of this class should be called. |
| 60 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
| 61 |
| 62 // True if |desktop_session_proxy_| is connected to a desktop session. |
| 63 bool connected_; |
| 64 |
| 65 // Used to bind to a desktop session and receive notifications every time |
| 66 // the desktop process is replaced. |
| 67 base::WeakPtr<DesktopSessionConnector> desktop_session_connector_; |
| 50 | 68 |
| 51 scoped_refptr<DesktopSessionProxy> desktop_session_proxy_; | 69 scoped_refptr<DesktopSessionProxy> desktop_session_proxy_; |
| 52 | 70 |
| 53 // True if |this| has been connected to a desktop session. | |
| 54 bool connected_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(IpcDesktopEnvironment); | 71 DISALLOW_COPY_AND_ASSIGN(IpcDesktopEnvironment); |
| 57 }; | 72 }; |
| 58 | 73 |
| 74 // Used to create IpcDesktopEnvironment objects integrating with the desktop via |
| 75 // a helper process and talking to that process via IPC. |
| 76 class IpcDesktopEnvironmentFactory |
| 77 : public DesktopEnvironmentFactory, |
| 78 public DesktopSessionConnector { |
| 79 public: |
| 80 // Passes a reference to the IPC channel connected to the daemon process and |
| 81 // relevant task runners. |daemon_channel| must outlive this object. |
| 82 IpcDesktopEnvironmentFactory( |
| 83 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 84 IPC::ChannelProxy* daemon_channel); |
| 85 virtual ~IpcDesktopEnvironmentFactory(); |
| 86 |
| 87 // DesktopEnvironmentFactory implementation. |
| 88 virtual scoped_ptr<DesktopEnvironment> Create( |
| 89 const std::string& client_jid, |
| 90 const base::Closure& disconnect_callback) OVERRIDE; |
| 91 virtual bool SupportsAudioCapture() const OVERRIDE; |
| 92 |
| 93 // DesktopSessionConnector implementation. |
| 94 virtual void ConnectTerminal( |
| 95 scoped_refptr<DesktopSessionProxy> desktop_session_proxy) OVERRIDE; |
| 96 virtual void DisconnectTerminal( |
| 97 scoped_refptr<DesktopSessionProxy> desktop_session_proxy) OVERRIDE; |
| 98 virtual void OnDesktopSessionAgentAttached( |
| 99 int terminal_id, |
| 100 IPC::PlatformFileForTransit desktop_process, |
| 101 IPC::PlatformFileForTransit desktop_pipe) OVERRIDE; |
| 102 virtual void OnTerminalDisconnected(int terminal_id) OVERRIDE; |
| 103 |
| 104 private: |
| 105 // Task runner on which public methods of this class should be called. |
| 106 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
| 107 |
| 108 // IPC channel connected to the daemon process. |
| 109 IPC::ChannelProxy* daemon_channel_; |
| 110 |
| 111 // List of DesktopEnvironment instances we've told the daemon process about. |
| 112 typedef std::map<int, scoped_refptr<DesktopSessionProxy> > |
| 113 ActiveConnectionsList; |
| 114 ActiveConnectionsList active_connections_; |
| 115 |
| 116 // Factory for weak pointers to DesktopSessionConnector interface. |
| 117 base::WeakPtrFactory<DesktopSessionConnector> connector_factory_; |
| 118 |
| 119 // Next desktop session ID. IDs are allocated sequentially starting from 0. |
| 120 // This gives us more than 67 years of unique IDs assuming a new ID is |
| 121 // allocated every second. |
| 122 int next_id_; |
| 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(IpcDesktopEnvironmentFactory); |
| 125 }; |
| 126 |
| 59 } // namespace remoting | 127 } // namespace remoting |
| 60 | 128 |
| 61 #endif // REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_ | 129 #endif // REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_ |
| OLD | NEW |