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_agent.h" | 5 #include "remoting/host/desktop_session_agent.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ipc/ipc_channel_proxy.h" | 8 #include "ipc/ipc_channel_proxy.h" |
| 9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
| 10 #include "ipc/ipc_message_macros.h" | 10 #include "ipc/ipc_message_macros.h" |
| 11 #include "media/video/capture/screen/screen_capture_data.h" | 11 #include "media/video/capture/screen/screen_capture_data.h" |
| 12 #include "remoting/base/auto_thread_task_runner.h" | 12 #include "remoting/base/auto_thread_task_runner.h" |
| 13 #include "remoting/base/constants.h" | 13 #include "remoting/base/constants.h" |
| 14 #include "remoting/base/util.h" | 14 #include "remoting/base/util.h" |
| 15 #include "remoting/host/audio_capturer.h" | 15 #include "remoting/host/audio_capturer.h" |
| 16 #include "remoting/host/chromoting_messages.h" | 16 #include "remoting/host/chromoting_messages.h" |
| 17 #include "remoting/host/desktop_environment.h" | 17 #include "remoting/host/desktop_environment.h" |
| 18 #include "remoting/host/disconnect_window.h" | 18 #include "remoting/host/disconnect_window.h" |
| 19 #include "remoting/host/event_executor.h" | 19 #include "remoting/host/event_executor.h" |
| 20 #include "remoting/host/local_input_monitor.h" | 20 #include "remoting/host/local_input_monitor.h" |
| 21 #include "remoting/host/remote_input_filter.h" | 21 #include "remoting/host/remote_input_filter.h" |
| 22 #include "remoting/proto/audio.pb.h" | 22 #include "remoting/proto/audio.pb.h" |
| 23 #include "remoting/proto/control.pb.h" | 23 #include "remoting/proto/control.pb.h" |
| 24 #include "remoting/proto/event.pb.h" | 24 #include "remoting/proto/event.pb.h" |
| 25 #include "remoting/protocol/clipboard_stub.h" | 25 #include "remoting/protocol/clipboard_stub.h" |
| 26 #include "remoting/protocol/input_event_tracker.h" | 26 #include "remoting/protocol/input_event_tracker.h" |
| 27 #include "third_party/skia/include/core/SkRegion.h" | 27 #include "third_party/skia/include/core/SkRegion.h" |
| 28 | 28 |
| 29 #if defined(OS_POSIX) | |
| 30 #include "base/file_descriptor_posix.h" | |
|
Sergey Ulanov
2013/02/04 21:04:41
nit: don't need #ifdef here - that header should c
alexeypa (please no reviews)
2013/02/04 23:45:58
Done.
| |
| 31 #endif // defined(OS_POSIX) | |
| 32 | |
| 29 namespace remoting { | 33 namespace remoting { |
| 30 | 34 |
| 31 namespace { | 35 namespace { |
| 32 | 36 |
| 33 // USB to XKB keycode map table. | 37 // USB to XKB keycode map table. |
| 34 #define USB_KEYMAP(usb, xkb, win, mac) {usb, xkb} | 38 #define USB_KEYMAP(usb, xkb, win, mac) {usb, xkb} |
| 35 #include "ui/base/keycodes/usb_keycode_map.h" | 39 #include "ui/base/keycodes/usb_keycode_map.h" |
| 36 #undef USB_KEYMAP | 40 #undef USB_KEYMAP |
| 37 | 41 |
| 38 // Routes local clipboard events though the IPC channel to the network process. | 42 // Routes local clipboard events though the IPC channel to the network process. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 68 } // namespace | 72 } // namespace |
| 69 | 73 |
| 70 DesktopSessionAgent::Delegate::~Delegate() { | 74 DesktopSessionAgent::Delegate::~Delegate() { |
| 71 } | 75 } |
| 72 | 76 |
| 73 DesktopSessionAgent::~DesktopSessionAgent() { | 77 DesktopSessionAgent::~DesktopSessionAgent() { |
| 74 DCHECK(!audio_capturer_); | 78 DCHECK(!audio_capturer_); |
| 75 DCHECK(!disconnect_window_); | 79 DCHECK(!disconnect_window_); |
| 76 DCHECK(!local_input_monitor_); | 80 DCHECK(!local_input_monitor_); |
| 77 DCHECK(!network_channel_); | 81 DCHECK(!network_channel_); |
| 82 DCHECK(desktop_pipe_ == IPC::InvalidPlatformFileForTransit()); | |
|
Sergey Ulanov
2013/02/04 21:04:41
DCHECK_EQ
alexeypa (please no reviews)
2013/02/04 23:45:58
Done.
| |
| 78 DCHECK(!video_capturer_); | 83 DCHECK(!video_capturer_); |
| 79 } | 84 } |
| 80 | 85 |
| 81 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { | 86 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { |
| 82 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 87 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 83 | 88 |
| 84 bool handled = true; | 89 bool handled = true; |
| 85 if (started_) { | 90 if (started_) { |
| 86 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) | 91 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) |
| 87 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame, | 92 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 112 OnChannelError(); | 117 OnChannelError(); |
| 113 } | 118 } |
| 114 | 119 |
| 115 return handled; | 120 return handled; |
| 116 } | 121 } |
| 117 | 122 |
| 118 void DesktopSessionAgent::OnChannelConnected(int32 peer_pid) { | 123 void DesktopSessionAgent::OnChannelConnected(int32 peer_pid) { |
| 119 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 124 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 120 | 125 |
| 121 VLOG(1) << "IPC: desktop <- network (" << peer_pid << ")"; | 126 VLOG(1) << "IPC: desktop <- network (" << peer_pid << ")"; |
| 127 | |
| 128 CloseDesktopPipeHandle(); | |
| 122 } | 129 } |
| 123 | 130 |
| 124 void DesktopSessionAgent::OnChannelError() { | 131 void DesktopSessionAgent::OnChannelError() { |
| 125 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 132 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 126 | 133 |
| 127 // Make sure the channel is closed. | 134 // Make sure the channel is closed. |
| 128 network_channel_.reset(); | 135 network_channel_.reset(); |
| 136 CloseDesktopPipeHandle(); | |
| 129 | 137 |
| 130 // Notify the caller that the channel has been disconnected. | 138 // Notify the caller that the channel has been disconnected. |
| 131 if (delegate_.get()) | 139 if (delegate_.get()) |
| 132 delegate_->OnNetworkProcessDisconnected(); | 140 delegate_->OnNetworkProcessDisconnected(); |
| 133 } | 141 } |
| 134 | 142 |
| 135 void DesktopSessionAgent::OnLocalMouseMoved(const SkIPoint& new_pos) { | 143 void DesktopSessionAgent::OnLocalMouseMoved(const SkIPoint& new_pos) { |
| 136 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 144 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 137 | 145 |
| 138 remote_input_filter_->LocalMouseMoved(new_pos); | 146 remote_input_filter_->LocalMouseMoved(new_pos); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 } | 294 } |
| 287 | 295 |
| 288 bool DesktopSessionAgent::Start(const base::WeakPtr<Delegate>& delegate, | 296 bool DesktopSessionAgent::Start(const base::WeakPtr<Delegate>& delegate, |
| 289 IPC::PlatformFileForTransit* desktop_pipe_out) { | 297 IPC::PlatformFileForTransit* desktop_pipe_out) { |
| 290 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 298 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 291 DCHECK(delegate_.get() == NULL); | 299 DCHECK(delegate_.get() == NULL); |
| 292 | 300 |
| 293 delegate_ = delegate; | 301 delegate_ = delegate; |
| 294 | 302 |
| 295 // Create an IPC channel to communicate with the network process. | 303 // Create an IPC channel to communicate with the network process. |
| 296 return CreateChannelForNetworkProcess(desktop_pipe_out, &network_channel_); | 304 bool result = CreateChannelForNetworkProcess(&desktop_pipe_, |
| 305 &network_channel_); | |
| 306 *desktop_pipe_out = desktop_pipe_; | |
| 307 return result; | |
| 297 } | 308 } |
| 298 | 309 |
| 299 void DesktopSessionAgent::Stop() { | 310 void DesktopSessionAgent::Stop() { |
| 300 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 311 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 301 | 312 |
| 302 delegate_.reset(); | 313 delegate_.reset(); |
| 303 | 314 |
| 304 // Make sure the channel is closed. | 315 // Make sure the channel is closed. |
| 305 network_channel_.reset(); | 316 network_channel_.reset(); |
| 306 | 317 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, | 532 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, |
| 522 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 533 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 523 scoped_refptr<AutoThreadTaskRunner> input_task_runner, | 534 scoped_refptr<AutoThreadTaskRunner> input_task_runner, |
| 524 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 535 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 525 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner) | 536 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner) |
| 526 : audio_capture_task_runner_(audio_capture_task_runner), | 537 : audio_capture_task_runner_(audio_capture_task_runner), |
| 527 caller_task_runner_(caller_task_runner), | 538 caller_task_runner_(caller_task_runner), |
| 528 input_task_runner_(input_task_runner), | 539 input_task_runner_(input_task_runner), |
| 529 io_task_runner_(io_task_runner), | 540 io_task_runner_(io_task_runner), |
| 530 video_capture_task_runner_(video_capture_task_runner), | 541 video_capture_task_runner_(video_capture_task_runner), |
| 542 desktop_pipe_(IPC::InvalidPlatformFileForTransit()), | |
| 531 current_size_(SkISize::Make(0, 0)), | 543 current_size_(SkISize::Make(0, 0)), |
| 532 next_shared_buffer_id_(1), | 544 next_shared_buffer_id_(1), |
| 533 started_(false) { | 545 started_(false) { |
| 534 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 546 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 535 } | 547 } |
| 536 | 548 |
| 549 void DesktopSessionAgent::CloseDesktopPipeHandle() { | |
| 550 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | |
| 551 | |
| 552 if (desktop_pipe_ != IPC::InvalidPlatformFileForTransit()) { | |
| 553 #if defined(OS_WIN) | |
| 554 base::ClosePlatformFile(desktop_pipe_); | |
| 555 #elif defined(OS_POSIX) | |
| 556 base::ClosePlatformFile(desktop_pipe_.fd); | |
| 557 #else // !defined(OS_POSIX) | |
| 558 #error Unsupported platform. | |
| 559 #endif // !defined(OS_POSIX) | |
| 560 | |
| 561 desktop_pipe_ = IPC::InvalidPlatformFileForTransit(); | |
| 562 } | |
| 563 } | |
| 564 | |
| 537 } // namespace remoting | 565 } // namespace remoting |
| OLD | NEW |