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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 } | 174 } |
175 | 175 |
176 if (i != active_connections_.end()) { | 176 if (i != active_connections_.end()) { |
177 daemon_channel_->Send(new ChromotingNetworkDaemonMsg_SetScreenResolution( | 177 daemon_channel_->Send(new ChromotingNetworkDaemonMsg_SetScreenResolution( |
178 i->first, resolution)); | 178 i->first, resolution)); |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 void IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached( | 182 void IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached( |
183 int terminal_id, | 183 int terminal_id, |
184 base::ProcessHandle desktop_process, | 184 base::ProcessHandle desktop_process_handle, |
185 IPC::PlatformFileForTransit desktop_pipe) { | 185 IPC::PlatformFileForTransit desktop_pipe) { |
186 if (!caller_task_runner_->BelongsToCurrentThread()) { | 186 if (!caller_task_runner_->BelongsToCurrentThread()) { |
187 caller_task_runner_->PostTask(FROM_HERE, base::Bind( | 187 caller_task_runner_->PostTask(FROM_HERE, base::Bind( |
188 &IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached, | 188 &IpcDesktopEnvironmentFactory::OnDesktopSessionAgentAttached, |
189 base::Unretained(this), terminal_id, desktop_process, desktop_pipe)); | 189 base::Unretained(this), terminal_id, desktop_process_handle, |
190 desktop_pipe)); | |
190 return; | 191 return; |
191 } | 192 } |
192 | 193 |
194 base::Process desktop_process; | |
195 // Unit tests may pass a pseudo-handle. | |
196 if (desktop_process_handle == base::GetCurrentProcessHandle()) | |
197 desktop_process = base::Process::Current(); | |
Sergey Ulanov
2015/01/24 18:04:29
nit: please add {} here and in the else case
Can
rvargas (doing something else)
2015/02/02 20:57:00
done
Sergey Ulanov
2015/02/02 21:36:31
Current process handle is used in tests only, so i
rvargas (doing something else)
2015/02/04 03:21:38
Done.
| |
198 else | |
199 desktop_process = base::Process(desktop_process_handle); | |
200 | |
193 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); | 201 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); |
194 if (i != active_connections_.end()) { | 202 if (i != active_connections_.end()) { |
195 i->second->DetachFromDesktop(); | 203 i->second->DetachFromDesktop(); |
196 i->second->AttachToDesktop(desktop_process, desktop_pipe); | 204 i->second->AttachToDesktop(desktop_process.Pass(), desktop_pipe); |
197 } else { | 205 } else { |
198 base::CloseProcessHandle(desktop_process); | |
199 | |
200 #if defined(OS_POSIX) | 206 #if defined(OS_POSIX) |
201 DCHECK(desktop_pipe.auto_close); | 207 DCHECK(desktop_pipe.auto_close); |
202 base::File pipe_closer(IPC::PlatformFileForTransitToFile(desktop_pipe)); | 208 base::File pipe_closer(IPC::PlatformFileForTransitToFile(desktop_pipe)); |
203 #endif // defined(OS_POSIX) | 209 #endif // defined(OS_POSIX) |
204 } | 210 } |
205 } | 211 } |
206 | 212 |
207 void IpcDesktopEnvironmentFactory::OnTerminalDisconnected(int terminal_id) { | 213 void IpcDesktopEnvironmentFactory::OnTerminalDisconnected(int terminal_id) { |
208 if (!caller_task_runner_->BelongsToCurrentThread()) { | 214 if (!caller_task_runner_->BelongsToCurrentThread()) { |
209 caller_task_runner_->PostTask(FROM_HERE, base::Bind( | 215 caller_task_runner_->PostTask(FROM_HERE, base::Bind( |
210 &IpcDesktopEnvironmentFactory::OnTerminalDisconnected, | 216 &IpcDesktopEnvironmentFactory::OnTerminalDisconnected, |
211 base::Unretained(this), terminal_id)); | 217 base::Unretained(this), terminal_id)); |
212 return; | 218 return; |
213 } | 219 } |
214 | 220 |
215 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); | 221 ActiveConnectionsList::iterator i = active_connections_.find(terminal_id); |
216 if (i != active_connections_.end()) { | 222 if (i != active_connections_.end()) { |
217 DesktopSessionProxy* desktop_session_proxy = i->second; | 223 DesktopSessionProxy* desktop_session_proxy = i->second; |
218 active_connections_.erase(i); | 224 active_connections_.erase(i); |
219 | 225 |
220 // Disconnect the client session. | 226 // Disconnect the client session. |
221 desktop_session_proxy->DisconnectSession(); | 227 desktop_session_proxy->DisconnectSession(); |
222 } | 228 } |
223 } | 229 } |
224 | 230 |
225 } // namespace remoting | 231 } // namespace remoting |
OLD | NEW |