| 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_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_ |
| 6 #define MOJO_EDK_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include "base/macros.h" |
| 9 | 9 #include "base/memory/ref_counted.h" |
| 10 #include <utility> | 10 #include "base/synchronization/lock.h" |
| 11 | |
| 12 #include "mojo/edk/embedder/scoped_platform_handle.h" | 11 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 13 #include "mojo/edk/system/simple_dispatcher.h" | 12 #include "mojo/edk/system/dispatcher.h" |
| 14 #include "mojo/edk/system/system_impl_export.h" | 13 #include "mojo/edk/system/system_impl_export.h" |
| 15 #include "mojo/public/cpp/system/macros.h" | |
| 16 | 14 |
| 17 namespace mojo { | 15 namespace mojo { |
| 18 namespace edk { | 16 namespace edk { |
| 19 | 17 |
| 20 // A dispatcher that simply wraps/transports a |PlatformHandle| (only for use by | 18 class MOJO_SYSTEM_IMPL_EXPORT PlatformHandleDispatcher : public Dispatcher { |
| 21 // the embedder). | |
| 22 class MOJO_SYSTEM_IMPL_EXPORT PlatformHandleDispatcher final | |
| 23 : public SimpleDispatcher { | |
| 24 public: | 19 public: |
| 25 static scoped_refptr<PlatformHandleDispatcher> Create( | 20 static scoped_refptr<PlatformHandleDispatcher> Create( |
| 26 ScopedPlatformHandle platform_handle) { | 21 ScopedPlatformHandle platform_handle); |
| 27 return make_scoped_refptr( | |
| 28 new PlatformHandleDispatcher(std::move(platform_handle))); | |
| 29 } | |
| 30 | 22 |
| 31 ScopedPlatformHandle PassPlatformHandle(); | 23 ScopedPlatformHandle PassPlatformHandle(); |
| 32 | 24 |
| 33 // |Dispatcher| public methods: | 25 // Dispatcher: |
| 34 Type GetType() const override; | 26 Type GetType() const override; |
| 27 MojoResult Close() override; |
| 28 void StartSerialize(uint32_t* num_bytes, |
| 29 uint32_t* num_ports, |
| 30 uint32_t* num_handles) override; |
| 31 bool EndSerialize(void* destination, |
| 32 ports::PortName* ports, |
| 33 PlatformHandle* handles) override; |
| 34 bool BeginTransit() override; |
| 35 void CompleteTransitAndClose() override; |
| 36 void CancelTransit() override; |
| 35 | 37 |
| 36 // The "opposite" of |SerializeAndClose()|. (Typically this is called by | |
| 37 // |Dispatcher::Deserialize()|.) | |
| 38 static scoped_refptr<PlatformHandleDispatcher> Deserialize( | 38 static scoped_refptr<PlatformHandleDispatcher> Deserialize( |
| 39 const void* source, | 39 const void* bytes, |
| 40 size_t size, | 40 size_t num_bytes, |
| 41 PlatformHandleVector* platform_handles); | 41 const ports::PortName* ports, |
| 42 size_t num_ports, |
| 43 PlatformHandle* handles, |
| 44 size_t num_handles); |
| 42 | 45 |
| 43 private: | 46 private: |
| 44 explicit PlatformHandleDispatcher( | 47 PlatformHandleDispatcher(ScopedPlatformHandle platform_handle); |
| 45 ScopedPlatformHandle platform_handle); | |
| 46 ~PlatformHandleDispatcher() override; | 48 ~PlatformHandleDispatcher() override; |
| 47 | 49 |
| 48 // |Dispatcher| protected methods: | 50 base::Lock lock_; |
| 49 void CloseImplNoLock() override; | 51 bool in_transit_ = false; |
| 50 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() | 52 bool is_closed_ = false; |
| 51 override; | |
| 52 void StartSerializeImplNoLock(size_t* max_size, | |
| 53 size_t* max_platform_handles) override; | |
| 54 bool EndSerializeAndCloseImplNoLock( | |
| 55 void* destination, | |
| 56 size_t* actual_size, | |
| 57 PlatformHandleVector* platform_handles) override; | |
| 58 | |
| 59 ScopedPlatformHandle platform_handle_; | 53 ScopedPlatformHandle platform_handle_; |
| 60 | 54 |
| 61 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformHandleDispatcher); | 55 DISALLOW_COPY_AND_ASSIGN(PlatformHandleDispatcher); |
| 62 }; | 56 }; |
| 63 | 57 |
| 64 } // namespace edk | 58 } // namespace edk |
| 65 } // namespace mojo | 59 } // namespace mojo |
| 66 | 60 |
| 67 #endif // MOJO_EDK_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_ | 61 #endif // MOJO_EDK_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_ |
| OLD | NEW |