| 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 #include "remoting/host/ipc_desktop_environment.h" | 5 #include "remoting/host/ipc_desktop_environment.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/process_util.h" |
| 12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 13 #include "ipc/ipc_channel_proxy.h" | 14 #include "ipc/ipc_channel_proxy.h" |
| 14 #include "media/video/capture/screen/screen_capturer.h" | 15 #include "media/video/capture/screen/screen_capturer.h" |
| 15 #include "remoting/host/audio_capturer.h" | 16 #include "remoting/host/audio_capturer.h" |
| 16 #include "remoting/host/chromoting_messages.h" | 17 #include "remoting/host/chromoting_messages.h" |
| 17 #include "remoting/host/desktop_session_proxy.h" | 18 #include "remoting/host/desktop_session_proxy.h" |
| 18 #include "remoting/host/event_executor.h" | 19 #include "remoting/host/event_executor.h" |
| 19 | 20 |
| 20 namespace remoting { | 21 namespace remoting { |
| 21 | 22 |
| 22 IpcDesktopEnvironment::IpcDesktopEnvironment( | 23 IpcDesktopEnvironment::IpcDesktopEnvironment( |
| 23 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 24 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 25 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 24 const std::string& client_jid, | 26 const std::string& client_jid, |
| 25 const base::Closure& disconnect_callback, | 27 const base::Closure& disconnect_callback, |
| 26 base::WeakPtr<DesktopSessionConnector> desktop_session_connector) | 28 base::WeakPtr<DesktopSessionConnector> desktop_session_connector) |
| 27 : caller_task_runner_(caller_task_runner), | 29 : caller_task_runner_(caller_task_runner), |
| 28 connected_(false), | 30 connected_(false), |
| 29 desktop_session_connector_(desktop_session_connector), | 31 desktop_session_connector_(desktop_session_connector), |
| 30 desktop_session_proxy_(new DesktopSessionProxy(caller_task_runner, | 32 desktop_session_proxy_(new DesktopSessionProxy(caller_task_runner, |
| 33 io_task_runner, |
| 31 client_jid, | 34 client_jid, |
| 32 disconnect_callback)) { | 35 disconnect_callback)) { |
| 33 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 36 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 34 } | 37 } |
| 35 | 38 |
| 36 IpcDesktopEnvironment::~IpcDesktopEnvironment() { | 39 IpcDesktopEnvironment::~IpcDesktopEnvironment() { |
| 37 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 40 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 38 | 41 |
| 39 if (connected_ && desktop_session_connector_) | 42 if (connected_ && desktop_session_connector_) |
| 40 desktop_session_connector_->DisconnectTerminal(desktop_session_proxy_); | 43 desktop_session_connector_->DisconnectTerminal(desktop_session_proxy_); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 75 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 73 | 76 |
| 74 if (!connected_) { | 77 if (!connected_) { |
| 75 connected_ = true; | 78 connected_ = true; |
| 76 desktop_session_connector_->ConnectTerminal(desktop_session_proxy_); | 79 desktop_session_connector_->ConnectTerminal(desktop_session_proxy_); |
| 77 } | 80 } |
| 78 } | 81 } |
| 79 | 82 |
| 80 IpcDesktopEnvironmentFactory::IpcDesktopEnvironmentFactory( | 83 IpcDesktopEnvironmentFactory::IpcDesktopEnvironmentFactory( |
| 81 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 84 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 85 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 82 IPC::ChannelProxy* daemon_channel) | 86 IPC::ChannelProxy* daemon_channel) |
| 83 : caller_task_runner_(caller_task_runner), | 87 : caller_task_runner_(caller_task_runner), |
| 88 io_task_runner_(io_task_runner), |
| 84 daemon_channel_(daemon_channel), | 89 daemon_channel_(daemon_channel), |
| 85 connector_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 90 connector_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 86 next_id_(0) { | 91 next_id_(0) { |
| 87 } | 92 } |
| 88 | 93 |
| 89 IpcDesktopEnvironmentFactory::~IpcDesktopEnvironmentFactory() { | 94 IpcDesktopEnvironmentFactory::~IpcDesktopEnvironmentFactory() { |
| 90 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 95 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 91 } | 96 } |
| 92 | 97 |
| 93 scoped_ptr<DesktopEnvironment> IpcDesktopEnvironmentFactory::Create( | 98 scoped_ptr<DesktopEnvironment> IpcDesktopEnvironmentFactory::Create( |
| 94 const std::string& client_jid, | 99 const std::string& client_jid, |
| 95 const base::Closure& disconnect_callback) { | 100 const base::Closure& disconnect_callback) { |
| 96 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 101 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 97 | 102 |
| 98 return scoped_ptr<DesktopEnvironment>(new IpcDesktopEnvironment( | 103 return scoped_ptr<DesktopEnvironment>(new IpcDesktopEnvironment( |
| 99 caller_task_runner_, client_jid, disconnect_callback, | 104 caller_task_runner_, io_task_runner_, client_jid, disconnect_callback, |
| 100 connector_factory_.GetWeakPtr())); | 105 connector_factory_.GetWeakPtr())); |
| 101 } | 106 } |
| 102 | 107 |
| 103 bool IpcDesktopEnvironmentFactory::SupportsAudioCapture() const { | 108 bool IpcDesktopEnvironmentFactory::SupportsAudioCapture() const { |
| 104 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 109 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 105 | 110 |
| 106 return AudioCapturer::IsSupported(); | 111 return AudioCapturer::IsSupported(); |
| 107 } | 112 } |
| 108 | 113 |
| 109 void IpcDesktopEnvironmentFactory::ConnectTerminal( | 114 void IpcDesktopEnvironmentFactory::ConnectTerminal( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 133 int id = i->first; | 138 int id = i->first; |
| 134 active_connections_.erase(i); | 139 active_connections_.erase(i); |
| 135 | 140 |
| 136 VLOG(1) << "Network: unregistered desktop environment " << id; | 141 VLOG(1) << "Network: unregistered desktop environment " << id; |
| 137 daemon_channel_->Send(new ChromotingNetworkHostMsg_DisconnectTerminal(id)); | 142 daemon_channel_->Send(new ChromotingNetworkHostMsg_DisconnectTerminal(id)); |
| 138 } | 143 } |
| 139 } | 144 } |
| 140 | 145 |
| 141 void IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached( | 146 void IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached( |
| 142 int terminal_id, | 147 int terminal_id, |
| 143 IPC::PlatformFileForTransit desktop_process, | 148 base::ProcessHandle desktop_process, |
| 144 IPC::PlatformFileForTransit desktop_pipe) { | 149 IPC::PlatformFileForTransit desktop_pipe) { |
| 145 if (!caller_task_runner_->BelongsToCurrentThread()) { | 150 if (!caller_task_runner_->BelongsToCurrentThread()) { |
| 146 caller_task_runner_->PostTask(FROM_HERE, base::Bind( | 151 caller_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 147 &IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached, | 152 &IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached, |
| 148 base::Unretained(this), terminal_id, desktop_process, desktop_pipe)); | 153 base::Unretained(this), terminal_id, desktop_process, desktop_pipe)); |
| 149 return; | 154 return; |
| 150 } | 155 } |
| 151 | 156 |
| 152 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); | 157 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); |
| 153 if (i != active_connections_.end()) { | 158 if (i != active_connections_.end()) { |
| 154 i->second->DetachFromDesktop(); | 159 i->second->DetachFromDesktop(); |
| 155 i->second->AttachToDesktop(desktop_process, desktop_pipe); | 160 i->second->AttachToDesktop(desktop_process, desktop_pipe); |
| 156 } else { | 161 } else { |
| 162 base::CloseProcessHandle(desktop_process); |
| 163 |
| 157 #if defined(OS_POSIX) | 164 #if defined(OS_POSIX) |
| 158 DCHECK(desktop_process.auto_close); | |
| 159 DCHECK(desktop_pipe.auto_close); | 165 DCHECK(desktop_pipe.auto_close); |
| 160 | 166 |
| 161 base::ClosePlatformFile(desktop_process.fd); | |
| 162 base::ClosePlatformFile(desktop_pipe.fd); | 167 base::ClosePlatformFile(desktop_pipe.fd); |
| 163 #elif defined(OS_WIN) | 168 #endif // defined(OS_POSIX) |
| 164 base::ClosePlatformFile(desktop_process); | |
| 165 #endif // defined(OS_WIN) | |
| 166 } | 169 } |
| 167 } | 170 } |
| 168 | 171 |
| 169 void IpcDesktopEnvironmentFactory::OnTerminalDisconnected(int terminal_id) { | 172 void IpcDesktopEnvironmentFactory::OnTerminalDisconnected(int terminal_id) { |
| 170 if (!caller_task_runner_->BelongsToCurrentThread()) { | 173 if (!caller_task_runner_->BelongsToCurrentThread()) { |
| 171 caller_task_runner_->PostTask(FROM_HERE, base::Bind( | 174 caller_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 172 &IpcDesktopEnvironmentFactory::OnTerminalDisconnected, | 175 &IpcDesktopEnvironmentFactory::OnTerminalDisconnected, |
| 173 base::Unretained(this), terminal_id)); | 176 base::Unretained(this), terminal_id)); |
| 174 return; | 177 return; |
| 175 } | 178 } |
| 176 | 179 |
| 177 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); | 180 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); |
| 178 if (i != active_connections_.end()) { | 181 if (i != active_connections_.end()) { |
| 179 scoped_refptr<DesktopSessionProxy> desktop_session_proxy = i->second; | 182 scoped_refptr<DesktopSessionProxy> desktop_session_proxy = i->second; |
| 180 active_connections_.erase(i); | 183 active_connections_.erase(i); |
| 181 | 184 |
| 182 // Disconnect the client session. | 185 // Disconnect the client session. |
| 183 desktop_session_proxy->DisconnectSession(); | 186 desktop_session_proxy->DisconnectSession(); |
| 184 } | 187 } |
| 185 } | 188 } |
| 186 | 189 |
| 187 } // namespace remoting | 190 } // namespace remoting |
| OLD | NEW |