blob: 5188cd0199610c6776d292dc2cfe6e04c76144b1 [file] [log] [blame]
morrita54f6f80c2014-09-23 21:16:001// 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
amistryd4aa70d2016-06-23 07:52:375#ifndef IPC_IPC_MOJO_BOOTSTRAP_H_
6#define IPC_IPC_MOJO_BOOTSTRAP_H_
morrita54f6f80c2014-09-23 21:16:007
avi246998d82015-12-22 02:39:048#include <stdint.h>
9
danakj03de39b22016-04-23 04:21:0910#include <memory>
11
avi246998d82015-12-22 02:39:0412#include "base/macros.h"
rockot8d890f62016-07-14 16:37:1413#include "base/memory/ref_counted.h"
rockot8d890f62016-07-14 16:37:1414#include "base/single_thread_task_runner.h"
avi246998d82015-12-22 02:39:0415#include "build/build_config.h"
amistryd4aa70d2016-06-23 07:52:3716#include "ipc/ipc.mojom.h"
morrita54f6f80c2014-09-23 21:16:0017#include "ipc/ipc_channel.h"
18#include "ipc/ipc_listener.h"
rockot7c6bf952016-07-14 00:34:1119#include "mojo/public/cpp/bindings/associated_group.h"
sammce4d0abd2016-03-07 22:38:0420#include "mojo/public/cpp/system/message_pipe.h"
morrita54f6f80c2014-09-23 21:16:0021
22namespace IPC {
23
sammce4d0abd2016-03-07 22:38:0424// MojoBootstrap establishes a pair of associated interfaces between two
25// processes in Chrome.
morrita54f6f80c2014-09-23 21:16:0026//
sammce4d0abd2016-03-07 22:38:0427// Clients should implement MojoBootstrap::Delegate to get the associated pipes
leon.hand20a6c4c2015-06-19 02:25:4828// from MojoBootstrap object.
morrita54f6f80c2014-09-23 21:16:0029//
30// This lives on IO thread other than Create(), which can be called from
31// UI thread as Channel::Create() can be.
amistryd4aa70d2016-06-23 07:52:3732class IPC_EXPORT MojoBootstrap {
morrita54f6f80c2014-09-23 21:16:0033 public:
34 class Delegate {
35 public:
rockot0e4de5f2016-07-22 21:18:0736 virtual ~Delegate() {}
37
38 virtual void OnPipesAvailable(mojom::ChannelAssociatedPtr sender,
39 mojom::ChannelAssociatedRequest receiver) = 0;
morrita54f6f80c2014-09-23 21:16:0040 };
41
rockot0e4de5f2016-07-22 21:18:0742 virtual ~MojoBootstrap() {}
43
sammc57ed9f982016-03-10 06:28:3544 // Create the MojoBootstrap instance, using |handle| as the message pipe, in
45 // mode as specified by |mode|. The result is passed to |delegate|.
danakj03de39b22016-04-23 04:21:0946 static std::unique_ptr<MojoBootstrap> Create(
47 mojo::ScopedMessagePipeHandle handle,
48 Channel::Mode mode,
rockot0e4de5f2016-07-22 21:18:0749 Delegate* delegate,
50 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner);
morrita54f6f80c2014-09-23 21:16:0051
sammce4d0abd2016-03-07 22:38:0452 // Start the handshake over the underlying message pipe.
53 virtual void Connect() = 0;
morrita54f6f80c2014-09-23 21:16:0054
rockot10188752016-09-08 18:24:5655 // Stop transmitting messages and start queueing them instead.
56 virtual void Pause() = 0;
57
rockot401fb2c2016-09-06 18:35:5758 // Stop queuing new messages and start transmitting them instead.
rockot10188752016-09-08 18:24:5659 virtual void Unpause() = 0;
rockot401fb2c2016-09-06 18:35:5760
61 // Flush outgoing messages which were queued before Start().
62 virtual void Flush() = 0;
63
rockot7c6bf952016-07-14 00:34:1164 virtual mojo::AssociatedGroup* GetAssociatedGroup() = 0;
morrita54f6f80c2014-09-23 21:16:0065};
66
67} // namespace IPC
68
amistryd4aa70d2016-06-23 07:52:3769#endif // IPC_IPC_MOJO_BOOTSTRAP_H_