blob: 5aba8a35840d39e7f217096debf0281f0e204177 [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
Ken Rockot3044d212018-01-23 02:44:3912#include "base/component_export.h"
avi246998d82015-12-22 02:39:0413#include "base/macros.h"
rockot8d890f62016-07-14 16:37:1414#include "base/memory/ref_counted.h"
rockot8d890f62016-07-14 16:37:1415#include "base/single_thread_task_runner.h"
avi246998d82015-12-22 02:39:0416#include "build/build_config.h"
amistryd4aa70d2016-06-23 07:52:3717#include "ipc/ipc.mojom.h"
morrita54f6f80c2014-09-23 21:16:0018#include "ipc/ipc_channel.h"
19#include "ipc/ipc_listener.h"
rockot7c6bf952016-07-14 00:34:1120#include "mojo/public/cpp/bindings/associated_group.h"
sammce4d0abd2016-03-07 22:38:0421#include "mojo/public/cpp/system/message_pipe.h"
morrita54f6f80c2014-09-23 21:16:0022
23namespace IPC {
24
sammce4d0abd2016-03-07 22:38:0425// MojoBootstrap establishes a pair of associated interfaces between two
26// processes in Chrome.
morrita54f6f80c2014-09-23 21:16:0027//
sammce4d0abd2016-03-07 22:38:0428// Clients should implement MojoBootstrap::Delegate to get the associated pipes
leon.hand20a6c4c2015-06-19 02:25:4829// from MojoBootstrap object.
morrita54f6f80c2014-09-23 21:16:0030//
31// This lives on IO thread other than Create(), which can be called from
32// UI thread as Channel::Create() can be.
Ken Rockot3044d212018-01-23 02:44:3933class COMPONENT_EXPORT(IPC) MojoBootstrap {
morrita54f6f80c2014-09-23 21:16:0034 public:
rockot0e4de5f2016-07-22 21:18:0735 virtual ~MojoBootstrap() {}
36
sammc57ed9f982016-03-10 06:28:3537 // Create the MojoBootstrap instance, using |handle| as the message pipe, in
38 // mode as specified by |mode|. The result is passed to |delegate|.
danakj03de39b22016-04-23 04:21:0939 static std::unique_ptr<MojoBootstrap> Create(
40 mojo::ScopedMessagePipeHandle handle,
41 Channel::Mode mode,
Hajime Hoshia98f1102017-11-20 06:34:3542 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner,
43 const scoped_refptr<base::SingleThreadTaskRunner>& proxy_task_runner);
morrita54f6f80c2014-09-23 21:16:0044
sammce4d0abd2016-03-07 22:38:0445 // Start the handshake over the underlying message pipe.
rockota628d0b2017-02-09 08:40:1546 virtual void Connect(mojom::ChannelAssociatedPtr* sender,
47 mojom::ChannelAssociatedRequest* receiver) = 0;
morrita54f6f80c2014-09-23 21:16:0048
rockot10188752016-09-08 18:24:5649 // Stop transmitting messages and start queueing them instead.
50 virtual void Pause() = 0;
51
rockot401fb2c2016-09-06 18:35:5752 // Stop queuing new messages and start transmitting them instead.
rockot10188752016-09-08 18:24:5653 virtual void Unpause() = 0;
rockot401fb2c2016-09-06 18:35:5754
55 // Flush outgoing messages which were queued before Start().
56 virtual void Flush() = 0;
57
rockot7c6bf952016-07-14 00:34:1158 virtual mojo::AssociatedGroup* GetAssociatedGroup() = 0;
Lukasz Anforowiczb29fffc22018-05-29 17:37:3359
60 enum { kMaxOutgoingMessagesSizeForTesting = 100000u };
morrita54f6f80c2014-09-23 21:16:0061};
62
63} // namespace IPC
64
amistryd4aa70d2016-06-23 07:52:3765#endif // IPC_IPC_MOJO_BOOTSTRAP_H_