OLD | NEW |
| (Empty) |
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_MOJO_IPC_MOJO_BOOTSTRAP_H_ | |
6 #define IPC_MOJO_IPC_MOJO_BOOTSTRAP_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <memory> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/process/process_handle.h" | |
14 #include "build/build_config.h" | |
15 #include "ipc/ipc_channel.h" | |
16 #include "ipc/ipc_listener.h" | |
17 #include "ipc/mojo/ipc.mojom.h" | |
18 #include "mojo/public/cpp/system/message_pipe.h" | |
19 | |
20 namespace IPC { | |
21 | |
22 // MojoBootstrap establishes a pair of associated interfaces between two | |
23 // processes in Chrome. | |
24 // | |
25 // Clients should implement MojoBootstrap::Delegate to get the associated pipes | |
26 // from MojoBootstrap object. | |
27 // | |
28 // This lives on IO thread other than Create(), which can be called from | |
29 // UI thread as Channel::Create() can be. | |
30 class IPC_MOJO_EXPORT MojoBootstrap { | |
31 public: | |
32 class Delegate { | |
33 public: | |
34 virtual void OnPipesAvailable( | |
35 mojom::ChannelAssociatedPtrInfo send_channel, | |
36 mojom::ChannelAssociatedRequest receive_channel, | |
37 int32_t peer_pid) = 0; | |
38 virtual void OnBootstrapError() = 0; | |
39 }; | |
40 | |
41 // Create the MojoBootstrap instance, using |handle| as the message pipe, in | |
42 // mode as specified by |mode|. The result is passed to |delegate|. | |
43 static std::unique_ptr<MojoBootstrap> Create( | |
44 mojo::ScopedMessagePipeHandle handle, | |
45 Channel::Mode mode, | |
46 Delegate* delegate); | |
47 | |
48 MojoBootstrap(); | |
49 virtual ~MojoBootstrap(); | |
50 | |
51 // Start the handshake over the underlying message pipe. | |
52 virtual void Connect() = 0; | |
53 | |
54 // GetSelfPID returns our PID. | |
55 base::ProcessId GetSelfPID() const; | |
56 | |
57 protected: | |
58 // On MojoServerBootstrap: INITIALIZED -> WAITING_ACK -> READY | |
59 // On MojoClientBootstrap: INITIALIZED -> READY | |
60 // STATE_ERROR is a catch-all state that captures any observed error. | |
61 enum State { STATE_INITIALIZED, STATE_WAITING_ACK, STATE_READY, STATE_ERROR }; | |
62 | |
63 Delegate* delegate() const { return delegate_; } | |
64 void Fail(); | |
65 bool HasFailed() const; | |
66 | |
67 State state() const { return state_; } | |
68 void set_state(State state) { state_ = state; } | |
69 | |
70 mojo::ScopedMessagePipeHandle TakeHandle(); | |
71 | |
72 private: | |
73 void Init(mojo::ScopedMessagePipeHandle, Delegate* delegate); | |
74 | |
75 mojo::ScopedMessagePipeHandle handle_; | |
76 Delegate* delegate_; | |
77 State state_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(MojoBootstrap); | |
80 }; | |
81 | |
82 } // namespace IPC | |
83 | |
84 #endif // IPC_MOJO_IPC_MOJO_BOOTSTRAP_H_ | |
OLD | NEW |