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/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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 return nullptr; | 82 return nullptr; |
83 #else | 83 #else |
84 if (!memory->CreateAndMapAnonymous(size)) | 84 if (!memory->CreateAndMapAnonymous(size)) |
85 return nullptr; | 85 return nullptr; |
86 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 86 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
87 return make_scoped_ptr(new SharedBuffer(agent, memory.Pass(), size, id)); | 87 return make_scoped_ptr(new SharedBuffer(agent, memory.Pass(), size, id)); |
88 } | 88 } |
89 | 89 |
90 ~SharedBuffer() override { agent_->OnSharedBufferDeleted(id()); } | 90 ~SharedBuffer() override { agent_->OnSharedBufferDeleted(id()); } |
91 | 91 |
| 92 base::SharedMemory* shared_memory() { return shared_memory_.get(); } |
| 93 |
92 private: | 94 private: |
93 SharedBuffer(DesktopSessionAgent* agent, | 95 SharedBuffer(DesktopSessionAgent* agent, |
94 scoped_ptr<base::SharedMemory> memory, | 96 scoped_ptr<base::SharedMemory> memory, |
95 size_t size, | 97 size_t size, |
96 int id) | 98 int id) |
97 : SharedMemory(memory->memory(), | 99 : SharedMemory(memory->memory(), size, 0, id), |
98 size, | |
99 #if defined(OS_WIN) | |
100 memory->handle().GetHandle(), | |
101 #else | |
102 base::SharedMemory::GetFdFromSharedMemoryHandle( | |
103 memory->handle()), | |
104 #endif | |
105 id), | |
106 agent_(agent), | 100 agent_(agent), |
107 shared_memory_(memory.Pass()) { | 101 shared_memory_(memory.Pass()) {} |
108 } | |
109 | 102 |
110 DesktopSessionAgent* agent_; | 103 DesktopSessionAgent* agent_; |
111 scoped_ptr<base::SharedMemory> shared_memory_; | 104 scoped_ptr<base::SharedMemory> shared_memory_; |
112 | 105 |
113 DISALLOW_COPY_AND_ASSIGN(SharedBuffer); | 106 DISALLOW_COPY_AND_ASSIGN(SharedBuffer); |
114 }; | 107 }; |
115 | 108 |
116 DesktopSessionAgent::Delegate::~Delegate() { | 109 DesktopSessionAgent::Delegate::~Delegate() { |
117 } | 110 } |
118 | 111 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // ID. | 194 // ID. |
202 // | 195 // |
203 // It is very unlikely (though theoretically possible) to allocate the same | 196 // It is very unlikely (though theoretically possible) to allocate the same |
204 // ID for two different buffers due to integer overflow. It should take | 197 // ID for two different buffers due to integer overflow. It should take |
205 // about a year of allocating 100 new buffers every second. Practically | 198 // about a year of allocating 100 new buffers every second. Practically |
206 // speaking it never happens. | 199 // speaking it never happens. |
207 next_shared_buffer_id_ += 2; | 200 next_shared_buffer_id_ += 2; |
208 | 201 |
209 IPC::PlatformFileForTransit handle; | 202 IPC::PlatformFileForTransit handle; |
210 #if defined(OS_WIN) | 203 #if defined(OS_WIN) |
211 handle = buffer->handle(); | 204 handle = buffer->shared_memory()->handle().GetHandle(), |
212 #else | 205 #else |
213 handle = base::FileDescriptor(buffer->handle(), false); | 206 handle = |
| 207 base::FileDescriptor(base::SharedMemory::GetFdFromSharedMemoryHandle( |
| 208 buffer->shared_memory()->handle()), false); |
214 #endif | 209 #endif |
215 SendToNetwork(new ChromotingDesktopNetworkMsg_CreateSharedBuffer( | 210 SendToNetwork(new ChromotingDesktopNetworkMsg_CreateSharedBuffer( |
216 buffer->id(), handle, buffer->size())); | 211 buffer->id(), handle, buffer->size())); |
217 } | 212 } |
218 | 213 |
219 return buffer.release(); | 214 return buffer.release(); |
220 } | 215 } |
221 | 216 |
222 DesktopSessionAgent::~DesktopSessionAgent() { | 217 DesktopSessionAgent::~DesktopSessionAgent() { |
223 DCHECK(!audio_capturer_); | 218 DCHECK(!audio_capturer_); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 void DesktopSessionAgent::OnSharedBufferDeleted(int id) { | 600 void DesktopSessionAgent::OnSharedBufferDeleted(int id) { |
606 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); | 601 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); |
607 DCHECK(id != 0); | 602 DCHECK(id != 0); |
608 | 603 |
609 shared_buffers_--; | 604 shared_buffers_--; |
610 DCHECK_GE(shared_buffers_, 0); | 605 DCHECK_GE(shared_buffers_, 0); |
611 SendToNetwork(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(id)); | 606 SendToNetwork(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(id)); |
612 } | 607 } |
613 | 608 |
614 } // namespace remoting | 609 } // namespace remoting |
OLD | NEW |