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

Unified Diff: mojo/public/cpp/system/buffer.cc

Issue 2036053002: Mojo: Add a C++-style SharedBuffer API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/system/buffer.h ('k') | mojo/public/cpp/system/handle.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/system/buffer.cc
diff --git a/mojo/public/cpp/system/buffer.cc b/mojo/public/cpp/system/buffer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c186465f40c0c0e608ab75e9f48d2b6594b5bc22
--- /dev/null
+++ b/mojo/public/cpp/system/buffer.cc
@@ -0,0 +1,37 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/cpp/system/buffer.h"
+
+namespace mojo {
+
+ScopedSharedBufferHandle SharedBufferHandle::Clone(
+ SharedBufferHandle::AccessMode access_mode) const {
+ ScopedSharedBufferHandle result;
+ if (!is_valid())
+ return result;
+
+ MojoDuplicateBufferHandleOptions options = {
+ sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
+ if (access_mode == AccessMode::READ_ONLY)
+ options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY;
+ SharedBufferHandle result_handle;
+ MojoDuplicateBufferHandle(value(), &options, result_handle.mutable_value());
+ result.reset(result_handle);
+ return result;
+}
+
+ScopedSharedBufferMapping SharedBufferHandle::Map(uint64_t size) const {
+ return MapAtOffset(size, 0);
+}
+
+ScopedSharedBufferMapping SharedBufferHandle::MapAtOffset(
+ uint64_t size,
+ uint64_t offset) const {
+ void* buffer = nullptr;
+ MojoMapBuffer(value(), offset, size, &buffer, MOJO_MAP_BUFFER_FLAG_NONE);
+ return ScopedSharedBufferMapping(buffer);
+}
+
+} // namespace mojo
« no previous file with comments | « mojo/public/cpp/system/buffer.h ('k') | mojo/public/cpp/system/handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698