• 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 #include "mojo/public/cpp/base/shared_memory_mojom_traits.h"
6 
7 #include "base/logging.h"
8 #include "mojo/public/cpp/system/platform_handle.h"
9 
10 namespace mojo {
11 
12 // static
13 bool StructTraits<mojo_base::mojom::ReadOnlySharedMemoryRegionDataView,
14                   base::ReadOnlySharedMemoryRegion>::
IsNull(const base::ReadOnlySharedMemoryRegion & region)15     IsNull(const base::ReadOnlySharedMemoryRegion& region) {
16   return !region.IsValid();
17 }
18 
19 // static
20 void StructTraits<mojo_base::mojom::ReadOnlySharedMemoryRegionDataView,
21                   base::ReadOnlySharedMemoryRegion>::
SetToNull(base::ReadOnlySharedMemoryRegion * region)22     SetToNull(base::ReadOnlySharedMemoryRegion* region) {
23   *region = base::ReadOnlySharedMemoryRegion();
24 }
25 
26 // static
27 mojo::ScopedSharedBufferHandle StructTraits<
28     mojo_base::mojom::ReadOnlySharedMemoryRegionDataView,
buffer(base::ReadOnlySharedMemoryRegion & in_region)29     base::ReadOnlySharedMemoryRegion>::buffer(base::ReadOnlySharedMemoryRegion&
30                                                   in_region) {
31   return mojo::WrapReadOnlySharedMemoryRegion(std::move(in_region));
32 }
33 
34 // static
35 bool StructTraits<mojo_base::mojom::ReadOnlySharedMemoryRegionDataView,
36                   base::ReadOnlySharedMemoryRegion>::
Read(mojo_base::mojom::ReadOnlySharedMemoryRegionDataView data,base::ReadOnlySharedMemoryRegion * out)37     Read(mojo_base::mojom::ReadOnlySharedMemoryRegionDataView data,
38          base::ReadOnlySharedMemoryRegion* out) {
39   *out = mojo::UnwrapReadOnlySharedMemoryRegion(data.TakeBuffer());
40   return out->IsValid();
41 }
42 
43 // static
44 bool StructTraits<mojo_base::mojom::UnsafeSharedMemoryRegionDataView,
45                   base::UnsafeSharedMemoryRegion>::
IsNull(const base::UnsafeSharedMemoryRegion & region)46     IsNull(const base::UnsafeSharedMemoryRegion& region) {
47   return !region.IsValid();
48 }
49 
50 // static
51 void StructTraits<mojo_base::mojom::UnsafeSharedMemoryRegionDataView,
52                   base::UnsafeSharedMemoryRegion>::
SetToNull(base::UnsafeSharedMemoryRegion * region)53     SetToNull(base::UnsafeSharedMemoryRegion* region) {
54   *region = base::UnsafeSharedMemoryRegion();
55 }
56 
57 // static
58 mojo::ScopedSharedBufferHandle StructTraits<
59     mojo_base::mojom::UnsafeSharedMemoryRegionDataView,
buffer(base::UnsafeSharedMemoryRegion & in_region)60     base::UnsafeSharedMemoryRegion>::buffer(base::UnsafeSharedMemoryRegion&
61                                                 in_region) {
62   return mojo::WrapUnsafeSharedMemoryRegion(std::move(in_region));
63 }
64 
65 // static
66 bool StructTraits<mojo_base::mojom::UnsafeSharedMemoryRegionDataView,
67                   base::UnsafeSharedMemoryRegion>::
Read(mojo_base::mojom::UnsafeSharedMemoryRegionDataView data,base::UnsafeSharedMemoryRegion * out)68     Read(mojo_base::mojom::UnsafeSharedMemoryRegionDataView data,
69          base::UnsafeSharedMemoryRegion* out) {
70   *out = mojo::UnwrapUnsafeSharedMemoryRegion(data.TakeBuffer());
71   return out->IsValid();
72 }
73 
74 // static
75 bool StructTraits<mojo_base::mojom::WritableSharedMemoryRegionDataView,
76                   base::WritableSharedMemoryRegion>::
IsNull(const base::WritableSharedMemoryRegion & region)77     IsNull(const base::WritableSharedMemoryRegion& region) {
78   return !region.IsValid();
79 }
80 
81 // static
82 void StructTraits<mojo_base::mojom::WritableSharedMemoryRegionDataView,
83                   base::WritableSharedMemoryRegion>::
SetToNull(base::WritableSharedMemoryRegion * region)84     SetToNull(base::WritableSharedMemoryRegion* region) {
85   *region = base::WritableSharedMemoryRegion();
86 }
87 
88 // static
89 mojo::ScopedSharedBufferHandle StructTraits<
90     mojo_base::mojom::WritableSharedMemoryRegionDataView,
buffer(base::WritableSharedMemoryRegion & in_region)91     base::WritableSharedMemoryRegion>::buffer(base::WritableSharedMemoryRegion&
92                                                   in_region) {
93   return mojo::WrapWritableSharedMemoryRegion(std::move(in_region));
94 }
95 
96 // static
97 bool StructTraits<mojo_base::mojom::WritableSharedMemoryRegionDataView,
98                   base::WritableSharedMemoryRegion>::
Read(mojo_base::mojom::WritableSharedMemoryRegionDataView data,base::WritableSharedMemoryRegion * out)99     Read(mojo_base::mojom::WritableSharedMemoryRegionDataView data,
100          base::WritableSharedMemoryRegion* out) {
101   *out = mojo::UnwrapWritableSharedMemoryRegion(data.TakeBuffer());
102   return out->IsValid();
103 }
104 
105 }  // namespace mojo
106