• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 #ifndef MOJO_PUBLIC_CPP_BASE_SHARED_MEMORY_MOJOM_TRAITS_H_
6 #define MOJO_PUBLIC_CPP_BASE_SHARED_MEMORY_MOJOM_TRAITS_H_
7 
8 #include "base/component_export.h"
9 #include "base/memory/read_only_shared_memory_region.h"
10 #include "base/memory/unsafe_shared_memory_region.h"
11 #include "base/memory/writable_shared_memory_region.h"
12 #include "mojo/public/cpp/bindings/struct_traits.h"
13 #include "mojo/public/cpp/system/handle.h"
14 #include "mojo/public/mojom/base/shared_memory.mojom-shared.h"
15 
16 namespace mojo {
17 
18 template <>
COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)19 struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)
20     StructTraits<mojo_base::mojom::ReadOnlySharedMemoryRegionDataView,
21                  base::ReadOnlySharedMemoryRegion> {
22   static bool IsNull(const base::ReadOnlySharedMemoryRegion& region);
23   static void SetToNull(base::ReadOnlySharedMemoryRegion* region);
24   static mojo::ScopedSharedBufferHandle buffer(
25       base::ReadOnlySharedMemoryRegion& in_region);
26   static bool Read(mojo_base::mojom::ReadOnlySharedMemoryRegionDataView data,
27                    base::ReadOnlySharedMemoryRegion* out);
28 };
29 
30 template <>
COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)31 struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)
32     StructTraits<mojo_base::mojom::UnsafeSharedMemoryRegionDataView,
33                  base::UnsafeSharedMemoryRegion> {
34   static bool IsNull(const base::UnsafeSharedMemoryRegion& region);
35   static void SetToNull(base::UnsafeSharedMemoryRegion* region);
36   static mojo::ScopedSharedBufferHandle buffer(
37       base::UnsafeSharedMemoryRegion& in_region);
38   static bool Read(mojo_base::mojom::UnsafeSharedMemoryRegionDataView data,
39                    base::UnsafeSharedMemoryRegion* out);
40 };
41 
42 template <>
COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)43 struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)
44     StructTraits<mojo_base::mojom::WritableSharedMemoryRegionDataView,
45                  base::WritableSharedMemoryRegion> {
46   static bool IsNull(const base::WritableSharedMemoryRegion& region);
47   static void SetToNull(base::WritableSharedMemoryRegion* region);
48   static mojo::ScopedSharedBufferHandle buffer(
49       base::WritableSharedMemoryRegion& in_region);
50   static bool Read(mojo_base::mojom::WritableSharedMemoryRegionDataView data,
51                    base::WritableSharedMemoryRegion* out);
52 };
53 
54 }  // namespace mojo
55 
56 #endif  // MOJO_PUBLIC_CPP_BASE_SHARED_MEMORY_MOJOM_TRAITS_H_
57