• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CORE_BROKER_H_
6 #define MOJO_CORE_BROKER_H_
7 
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/writable_shared_memory_region.h"
11 #include "base/synchronization/lock.h"
12 #include "mojo/public/cpp/platform/platform_channel_endpoint.h"
13 #include "mojo/public/cpp/platform/platform_handle.h"
14 
15 namespace mojo {
16 namespace core {
17 
18 // The Broker is a channel to the broker process, which allows synchronous IPCs
19 // to fulfill shared memory allocation requests on some platforms.
20 class Broker {
21  public:
22   // Note: This is blocking, and will wait for the first message over
23   // the endpoint handle in |handle|.
24   explicit Broker(PlatformHandle handle);
25   ~Broker();
26 
27   // Returns the platform handle that should be used to establish a NodeChannel
28   // to the process which is inviting us to join its network. This is the first
29   // handle read off the Broker channel upon construction.
30   PlatformChannelEndpoint GetInviterEndpoint();
31 
32   // Request a shared buffer from the broker process. Blocks the current thread.
33   base::WritableSharedMemoryRegion GetWritableSharedMemoryRegion(
34       size_t num_bytes);
35 
36  private:
37   // Handle to the broker process, used for synchronous IPCs.
38   PlatformHandle sync_channel_;
39 
40   // Channel endpoint connected to the inviter process. Recieved in the first
41   // first message over |sync_channel_|.
42   PlatformChannelEndpoint inviter_endpoint_;
43 
44   // Lock to only allow one sync message at a time. This avoids having to deal
45   // with message ordering since we can only have one request at a time
46   // in-flight.
47   base::Lock lock_;
48 
49   DISALLOW_COPY_AND_ASSIGN(Broker);
50 };
51 
52 }  // namespace core
53 }  // namespace mojo
54 
55 #endif  // MOJO_CORE_BROKER_H_
56