OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef IPC_IPC_CHANNEL_MOJO_H_ | 5 #ifndef IPC_IPC_CHANNEL_MOJO_H_ |
6 #define IPC_IPC_CHANNEL_MOJO_H_ | 6 #define IPC_IPC_CHANNEL_MOJO_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 virtual ~Delegate() {} | 62 virtual ~Delegate() {} |
63 virtual base::WeakPtr<Delegate> ToWeakPtr() = 0; | 63 virtual base::WeakPtr<Delegate> ToWeakPtr() = 0; |
64 virtual void OnChannelCreated(base::WeakPtr<ChannelMojo> channel) = 0; | 64 virtual void OnChannelCreated(base::WeakPtr<ChannelMojo> channel) = 0; |
65 }; | 65 }; |
66 | 66 |
67 // True if ChannelMojo should be used regardless of the flag. | 67 // True if ChannelMojo should be used regardless of the flag. |
68 static bool ShouldBeUsed(); | 68 static bool ShouldBeUsed(); |
69 | 69 |
70 // Create ChannelMojo. A bootstrap channel is created as well. | 70 // Create ChannelMojo. A bootstrap channel is created as well. |
71 // |host| must not be null for server channels. | 71 // |host| must not be null for server channels. |
| 72 // |broker| must outlive the newly created channel. |
72 static scoped_ptr<ChannelMojo> Create( | 73 static scoped_ptr<ChannelMojo> Create( |
73 Delegate* delegate, | 74 Delegate* delegate, |
74 scoped_refptr<base::TaskRunner> io_runner, | 75 scoped_refptr<base::TaskRunner> io_runner, |
75 const ChannelHandle& channel_handle, | 76 const ChannelHandle& channel_handle, |
76 Mode mode, | 77 Mode mode, |
77 Listener* listener); | 78 Listener* listener, |
| 79 AttachmentBroker* broker); |
78 | 80 |
79 // Create a factory object for ChannelMojo. | 81 // Create a factory object for ChannelMojo. |
80 // The factory is used to create Mojo-based ChannelProxy family. | 82 // The factory is used to create Mojo-based ChannelProxy family. |
81 // |host| must not be null. | 83 // |host| must not be null. |
| 84 // TODO(erikchen): Remove default parameter for |broker|. It exists only to |
| 85 // make the upcoming refactor decomposable into smaller CLs. |
| 86 // http://crbug.com/493414. |
| 87 // |broker| must outlive the factory and all channels it creates. |
82 static scoped_ptr<ChannelFactory> CreateServerFactory( | 88 static scoped_ptr<ChannelFactory> CreateServerFactory( |
83 Delegate* delegate, | 89 Delegate* delegate, |
84 scoped_refptr<base::TaskRunner> io_runner, | 90 scoped_refptr<base::TaskRunner> io_runner, |
85 const ChannelHandle& channel_handle); | 91 const ChannelHandle& channel_handle, |
| 92 AttachmentBroker* broker = nullptr); |
86 | 93 |
| 94 // TODO(erikchen): Remove default parameter for |broker|. It exists only to |
| 95 // make the upcoming refactor decomposable into smaller CLs. |
| 96 // http://crbug.com/493414. |
| 97 // |broker| must outlive the factory and all channels it creates. |
87 static scoped_ptr<ChannelFactory> CreateClientFactory( | 98 static scoped_ptr<ChannelFactory> CreateClientFactory( |
88 Delegate* delegate, | 99 Delegate* delegate, |
89 scoped_refptr<base::TaskRunner> io_runner, | 100 scoped_refptr<base::TaskRunner> io_runner, |
90 const ChannelHandle& channel_handle); | 101 const ChannelHandle& channel_handle, |
| 102 AttachmentBroker* broker = nullptr); |
91 | 103 |
92 ~ChannelMojo() override; | 104 ~ChannelMojo() override; |
93 | 105 |
94 // ChannelMojoHost tells the client handle using this API. | 106 // ChannelMojoHost tells the client handle using this API. |
95 void OnClientLaunched(base::ProcessHandle handle); | 107 void OnClientLaunched(base::ProcessHandle handle); |
96 | 108 |
97 // Channel implementation | 109 // Channel implementation |
98 bool Connect() override; | 110 bool Connect() override; |
99 void Close() override; | 111 void Close() override; |
100 bool Send(Message* message) override; | 112 bool Send(Message* message) override; |
(...skipping 21 matching lines...) Expand all Loading... |
122 // MessagePipeReader::Delegate | 134 // MessagePipeReader::Delegate |
123 void OnMessageReceived(Message& message) override; | 135 void OnMessageReceived(Message& message) override; |
124 void OnPipeClosed(internal::MessagePipeReader* reader) override; | 136 void OnPipeClosed(internal::MessagePipeReader* reader) override; |
125 void OnPipeError(internal::MessagePipeReader* reader) override; | 137 void OnPipeError(internal::MessagePipeReader* reader) override; |
126 | 138 |
127 protected: | 139 protected: |
128 ChannelMojo(Delegate* delegate, | 140 ChannelMojo(Delegate* delegate, |
129 scoped_refptr<base::TaskRunner> io_runner, | 141 scoped_refptr<base::TaskRunner> io_runner, |
130 const ChannelHandle& channel_handle, | 142 const ChannelHandle& channel_handle, |
131 Mode mode, | 143 Mode mode, |
132 Listener* listener); | 144 Listener* listener, |
| 145 AttachmentBroker* broker); |
133 | 146 |
134 void CreateMessagingPipe(mojo::embedder::ScopedPlatformHandle handle, | 147 void CreateMessagingPipe(mojo::embedder::ScopedPlatformHandle handle, |
135 const CreateMessagingPipeCallback& callback); | 148 const CreateMessagingPipeCallback& callback); |
136 void InitMessageReader(mojo::ScopedMessagePipeHandle pipe, int32_t peer_pid); | 149 void InitMessageReader(mojo::ScopedMessagePipeHandle pipe, int32_t peer_pid); |
137 | 150 |
138 Listener* listener() const { return listener_; } | 151 Listener* listener() const { return listener_; } |
139 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } | 152 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } |
140 | 153 |
141 private: | 154 private: |
142 struct ChannelInfoDeleter { | 155 struct ChannelInfoDeleter { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 scoped_ptr<ScopedIPCSupport> ipc_support_; | 197 scoped_ptr<ScopedIPCSupport> ipc_support_; |
185 | 198 |
186 base::WeakPtrFactory<ChannelMojo> weak_factory_; | 199 base::WeakPtrFactory<ChannelMojo> weak_factory_; |
187 | 200 |
188 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); | 201 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); |
189 }; | 202 }; |
190 | 203 |
191 } // namespace IPC | 204 } // namespace IPC |
192 | 205 |
193 #endif // IPC_IPC_CHANNEL_MOJO_H_ | 206 #endif // IPC_IPC_CHANNEL_MOJO_H_ |
OLD | NEW |