| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
| 15 #include "base/process/process_handle.h" | 16 #include "base/process/process_handle.h" |
| 16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 18 #include "ipc/ipc_channel_proxy.h" | 19 #include "ipc/ipc_channel_proxy.h" |
| 19 #include "ipc/ipc_message_macros.h" | 20 #include "ipc/ipc_message_macros.h" |
| 20 #include "remoting/base/capabilities.h" | 21 #include "remoting/base/capabilities.h" |
| 21 #include "remoting/host/chromoting_messages.h" | 22 #include "remoting/host/chromoting_messages.h" |
| 22 #include "remoting/host/client_session.h" | 23 #include "remoting/host/client_session.h" |
| 23 #include "remoting/host/client_session_control.h" | 24 #include "remoting/host/client_session_control.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 io_task_runner_(io_task_runner), | 100 io_task_runner_(io_task_runner), |
| 100 client_session_control_(client_session_control), | 101 client_session_control_(client_session_control), |
| 101 desktop_session_connector_(desktop_session_connector), | 102 desktop_session_connector_(desktop_session_connector), |
| 102 pending_capture_frame_requests_(0), | 103 pending_capture_frame_requests_(0), |
| 103 is_desktop_session_connected_(false), | 104 is_desktop_session_connected_(false), |
| 104 virtual_terminal_(virtual_terminal), | 105 virtual_terminal_(virtual_terminal), |
| 105 supports_touch_events_(supports_touch_events) { | 106 supports_touch_events_(supports_touch_events) { |
| 106 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 107 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 107 } | 108 } |
| 108 | 109 |
| 109 scoped_ptr<AudioCapturer> DesktopSessionProxy::CreateAudioCapturer() { | 110 std::unique_ptr<AudioCapturer> DesktopSessionProxy::CreateAudioCapturer() { |
| 110 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 111 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 111 | 112 |
| 112 return make_scoped_ptr(new IpcAudioCapturer(this)); | 113 return base::WrapUnique(new IpcAudioCapturer(this)); |
| 113 } | 114 } |
| 114 | 115 |
| 115 scoped_ptr<InputInjector> DesktopSessionProxy::CreateInputInjector() { | 116 std::unique_ptr<InputInjector> DesktopSessionProxy::CreateInputInjector() { |
| 116 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 117 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 117 | 118 |
| 118 return make_scoped_ptr(new IpcInputInjector(this)); | 119 return base::WrapUnique(new IpcInputInjector(this)); |
| 119 } | 120 } |
| 120 | 121 |
| 121 scoped_ptr<ScreenControls> DesktopSessionProxy::CreateScreenControls() { | 122 std::unique_ptr<ScreenControls> DesktopSessionProxy::CreateScreenControls() { |
| 122 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 123 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 123 | 124 |
| 124 return make_scoped_ptr(new IpcScreenControls(this)); | 125 return base::WrapUnique(new IpcScreenControls(this)); |
| 125 } | 126 } |
| 126 | 127 |
| 127 scoped_ptr<webrtc::DesktopCapturer> DesktopSessionProxy::CreateVideoCapturer() { | 128 std::unique_ptr<webrtc::DesktopCapturer> |
| 129 DesktopSessionProxy::CreateVideoCapturer() { |
| 128 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 130 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 129 | 131 |
| 130 return make_scoped_ptr(new IpcVideoFrameCapturer(this)); | 132 return base::WrapUnique(new IpcVideoFrameCapturer(this)); |
| 131 } | 133 } |
| 132 | 134 |
| 133 scoped_ptr<webrtc::MouseCursorMonitor> | 135 std::unique_ptr<webrtc::MouseCursorMonitor> |
| 134 DesktopSessionProxy::CreateMouseCursorMonitor() { | 136 DesktopSessionProxy::CreateMouseCursorMonitor() { |
| 135 return make_scoped_ptr(new IpcMouseCursorMonitor(this)); | 137 return base::WrapUnique(new IpcMouseCursorMonitor(this)); |
| 136 } | 138 } |
| 137 | 139 |
| 138 std::string DesktopSessionProxy::GetCapabilities() const { | 140 std::string DesktopSessionProxy::GetCapabilities() const { |
| 139 std::string result = protocol::kRateLimitResizeRequests; | 141 std::string result = protocol::kRateLimitResizeRequests; |
| 140 // Ask the client to send its resolution unconditionally. | 142 // Ask the client to send its resolution unconditionally. |
| 141 if (virtual_terminal_) | 143 if (virtual_terminal_) |
| 142 result = result + " " + protocol::kSendInitialResolution; | 144 result = result + " " + protocol::kSendInitialResolution; |
| 143 | 145 |
| 144 if (supports_touch_events_) | 146 if (supports_touch_events_) |
| 145 result = result + " " + protocol::kTouchEventsCapability; | 147 result = result + " " + protocol::kTouchEventsCapability; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 if (!event.SerializeToString(&serialized_event)) { | 366 if (!event.SerializeToString(&serialized_event)) { |
| 365 LOG(ERROR) << "Failed to serialize protocol::TouchEvent."; | 367 LOG(ERROR) << "Failed to serialize protocol::TouchEvent."; |
| 366 return; | 368 return; |
| 367 } | 369 } |
| 368 | 370 |
| 369 SendToDesktop( | 371 SendToDesktop( |
| 370 new ChromotingNetworkDesktopMsg_InjectTouchEvent(serialized_event)); | 372 new ChromotingNetworkDesktopMsg_InjectTouchEvent(serialized_event)); |
| 371 } | 373 } |
| 372 | 374 |
| 373 void DesktopSessionProxy::StartInputInjector( | 375 void DesktopSessionProxy::StartInputInjector( |
| 374 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 376 std::unique_ptr<protocol::ClipboardStub> client_clipboard) { |
| 375 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 377 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 376 | 378 |
| 377 client_clipboard_ = std::move(client_clipboard); | 379 client_clipboard_ = std::move(client_clipboard); |
| 378 } | 380 } |
| 379 | 381 |
| 380 void DesktopSessionProxy::SetScreenResolution( | 382 void DesktopSessionProxy::SetScreenResolution( |
| 381 const ScreenResolution& resolution) { | 383 const ScreenResolution& resolution) { |
| 382 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 384 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 383 | 385 |
| 384 if (resolution.IsEmpty()) | 386 if (resolution.IsEmpty()) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 LOG(ERROR) << "Failed to find the shared buffer " << id; | 426 LOG(ERROR) << "Failed to find the shared buffer " << id; |
| 425 return nullptr; | 427 return nullptr; |
| 426 } | 428 } |
| 427 } | 429 } |
| 428 | 430 |
| 429 void DesktopSessionProxy::OnAudioPacket(const std::string& serialized_packet) { | 431 void DesktopSessionProxy::OnAudioPacket(const std::string& serialized_packet) { |
| 430 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 432 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 431 | 433 |
| 432 // Parse a serialized audio packet. No further validation is done since | 434 // Parse a serialized audio packet. No further validation is done since |
| 433 // the message was sent by more privileged process. | 435 // the message was sent by more privileged process. |
| 434 scoped_ptr<AudioPacket> packet(new AudioPacket()); | 436 std::unique_ptr<AudioPacket> packet(new AudioPacket()); |
| 435 if (!packet->ParseFromString(serialized_packet)) { | 437 if (!packet->ParseFromString(serialized_packet)) { |
| 436 LOG(ERROR) << "Failed to parse AudioPacket."; | 438 LOG(ERROR) << "Failed to parse AudioPacket."; |
| 437 return; | 439 return; |
| 438 } | 440 } |
| 439 | 441 |
| 440 // Pass a captured audio packet to |audio_capturer_|. | 442 // Pass a captured audio packet to |audio_capturer_|. |
| 441 audio_capture_task_runner_->PostTask( | 443 audio_capture_task_runner_->PostTask( |
| 442 FROM_HERE, base::Bind(&IpcAudioCapturer::OnAudioPacket, audio_capturer_, | 444 FROM_HERE, base::Bind(&IpcAudioCapturer::OnAudioPacket, audio_capturer_, |
| 443 base::Passed(&packet))); | 445 base::Passed(&packet))); |
| 444 } | 446 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 468 void DesktopSessionProxy::OnCaptureCompleted( | 470 void DesktopSessionProxy::OnCaptureCompleted( |
| 469 const SerializedDesktopFrame& serialized_frame) { | 471 const SerializedDesktopFrame& serialized_frame) { |
| 470 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 472 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 471 | 473 |
| 472 // Assume that |serialized_frame| is well-formed because it was received from | 474 // Assume that |serialized_frame| is well-formed because it was received from |
| 473 // a more privileged process. | 475 // a more privileged process. |
| 474 scoped_refptr<IpcSharedBufferCore> shared_buffer_core = | 476 scoped_refptr<IpcSharedBufferCore> shared_buffer_core = |
| 475 GetSharedBufferCore(serialized_frame.shared_buffer_id); | 477 GetSharedBufferCore(serialized_frame.shared_buffer_id); |
| 476 CHECK(shared_buffer_core.get()); | 478 CHECK(shared_buffer_core.get()); |
| 477 | 479 |
| 478 scoped_ptr<webrtc::DesktopFrame> frame( | 480 std::unique_ptr<webrtc::DesktopFrame> frame( |
| 479 new webrtc::SharedMemoryDesktopFrame( | 481 new webrtc::SharedMemoryDesktopFrame( |
| 480 serialized_frame.dimensions, serialized_frame.bytes_per_row, | 482 serialized_frame.dimensions, serialized_frame.bytes_per_row, |
| 481 new IpcSharedBuffer(shared_buffer_core))); | 483 new IpcSharedBuffer(shared_buffer_core))); |
| 482 frame->set_capture_time_ms(serialized_frame.capture_time_ms); | 484 frame->set_capture_time_ms(serialized_frame.capture_time_ms); |
| 483 frame->set_dpi(serialized_frame.dpi); | 485 frame->set_dpi(serialized_frame.dpi); |
| 484 | 486 |
| 485 for (size_t i = 0; i < serialized_frame.dirty_region.size(); ++i) { | 487 for (size_t i = 0; i < serialized_frame.dirty_region.size(); ++i) { |
| 486 frame->mutable_updated_region()->AddRect(serialized_frame.dirty_region[i]); | 488 frame->mutable_updated_region()->AddRect(serialized_frame.dirty_region[i]); |
| 487 } | 489 } |
| 488 | 490 |
| 489 --pending_capture_frame_requests_; | 491 --pending_capture_frame_requests_; |
| 490 video_capturer_->OnCaptureCompleted(std::move(frame)); | 492 video_capturer_->OnCaptureCompleted(std::move(frame)); |
| 491 } | 493 } |
| 492 | 494 |
| 493 void DesktopSessionProxy::OnMouseCursor( | 495 void DesktopSessionProxy::OnMouseCursor( |
| 494 const webrtc::MouseCursor& mouse_cursor) { | 496 const webrtc::MouseCursor& mouse_cursor) { |
| 495 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 497 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 496 | 498 |
| 497 if (mouse_cursor_monitor_) { | 499 if (mouse_cursor_monitor_) { |
| 498 mouse_cursor_monitor_->OnMouseCursor( | 500 mouse_cursor_monitor_->OnMouseCursor( |
| 499 make_scoped_ptr(webrtc::MouseCursor::CopyOf(mouse_cursor))); | 501 base::WrapUnique(webrtc::MouseCursor::CopyOf(mouse_cursor))); |
| 500 } | 502 } |
| 501 } | 503 } |
| 502 | 504 |
| 503 void DesktopSessionProxy::OnInjectClipboardEvent( | 505 void DesktopSessionProxy::OnInjectClipboardEvent( |
| 504 const std::string& serialized_event) { | 506 const std::string& serialized_event) { |
| 505 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 507 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 506 | 508 |
| 507 if (client_clipboard_) { | 509 if (client_clipboard_) { |
| 508 protocol::ClipboardEvent event; | 510 protocol::ClipboardEvent event; |
| 509 if (!event.ParseFromString(serialized_event)) { | 511 if (!event.ParseFromString(serialized_event)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 526 } | 528 } |
| 527 | 529 |
| 528 // static | 530 // static |
| 529 void DesktopSessionProxyTraits::Destruct( | 531 void DesktopSessionProxyTraits::Destruct( |
| 530 const DesktopSessionProxy* desktop_session_proxy) { | 532 const DesktopSessionProxy* desktop_session_proxy) { |
| 531 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, | 533 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, |
| 532 desktop_session_proxy); | 534 desktop_session_proxy); |
| 533 } | 535 } |
| 534 | 536 |
| 535 } // namespace remoting | 537 } // namespace remoting |
| OLD | NEW |