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