| 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_EDK_EMBEDDER_SIMPLE_PLATFORM_SHARED_BUFFER_H_ | 5 #ifndef MOJO_EDK_EMBEDDER_SIMPLE_PLATFORM_SHARED_BUFFER_H_ |
| 6 #define MOJO_EDK_EMBEDDER_SIMPLE_PLATFORM_SHARED_BUFFER_H_ | 6 #define MOJO_EDK_EMBEDDER_SIMPLE_PLATFORM_SHARED_BUFFER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "mojo/edk/embedder/platform_shared_buffer.h" | 10 #include "mojo/edk/embedder/platform_shared_buffer.h" |
| 11 #include "mojo/edk/util/ref_ptr.h" | 11 #include "mojo/edk/util/ref_ptr.h" |
| 12 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.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 SimplePlatformSharedBuffer final : public PlatformSharedBuffer { | 18 class SimplePlatformSharedBuffer final : public PlatformSharedBuffer { |
| 19 public: | 19 public: |
| 20 // Creates a shared buffer of size |num_bytes| bytes (initially zero-filled). | 20 // Creates a shared buffer of size |num_bytes| bytes (initially zero-filled). |
| 21 // |num_bytes| must be nonzero. Returns null on failure. | 21 // |num_bytes| must be nonzero. Returns null on failure. |
| 22 static util::RefPtr<SimplePlatformSharedBuffer> Create(size_t num_bytes); | 22 static util::RefPtr<SimplePlatformSharedBuffer> Create(size_t num_bytes); |
| 23 | 23 |
| 24 static util::RefPtr<SimplePlatformSharedBuffer> CreateFromPlatformHandle( | 24 static util::RefPtr<SimplePlatformSharedBuffer> CreateFromPlatformHandle( |
| 25 size_t num_bytes, | 25 size_t num_bytes, |
| 26 ScopedPlatformHandle platform_handle); | 26 platform::ScopedPlatformHandle platform_handle); |
| 27 | 27 |
| 28 // |PlatformSharedBuffer| implementation: | 28 // |PlatformSharedBuffer| implementation: |
| 29 size_t GetNumBytes() const override; | 29 size_t GetNumBytes() const override; |
| 30 std::unique_ptr<PlatformSharedBufferMapping> Map(size_t offset, | 30 std::unique_ptr<PlatformSharedBufferMapping> Map(size_t offset, |
| 31 size_t length) override; | 31 size_t length) override; |
| 32 bool IsValidMap(size_t offset, size_t length) override; | 32 bool IsValidMap(size_t offset, size_t length) override; |
| 33 std::unique_ptr<PlatformSharedBufferMapping> MapNoCheck( | 33 std::unique_ptr<PlatformSharedBufferMapping> MapNoCheck( |
| 34 size_t offset, | 34 size_t offset, |
| 35 size_t length) override; | 35 size_t length) override; |
| 36 ScopedPlatformHandle DuplicatePlatformHandle() override; | 36 platform::ScopedPlatformHandle DuplicatePlatformHandle() override; |
| 37 ScopedPlatformHandle PassPlatformHandle() override; | 37 platform::ScopedPlatformHandle PassPlatformHandle() override; |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 explicit SimplePlatformSharedBuffer(size_t num_bytes); | 40 explicit SimplePlatformSharedBuffer(size_t num_bytes); |
| 41 ~SimplePlatformSharedBuffer() override; | 41 ~SimplePlatformSharedBuffer() override; |
| 42 | 42 |
| 43 // This is called by |Create()| before this object is given to anyone. | 43 // This is called by |Create()| before this object is given to anyone. |
| 44 bool Init(); | 44 bool Init(); |
| 45 | 45 |
| 46 // This is like |Init()|, but for |CreateFromPlatformHandle()|. (Note: It | 46 // This is like |Init()|, but for |CreateFromPlatformHandle()|. (Note: It |
| 47 // should verify that |platform_handle| is an appropriate handle for the | 47 // should verify that |platform_handle| is an appropriate handle for the |
| 48 // claimed |num_bytes_|.) | 48 // claimed |num_bytes_|.) |
| 49 bool InitFromPlatformHandle(ScopedPlatformHandle platform_handle); | 49 bool InitFromPlatformHandle(platform::ScopedPlatformHandle platform_handle); |
| 50 | 50 |
| 51 const size_t num_bytes_; | 51 const size_t num_bytes_; |
| 52 | 52 |
| 53 // This is set in |Init()|/|InitFromPlatformHandle()| and never modified | 53 // This is set in |Init()|/|InitFromPlatformHandle()| and never modified |
| 54 // (except by |PassPlatformHandle()|; see the comments above its declaration), | 54 // (except by |PassPlatformHandle()|; see the comments above its declaration), |
| 55 // hence does not need to be protected by a lock. | 55 // hence does not need to be protected by a lock. |
| 56 ScopedPlatformHandle handle_; | 56 platform::ScopedPlatformHandle handle_; |
| 57 | 57 |
| 58 MOJO_DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBuffer); | 58 MOJO_DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBuffer); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // An implementation of |PlatformSharedBufferMapping|, produced by | 61 // An implementation of |PlatformSharedBufferMapping|, produced by |
| 62 // |SimplePlatformSharedBuffer|. | 62 // |SimplePlatformSharedBuffer|. |
| 63 class SimplePlatformSharedBufferMapping final | 63 class SimplePlatformSharedBufferMapping final |
| 64 : public PlatformSharedBufferMapping { | 64 : public PlatformSharedBufferMapping { |
| 65 public: | 65 public: |
| 66 ~SimplePlatformSharedBufferMapping() override; | 66 ~SimplePlatformSharedBufferMapping() override; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 87 void* const real_base_; | 87 void* const real_base_; |
| 88 const size_t real_length_; | 88 const size_t real_length_; |
| 89 | 89 |
| 90 MOJO_DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBufferMapping); | 90 MOJO_DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBufferMapping); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 } // namespace embedder | 93 } // namespace embedder |
| 94 } // namespace mojo | 94 } // namespace mojo |
| 95 | 95 |
| 96 #endif // MOJO_EDK_EMBEDDER_SIMPLE_PLATFORM_SHARED_BUFFER_H_ | 96 #endif // MOJO_EDK_EMBEDDER_SIMPLE_PLATFORM_SHARED_BUFFER_H_ |
| OLD | NEW |