| Index: mojo/edk/system/shared_buffer_dispatcher.cc
|
| diff --git a/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc b/mojo/edk/system/shared_buffer_dispatcher.cc
|
| similarity index 89%
|
| copy from third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc
|
| copy to mojo/edk/system/shared_buffer_dispatcher.cc
|
| index caf8e0b64bfb313975c6cdef71a6a4d3e283ca34..eb6db8d23de05ca61d88a4805ae38f9ae18875af 100644
|
| --- a/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc
|
| +++ b/mojo/edk/system/shared_buffer_dispatcher.cc
|
| @@ -8,19 +8,19 @@
|
|
|
| #include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "mojo/edk/embedder/embedder_internal.h"
|
| #include "mojo/edk/embedder/platform_support.h"
|
| -#include "mojo/edk/system/channel.h"
|
| #include "mojo/edk/system/configuration.h"
|
| #include "mojo/edk/system/memory.h"
|
| #include "mojo/edk/system/options_validation.h"
|
| #include "mojo/public/c/system/macros.h"
|
|
|
| namespace mojo {
|
| -namespace system {
|
| +namespace edk {
|
|
|
| namespace {
|
|
|
| -struct SerializedSharedBufferDispatcher {
|
| +struct MOJO_ALIGNAS(8) SerializedSharedBufferDispatcher {
|
| size_t num_bytes;
|
| size_t platform_handle_index;
|
| };
|
| @@ -63,7 +63,7 @@ MojoResult SharedBufferDispatcher::ValidateCreateOptions(
|
|
|
| // static
|
| MojoResult SharedBufferDispatcher::Create(
|
| - embedder::PlatformSupport* platform_support,
|
| + PlatformSupport* platform_support,
|
| const MojoCreateSharedBufferOptions& /*validated_options*/,
|
| uint64_t num_bytes,
|
| scoped_refptr<SharedBufferDispatcher>* result) {
|
| @@ -72,7 +72,7 @@ MojoResult SharedBufferDispatcher::Create(
|
| if (num_bytes > GetConfiguration().max_shared_memory_num_bytes)
|
| return MOJO_RESULT_RESOURCE_EXHAUSTED;
|
|
|
| - scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer(
|
| + scoped_refptr<PlatformSharedBuffer> shared_buffer(
|
| platform_support->CreateSharedBuffer(static_cast<size_t>(num_bytes)));
|
| if (!shared_buffer)
|
| return MOJO_RESULT_RESOURCE_EXHAUSTED;
|
| @@ -87,11 +87,9 @@ Dispatcher::Type SharedBufferDispatcher::GetType() const {
|
|
|
| // static
|
| scoped_refptr<SharedBufferDispatcher> SharedBufferDispatcher::Deserialize(
|
| - Channel* channel,
|
| const void* source,
|
| size_t size,
|
| - embedder::PlatformHandleVector* platform_handles) {
|
| - DCHECK(channel);
|
| + PlatformHandleVector* platform_handles) {
|
|
|
| if (size != sizeof(SerializedSharedBufferDispatcher)) {
|
| LOG(ERROR) << "Invalid serialized shared buffer dispatcher (bad size)";
|
| @@ -116,16 +114,16 @@ scoped_refptr<SharedBufferDispatcher> SharedBufferDispatcher::Deserialize(
|
| }
|
|
|
| // Starts off invalid, which is what we want.
|
| - embedder::PlatformHandle platform_handle;
|
| + PlatformHandle platform_handle;
|
| // We take ownership of the handle, so we have to invalidate the one in
|
| // |platform_handles|.
|
| std::swap(platform_handle, (*platform_handles)[platform_handle_index]);
|
|
|
| // Wrapping |platform_handle| in a |ScopedPlatformHandle| means that it'll be
|
| // closed even if creation fails.
|
| - scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer(
|
| - channel->platform_support()->CreateSharedBufferFromHandle(
|
| - num_bytes, embedder::ScopedPlatformHandle(platform_handle)));
|
| + scoped_refptr<PlatformSharedBuffer> shared_buffer(
|
| + internal::g_platform_support->CreateSharedBufferFromHandle(
|
| + num_bytes, ScopedPlatformHandle(platform_handle)));
|
| if (!shared_buffer) {
|
| LOG(ERROR)
|
| << "Invalid serialized shared buffer dispatcher (invalid num_bytes?)";
|
| @@ -136,7 +134,7 @@ scoped_refptr<SharedBufferDispatcher> SharedBufferDispatcher::Deserialize(
|
| }
|
|
|
| SharedBufferDispatcher::SharedBufferDispatcher(
|
| - scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer)
|
| + scoped_refptr<PlatformSharedBuffer> shared_buffer)
|
| : shared_buffer_(shared_buffer) {
|
| DCHECK(shared_buffer_);
|
| }
|
| @@ -177,14 +175,14 @@ MojoResult SharedBufferDispatcher::ValidateDuplicateOptions(
|
| }
|
|
|
| void SharedBufferDispatcher::CloseImplNoLock() {
|
| - mutex().AssertHeld();
|
| + lock().AssertAcquired();
|
| DCHECK(shared_buffer_);
|
| shared_buffer_ = nullptr;
|
| }
|
|
|
| scoped_refptr<Dispatcher>
|
| SharedBufferDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
|
| - mutex().AssertHeld();
|
| + lock().AssertAcquired();
|
| DCHECK(shared_buffer_);
|
| return CreateInternal(shared_buffer_.Pass());
|
| }
|
| @@ -192,7 +190,7 @@ SharedBufferDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
|
| MojoResult SharedBufferDispatcher::DuplicateBufferHandleImplNoLock(
|
| UserPointer<const MojoDuplicateBufferHandleOptions> options,
|
| scoped_refptr<Dispatcher>* new_dispatcher) {
|
| - mutex().AssertHeld();
|
| + lock().AssertAcquired();
|
|
|
| MojoDuplicateBufferHandleOptions validated_options;
|
| MojoResult result = ValidateDuplicateOptions(options, &validated_options);
|
| @@ -208,8 +206,8 @@ MojoResult SharedBufferDispatcher::MapBufferImplNoLock(
|
| uint64_t offset,
|
| uint64_t num_bytes,
|
| MojoMapBufferFlags flags,
|
| - scoped_ptr<embedder::PlatformSharedBufferMapping>* mapping) {
|
| - mutex().AssertHeld();
|
| + scoped_ptr<PlatformSharedBufferMapping>* mapping) {
|
| + lock().AssertAcquired();
|
| DCHECK(shared_buffer_);
|
|
|
| if (offset > static_cast<uint64_t>(std::numeric_limits<size_t>::max()))
|
| @@ -231,7 +229,6 @@ MojoResult SharedBufferDispatcher::MapBufferImplNoLock(
|
| }
|
|
|
| void SharedBufferDispatcher::StartSerializeImplNoLock(
|
| - Channel* /*channel*/,
|
| size_t* max_size,
|
| size_t* max_platform_handles) {
|
| DCHECK(HasOneRef()); // Only one ref => no need to take the lock.
|
| @@ -240,10 +237,9 @@ void SharedBufferDispatcher::StartSerializeImplNoLock(
|
| }
|
|
|
| bool SharedBufferDispatcher::EndSerializeAndCloseImplNoLock(
|
| - Channel* /*channel*/,
|
| void* destination,
|
| size_t* actual_size,
|
| - embedder::PlatformHandleVector* platform_handles) {
|
| + PlatformHandleVector* platform_handles) {
|
| DCHECK(HasOneRef()); // Only one ref => no need to take the lock.
|
| DCHECK(shared_buffer_);
|
|
|
| @@ -252,7 +248,7 @@ bool SharedBufferDispatcher::EndSerializeAndCloseImplNoLock(
|
| // If there's only one reference to |shared_buffer_|, then it's ours (and no
|
| // one else can make any more references to it), so we can just take its
|
| // handle.
|
| - embedder::ScopedPlatformHandle platform_handle(
|
| + ScopedPlatformHandle platform_handle(
|
| shared_buffer_->HasOneRef() ? shared_buffer_->PassPlatformHandle()
|
| : shared_buffer_->DuplicatePlatformHandle());
|
| if (!platform_handle.is_valid()) {
|
| @@ -270,5 +266,6 @@ bool SharedBufferDispatcher::EndSerializeAndCloseImplNoLock(
|
| return true;
|
| }
|
|
|
| -} // namespace system
|
| +
|
| +} // namespace edk
|
| } // namespace mojo
|
|
|