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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 // separate class to clarify what ChannelMojo relies | 44 // separate class to clarify what ChannelMojo relies |
45 // on. | 45 // on. |
46 // TODO(morrita): Add APIs to create extra MessagePipes to let | 46 // TODO(morrita): Add APIs to create extra MessagePipes to let |
47 // Mojo-based objects talk over this Channel. | 47 // Mojo-based objects talk over this Channel. |
48 // | 48 // |
49 class IPC_MOJO_EXPORT ChannelMojo | 49 class IPC_MOJO_EXPORT ChannelMojo |
50 : public Channel, | 50 : public Channel, |
51 public MojoBootstrap::Delegate, | 51 public MojoBootstrap::Delegate, |
52 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) { | 52 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) { |
53 public: | 53 public: |
54 using CreateMessagingPipeCallback = | |
55 base::Callback<void(mojo::ScopedMessagePipeHandle)>; | |
56 using CreateMessagingPipeOnIOThreadCallback = | |
57 base::Callback<void(mojo::ScopedMessagePipeHandle, | |
58 mojo::embedder::ChannelInfo*)>; | |
59 | |
54 class Delegate { | 60 class Delegate { |
55 public: | 61 public: |
56 virtual ~Delegate() {} | 62 virtual ~Delegate() {} |
57 virtual base::WeakPtr<Delegate> ToWeakPtr() = 0; | 63 virtual base::WeakPtr<Delegate> ToWeakPtr() = 0; |
58 virtual void OnChannelCreated(base::WeakPtr<ChannelMojo> channel) = 0; | 64 virtual void OnChannelCreated(base::WeakPtr<ChannelMojo> channel) = 0; |
59 }; | 65 }; |
60 | 66 |
61 // True if ChannelMojo should be used regardless of the flag. | 67 // True if ChannelMojo should be used regardless of the flag. |
62 static bool ShouldBeUsed(); | 68 static bool ShouldBeUsed(); |
63 | 69 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 void OnPipeClosed(internal::MessagePipeReader* reader) override; | 124 void OnPipeClosed(internal::MessagePipeReader* reader) override; |
119 void OnPipeError(internal::MessagePipeReader* reader) override; | 125 void OnPipeError(internal::MessagePipeReader* reader) override; |
120 | 126 |
121 protected: | 127 protected: |
122 ChannelMojo(Delegate* delegate, | 128 ChannelMojo(Delegate* delegate, |
123 scoped_refptr<base::TaskRunner> io_runner, | 129 scoped_refptr<base::TaskRunner> io_runner, |
124 const ChannelHandle& channel_handle, | 130 const ChannelHandle& channel_handle, |
125 Mode mode, | 131 Mode mode, |
126 Listener* listener); | 132 Listener* listener); |
127 | 133 |
128 mojo::ScopedMessagePipeHandle CreateMessagingPipe( | 134 void CreateMessagingPipe(mojo::embedder::ScopedPlatformHandle handle, |
129 mojo::embedder::ScopedPlatformHandle handle); | 135 const CreateMessagingPipeCallback& callback); |
130 void InitMessageReader(mojo::ScopedMessagePipeHandle pipe, int32_t peer_pid); | 136 void InitMessageReader(mojo::ScopedMessagePipeHandle pipe, int32_t peer_pid); |
131 | 137 |
132 Listener* listener() const { return listener_; } | 138 Listener* listener() const { return listener_; } |
133 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } | 139 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } |
134 | 140 |
135 private: | 141 private: |
136 struct ChannelInfoDeleter { | 142 struct ChannelInfoDeleter { |
143 explicit ChannelInfoDeleter(scoped_refptr<base::TaskRunner> io_runer); | |
jam
2015/05/11 15:53:25
nit: io_runner
Ken Rockot(use gerrit already)
2015/05/11 16:11:53
Done.
| |
144 ~ChannelInfoDeleter(); | |
145 | |
137 void operator()(mojo::embedder::ChannelInfo* ptr) const; | 146 void operator()(mojo::embedder::ChannelInfo* ptr) const; |
147 | |
148 scoped_refptr<base::TaskRunner> io_runner; | |
138 }; | 149 }; |
139 | 150 |
140 // ChannelMojo needs to kill its MessagePipeReader in delayed manner | 151 // ChannelMojo needs to kill its MessagePipeReader in delayed manner |
141 // because the channel wants to kill these readers during the | 152 // because the channel wants to kill these readers during the |
142 // notifications invoked by them. | 153 // notifications invoked by them. |
143 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; | 154 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; |
144 | 155 |
145 void InitOnIOThread(ChannelMojo::Delegate* delegate); | 156 void InitOnIOThread(ChannelMojo::Delegate* delegate); |
146 | 157 |
158 static void CreateMessagingPipeOnIOThread( | |
159 mojo::embedder::ScopedPlatformHandle handle, | |
160 scoped_refptr<base::TaskRunner> callback_runner, | |
161 const CreateMessagingPipeOnIOThreadCallback& callback); | |
162 void OnMessagingPipeCreated(const CreateMessagingPipeCallback& callback, | |
163 mojo::ScopedMessagePipeHandle handle, | |
164 mojo::embedder::ChannelInfo* channel_info); | |
165 | |
147 scoped_ptr<MojoBootstrap> bootstrap_; | 166 scoped_ptr<MojoBootstrap> bootstrap_; |
148 base::WeakPtr<Delegate> delegate_; | 167 base::WeakPtr<Delegate> delegate_; |
149 Mode mode_; | 168 Mode mode_; |
150 Listener* listener_; | 169 Listener* listener_; |
151 base::ProcessId peer_pid_; | 170 base::ProcessId peer_pid_; |
152 scoped_refptr<base::TaskRunner> io_runner_; | 171 scoped_refptr<base::TaskRunner> io_runner_; |
153 scoped_ptr<mojo::embedder::ChannelInfo, | 172 scoped_ptr<mojo::embedder::ChannelInfo, |
154 ChannelInfoDeleter> channel_info_; | 173 ChannelInfoDeleter> channel_info_; |
155 | 174 |
156 // Guards |message_reader_| and |pending_messages_| | 175 // Guards |message_reader_| and |pending_messages_| |
157 // | 176 // |
158 // * The contents of |pending_messages_| can be modified from any thread. | 177 // * The contents of |pending_messages_| can be modified from any thread. |
159 // * |message_reader_| is modified only from the IO thread, | 178 // * |message_reader_| is modified only from the IO thread, |
160 // but they can be referenced from other threads. | 179 // but they can be referenced from other threads. |
161 base::Lock lock_; | 180 base::Lock lock_; |
162 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_; | 181 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_; |
163 ScopedVector<Message> pending_messages_; | 182 ScopedVector<Message> pending_messages_; |
164 | 183 |
165 scoped_ptr<ScopedIPCSupport> ipc_support_; | 184 scoped_ptr<ScopedIPCSupport> ipc_support_; |
166 | 185 |
167 base::WeakPtrFactory<ChannelMojo> weak_factory_; | 186 base::WeakPtrFactory<ChannelMojo> weak_factory_; |
168 | 187 |
169 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); | 188 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); |
170 }; | 189 }; |
171 | 190 |
172 } // namespace IPC | 191 } // namespace IPC |
173 | 192 |
174 #endif // IPC_IPC_CHANNEL_MOJO_H_ | 193 #endif // IPC_IPC_CHANNEL_MOJO_H_ |
OLD | NEW |