morrita | 54f6f80c | 2014-09-23 21:16:00 | [diff] [blame] | 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 | |
amistry | d4aa70d | 2016-06-23 07:52:37 | [diff] [blame] | 5 | #ifndef IPC_IPC_MOJO_BOOTSTRAP_H_ |
| 6 | #define IPC_IPC_MOJO_BOOTSTRAP_H_ |
morrita | 54f6f80c | 2014-09-23 21:16:00 | [diff] [blame] | 7 | |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
danakj | 03de39b2 | 2016-04-23 04:21:09 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
Ken Rockot | 3044d21 | 2018-01-23 02:44:39 | [diff] [blame] | 12 | #include "base/component_export.h" |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 13 | #include "base/macros.h" |
rockot | 8d890f6 | 2016-07-14 16:37:14 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
rockot | 8d890f6 | 2016-07-14 16:37:14 | [diff] [blame] | 15 | #include "base/single_thread_task_runner.h" |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 16 | #include "build/build_config.h" |
amistry | d4aa70d | 2016-06-23 07:52:37 | [diff] [blame] | 17 | #include "ipc/ipc.mojom.h" |
morrita | 54f6f80c | 2014-09-23 21:16:00 | [diff] [blame] | 18 | #include "ipc/ipc_channel.h" |
| 19 | #include "ipc/ipc_listener.h" |
rockot | 7c6bf95 | 2016-07-14 00:34:11 | [diff] [blame] | 20 | #include "mojo/public/cpp/bindings/associated_group.h" |
sammc | e4d0abd | 2016-03-07 22:38:04 | [diff] [blame] | 21 | #include "mojo/public/cpp/system/message_pipe.h" |
morrita | 54f6f80c | 2014-09-23 21:16:00 | [diff] [blame] | 22 | |
| 23 | namespace IPC { |
| 24 | |
sammc | e4d0abd | 2016-03-07 22:38:04 | [diff] [blame] | 25 | // MojoBootstrap establishes a pair of associated interfaces between two |
| 26 | // processes in Chrome. |
morrita | 54f6f80c | 2014-09-23 21:16:00 | [diff] [blame] | 27 | // |
sammc | e4d0abd | 2016-03-07 22:38:04 | [diff] [blame] | 28 | // Clients should implement MojoBootstrap::Delegate to get the associated pipes |
leon.han | d20a6c4c | 2015-06-19 02:25:48 | [diff] [blame] | 29 | // from MojoBootstrap object. |
morrita | 54f6f80c | 2014-09-23 21:16:00 | [diff] [blame] | 30 | // |
| 31 | // This lives on IO thread other than Create(), which can be called from |
| 32 | // UI thread as Channel::Create() can be. |
Ken Rockot | 3044d21 | 2018-01-23 02:44:39 | [diff] [blame] | 33 | class COMPONENT_EXPORT(IPC) MojoBootstrap { |
morrita | 54f6f80c | 2014-09-23 21:16:00 | [diff] [blame] | 34 | public: |
rockot | 0e4de5f | 2016-07-22 21:18:07 | [diff] [blame] | 35 | virtual ~MojoBootstrap() {} |
| 36 | |
sammc | 57ed9f98 | 2016-03-10 06:28:35 | [diff] [blame] | 37 | // Create the MojoBootstrap instance, using |handle| as the message pipe, in |
| 38 | // mode as specified by |mode|. The result is passed to |delegate|. |
danakj | 03de39b2 | 2016-04-23 04:21:09 | [diff] [blame] | 39 | static std::unique_ptr<MojoBootstrap> Create( |
| 40 | mojo::ScopedMessagePipeHandle handle, |
| 41 | Channel::Mode mode, |
Hajime Hoshi | a98f110 | 2017-11-20 06:34:35 | [diff] [blame] | 42 | const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
| 43 | const scoped_refptr<base::SingleThreadTaskRunner>& proxy_task_runner); |
morrita | 54f6f80c | 2014-09-23 21:16:00 | [diff] [blame] | 44 | |
sammc | e4d0abd | 2016-03-07 22:38:04 | [diff] [blame] | 45 | // Start the handshake over the underlying message pipe. |
rockot | a628d0b | 2017-02-09 08:40:15 | [diff] [blame] | 46 | virtual void Connect(mojom::ChannelAssociatedPtr* sender, |
| 47 | mojom::ChannelAssociatedRequest* receiver) = 0; |
morrita | 54f6f80c | 2014-09-23 21:16:00 | [diff] [blame] | 48 | |
rockot | 1018875 | 2016-09-08 18:24:56 | [diff] [blame] | 49 | // Stop transmitting messages and start queueing them instead. |
| 50 | virtual void Pause() = 0; |
| 51 | |
rockot | 401fb2c | 2016-09-06 18:35:57 | [diff] [blame] | 52 | // Stop queuing new messages and start transmitting them instead. |
rockot | 1018875 | 2016-09-08 18:24:56 | [diff] [blame] | 53 | virtual void Unpause() = 0; |
rockot | 401fb2c | 2016-09-06 18:35:57 | [diff] [blame] | 54 | |
| 55 | // Flush outgoing messages which were queued before Start(). |
| 56 | virtual void Flush() = 0; |
| 57 | |
rockot | 7c6bf95 | 2016-07-14 00:34:11 | [diff] [blame] | 58 | virtual mojo::AssociatedGroup* GetAssociatedGroup() = 0; |
Lukasz Anforowicz | b29fffc2 | 2018-05-29 17:37:33 | [diff] [blame] | 59 | |
| 60 | enum { kMaxOutgoingMessagesSizeForTesting = 100000u }; |
morrita | 54f6f80c | 2014-09-23 21:16:00 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } // namespace IPC |
| 64 | |
amistry | d4aa70d | 2016-06-23 07:52:37 | [diff] [blame] | 65 | #endif // IPC_IPC_MOJO_BOOTSTRAP_H_ |