OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_SYSTEM_SIMPLE_PLATFORM_SHARED_BUFFER_H_ | 5 #ifndef MOJO_SYSTEM_SIMPLE_PLATFORM_SHARED_BUFFER_H_ |
6 #define MOJO_SYSTEM_SIMPLE_PLATFORM_SHARED_BUFFER_H_ | 6 #define MOJO_SYSTEM_SIMPLE_PLATFORM_SHARED_BUFFER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "mojo/embedder/platform_shared_buffer.h" | 11 #include "mojo/embedder/platform_shared_buffer.h" |
12 #include "mojo/system/system_impl_export.h" | 12 #include "mojo/system/system_impl_export.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 namespace embedder { | 15 namespace embedder { |
16 | 16 |
17 // A simple implementation of |PlatformSharedBuffer|. | 17 // A simple implementation of |PlatformSharedBuffer|. |
18 class MOJO_SYSTEM_IMPL_EXPORT SimplePlatformSharedBuffer | 18 class MOJO_SYSTEM_IMPL_EXPORT SimplePlatformSharedBuffer |
19 : public PlatformSharedBuffer { | 19 : public PlatformSharedBuffer { |
20 public: | 20 public: |
21 // Creates a shared buffer of size |num_bytes| bytes (initially zero-filled). | 21 // Creates a shared buffer of size |num_bytes| bytes (initially zero-filled). |
22 // |num_bytes| must be nonzero. Returns null on failure. | 22 // |num_bytes| must be nonzero. Returns null on failure. |
23 static SimplePlatformSharedBuffer* Create(size_t num_bytes); | 23 static SimplePlatformSharedBuffer* Create(size_t num_bytes); |
24 | 24 |
25 static SimplePlatformSharedBuffer* CreateFromPlatformHandle( | 25 static SimplePlatformSharedBuffer* CreateFromPlatformHandle( |
26 size_t num_bytes, | 26 size_t num_bytes, |
27 ScopedPlatformHandle platform_handle); | 27 ScopedPlatformHandle platform_handle); |
28 | 28 |
29 // |PlatformSharedBuffer| implementation: | 29 // |PlatformSharedBuffer| implementation: |
30 virtual size_t GetNumBytes() const OVERRIDE; | 30 virtual size_t GetNumBytes() const override; |
31 virtual scoped_ptr<PlatformSharedBufferMapping> Map(size_t offset, | 31 virtual scoped_ptr<PlatformSharedBufferMapping> Map(size_t offset, |
32 size_t length) OVERRIDE; | 32 size_t length) override; |
33 virtual bool IsValidMap(size_t offset, size_t length) OVERRIDE; | 33 virtual bool IsValidMap(size_t offset, size_t length) override; |
34 virtual scoped_ptr<PlatformSharedBufferMapping> MapNoCheck( | 34 virtual scoped_ptr<PlatformSharedBufferMapping> MapNoCheck( |
35 size_t offset, | 35 size_t offset, |
36 size_t length) OVERRIDE; | 36 size_t length) override; |
37 virtual ScopedPlatformHandle DuplicatePlatformHandle() OVERRIDE; | 37 virtual ScopedPlatformHandle DuplicatePlatformHandle() override; |
38 virtual ScopedPlatformHandle PassPlatformHandle() OVERRIDE; | 38 virtual ScopedPlatformHandle PassPlatformHandle() override; |
39 | 39 |
40 private: | 40 private: |
41 explicit SimplePlatformSharedBuffer(size_t num_bytes); | 41 explicit SimplePlatformSharedBuffer(size_t num_bytes); |
42 virtual ~SimplePlatformSharedBuffer(); | 42 virtual ~SimplePlatformSharedBuffer(); |
43 | 43 |
44 // Implemented in simple_platform_shared_buffer_{posix,win}.cc: | 44 // Implemented in simple_platform_shared_buffer_{posix,win}.cc: |
45 | 45 |
46 // This is called by |Create()| before this object is given to anyone. | 46 // This is called by |Create()| before this object is given to anyone. |
47 bool Init(); | 47 bool Init(); |
48 | 48 |
(...skipping 15 matching lines...) Expand all Loading... |
64 DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBuffer); | 64 DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBuffer); |
65 }; | 65 }; |
66 | 66 |
67 // An implementation of |PlatformSharedBufferMapping|, produced by | 67 // An implementation of |PlatformSharedBufferMapping|, produced by |
68 // |SimplePlatformSharedBuffer|. | 68 // |SimplePlatformSharedBuffer|. |
69 class MOJO_SYSTEM_IMPL_EXPORT SimplePlatformSharedBufferMapping | 69 class MOJO_SYSTEM_IMPL_EXPORT SimplePlatformSharedBufferMapping |
70 : public PlatformSharedBufferMapping { | 70 : public PlatformSharedBufferMapping { |
71 public: | 71 public: |
72 virtual ~SimplePlatformSharedBufferMapping(); | 72 virtual ~SimplePlatformSharedBufferMapping(); |
73 | 73 |
74 virtual void* GetBase() const OVERRIDE; | 74 virtual void* GetBase() const override; |
75 virtual size_t GetLength() const OVERRIDE; | 75 virtual size_t GetLength() const override; |
76 | 76 |
77 private: | 77 private: |
78 friend class SimplePlatformSharedBuffer; | 78 friend class SimplePlatformSharedBuffer; |
79 | 79 |
80 SimplePlatformSharedBufferMapping(void* base, | 80 SimplePlatformSharedBufferMapping(void* base, |
81 size_t length, | 81 size_t length, |
82 void* real_base, | 82 void* real_base, |
83 size_t real_length) | 83 size_t real_length) |
84 : base_(base), | 84 : base_(base), |
85 length_(length), | 85 length_(length), |
86 real_base_(real_base), | 86 real_base_(real_base), |
87 real_length_(real_length) {} | 87 real_length_(real_length) {} |
88 void Unmap(); | 88 void Unmap(); |
89 | 89 |
90 void* const base_; | 90 void* const base_; |
91 const size_t length_; | 91 const size_t length_; |
92 | 92 |
93 void* const real_base_; | 93 void* const real_base_; |
94 const size_t real_length_; | 94 const size_t real_length_; |
95 | 95 |
96 DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBufferMapping); | 96 DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBufferMapping); |
97 }; | 97 }; |
98 | 98 |
99 } // namespace embedder | 99 } // namespace embedder |
100 } // namespace mojo | 100 } // namespace mojo |
101 | 101 |
102 #endif // MOJO_SYSTEM_SIMPLE_PLATFORM_SHARED_BUFFER_H_ | 102 #endif // MOJO_SYSTEM_SIMPLE_PLATFORM_SHARED_BUFFER_H_ |
OLD | NEW |