OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/edk/system/core.h" | 5 #include "mojo/edk/system/core.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 phd->Close(); | 153 phd->Close(); |
154 return MOJO_RESULT_OK; | 154 return MOJO_RESULT_OK; |
155 } | 155 } |
156 | 156 |
157 MojoResult Core::CreateSharedBufferWrapper( | 157 MojoResult Core::CreateSharedBufferWrapper( |
158 base::SharedMemoryHandle shared_memory_handle, | 158 base::SharedMemoryHandle shared_memory_handle, |
159 size_t num_bytes, | 159 size_t num_bytes, |
160 bool read_only, | 160 bool read_only, |
161 MojoHandle* mojo_wrapper_handle) { | 161 MojoHandle* mojo_wrapper_handle) { |
162 DCHECK(num_bytes); | 162 DCHECK(num_bytes); |
163 CHECK(!read_only); | |
164 scoped_refptr<PlatformSharedBuffer> platform_buffer = | 163 scoped_refptr<PlatformSharedBuffer> platform_buffer = |
165 PlatformSharedBuffer::CreateFromSharedMemoryHandle(num_bytes, read_only, | 164 PlatformSharedBuffer::CreateFromSharedMemoryHandle(num_bytes, read_only, |
166 shared_memory_handle); | 165 shared_memory_handle); |
167 if (!platform_buffer) | 166 if (!platform_buffer) |
168 return MOJO_RESULT_UNKNOWN; | 167 return MOJO_RESULT_UNKNOWN; |
169 | 168 |
170 scoped_refptr<SharedBufferDispatcher> dispatcher; | 169 scoped_refptr<SharedBufferDispatcher> dispatcher; |
171 MojoResult result = SharedBufferDispatcher::CreateFromPlatformSharedBuffer( | 170 MojoResult result = SharedBufferDispatcher::CreateFromPlatformSharedBuffer( |
172 platform_buffer, &dispatcher); | 171 platform_buffer, &dispatcher); |
173 if (result != MOJO_RESULT_OK) | 172 if (result != MOJO_RESULT_OK) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 static_cast<SharedBufferDispatcher*>(dispatcher.get()); | 206 static_cast<SharedBufferDispatcher*>(dispatcher.get()); |
208 scoped_refptr<PlatformSharedBuffer> platform_shared_buffer = | 207 scoped_refptr<PlatformSharedBuffer> platform_shared_buffer = |
209 shm_dispatcher->PassPlatformSharedBuffer(); | 208 shm_dispatcher->PassPlatformSharedBuffer(); |
210 | 209 |
211 if (!platform_shared_buffer) | 210 if (!platform_shared_buffer) |
212 return MOJO_RESULT_INVALID_ARGUMENT; | 211 return MOJO_RESULT_INVALID_ARGUMENT; |
213 | 212 |
214 if (num_bytes) | 213 if (num_bytes) |
215 *num_bytes = platform_shared_buffer->GetNumBytes(); | 214 *num_bytes = platform_shared_buffer->GetNumBytes(); |
216 if (read_only) | 215 if (read_only) |
217 *read_only = false; | 216 *read_only = platform_shared_buffer->IsReadOnly(); |
218 *shared_memory_handle = platform_shared_buffer->DuplicateSharedMemoryHandle(); | 217 *shared_memory_handle = platform_shared_buffer->DuplicateSharedMemoryHandle(); |
219 | 218 |
220 shm_dispatcher->Close(); | 219 shm_dispatcher->Close(); |
221 return result; | 220 return result; |
222 } | 221 } |
223 | 222 |
224 void Core::RequestShutdown(const base::Closure& callback) { | 223 void Core::RequestShutdown(const base::Closure& callback) { |
225 base::Closure on_shutdown; | 224 base::Closure on_shutdown; |
226 if (base::ThreadTaskRunnerHandle::IsSet()) { | 225 if (base::ThreadTaskRunnerHandle::IsSet()) { |
227 on_shutdown = base::Bind(base::IgnoreResult(&base::TaskRunner::PostTask), | 226 on_shutdown = base::Bind(base::IgnoreResult(&base::TaskRunner::PostTask), |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 scoped_ptr<NodeController> node_controller) { | 863 scoped_ptr<NodeController> node_controller) { |
865 // It's OK to leak this reference. At this point we know the IO loop is still | 864 // It's OK to leak this reference. At this point we know the IO loop is still |
866 // running, and we know the NodeController will observe its eventual | 865 // running, and we know the NodeController will observe its eventual |
867 // destruction. This tells the NodeController to delete itself when that | 866 // destruction. This tells the NodeController to delete itself when that |
868 // happens. | 867 // happens. |
869 node_controller.release()->DestroyOnIOThreadShutdown(); | 868 node_controller.release()->DestroyOnIOThreadShutdown(); |
870 } | 869 } |
871 | 870 |
872 } // namespace edk | 871 } // namespace edk |
873 } // namespace mojo | 872 } // namespace mojo |
OLD | NEW |