Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: remoting/host/desktop_session_agent.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/desktop_session_agent.h ('k') | remoting/host/desktop_session_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
12 #include "base/memory/shared_memory.h" 13 #include "base/memory/shared_memory.h"
13 #include "base/process/process_handle.h" 14 #include "base/process/process_handle.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 #include "ipc/ipc_channel_proxy.h" 16 #include "ipc/ipc_channel_proxy.h"
16 #include "ipc/ipc_message.h" 17 #include "ipc/ipc_message.h"
17 #include "ipc/ipc_message_macros.h" 18 #include "ipc/ipc_message_macros.h"
18 #include "remoting/base/auto_thread_task_runner.h" 19 #include "remoting/base/auto_thread_task_runner.h"
19 #include "remoting/base/constants.h" 20 #include "remoting/base/constants.h"
20 #include "remoting/host/audio_capturer.h" 21 #include "remoting/host/audio_capturer.h"
21 #include "remoting/host/chromoting_messages.h" 22 #include "remoting/host/chromoting_messages.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 DesktopSessionClipboardStub::~DesktopSessionClipboardStub() {} 64 DesktopSessionClipboardStub::~DesktopSessionClipboardStub() {}
64 65
65 void DesktopSessionClipboardStub::InjectClipboardEvent( 66 void DesktopSessionClipboardStub::InjectClipboardEvent(
66 const protocol::ClipboardEvent& event) { 67 const protocol::ClipboardEvent& event) {
67 desktop_session_agent_->InjectClipboardEvent(event); 68 desktop_session_agent_->InjectClipboardEvent(event);
68 } 69 }
69 70
70 // webrtc::SharedMemory implementation that creates base::SharedMemory. 71 // webrtc::SharedMemory implementation that creates base::SharedMemory.
71 class SharedMemoryImpl : public webrtc::SharedMemory { 72 class SharedMemoryImpl : public webrtc::SharedMemory {
72 public: 73 public:
73 static scoped_ptr<SharedMemoryImpl> 74 static std::unique_ptr<SharedMemoryImpl>
74 Create(size_t size, int id, const base::Closure& on_deleted_callback) { 75 Create(size_t size, int id, const base::Closure& on_deleted_callback) {
75 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory()); 76 std::unique_ptr<base::SharedMemory> memory(new base::SharedMemory());
76 if (!memory->CreateAndMapAnonymous(size)) 77 if (!memory->CreateAndMapAnonymous(size))
77 return nullptr; 78 return nullptr;
78 return make_scoped_ptr( 79 return base::WrapUnique(
79 new SharedMemoryImpl(std::move(memory), size, id, on_deleted_callback)); 80 new SharedMemoryImpl(std::move(memory), size, id, on_deleted_callback));
80 } 81 }
81 82
82 ~SharedMemoryImpl() override { on_deleted_callback_.Run(); } 83 ~SharedMemoryImpl() override { on_deleted_callback_.Run(); }
83 84
84 base::SharedMemory* shared_memory() { return shared_memory_.get(); } 85 base::SharedMemory* shared_memory() { return shared_memory_.get(); }
85 86
86 private: 87 private:
87 SharedMemoryImpl(scoped_ptr<base::SharedMemory> memory, 88 SharedMemoryImpl(std::unique_ptr<base::SharedMemory> memory,
88 size_t size, 89 size_t size,
89 int id, 90 int id,
90 const base::Closure& on_deleted_callback) 91 const base::Closure& on_deleted_callback)
91 : SharedMemory(memory->memory(), 92 : SharedMemory(memory->memory(),
92 size, 93 size,
93 // webrtc::ScreenCapturer uses webrtc::SharedMemory::handle() only on Windows. 94 // webrtc::ScreenCapturer uses webrtc::SharedMemory::handle() only on Windows.
94 #if defined(OS_WIN) 95 #if defined(OS_WIN)
95 memory->handle().GetHandle(), 96 memory->handle().GetHandle(),
96 #else 97 #else
97 0, 98 0,
98 #endif 99 #endif
99 id), 100 id),
100 on_deleted_callback_(on_deleted_callback), 101 on_deleted_callback_(on_deleted_callback),
101 shared_memory_(std::move(memory)) { 102 shared_memory_(std::move(memory)) {
102 } 103 }
103 104
104 base::Closure on_deleted_callback_; 105 base::Closure on_deleted_callback_;
105 scoped_ptr<base::SharedMemory> shared_memory_; 106 std::unique_ptr<base::SharedMemory> shared_memory_;
106 107
107 DISALLOW_COPY_AND_ASSIGN(SharedMemoryImpl); 108 DISALLOW_COPY_AND_ASSIGN(SharedMemoryImpl);
108 }; 109 };
109 110
110 class SharedMemoryFactoryImpl : public webrtc::SharedMemoryFactory { 111 class SharedMemoryFactoryImpl : public webrtc::SharedMemoryFactory {
111 public: 112 public:
112 typedef base::Callback<void(scoped_ptr<IPC::Message> message)> 113 typedef base::Callback<void(std::unique_ptr<IPC::Message> message)>
113 SendMessageCallback; 114 SendMessageCallback;
114 115
115 SharedMemoryFactoryImpl(const SendMessageCallback& send_message_callback) 116 SharedMemoryFactoryImpl(const SendMessageCallback& send_message_callback)
116 : send_message_callback_(send_message_callback) {} 117 : send_message_callback_(send_message_callback) {}
117 118
118 rtc::scoped_ptr<webrtc::SharedMemory> CreateSharedMemory( 119 rtc::scoped_ptr<webrtc::SharedMemory> CreateSharedMemory(
119 size_t size) override { 120 size_t size) override {
120 base::Closure release_buffer_callback = base::Bind( 121 base::Closure release_buffer_callback =
121 send_message_callback_, 122 base::Bind(send_message_callback_,
122 base::Passed( 123 base::Passed(base::WrapUnique(
123 make_scoped_ptr(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer( 124 new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(
124 next_shared_buffer_id_)))); 125 next_shared_buffer_id_))));
125 scoped_ptr<SharedMemoryImpl> buffer = SharedMemoryImpl::Create( 126 std::unique_ptr<SharedMemoryImpl> buffer = SharedMemoryImpl::Create(
126 size, next_shared_buffer_id_, release_buffer_callback); 127 size, next_shared_buffer_id_, release_buffer_callback);
127 if (buffer) { 128 if (buffer) {
128 // |next_shared_buffer_id_| starts from 1 and incrementing it by 2 makes 129 // |next_shared_buffer_id_| starts from 1 and incrementing it by 2 makes
129 // sure it is always odd and therefore zero is never used as a valid 130 // sure it is always odd and therefore zero is never used as a valid
130 // buffer ID. 131 // buffer ID.
131 // 132 //
132 // It is very unlikely (though theoretically possible) to allocate the 133 // It is very unlikely (though theoretically possible) to allocate the
133 // same ID for two different buffers due to integer overflow. It should 134 // same ID for two different buffers due to integer overflow. It should
134 // take about a year of allocating 100 new buffers every second. 135 // take about a year of allocating 100 new buffers every second.
135 // Practically speaking it never happens. 136 // Practically speaking it never happens.
136 next_shared_buffer_id_ += 2; 137 next_shared_buffer_id_ += 2;
137 138
138 send_message_callback_.Run( 139 send_message_callback_.Run(
139 make_scoped_ptr(new ChromotingDesktopNetworkMsg_CreateSharedBuffer( 140 base::WrapUnique(new ChromotingDesktopNetworkMsg_CreateSharedBuffer(
140 buffer->id(), buffer->shared_memory()->handle(), 141 buffer->id(), buffer->shared_memory()->handle(),
141 buffer->size()))); 142 buffer->size())));
142 } 143 }
143 144
144 return rtc_make_scoped_ptr(buffer.release()); 145 return rtc_make_scoped_ptr(buffer.release());
145 } 146 }
146 147
147 private: 148 private:
148 int next_shared_buffer_id_ = 1; 149 int next_shared_buffer_id_ = 1;
149 SendMessageCallback send_message_callback_; 150 SendMessageCallback send_message_callback_;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 DCHECK(!network_channel_); 229 DCHECK(!network_channel_);
229 DCHECK(!screen_controls_); 230 DCHECK(!screen_controls_);
230 DCHECK(!video_capturer_); 231 DCHECK(!video_capturer_);
231 } 232 }
232 233
233 const std::string& DesktopSessionAgent::client_jid() const { 234 const std::string& DesktopSessionAgent::client_jid() const {
234 return client_jid_; 235 return client_jid_;
235 } 236 }
236 237
237 void DesktopSessionAgent::DisconnectSession(protocol::ErrorCode error) { 238 void DesktopSessionAgent::DisconnectSession(protocol::ErrorCode error) {
238 SendToNetwork(make_scoped_ptr( 239 SendToNetwork(base::WrapUnique(
239 new ChromotingDesktopNetworkMsg_DisconnectSession(error))); 240 new ChromotingDesktopNetworkMsg_DisconnectSession(error)));
240 } 241 }
241 242
242 void DesktopSessionAgent::OnLocalMouseMoved( 243 void DesktopSessionAgent::OnLocalMouseMoved(
243 const webrtc::DesktopVector& new_pos) { 244 const webrtc::DesktopVector& new_pos) {
244 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 245 DCHECK(caller_task_runner_->BelongsToCurrentThread());
245 246
246 remote_input_filter_->LocalMouseMoved(new_pos); 247 remote_input_filter_->LocalMouseMoved(new_pos);
247 } 248 }
248 249
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 input_tracker_.reset(new protocol::InputEventTracker(input_injector_.get())); 288 input_tracker_.reset(new protocol::InputEventTracker(input_injector_.get()));
288 remote_input_filter_.reset(new RemoteInputFilter(input_tracker_.get())); 289 remote_input_filter_.reset(new RemoteInputFilter(input_tracker_.get()));
289 290
290 #if defined(OS_WIN) 291 #if defined(OS_WIN)
291 // LocalInputMonitorWin filters out an echo of the injected input before it 292 // LocalInputMonitorWin filters out an echo of the injected input before it
292 // reaches |remote_input_filter_|. 293 // reaches |remote_input_filter_|.
293 remote_input_filter_->SetExpectLocalEcho(false); 294 remote_input_filter_->SetExpectLocalEcho(false);
294 #endif // defined(OS_WIN) 295 #endif // defined(OS_WIN)
295 296
296 // Start the input injector. 297 // Start the input injector.
297 scoped_ptr<protocol::ClipboardStub> clipboard_stub( 298 std::unique_ptr<protocol::ClipboardStub> clipboard_stub(
298 new DesktopSessionClipboardStub(this)); 299 new DesktopSessionClipboardStub(this));
299 input_injector_->Start(std::move(clipboard_stub)); 300 input_injector_->Start(std::move(clipboard_stub));
300 301
301 // Start the audio capturer. 302 // Start the audio capturer.
302 if (delegate_->desktop_environment_factory().SupportsAudioCapture()) { 303 if (delegate_->desktop_environment_factory().SupportsAudioCapture()) {
303 audio_capturer_ = desktop_environment_->CreateAudioCapturer(); 304 audio_capturer_ = desktop_environment_->CreateAudioCapturer();
304 audio_capture_task_runner_->PostTask( 305 audio_capture_task_runner_->PostTask(
305 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this)); 306 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this));
306 } 307 }
307 308
(...skipping 19 matching lines...) Expand all
327 serialized_frame.shared_buffer_id = frame->shared_memory()->id(); 328 serialized_frame.shared_buffer_id = frame->shared_memory()->id();
328 serialized_frame.bytes_per_row = frame->stride(); 329 serialized_frame.bytes_per_row = frame->stride();
329 serialized_frame.dimensions = frame->size(); 330 serialized_frame.dimensions = frame->size();
330 serialized_frame.capture_time_ms = frame->capture_time_ms(); 331 serialized_frame.capture_time_ms = frame->capture_time_ms();
331 serialized_frame.dpi = frame->dpi(); 332 serialized_frame.dpi = frame->dpi();
332 for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); 333 for (webrtc::DesktopRegion::Iterator i(frame->updated_region());
333 !i.IsAtEnd(); i.Advance()) { 334 !i.IsAtEnd(); i.Advance()) {
334 serialized_frame.dirty_region.push_back(i.rect()); 335 serialized_frame.dirty_region.push_back(i.rect());
335 } 336 }
336 337
337 SendToNetwork(make_scoped_ptr( 338 SendToNetwork(base::WrapUnique(
338 new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_frame))); 339 new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_frame)));
339 } 340 }
340 341
341 void DesktopSessionAgent::OnMouseCursor(webrtc::MouseCursor* cursor) { 342 void DesktopSessionAgent::OnMouseCursor(webrtc::MouseCursor* cursor) {
342 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 343 DCHECK(caller_task_runner_->BelongsToCurrentThread());
343 344
344 scoped_ptr<webrtc::MouseCursor> owned_cursor(cursor); 345 std::unique_ptr<webrtc::MouseCursor> owned_cursor(cursor);
345 346
346 SendToNetwork(make_scoped_ptr( 347 SendToNetwork(base::WrapUnique(
347 new ChromotingDesktopNetworkMsg_MouseCursor(*owned_cursor))); 348 new ChromotingDesktopNetworkMsg_MouseCursor(*owned_cursor)));
348 } 349 }
349 350
350 void DesktopSessionAgent::OnMouseCursorPosition( 351 void DesktopSessionAgent::OnMouseCursorPosition(
351 webrtc::MouseCursorMonitor::CursorState state, 352 webrtc::MouseCursorMonitor::CursorState state,
352 const webrtc::DesktopVector& position) { 353 const webrtc::DesktopVector& position) {
353 // We're not subscribing to mouse position changes. 354 // We're not subscribing to mouse position changes.
354 NOTREACHED(); 355 NOTREACHED();
355 } 356 }
356 357
357 void DesktopSessionAgent::InjectClipboardEvent( 358 void DesktopSessionAgent::InjectClipboardEvent(
358 const protocol::ClipboardEvent& event) { 359 const protocol::ClipboardEvent& event) {
359 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 360 DCHECK(caller_task_runner_->BelongsToCurrentThread());
360 361
361 std::string serialized_event; 362 std::string serialized_event;
362 if (!event.SerializeToString(&serialized_event)) { 363 if (!event.SerializeToString(&serialized_event)) {
363 LOG(ERROR) << "Failed to serialize protocol::ClipboardEvent."; 364 LOG(ERROR) << "Failed to serialize protocol::ClipboardEvent.";
364 return; 365 return;
365 } 366 }
366 367
367 SendToNetwork(make_scoped_ptr( 368 SendToNetwork(base::WrapUnique(
368 new ChromotingDesktopNetworkMsg_InjectClipboardEvent(serialized_event))); 369 new ChromotingDesktopNetworkMsg_InjectClipboardEvent(serialized_event)));
369 } 370 }
370 371
371 void DesktopSessionAgent::ProcessAudioPacket(scoped_ptr<AudioPacket> packet) { 372 void DesktopSessionAgent::ProcessAudioPacket(
373 std::unique_ptr<AudioPacket> packet) {
372 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); 374 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread());
373 375
374 std::string serialized_packet; 376 std::string serialized_packet;
375 if (!packet->SerializeToString(&serialized_packet)) { 377 if (!packet->SerializeToString(&serialized_packet)) {
376 LOG(ERROR) << "Failed to serialize AudioPacket."; 378 LOG(ERROR) << "Failed to serialize AudioPacket.";
377 return; 379 return;
378 } 380 }
379 381
380 SendToNetwork(make_scoped_ptr( 382 SendToNetwork(base::WrapUnique(
381 new ChromotingDesktopNetworkMsg_AudioPacket(serialized_packet))); 383 new ChromotingDesktopNetworkMsg_AudioPacket(serialized_packet)));
382 } 384 }
383 385
384 bool DesktopSessionAgent::Start(const base::WeakPtr<Delegate>& delegate, 386 bool DesktopSessionAgent::Start(const base::WeakPtr<Delegate>& delegate,
385 IPC::PlatformFileForTransit* desktop_pipe_out) { 387 IPC::PlatformFileForTransit* desktop_pipe_out) {
386 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 388 DCHECK(caller_task_runner_->BelongsToCurrentThread());
387 DCHECK(delegate_.get() == nullptr); 389 DCHECK(delegate_.get() == nullptr);
388 390
389 delegate_ = delegate; 391 delegate_ = delegate;
390 392
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 } 540 }
539 541
540 void DesktopSessionAgent::SetScreenResolution( 542 void DesktopSessionAgent::SetScreenResolution(
541 const ScreenResolution& resolution) { 543 const ScreenResolution& resolution) {
542 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 544 DCHECK(caller_task_runner_->BelongsToCurrentThread());
543 545
544 if (screen_controls_ && resolution.IsEmpty()) 546 if (screen_controls_ && resolution.IsEmpty())
545 screen_controls_->SetScreenResolution(resolution); 547 screen_controls_->SetScreenResolution(resolution);
546 } 548 }
547 549
548 void DesktopSessionAgent::SendToNetwork(scoped_ptr<IPC::Message> message) { 550 void DesktopSessionAgent::SendToNetwork(std::unique_ptr<IPC::Message> message) {
549 if (!caller_task_runner_->BelongsToCurrentThread()) { 551 if (!caller_task_runner_->BelongsToCurrentThread()) {
550 caller_task_runner_->PostTask( 552 caller_task_runner_->PostTask(
551 FROM_HERE, base::Bind(&DesktopSessionAgent::SendToNetwork, this, 553 FROM_HERE, base::Bind(&DesktopSessionAgent::SendToNetwork, this,
552 base::Passed(&message))); 554 base::Passed(&message)));
553 return; 555 return;
554 } 556 }
555 557
556 if (network_channel_) { 558 if (network_channel_) {
557 network_channel_->Send(message.release()); 559 network_channel_->Send(message.release());
558 } 560 }
559 } 561 }
560 562
561 void DesktopSessionAgent::StartAudioCapturer() { 563 void DesktopSessionAgent::StartAudioCapturer() {
562 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); 564 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread());
563 565
564 if (audio_capturer_) { 566 if (audio_capturer_) {
565 audio_capturer_->Start(base::Bind(&DesktopSessionAgent::ProcessAudioPacket, 567 audio_capturer_->Start(base::Bind(&DesktopSessionAgent::ProcessAudioPacket,
566 this)); 568 this));
567 } 569 }
568 } 570 }
569 571
570 void DesktopSessionAgent::StopAudioCapturer() { 572 void DesktopSessionAgent::StopAudioCapturer() {
571 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); 573 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread());
572 574
573 audio_capturer_.reset(); 575 audio_capturer_.reset();
574 } 576 }
575 577
576 } // namespace remoting 578 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/desktop_session_agent.h ('k') | remoting/host/desktop_session_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698