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/desktop_session_proxy.h" | 5 #include "remoting/host/desktop_session_proxy.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/platform_file.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "ipc/ipc_channel_proxy.h" | 12 #include "ipc/ipc_channel_proxy.h" |
13 #include "ipc/ipc_message_macros.h" | 13 #include "ipc/ipc_message_macros.h" |
14 #include "media/video/capture/screen/screen_capture_data.h" | 14 #include "media/video/capture/screen/screen_capture_data.h" |
| 15 #include "remoting/base/capabilities.h" |
15 #include "remoting/host/chromoting_messages.h" | 16 #include "remoting/host/chromoting_messages.h" |
16 #include "remoting/host/client_session.h" | 17 #include "remoting/host/client_session.h" |
17 #include "remoting/host/client_session_control.h" | 18 #include "remoting/host/client_session_control.h" |
18 #include "remoting/host/desktop_session_connector.h" | 19 #include "remoting/host/desktop_session_connector.h" |
19 #include "remoting/host/ipc_audio_capturer.h" | 20 #include "remoting/host/ipc_audio_capturer.h" |
20 #include "remoting/host/ipc_input_injector.h" | 21 #include "remoting/host/ipc_input_injector.h" |
21 #include "remoting/host/ipc_screen_controls.h" | 22 #include "remoting/host/ipc_screen_controls.h" |
22 #include "remoting/host/ipc_video_frame_capturer.h" | 23 #include "remoting/host/ipc_video_frame_capturer.h" |
23 #include "remoting/proto/audio.pb.h" | 24 #include "remoting/proto/audio.pb.h" |
24 #include "remoting/proto/control.pb.h" | 25 #include "remoting/proto/control.pb.h" |
25 #include "remoting/proto/event.pb.h" | 26 #include "remoting/proto/event.pb.h" |
26 | 27 |
27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
28 #include "base/win/scoped_handle.h" | 29 #include "base/win/scoped_handle.h" |
29 #endif // defined(OS_WIN) | 30 #endif // defined(OS_WIN) |
30 | 31 |
| 32 const char kSendInitialResolution[] = "sendInitialResolution"; |
| 33 |
31 namespace remoting { | 34 namespace remoting { |
32 | 35 |
33 DesktopSessionProxy::DesktopSessionProxy( | 36 DesktopSessionProxy::DesktopSessionProxy( |
34 scoped_refptr<base::SingleThreadTaskRunner> audio_capture_task_runner, | 37 scoped_refptr<base::SingleThreadTaskRunner> audio_capture_task_runner, |
35 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 38 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
36 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 39 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
37 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, | 40 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, |
38 base::WeakPtr<ClientSessionControl> client_session_control) | 41 base::WeakPtr<ClientSessionControl> client_session_control, |
| 42 base::WeakPtr<DesktopSessionConnector> desktop_session_connector, |
| 43 bool virtual_terminal) |
39 : audio_capture_task_runner_(audio_capture_task_runner), | 44 : audio_capture_task_runner_(audio_capture_task_runner), |
40 caller_task_runner_(caller_task_runner), | 45 caller_task_runner_(caller_task_runner), |
41 io_task_runner_(io_task_runner), | 46 io_task_runner_(io_task_runner), |
42 video_capture_task_runner_(video_capture_task_runner), | 47 video_capture_task_runner_(video_capture_task_runner), |
43 client_session_control_(client_session_control), | 48 client_session_control_(client_session_control), |
| 49 desktop_session_connector_(desktop_session_connector), |
44 desktop_process_(base::kNullProcessHandle), | 50 desktop_process_(base::kNullProcessHandle), |
45 pending_capture_frame_requests_(0) { | 51 pending_capture_frame_requests_(0), |
| 52 is_desktop_session_connected_(false), |
| 53 virtual_terminal_(virtual_terminal) { |
46 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 54 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
47 } | 55 } |
48 | 56 |
49 scoped_ptr<AudioCapturer> DesktopSessionProxy::CreateAudioCapturer() { | 57 scoped_ptr<AudioCapturer> DesktopSessionProxy::CreateAudioCapturer() { |
50 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 58 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
51 | 59 |
52 return scoped_ptr<AudioCapturer>(new IpcAudioCapturer(this)); | 60 return scoped_ptr<AudioCapturer>(new IpcAudioCapturer(this)); |
53 } | 61 } |
54 | 62 |
55 scoped_ptr<InputInjector> DesktopSessionProxy::CreateInputInjector() { | 63 scoped_ptr<InputInjector> DesktopSessionProxy::CreateInputInjector() { |
56 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 64 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
57 | 65 |
58 return scoped_ptr<InputInjector>(new IpcInputInjector(this)); | 66 return scoped_ptr<InputInjector>(new IpcInputInjector(this)); |
59 } | 67 } |
60 | 68 |
61 scoped_ptr<ScreenControls> DesktopSessionProxy::CreateScreenControls() { | 69 scoped_ptr<ScreenControls> DesktopSessionProxy::CreateScreenControls() { |
62 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 70 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
63 | 71 |
64 return scoped_ptr<ScreenControls>(new IpcScreenControls(this)); | 72 return scoped_ptr<ScreenControls>(new IpcScreenControls(this)); |
65 } | 73 } |
66 | 74 |
67 scoped_ptr<media::ScreenCapturer> DesktopSessionProxy::CreateVideoCapturer() { | 75 scoped_ptr<media::ScreenCapturer> DesktopSessionProxy::CreateVideoCapturer() { |
68 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 76 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
69 | 77 |
70 return scoped_ptr<media::ScreenCapturer>(new IpcVideoFrameCapturer(this)); | 78 return scoped_ptr<media::ScreenCapturer>(new IpcVideoFrameCapturer(this)); |
71 } | 79 } |
72 | 80 |
| 81 std::string DesktopSessionProxy::GetCapabilities() const { |
| 82 // Ask the client to send it's resolution unconditionally. |
| 83 return virtual_terminal_ ? kSendInitialResolution : std::string(); |
| 84 } |
| 85 |
| 86 void DesktopSessionProxy::SetCapabilities(const std::string& capabilities) { |
| 87 // Delay creation of the desktop session until the client screen resolution is |
| 88 // received if the desktop session requires the initial screen resolution |
| 89 // (when |virtual_terminal_| is true) and the client is expected to |
| 90 // sent its screen resolution (the 'sendInitialResolution' capability is |
| 91 // supported). |
| 92 if (virtual_terminal_ && |
| 93 HasCapability(capabilities, kSendInitialResolution)) { |
| 94 VLOG(1) << "Waiting for the client screen resolution."; |
| 95 return; |
| 96 } |
| 97 |
| 98 // Connect to the desktop session. |
| 99 if (!is_desktop_session_connected_) { |
| 100 is_desktop_session_connected_ = true; |
| 101 if (desktop_session_connector_) { |
| 102 desktop_session_connector_->ConnectTerminal(this, screen_resolution_, |
| 103 virtual_terminal_); |
| 104 } |
| 105 } |
| 106 } |
| 107 |
73 bool DesktopSessionProxy::OnMessageReceived(const IPC::Message& message) { | 108 bool DesktopSessionProxy::OnMessageReceived(const IPC::Message& message) { |
74 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 109 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
75 | 110 |
76 bool handled = true; | 111 bool handled = true; |
77 IPC_BEGIN_MESSAGE_MAP(DesktopSessionProxy, message) | 112 IPC_BEGIN_MESSAGE_MAP(DesktopSessionProxy, message) |
78 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_AudioPacket, | 113 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_AudioPacket, |
79 OnAudioPacket) | 114 OnAudioPacket) |
80 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CaptureCompleted, | 115 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CaptureCompleted, |
81 OnCaptureCompleted) | 116 OnCaptureCompleted) |
82 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CursorShapeChanged, | 117 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CursorShapeChanged, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 316 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
282 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 317 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
283 | 318 |
284 client_clipboard_ = client_clipboard.Pass(); | 319 client_clipboard_ = client_clipboard.Pass(); |
285 } | 320 } |
286 | 321 |
287 void DesktopSessionProxy::SetScreenResolution( | 322 void DesktopSessionProxy::SetScreenResolution( |
288 const ScreenResolution& resolution) { | 323 const ScreenResolution& resolution) { |
289 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 324 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
290 | 325 |
291 screen_resolution_ = resolution; | 326 if (!resolution.IsValid()) |
292 if (!screen_resolution_.IsValid()) | |
293 return; | 327 return; |
294 | 328 |
| 329 screen_resolution_ = resolution; |
| 330 |
| 331 // Connect to the desktop session if it is not done yet. |
| 332 if (!is_desktop_session_connected_) { |
| 333 is_desktop_session_connected_ = true; |
| 334 if (desktop_session_connector_) { |
| 335 desktop_session_connector_->ConnectTerminal(this, screen_resolution_, |
| 336 virtual_terminal_); |
| 337 } |
| 338 return; |
| 339 } |
| 340 |
295 // Pass the client's resolution to both daemon and desktop session agent. | 341 // Pass the client's resolution to both daemon and desktop session agent. |
296 // Depending on the session kind the screen resolution ccan be set by either | 342 // Depending on the session kind the screen resolution can be set by either |
297 // the daemon (for example RDP sessions on Windows) or by the desktop session | 343 // the daemon (for example RDP sessions on Windows) or by the desktop session |
298 // agent (when sharing the physical console). | 344 // agent (when sharing the physical console). |
299 if (desktop_session_connector_) | 345 if (desktop_session_connector_) |
300 desktop_session_connector_->SetScreenResolution(this, resolution); | 346 desktop_session_connector_->SetScreenResolution(this, screen_resolution_); |
301 SendToDesktop( | 347 SendToDesktop( |
302 new ChromotingNetworkDesktopMsg_SetScreenResolution(resolution)); | 348 new ChromotingNetworkDesktopMsg_SetScreenResolution(screen_resolution_)); |
303 } | |
304 | |
305 void DesktopSessionProxy::ConnectToDesktopSession( | |
306 base::WeakPtr<DesktopSessionConnector> desktop_session_connector, | |
307 bool virtual_terminal) { | |
308 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | |
309 DCHECK(!desktop_session_connector_); | |
310 DCHECK(desktop_session_connector); | |
311 | |
312 desktop_session_connector_ = desktop_session_connector; | |
313 desktop_session_connector_->ConnectTerminal( | |
314 this, ScreenResolution(), virtual_terminal); | |
315 } | 349 } |
316 | 350 |
317 DesktopSessionProxy::~DesktopSessionProxy() { | 351 DesktopSessionProxy::~DesktopSessionProxy() { |
318 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 352 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
319 | 353 |
320 if (desktop_session_connector_) | 354 if (desktop_session_connector_ && is_desktop_session_connected_) |
321 desktop_session_connector_->DisconnectTerminal(this); | 355 desktop_session_connector_->DisconnectTerminal(this); |
322 | 356 |
323 if (desktop_process_ != base::kNullProcessHandle) { | 357 if (desktop_process_ != base::kNullProcessHandle) { |
324 base::CloseProcessHandle(desktop_process_); | 358 base::CloseProcessHandle(desktop_process_); |
325 desktop_process_ = base::kNullProcessHandle; | 359 desktop_process_ = base::kNullProcessHandle; |
326 } | 360 } |
327 } | 361 } |
328 | 362 |
329 scoped_refptr<media::SharedBuffer> DesktopSessionProxy::GetSharedBuffer( | 363 scoped_refptr<media::SharedBuffer> DesktopSessionProxy::GetSharedBuffer( |
330 int id) { | 364 int id) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 } | 521 } |
488 | 522 |
489 // static | 523 // static |
490 void DesktopSessionProxyTraits::Destruct( | 524 void DesktopSessionProxyTraits::Destruct( |
491 const DesktopSessionProxy* desktop_session_proxy) { | 525 const DesktopSessionProxy* desktop_session_proxy) { |
492 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, | 526 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, |
493 desktop_session_proxy); | 527 desktop_session_proxy); |
494 } | 528 } |
495 | 529 |
496 } // namespace remoting | 530 } // namespace remoting |
OLD | NEW |