Home | History | Annotate | Download | only in system
      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_EDK_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_
      6 #define MOJO_EDK_SYSTEM_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/edk/embedder/scoped_platform_handle.h"
     12 #include "mojo/edk/system/dispatcher.h"
     13 #include "mojo/edk/system/system_impl_export.h"
     14 
     15 namespace mojo {
     16 namespace edk {
     17 
     18 class MOJO_SYSTEM_IMPL_EXPORT PlatformHandleDispatcher : public Dispatcher {
     19  public:
     20   static scoped_refptr<PlatformHandleDispatcher> Create(
     21       ScopedPlatformHandle platform_handle);
     22 
     23   ScopedPlatformHandle PassPlatformHandle();
     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(ScopedPlatformHandle platform_handle);
     48   ~PlatformHandleDispatcher() override;
     49 
     50   base::Lock lock_;
     51   bool in_transit_ = false;
     52   bool is_closed_ = false;
     53   ScopedPlatformHandle platform_handle_;
     54 
     55   DISALLOW_COPY_AND_ASSIGN(PlatformHandleDispatcher);
     56 };
     57 
     58 }  // namespace edk
     59 }  // namespace mojo
     60 
     61 #endif  // MOJO_EDK_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_
     62