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