xref: /aosp_15_r20/external/libchrome/ipc/ipc_mojo_bootstrap.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright 2014 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #ifndef IPC_IPC_MOJO_BOOTSTRAP_H_
6*635a8641SAndroid Build Coastguard Worker #define IPC_IPC_MOJO_BOOTSTRAP_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include <stdint.h>
9*635a8641SAndroid Build Coastguard Worker 
10*635a8641SAndroid Build Coastguard Worker #include <memory>
11*635a8641SAndroid Build Coastguard Worker 
12*635a8641SAndroid Build Coastguard Worker #include "base/component_export.h"
13*635a8641SAndroid Build Coastguard Worker #include "base/macros.h"
14*635a8641SAndroid Build Coastguard Worker #include "base/memory/ref_counted.h"
15*635a8641SAndroid Build Coastguard Worker #include "base/single_thread_task_runner.h"
16*635a8641SAndroid Build Coastguard Worker #include "build/build_config.h"
17*635a8641SAndroid Build Coastguard Worker #include "ipc/ipc.mojom.h"
18*635a8641SAndroid Build Coastguard Worker #include "ipc/ipc_channel.h"
19*635a8641SAndroid Build Coastguard Worker #include "ipc/ipc_listener.h"
20*635a8641SAndroid Build Coastguard Worker #include "mojo/public/cpp/bindings/associated_group.h"
21*635a8641SAndroid Build Coastguard Worker #include "mojo/public/cpp/system/message_pipe.h"
22*635a8641SAndroid Build Coastguard Worker 
23*635a8641SAndroid Build Coastguard Worker namespace IPC {
24*635a8641SAndroid Build Coastguard Worker 
25*635a8641SAndroid Build Coastguard Worker // MojoBootstrap establishes a pair of associated interfaces between two
26*635a8641SAndroid Build Coastguard Worker // processes in Chrome.
27*635a8641SAndroid Build Coastguard Worker //
28*635a8641SAndroid Build Coastguard Worker // Clients should implement MojoBootstrap::Delegate to get the associated pipes
29*635a8641SAndroid Build Coastguard Worker // from MojoBootstrap object.
30*635a8641SAndroid Build Coastguard Worker //
31*635a8641SAndroid Build Coastguard Worker // This lives on IO thread other than Create(), which can be called from
32*635a8641SAndroid Build Coastguard Worker // UI thread as Channel::Create() can be.
COMPONENT_EXPORT(IPC)33*635a8641SAndroid Build Coastguard Worker class COMPONENT_EXPORT(IPC) MojoBootstrap {
34*635a8641SAndroid Build Coastguard Worker  public:
35*635a8641SAndroid Build Coastguard Worker   virtual ~MojoBootstrap() {}
36*635a8641SAndroid Build Coastguard Worker 
37*635a8641SAndroid Build Coastguard Worker   // Create the MojoBootstrap instance, using |handle| as the message pipe, in
38*635a8641SAndroid Build Coastguard Worker   // mode as specified by |mode|. The result is passed to |delegate|.
39*635a8641SAndroid Build Coastguard Worker   static std::unique_ptr<MojoBootstrap> Create(
40*635a8641SAndroid Build Coastguard Worker       mojo::ScopedMessagePipeHandle handle,
41*635a8641SAndroid Build Coastguard Worker       Channel::Mode mode,
42*635a8641SAndroid Build Coastguard Worker       const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner,
43*635a8641SAndroid Build Coastguard Worker       const scoped_refptr<base::SingleThreadTaskRunner>& proxy_task_runner);
44*635a8641SAndroid Build Coastguard Worker 
45*635a8641SAndroid Build Coastguard Worker   // Start the handshake over the underlying message pipe.
46*635a8641SAndroid Build Coastguard Worker   virtual void Connect(mojom::ChannelAssociatedPtr* sender,
47*635a8641SAndroid Build Coastguard Worker                        mojom::ChannelAssociatedRequest* receiver) = 0;
48*635a8641SAndroid Build Coastguard Worker 
49*635a8641SAndroid Build Coastguard Worker   // Stop transmitting messages and start queueing them instead.
50*635a8641SAndroid Build Coastguard Worker   virtual void Pause() = 0;
51*635a8641SAndroid Build Coastguard Worker 
52*635a8641SAndroid Build Coastguard Worker   // Stop queuing new messages and start transmitting them instead.
53*635a8641SAndroid Build Coastguard Worker   virtual void Unpause() = 0;
54*635a8641SAndroid Build Coastguard Worker 
55*635a8641SAndroid Build Coastguard Worker   // Flush outgoing messages which were queued before Start().
56*635a8641SAndroid Build Coastguard Worker   virtual void Flush() = 0;
57*635a8641SAndroid Build Coastguard Worker 
58*635a8641SAndroid Build Coastguard Worker   virtual mojo::AssociatedGroup* GetAssociatedGroup() = 0;
59*635a8641SAndroid Build Coastguard Worker 
60*635a8641SAndroid Build Coastguard Worker   enum { kMaxOutgoingMessagesSizeForTesting = 100000u };
61*635a8641SAndroid Build Coastguard Worker };
62*635a8641SAndroid Build Coastguard Worker 
63*635a8641SAndroid Build Coastguard Worker }  // namespace IPC
64*635a8641SAndroid Build Coastguard Worker 
65*635a8641SAndroid Build Coastguard Worker #endif  // IPC_IPC_MOJO_BOOTSTRAP_H_
66