Home | History | Annotate | Download | only in system
      1 // Copyright 2016 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_BROKER_H_
      6 #define MOJO_EDK_SYSTEM_BROKER_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 
     13 namespace mojo {
     14 namespace edk {
     15 
     16 class PlatformSharedBuffer;
     17 
     18 // The Broker is a channel to the parent process, which allows synchronous IPCs.
     19 class Broker {
     20  public:
     21   // Note: This is blocking, and will wait for the first message over
     22   // |platform_handle|.
     23   explicit Broker(ScopedPlatformHandle platform_handle);
     24   ~Broker();
     25 
     26   // Returns the platform handle that should be used to establish a NodeChannel
     27   // to the parent process.
     28   ScopedPlatformHandle GetParentPlatformHandle();
     29 
     30   // Request a shared buffer from the parent process. Blocks the current thread.
     31   scoped_refptr<PlatformSharedBuffer> GetSharedBuffer(size_t num_bytes);
     32 
     33  private:
     34   // Handle to the parent process, used for synchronous IPCs.
     35   ScopedPlatformHandle sync_channel_;
     36 
     37   // Handle to the parent process which is recieved in the first first message
     38   // over |sync_channel_|.
     39   ScopedPlatformHandle parent_channel_;
     40 
     41   // Lock to only allow one sync message at a time. This avoids having to deal
     42   // with message ordering since we can only have one request at a time
     43   // in-flight.
     44   base::Lock lock_;
     45 
     46   DISALLOW_COPY_AND_ASSIGN(Broker);
     47 };
     48 
     49 }  // namespace edk
     50 }  // namespace mojo
     51 
     52 #endif  // MOJO_EDK_SYSTEM_BROKER_H_
     53