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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 class SharedMemoryFactoryImpl : public webrtc::SharedMemoryFactory { | 112 class SharedMemoryFactoryImpl : public webrtc::SharedMemoryFactory { |
113 public: | 113 public: |
114 typedef base::Callback<void(std::unique_ptr<IPC::Message> message)> | 114 typedef base::Callback<void(std::unique_ptr<IPC::Message> message)> |
115 SendMessageCallback; | 115 SendMessageCallback; |
116 | 116 |
117 SharedMemoryFactoryImpl(const SendMessageCallback& send_message_callback) | 117 SharedMemoryFactoryImpl(const SendMessageCallback& send_message_callback) |
118 : send_message_callback_(send_message_callback) {} | 118 : send_message_callback_(send_message_callback) {} |
119 | 119 |
120 std::unique_ptr<webrtc::SharedMemory> CreateSharedMemory( | 120 std::unique_ptr<webrtc::SharedMemory> CreateSharedMemory( |
121 size_t size) override { | 121 size_t size) override { |
122 base::Closure release_buffer_callback = | 122 base::Closure release_buffer_callback = base::Bind( |
123 base::Bind(send_message_callback_, | 123 send_message_callback_, |
124 base::Passed(base::WrapUnique( | 124 base::Passed( |
125 new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer( | 125 base::MakeUnique<ChromotingDesktopNetworkMsg_ReleaseSharedBuffer>( |
126 next_shared_buffer_id_)))); | 126 next_shared_buffer_id_))); |
127 std::unique_ptr<SharedMemoryImpl> buffer = SharedMemoryImpl::Create( | 127 std::unique_ptr<SharedMemoryImpl> buffer = SharedMemoryImpl::Create( |
128 size, next_shared_buffer_id_, release_buffer_callback); | 128 size, next_shared_buffer_id_, release_buffer_callback); |
129 if (buffer) { | 129 if (buffer) { |
130 // |next_shared_buffer_id_| starts from 1 and incrementing it by 2 makes | 130 // |next_shared_buffer_id_| starts from 1 and incrementing it by 2 makes |
131 // sure it is always odd and therefore zero is never used as a valid | 131 // sure it is always odd and therefore zero is never used as a valid |
132 // buffer ID. | 132 // buffer ID. |
133 // | 133 // |
134 // It is very unlikely (though theoretically possible) to allocate the | 134 // It is very unlikely (though theoretically possible) to allocate the |
135 // same ID for two different buffers due to integer overflow. It should | 135 // same ID for two different buffers due to integer overflow. It should |
136 // take about a year of allocating 100 new buffers every second. | 136 // take about a year of allocating 100 new buffers every second. |
137 // Practically speaking it never happens. | 137 // Practically speaking it never happens. |
138 next_shared_buffer_id_ += 2; | 138 next_shared_buffer_id_ += 2; |
139 | 139 |
140 send_message_callback_.Run( | 140 send_message_callback_.Run( |
141 base::WrapUnique(new ChromotingDesktopNetworkMsg_CreateSharedBuffer( | 141 base::MakeUnique<ChromotingDesktopNetworkMsg_CreateSharedBuffer>( |
142 buffer->id(), buffer->shared_memory()->handle(), | 142 buffer->id(), buffer->shared_memory()->handle(), buffer->size())); |
143 buffer->size()))); | |
144 } | 143 } |
145 | 144 |
146 return std::move(buffer); | 145 return std::move(buffer); |
147 } | 146 } |
148 | 147 |
149 private: | 148 private: |
150 int next_shared_buffer_id_ = 1; | 149 int next_shared_buffer_id_ = 1; |
151 SendMessageCallback send_message_callback_; | 150 SendMessageCallback send_message_callback_; |
152 | 151 |
153 DISALLOW_COPY_AND_ASSIGN(SharedMemoryFactoryImpl); | 152 DISALLOW_COPY_AND_ASSIGN(SharedMemoryFactoryImpl); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 DCHECK(!network_channel_); | 233 DCHECK(!network_channel_); |
235 DCHECK(!screen_controls_); | 234 DCHECK(!screen_controls_); |
236 DCHECK(!video_capturer_); | 235 DCHECK(!video_capturer_); |
237 } | 236 } |
238 | 237 |
239 const std::string& DesktopSessionAgent::client_jid() const { | 238 const std::string& DesktopSessionAgent::client_jid() const { |
240 return client_jid_; | 239 return client_jid_; |
241 } | 240 } |
242 | 241 |
243 void DesktopSessionAgent::DisconnectSession(protocol::ErrorCode error) { | 242 void DesktopSessionAgent::DisconnectSession(protocol::ErrorCode error) { |
244 SendToNetwork(base::WrapUnique( | 243 SendToNetwork( |
245 new ChromotingDesktopNetworkMsg_DisconnectSession(error))); | 244 base::MakeUnique<ChromotingDesktopNetworkMsg_DisconnectSession>(error)); |
246 } | 245 } |
247 | 246 |
248 void DesktopSessionAgent::OnLocalMouseMoved( | 247 void DesktopSessionAgent::OnLocalMouseMoved( |
249 const webrtc::DesktopVector& new_pos) { | 248 const webrtc::DesktopVector& new_pos) { |
250 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 249 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
251 | 250 |
252 remote_input_filter_->LocalMouseMoved(new_pos); | 251 remote_input_filter_->LocalMouseMoved(new_pos); |
253 } | 252 } |
254 | 253 |
255 void DesktopSessionAgent::SetDisableInputs(bool disable_inputs) { | 254 void DesktopSessionAgent::SetDisableInputs(bool disable_inputs) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 serialized_frame.capture_time_ms = frame->capture_time_ms(); | 334 serialized_frame.capture_time_ms = frame->capture_time_ms(); |
336 serialized_frame.dpi = frame->dpi(); | 335 serialized_frame.dpi = frame->dpi(); |
337 for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); | 336 for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); |
338 !i.IsAtEnd(); i.Advance()) { | 337 !i.IsAtEnd(); i.Advance()) { |
339 serialized_frame.dirty_region.push_back(i.rect()); | 338 serialized_frame.dirty_region.push_back(i.rect()); |
340 } | 339 } |
341 } | 340 } |
342 | 341 |
343 last_frame_ = std::move(frame); | 342 last_frame_ = std::move(frame); |
344 | 343 |
345 SendToNetwork(base::WrapUnique( | 344 SendToNetwork(base::MakeUnique<ChromotingDesktopNetworkMsg_CaptureResult>( |
346 new ChromotingDesktopNetworkMsg_CaptureResult(result, serialized_frame))); | 345 result, serialized_frame)); |
347 } | 346 } |
348 | 347 |
349 void DesktopSessionAgent::OnMouseCursor(webrtc::MouseCursor* cursor) { | 348 void DesktopSessionAgent::OnMouseCursor(webrtc::MouseCursor* cursor) { |
350 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 349 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
351 | 350 |
352 std::unique_ptr<webrtc::MouseCursor> owned_cursor(cursor); | 351 std::unique_ptr<webrtc::MouseCursor> owned_cursor(cursor); |
353 | 352 |
354 SendToNetwork(base::WrapUnique( | 353 SendToNetwork( |
355 new ChromotingDesktopNetworkMsg_MouseCursor(*owned_cursor))); | 354 base::MakeUnique<ChromotingDesktopNetworkMsg_MouseCursor>(*owned_cursor)); |
356 } | 355 } |
357 | 356 |
358 void DesktopSessionAgent::OnMouseCursorPosition( | 357 void DesktopSessionAgent::OnMouseCursorPosition( |
359 webrtc::MouseCursorMonitor::CursorState state, | 358 webrtc::MouseCursorMonitor::CursorState state, |
360 const webrtc::DesktopVector& position) { | 359 const webrtc::DesktopVector& position) { |
361 // We're not subscribing to mouse position changes. | 360 // We're not subscribing to mouse position changes. |
362 NOTREACHED(); | 361 NOTREACHED(); |
363 } | 362 } |
364 | 363 |
365 void DesktopSessionAgent::InjectClipboardEvent( | 364 void DesktopSessionAgent::InjectClipboardEvent( |
366 const protocol::ClipboardEvent& event) { | 365 const protocol::ClipboardEvent& event) { |
367 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 366 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
368 | 367 |
369 std::string serialized_event; | 368 std::string serialized_event; |
370 if (!event.SerializeToString(&serialized_event)) { | 369 if (!event.SerializeToString(&serialized_event)) { |
371 LOG(ERROR) << "Failed to serialize protocol::ClipboardEvent."; | 370 LOG(ERROR) << "Failed to serialize protocol::ClipboardEvent."; |
372 return; | 371 return; |
373 } | 372 } |
374 | 373 |
375 SendToNetwork(base::WrapUnique( | 374 SendToNetwork( |
376 new ChromotingDesktopNetworkMsg_InjectClipboardEvent(serialized_event))); | 375 base::MakeUnique<ChromotingDesktopNetworkMsg_InjectClipboardEvent>( |
| 376 serialized_event)); |
377 } | 377 } |
378 | 378 |
379 void DesktopSessionAgent::ProcessAudioPacket( | 379 void DesktopSessionAgent::ProcessAudioPacket( |
380 std::unique_ptr<AudioPacket> packet) { | 380 std::unique_ptr<AudioPacket> packet) { |
381 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); | 381 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); |
382 | 382 |
383 std::string serialized_packet; | 383 std::string serialized_packet; |
384 if (!packet->SerializeToString(&serialized_packet)) { | 384 if (!packet->SerializeToString(&serialized_packet)) { |
385 LOG(ERROR) << "Failed to serialize AudioPacket."; | 385 LOG(ERROR) << "Failed to serialize AudioPacket."; |
386 return; | 386 return; |
387 } | 387 } |
388 | 388 |
389 SendToNetwork(base::WrapUnique( | 389 SendToNetwork(base::MakeUnique<ChromotingDesktopNetworkMsg_AudioPacket>( |
390 new ChromotingDesktopNetworkMsg_AudioPacket(serialized_packet))); | 390 serialized_packet)); |
391 } | 391 } |
392 | 392 |
393 bool DesktopSessionAgent::Start(const base::WeakPtr<Delegate>& delegate, | 393 bool DesktopSessionAgent::Start(const base::WeakPtr<Delegate>& delegate, |
394 IPC::PlatformFileForTransit* desktop_pipe_out) { | 394 IPC::PlatformFileForTransit* desktop_pipe_out) { |
395 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 395 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
396 DCHECK(delegate_.get() == nullptr); | 396 DCHECK(delegate_.get() == nullptr); |
397 | 397 |
398 delegate_ = delegate; | 398 delegate_ = delegate; |
399 | 399 |
400 // Create an IPC channel to communicate with the network process. | 400 // Create an IPC channel to communicate with the network process. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 } | 580 } |
581 } | 581 } |
582 | 582 |
583 void DesktopSessionAgent::StopAudioCapturer() { | 583 void DesktopSessionAgent::StopAudioCapturer() { |
584 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); | 584 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); |
585 | 585 |
586 audio_capturer_.reset(); | 586 audio_capturer_.reset(); |
587 } | 587 } |
588 | 588 |
589 } // namespace remoting | 589 } // namespace remoting |
OLD | NEW |