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 82% |
copy from third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc |
copy to mojo/edk/system/shared_buffer_dispatcher.cc |
index 75c85cfaa6707ee1f56bd46e08f19c0e05d9c959..bf68eb3f5c3879e37c164f9c82de5d63942ff7a7 100644 |
--- a/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc |
+++ b/mojo/edk/system/shared_buffer_dispatcher.cc |
@@ -2,25 +2,24 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.h" |
+#include "mojo/edk/system/shared_buffer_dispatcher.h" |
#include <limits> |
#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/configuration.h" |
+#include "mojo/edk/system/options_validation.h" |
#include "mojo/public/c/system/macros.h" |
-#include "third_party/mojo/src/mojo/edk/embedder/platform_support.h" |
-#include "third_party/mojo/src/mojo/edk/system/channel.h" |
-#include "third_party/mojo/src/mojo/edk/system/configuration.h" |
-#include "third_party/mojo/src/mojo/edk/system/memory.h" |
-#include "third_party/mojo/src/mojo/edk/system/options_validation.h" |
namespace mojo { |
-namespace system { |
+namespace edk { |
namespace { |
-struct SerializedSharedBufferDispatcher { |
+struct MOJO_ALIGNAS(8) SerializedSharedBufferDispatcher { |
size_t num_bytes; |
size_t platform_handle_index; |
}; |
@@ -35,13 +34,13 @@ const MojoCreateSharedBufferOptions |
// static |
MojoResult SharedBufferDispatcher::ValidateCreateOptions( |
- UserPointer<const MojoCreateSharedBufferOptions> in_options, |
+ const MojoCreateSharedBufferOptions* in_options, |
MojoCreateSharedBufferOptions* out_options) { |
const MojoCreateSharedBufferOptionsFlags kKnownFlags = |
MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; |
*out_options = kDefaultCreateOptions; |
- if (in_options.IsNull()) |
+ if (!in_options) |
return MOJO_RESULT_OK; |
UserOptionsReader<MojoCreateSharedBufferOptions> reader(in_options); |
@@ -63,7 +62,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 +71,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 +86,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 +113,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 +133,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_); |
} |
@@ -146,7 +143,7 @@ SharedBufferDispatcher::~SharedBufferDispatcher() { |
// static |
MojoResult SharedBufferDispatcher::ValidateDuplicateOptions( |
- UserPointer<const MojoDuplicateBufferHandleOptions> in_options, |
+ const MojoDuplicateBufferHandleOptions* in_options, |
MojoDuplicateBufferHandleOptions* out_options) { |
const MojoDuplicateBufferHandleOptionsFlags kKnownFlags = |
MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE; |
@@ -155,7 +152,7 @@ MojoResult SharedBufferDispatcher::ValidateDuplicateOptions( |
MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE}; |
*out_options = kDefaultOptions; |
- if (in_options.IsNull()) |
+ if (!in_options) |
return MOJO_RESULT_OK; |
UserOptionsReader<MojoDuplicateBufferHandleOptions> reader(in_options); |
@@ -177,22 +174,22 @@ 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()); |
} |
MojoResult SharedBufferDispatcher::DuplicateBufferHandleImplNoLock( |
- UserPointer<const MojoDuplicateBufferHandleOptions> options, |
+ const MojoDuplicateBufferHandleOptions* options, |
scoped_refptr<Dispatcher>* new_dispatcher) { |
- mutex().AssertHeld(); |
+ lock().AssertAcquired(); |
MojoDuplicateBufferHandleOptions validated_options; |
MojoResult result = ValidateDuplicateOptions(options, &validated_options); |
@@ -208,8 +205,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 +228,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 +236,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 +247,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 +265,6 @@ bool SharedBufferDispatcher::EndSerializeAndCloseImplNoLock( |
return true; |
} |
-} // namespace system |
+ |
+} // namespace edk |
} // namespace mojo |