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