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 "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/platform_file.h" |
9 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "ipc/ipc_channel_proxy.h" |
10 #include "remoting/host/audio_capturer.h" | 12 #include "remoting/host/audio_capturer.h" |
11 #include "remoting/host/client_session.h" | 13 #include "remoting/host/client_session.h" |
12 #include "remoting/host/desktop_session_connector.h" | 14 #include "remoting/host/desktop_session_connector.h" |
13 #include "remoting/host/event_executor.h" | 15 #include "remoting/host/event_executor.h" |
14 #include "remoting/host/video_frame_capturer.h" | 16 #include "remoting/host/video_frame_capturer.h" |
15 | 17 |
| 18 #if defined(OS_WIN) |
| 19 #include "base/win/scoped_handle.h" |
| 20 #endif // defined(OS_WIN) |
| 21 |
16 namespace remoting { | 22 namespace remoting { |
17 | 23 |
18 IpcDesktopEnvironment::IpcDesktopEnvironment( | 24 IpcDesktopEnvironment::IpcDesktopEnvironment( |
19 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 25 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 26 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
20 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 27 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
21 DesktopSessionConnector* desktop_session_connector, | 28 DesktopSessionConnector* desktop_session_connector, |
22 ClientSession* client) | 29 ClientSession* client) |
23 : DesktopEnvironment( | 30 : DesktopEnvironment( |
24 AudioCapturer::Create(), | 31 AudioCapturer::Create(), |
25 EventExecutor::Create(input_task_runner, ui_task_runner), | 32 EventExecutor::Create(input_task_runner, ui_task_runner), |
26 scoped_ptr<VideoFrameCapturer>(VideoFrameCapturer::Create())), | 33 scoped_ptr<VideoFrameCapturer>(VideoFrameCapturer::Create())), |
| 34 network_task_runner_(network_task_runner), |
27 desktop_session_connector_(desktop_session_connector), | 35 desktop_session_connector_(desktop_session_connector), |
28 client_(client), | 36 client_(client), |
29 connected_(false) { | 37 connected_(false) { |
30 } | 38 } |
31 | 39 |
| 40 bool IpcDesktopEnvironment::OnMessageReceived(const IPC::Message& message) { |
| 41 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 42 |
| 43 NOTIMPLEMENTED(); |
| 44 return false; |
| 45 } |
| 46 |
| 47 void IpcDesktopEnvironment::OnChannelConnected(int32 peer_pid) { |
| 48 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 49 |
| 50 VLOG(1) << "IPC: network <- desktop (" << peer_pid << ")"; |
| 51 } |
| 52 |
| 53 void IpcDesktopEnvironment::OnChannelError() { |
| 54 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 55 |
| 56 desktop_channel_.reset(); |
| 57 } |
| 58 |
32 void IpcDesktopEnvironment::Start( | 59 void IpcDesktopEnvironment::Start( |
33 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 60 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
| 61 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
34 DCHECK(!connected_); | 62 DCHECK(!connected_); |
35 | 63 |
36 connected_ = true; | 64 connected_ = true; |
37 desktop_session_connector_->ConnectTerminal(this); | 65 desktop_session_connector_->ConnectTerminal(this); |
38 | 66 |
39 DesktopEnvironment::Start(client_clipboard.Pass()); | 67 DesktopEnvironment::Start(client_clipboard.Pass()); |
40 } | 68 } |
41 | 69 |
42 void IpcDesktopEnvironment::DisconnectClient() { | 70 void IpcDesktopEnvironment::DisconnectClient() { |
| 71 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 72 |
43 client_->Disconnect(); | 73 client_->Disconnect(); |
44 } | 74 } |
45 | 75 |
| 76 void IpcDesktopEnvironment::OnDesktopSessionAgentAttached( |
| 77 IPC::PlatformFileForTransit desktop_process, |
| 78 IPC::PlatformFileForTransit desktop_pipe) { |
| 79 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 80 |
| 81 #if defined(OS_WIN) |
| 82 // On Windows: |desktop_process| is a valid handle, but |desktop_pipe| needs |
| 83 // to be duplicated from the desktop process. |
| 84 base::win::ScopedHandle pipe; |
| 85 if (!DuplicateHandle(desktop_process, desktop_pipe, GetCurrentProcess(), |
| 86 pipe.Receive(), 0, FALSE, DUPLICATE_SAME_ACCESS)) { |
| 87 LOG_GETLASTERROR(ERROR) << "Failed to duplicate the desktop-to-network" |
| 88 " pipe handle"; |
| 89 return; |
| 90 } |
| 91 |
| 92 base::ClosePlatformFile(desktop_process); |
| 93 |
| 94 // Connect to the desktop process. |
| 95 desktop_channel_.reset(new IPC::ChannelProxy(IPC::ChannelHandle(pipe), |
| 96 IPC::Channel::MODE_CLIENT, |
| 97 this, |
| 98 network_task_runner_)); |
| 99 #elif defined(OS_POSIX) |
| 100 // On posix: both |desktop_process| and |desktop_pipe| are valid file |
| 101 // descriptors. |
| 102 DCHECK(desktop_process.auto_close); |
| 103 DCHECK(desktop_pipe.auto_close); |
| 104 |
| 105 base::ClosePlatformFile(desktop_process.fd); |
| 106 |
| 107 // Connect to the desktop process. |
| 108 desktop_channel_.reset(new IPC::ChannelProxy( |
| 109 IPC::ChannelHandle("", desktop_pipe), |
| 110 IPC::Channel::MODE_CLIENT, |
| 111 this, |
| 112 network_task_runner_)); |
| 113 #else |
| 114 #error Unsupported platform. |
| 115 #endif |
| 116 } |
| 117 |
46 IpcDesktopEnvironment::~IpcDesktopEnvironment() { | 118 IpcDesktopEnvironment::~IpcDesktopEnvironment() { |
47 if (connected_) { | 119 if (connected_) { |
48 connected_ = false; | 120 connected_ = false; |
49 desktop_session_connector_->DisconnectTerminal(this); | 121 desktop_session_connector_->DisconnectTerminal(this); |
50 } | 122 } |
51 } | 123 } |
52 | 124 |
53 } // namespace remoting | 125 } // namespace remoting |
OLD | NEW |