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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/cpp/system/buffer.h"
6
7 namespace mojo {
8
9 ScopedSharedBufferHandle SharedBufferHandle::Clone(
10 SharedBufferHandle::AccessMode access_mode) const {
11 ScopedSharedBufferHandle result;
12 if (!is_valid())
13 return result;
14
15 MojoDuplicateBufferHandleOptions options = {
16 sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
17 if (access_mode == AccessMode::READ_ONLY)
18 options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY;
19 SharedBufferHandle result_handle;
20 MojoDuplicateBufferHandle(value(), &options, result_handle.mutable_value());
21 result.reset(result_handle);
22 return result;
23 }
24
25 ScopedSharedBufferMapping SharedBufferHandle::Map(uint64_t size) const {
26 return MapAtOffset(size, 0);
27 }
28
29 ScopedSharedBufferMapping SharedBufferHandle::MapAtOffset(
30 uint64_t size,
31 uint64_t offset) const {
32 void* buffer = nullptr;
33 MojoMapBuffer(value(), offset, size, &buffer, MOJO_MAP_BUFFER_FLAG_NONE);
34 return ScopedSharedBufferMapping(buffer);
35 }
36
37 } // namespace mojo
OLDNEW
« 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