Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: ipc/mojo/ipc_channel_mojo.h

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to mojo::edk namespace in preparation for runtim flag Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "ipc/ipc_channel.h" 14 #include "ipc/ipc_channel.h"
15 #include "ipc/ipc_channel_factory.h" 15 #include "ipc/ipc_channel_factory.h"
16 #include "ipc/ipc_export.h" 16 #include "ipc/ipc_export.h"
17 #include "ipc/mojo/ipc_message_pipe_reader.h" 17 #include "ipc/mojo/ipc_message_pipe_reader.h"
18 #include "ipc/mojo/ipc_mojo_bootstrap.h" 18 #include "ipc/mojo/ipc_mojo_bootstrap.h"
19 #include "ipc/mojo/scoped_ipc_support.h" 19 #include "ipc/mojo/scoped_ipc_support.h"
20 #include "third_party/mojo/src/mojo/public/cpp/system/core.h"
21
22 #if !defined(USE_CHROME_EDK)
20 #include "third_party/mojo/src/mojo/edk/embedder/channel_info_forward.h" 23 #include "third_party/mojo/src/mojo/edk/embedder/channel_info_forward.h"
21 #include "third_party/mojo/src/mojo/public/cpp/system/core.h" 24 #endif
22 25
23 namespace IPC { 26 namespace IPC {
24 27
25 // Mojo-based IPC::Channel implementation over a platform handle. 28 // Mojo-based IPC::Channel implementation over a platform handle.
26 // 29 //
27 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by 30 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by
28 // "bootstrap" IPC::Channel which creates and owns platform pipe like 31 // "bootstrap" IPC::Channel which creates and owns platform pipe like
29 // named socket. The bootstrap Channel is used only for establishing 32 // named socket. The bootstrap Channel is used only for establishing
30 // the underlying connection. ChannelMojo takes its handle over once 33 // the underlying connection. ChannelMojo takes its handle over once
31 // the it is made and puts MessagePipe on it. 34 // the it is made and puts MessagePipe on it.
(...skipping 14 matching lines...) Expand all
46 // TODO(morrita): Add APIs to create extra MessagePipes to let 49 // TODO(morrita): Add APIs to create extra MessagePipes to let
47 // Mojo-based objects talk over this Channel. 50 // Mojo-based objects talk over this Channel.
48 // 51 //
49 class IPC_MOJO_EXPORT ChannelMojo 52 class IPC_MOJO_EXPORT ChannelMojo
50 : public Channel, 53 : public Channel,
51 public MojoBootstrap::Delegate, 54 public MojoBootstrap::Delegate,
52 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) { 55 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) {
53 public: 56 public:
54 using CreateMessagingPipeCallback = 57 using CreateMessagingPipeCallback =
55 base::Callback<void(mojo::ScopedMessagePipeHandle)>; 58 base::Callback<void(mojo::ScopedMessagePipeHandle)>;
59 #if !defined(USE_CHROME_EDK)
56 using CreateMessagingPipeOnIOThreadCallback = 60 using CreateMessagingPipeOnIOThreadCallback =
57 base::Callback<void(mojo::ScopedMessagePipeHandle, 61 base::Callback<void(mojo::ScopedMessagePipeHandle,
58 mojo::embedder::ChannelInfo*)>; 62 mojo::embedder::ChannelInfo*)>;
63 #endif
59 64
60 // True if ChannelMojo should be used regardless of the flag. 65 // True if ChannelMojo should be used regardless of the flag.
61 static bool ShouldBeUsed(); 66 static bool ShouldBeUsed();
62 67
63 // Create ChannelMojo. A bootstrap channel is created as well. 68 // Create ChannelMojo. A bootstrap channel is created as well.
64 // |broker| must outlive the newly created channel. 69 // |broker| must outlive the newly created channel.
65 static scoped_ptr<ChannelMojo> Create( 70 static scoped_ptr<ChannelMojo> Create(
66 scoped_refptr<base::TaskRunner> io_runner, 71 scoped_refptr<base::TaskRunner> io_runner,
67 const ChannelHandle& channel_handle, 72 const ChannelHandle& channel_handle,
68 Mode mode, 73 Mode mode,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 void OnMessageReceived(Message& message) override; 126 void OnMessageReceived(Message& message) override;
122 void OnPipeClosed(internal::MessagePipeReader* reader) override; 127 void OnPipeClosed(internal::MessagePipeReader* reader) override;
123 void OnPipeError(internal::MessagePipeReader* reader) override; 128 void OnPipeError(internal::MessagePipeReader* reader) override;
124 129
125 protected: 130 protected:
126 ChannelMojo(scoped_refptr<base::TaskRunner> io_runner, 131 ChannelMojo(scoped_refptr<base::TaskRunner> io_runner,
127 const ChannelHandle& channel_handle, 132 const ChannelHandle& channel_handle,
128 Mode mode, 133 Mode mode,
129 Listener* listener, 134 Listener* listener,
130 AttachmentBroker* broker); 135 AttachmentBroker* broker);
131 136 #if defined(USE_CHROME_EDK)
137 void CreateMessagingPipe(mojo::edk::ScopedPlatformHandle handle,
138 const CreateMessagingPipeCallback& callback);
139 #else
132 void CreateMessagingPipe(mojo::embedder::ScopedPlatformHandle handle, 140 void CreateMessagingPipe(mojo::embedder::ScopedPlatformHandle handle,
133 const CreateMessagingPipeCallback& callback); 141 const CreateMessagingPipeCallback& callback);
142 #endif
134 void InitMessageReader(mojo::ScopedMessagePipeHandle pipe, int32_t peer_pid); 143 void InitMessageReader(mojo::ScopedMessagePipeHandle pipe, int32_t peer_pid);
135 144
136 Listener* listener() const { return listener_; } 145 Listener* listener() const { return listener_; }
137 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } 146 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; }
138 147
139 private: 148 private:
149 #if !defined(USE_CHROME_EDK)
140 struct ChannelInfoDeleter { 150 struct ChannelInfoDeleter {
141 explicit ChannelInfoDeleter(scoped_refptr<base::TaskRunner> io_runner); 151 explicit ChannelInfoDeleter(scoped_refptr<base::TaskRunner> io_runner);
142 ~ChannelInfoDeleter(); 152 ~ChannelInfoDeleter();
143 153
144 void operator()(mojo::embedder::ChannelInfo* ptr) const; 154 void operator()(mojo::embedder::ChannelInfo* ptr) const;
145 155
146 scoped_refptr<base::TaskRunner> io_runner; 156 scoped_refptr<base::TaskRunner> io_runner;
147 }; 157 };
158 #endif
148 159
149 // ChannelMojo needs to kill its MessagePipeReader in delayed manner 160 // ChannelMojo needs to kill its MessagePipeReader in delayed manner
150 // because the channel wants to kill these readers during the 161 // because the channel wants to kill these readers during the
151 // notifications invoked by them. 162 // notifications invoked by them.
152 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; 163 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter;
153 164
154 void InitOnIOThread(); 165 void InitOnIOThread();
155 166
167 #if !defined(USE_CHROME_EDK)
156 static void CreateMessagingPipeOnIOThread( 168 static void CreateMessagingPipeOnIOThread(
157 mojo::embedder::ScopedPlatformHandle handle, 169 mojo::embedder::ScopedPlatformHandle handle,
158 scoped_refptr<base::TaskRunner> callback_runner, 170 scoped_refptr<base::TaskRunner> callback_runner,
159 const CreateMessagingPipeOnIOThreadCallback& callback); 171 const CreateMessagingPipeOnIOThreadCallback& callback);
160 void OnMessagingPipeCreated(const CreateMessagingPipeCallback& callback, 172 void OnMessagingPipeCreated(const CreateMessagingPipeCallback& callback,
161 mojo::ScopedMessagePipeHandle handle, 173 mojo::ScopedMessagePipeHandle handle,
162 mojo::embedder::ChannelInfo* channel_info); 174 mojo::embedder::ChannelInfo* channel_info);
175 #endif
163 176
164 scoped_ptr<MojoBootstrap> bootstrap_; 177 scoped_ptr<MojoBootstrap> bootstrap_;
165 Listener* listener_; 178 Listener* listener_;
166 base::ProcessId peer_pid_; 179 base::ProcessId peer_pid_;
167 scoped_refptr<base::TaskRunner> io_runner_; 180 scoped_refptr<base::TaskRunner> io_runner_;
181 #if !defined(USE_CHROME_EDK)
168 scoped_ptr<mojo::embedder::ChannelInfo, 182 scoped_ptr<mojo::embedder::ChannelInfo,
169 ChannelInfoDeleter> channel_info_; 183 ChannelInfoDeleter> channel_info_;
184 #endif
170 185
171 // Guards |message_reader_|, |waiting_connect_| and |pending_messages_| 186 // Guards |message_reader_|, |waiting_connect_| and |pending_messages_|
172 // 187 //
173 // * The contents of |pending_messages_| can be modified from any thread. 188 // * The contents of |pending_messages_| can be modified from any thread.
174 // * |message_reader_| is modified only from the IO thread, 189 // * |message_reader_| is modified only from the IO thread,
175 // but they can be referenced from other threads. 190 // but they can be referenced from other threads.
176 base::Lock lock_; 191 base::Lock lock_;
177 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_; 192 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_;
178 ScopedVector<Message> pending_messages_; 193 ScopedVector<Message> pending_messages_;
179 bool waiting_connect_; 194 bool waiting_connect_;
180 195
181 scoped_ptr<ScopedIPCSupport> ipc_support_; 196 scoped_ptr<ScopedIPCSupport> ipc_support_;
182 197
183 base::WeakPtrFactory<ChannelMojo> weak_factory_; 198 base::WeakPtrFactory<ChannelMojo> weak_factory_;
184 199
185 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); 200 DISALLOW_COPY_AND_ASSIGN(ChannelMojo);
186 }; 201 };
187 202
188 } // namespace IPC 203 } // namespace IPC
189 204
190 #endif // IPC_IPC_CHANNEL_MOJO_H_ 205 #endif // IPC_IPC_CHANNEL_MOJO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698