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

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

Issue 1509063003: Remoting: Remove references to POSIX shared memory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp57_base
Patch Set: Created 5 years 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
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 "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "ipc/ipc_channel_proxy.h" 10 #include "ipc/ipc_channel_proxy.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } // namespace 67 } // namespace
68 68
69 // webrtc::SharedMemory implementation that notifies creating 69 // webrtc::SharedMemory implementation that notifies creating
70 // DesktopSessionAgent when it's deleted. 70 // DesktopSessionAgent when it's deleted.
71 class DesktopSessionAgent::SharedBuffer : public webrtc::SharedMemory { 71 class DesktopSessionAgent::SharedBuffer : public webrtc::SharedMemory {
72 public: 72 public:
73 static scoped_ptr<SharedBuffer> Create(DesktopSessionAgent* agent, 73 static scoped_ptr<SharedBuffer> Create(DesktopSessionAgent* agent,
74 size_t size, 74 size_t size,
75 int id) { 75 int id) {
76 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory()); 76 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory());
77 #if defined(OS_MACOSX) && !defined(OS_IOS)
78 // Remoting does not yet support Mach primitive backed SharedMemory, so
79 // force the underlying primitive to be a POSIX fd.
80 // https://crbug.com/547247.
81 if (!memory->CreateAndMapAnonymousPosix(size))
82 return nullptr;
83 #else
84 if (!memory->CreateAndMapAnonymous(size)) 77 if (!memory->CreateAndMapAnonymous(size))
85 return nullptr; 78 return nullptr;
86 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
87 return make_scoped_ptr(new SharedBuffer(agent, memory.Pass(), size, id)); 79 return make_scoped_ptr(new SharedBuffer(agent, memory.Pass(), size, id));
88 } 80 }
89 81
90 ~SharedBuffer() override { agent_->OnSharedBufferDeleted(id()); } 82 ~SharedBuffer() override { agent_->OnSharedBufferDeleted(id()); }
91 83
92 base::SharedMemory* shared_memory() { return shared_memory_.get(); } 84 base::SharedMemory* shared_memory() { return shared_memory_.get(); }
93 85
94 private: 86 private:
95 SharedBuffer(DesktopSessionAgent* agent, 87 SharedBuffer(DesktopSessionAgent* agent,
96 scoped_ptr<base::SharedMemory> memory, 88 scoped_ptr<base::SharedMemory> memory,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // |next_shared_buffer_id_| starts from 1 and incrementing it by 2 makes 184 // |next_shared_buffer_id_| starts from 1 and incrementing it by 2 makes
193 // sure it is always odd and therefore zero is never used as a valid buffer 185 // sure it is always odd and therefore zero is never used as a valid buffer
194 // ID. 186 // ID.
195 // 187 //
196 // It is very unlikely (though theoretically possible) to allocate the same 188 // It is very unlikely (though theoretically possible) to allocate the same
197 // ID for two different buffers due to integer overflow. It should take 189 // ID for two different buffers due to integer overflow. It should take
198 // about a year of allocating 100 new buffers every second. Practically 190 // about a year of allocating 100 new buffers every second. Practically
199 // speaking it never happens. 191 // speaking it never happens.
200 next_shared_buffer_id_ += 2; 192 next_shared_buffer_id_ += 2;
201 193
202 IPC::PlatformFileForTransit handle;
203 #if defined(OS_WIN)
204 handle = buffer->shared_memory()->handle().GetHandle(),
205 #else
206 handle =
207 base::FileDescriptor(base::SharedMemory::GetFdFromSharedMemoryHandle(
208 buffer->shared_memory()->handle()), false);
209 #endif
210 SendToNetwork(new ChromotingDesktopNetworkMsg_CreateSharedBuffer( 194 SendToNetwork(new ChromotingDesktopNetworkMsg_CreateSharedBuffer(
211 buffer->id(), handle, buffer->size())); 195 buffer->id(), buffer->shared_memory()->handle(), buffer->size()));
212 } 196 }
213 197
214 return buffer.release(); 198 return buffer.release();
215 } 199 }
216 200
217 DesktopSessionAgent::~DesktopSessionAgent() { 201 DesktopSessionAgent::~DesktopSessionAgent() {
218 DCHECK(!audio_capturer_); 202 DCHECK(!audio_capturer_);
219 DCHECK(!desktop_environment_); 203 DCHECK(!desktop_environment_);
220 DCHECK(!network_channel_); 204 DCHECK(!network_channel_);
221 DCHECK(!screen_controls_); 205 DCHECK(!screen_controls_);
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 void DesktopSessionAgent::OnSharedBufferDeleted(int id) { 584 void DesktopSessionAgent::OnSharedBufferDeleted(int id) {
601 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); 585 DCHECK(video_capture_task_runner_->BelongsToCurrentThread());
602 DCHECK(id != 0); 586 DCHECK(id != 0);
603 587
604 shared_buffers_--; 588 shared_buffers_--;
605 DCHECK_GE(shared_buffers_, 0); 589 DCHECK_GE(shared_buffers_, 0);
606 SendToNetwork(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(id)); 590 SendToNetwork(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(id));
607 } 591 }
608 592
609 } // namespace remoting 593 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698