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 3 // found in the LICENSE file. 4 5 #ifndef MOJO_CORE_PLATFORM_HANDLE_DISPATCHER_H_ 6 #define MOJO_CORE_PLATFORM_HANDLE_DISPATCHER_H_ 7 8 #include "base/macros.h" 9 #include "base/memory/ref_counted.h" 10 #include "base/synchronization/lock.h" 11 #include "mojo/core/dispatcher.h" 12 #include "mojo/core/system_impl_export.h" 13 #include "mojo/public/cpp/platform/platform_handle.h" 14 15 namespace mojo { 16 namespace core { 17 18 class MOJO_SYSTEM_IMPL_EXPORT PlatformHandleDispatcher : public Dispatcher { 19 public: 20 static scoped_refptr<PlatformHandleDispatcher> Create( 21 PlatformHandle platform_handle); 22 23 PlatformHandle TakePlatformHandle(); 24 25 // Dispatcher: 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; 37 38 static scoped_refptr<PlatformHandleDispatcher> Deserialize( 39 const void* bytes, 40 size_t num_bytes, 41 const ports::PortName* ports, 42 size_t num_ports, 43 PlatformHandle* handles, 44 size_t num_handles); 45 46 private: 47 PlatformHandleDispatcher(PlatformHandle platform_handle); 48 ~PlatformHandleDispatcher() override; 49 50 base::Lock lock_; 51 bool in_transit_ = false; 52 bool is_closed_ = false; 53 PlatformHandle platform_handle_; 54 55 DISALLOW_COPY_AND_ASSIGN(PlatformHandleDispatcher); 56 }; 57 58 } // namespace core 59 } // namespace mojo 60 61 #endif // MOJO_CORE_PLATFORM_HANDLE_DISPATCHER_H_ 62