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

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

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, 3 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 #include "ipc/mojo/ipc_channel_mojo.h" 5 #include "ipc/mojo/ipc_channel_mojo.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "ipc/ipc_listener.h" 11 #include "ipc/ipc_listener.h"
12 #include "ipc/ipc_logging.h" 12 #include "ipc/ipc_logging.h"
13 #include "ipc/ipc_message_attachment_set.h" 13 #include "ipc/ipc_message_attachment_set.h"
14 #include "ipc/ipc_message_macros.h" 14 #include "ipc/ipc_message_macros.h"
15 #include "ipc/mojo/client_channel.mojom.h" 15 #include "ipc/mojo/client_channel.mojom.h"
16 #include "ipc/mojo/ipc_mojo_bootstrap.h" 16 #include "ipc/mojo/ipc_mojo_bootstrap.h"
17 #include "ipc/mojo/ipc_mojo_handle_attachment.h" 17 #include "ipc/mojo/ipc_mojo_handle_attachment.h"
18 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
19
20 #if defined(USE_CHROME_EDK)
21 #include "mojo/edk/embedder/embedder.h"
22 #else
18 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" 23 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
19 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" 24 #endif
20 25
21 #if defined(OS_POSIX) && !defined(OS_NACL) 26 #if defined(OS_POSIX) && !defined(OS_NACL)
22 #include "ipc/ipc_platform_file_attachment_posix.h" 27 #include "ipc/ipc_platform_file_attachment_posix.h"
23 #endif 28 #endif
24 29
30 // TODO(jam): do more tests on using channel on same thread if it supports it (
31 // i.e. with USE_CHROME_EDK and Windows). Also see message_pipe_dispatcher.cc
32 bool g_use_channel_on_io = true;
33
25 namespace IPC { 34 namespace IPC {
26 35
27 namespace { 36 namespace {
28 37
29 class MojoChannelFactory : public ChannelFactory { 38 class MojoChannelFactory : public ChannelFactory {
30 public: 39 public:
31 MojoChannelFactory(scoped_refptr<base::TaskRunner> io_runner, 40 MojoChannelFactory(scoped_refptr<base::TaskRunner> io_runner,
32 ChannelHandle channel_handle, 41 ChannelHandle channel_handle,
33 Channel::Mode mode, 42 Channel::Mode mode,
34 AttachmentBroker* broker) 43 AttachmentBroker* broker)
(...skipping 13 matching lines...) Expand all
48 57
49 private: 58 private:
50 scoped_refptr<base::TaskRunner> io_runner_; 59 scoped_refptr<base::TaskRunner> io_runner_;
51 ChannelHandle channel_handle_; 60 ChannelHandle channel_handle_;
52 Channel::Mode mode_; 61 Channel::Mode mode_;
53 AttachmentBroker* broker_; 62 AttachmentBroker* broker_;
54 }; 63 };
55 64
56 //------------------------------------------------------------------------------ 65 //------------------------------------------------------------------------------
57 66
58 class ClientChannelMojo : public ChannelMojo, public ClientChannel { 67 class ClientChannelMojo
68 : public ChannelMojo
69 #if !defined(USE_CHROME_EDK)
70 , public ClientChannel
71 #endif
72 {
59 public: 73 public:
60 ClientChannelMojo(scoped_refptr<base::TaskRunner> io_runner, 74 ClientChannelMojo(scoped_refptr<base::TaskRunner> io_runner,
61 const ChannelHandle& handle, 75 const ChannelHandle& handle,
62 Listener* listener, 76 Listener* listener,
63 AttachmentBroker* broker); 77 AttachmentBroker* broker)
64 ~ClientChannelMojo() override; 78 : ChannelMojo(io_runner, handle, Channel::MODE_CLIENT, listener, broker),
79 #if !defined(USE_CHROME_EDK)
80 binding_(this),
81 #endif
82 weak_factory_(this) {
83 }
84 ~ClientChannelMojo() override {}
65 // MojoBootstrap::Delegate implementation 85 // MojoBootstrap::Delegate implementation
66 void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle) override;
67 86
87 #if defined(USE_CHROME_EDK)
88 void OnPipeAvailable(mojo::edk::ScopedPlatformHandle handle,
89 int32 peer_pid) override {
90 InitMessageReader(
91 mojo::edk::CreateMessagePipe(handle.Pass()), peer_pid);
92 }
93 #else
94 void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle,
95 int32 peer_pid) override {
96 CreateMessagingPipe(handle.Pass(), base::Bind(&ClientChannelMojo::BindPipe,
97 weak_factory_.GetWeakPtr()));
98 }
99 #endif
100
101 #if !defined(USE_CHROME_EDK)
68 // ClientChannel implementation 102 // ClientChannel implementation
69 void Init( 103 void Init(
70 mojo::ScopedMessagePipeHandle pipe, 104 mojo::ScopedMessagePipeHandle pipe,
71 int32_t peer_pid, 105 int32_t peer_pid,
72 const mojo::Callback<void(int32_t)>& callback) override; 106 const mojo::Callback<void(int32_t)>& callback) override {
107 InitMessageReader(pipe.Pass(), static_cast<base::ProcessId>(peer_pid));
108 callback.Run(GetSelfPID());
109 }
110 #endif
73 111
74 private: 112 private:
75 void BindPipe(mojo::ScopedMessagePipeHandle handle); 113 #if !defined(USE_CHROME_EDK)
76 void OnConnectionError(); 114 void BindPipe(mojo::ScopedMessagePipeHandle handle) {
115 // binding_.Bind(handle.Pass());
116 }
117 void OnConnectionError() {
118 listener()->OnChannelError();
119 }
77 120
78 mojo::Binding<ClientChannel> binding_; 121 mojo::Binding<ClientChannel> binding_;
122 #endif
79 base::WeakPtrFactory<ClientChannelMojo> weak_factory_; 123 base::WeakPtrFactory<ClientChannelMojo> weak_factory_;
80 124
81 DISALLOW_COPY_AND_ASSIGN(ClientChannelMojo); 125 DISALLOW_COPY_AND_ASSIGN(ClientChannelMojo);
82 }; 126 };
83 127
84 ClientChannelMojo::ClientChannelMojo(scoped_refptr<base::TaskRunner> io_runner,
85 const ChannelHandle& handle,
86 Listener* listener,
87 AttachmentBroker* broker)
88 : ChannelMojo(io_runner, handle, Channel::MODE_CLIENT, listener, broker),
89 binding_(this),
90 weak_factory_(this) {
91 }
92
93 ClientChannelMojo::~ClientChannelMojo() {
94 }
95
96 void ClientChannelMojo::OnPipeAvailable(
97 mojo::embedder::ScopedPlatformHandle handle) {
98 CreateMessagingPipe(handle.Pass(), base::Bind(&ClientChannelMojo::BindPipe,
99 weak_factory_.GetWeakPtr()));
100 }
101
102 void ClientChannelMojo::Init(
103 mojo::ScopedMessagePipeHandle pipe,
104 int32_t peer_pid,
105 const mojo::Callback<void(int32_t)>& callback) {
106 InitMessageReader(pipe.Pass(), static_cast<base::ProcessId>(peer_pid));
107 callback.Run(GetSelfPID());
108 }
109
110 void ClientChannelMojo::BindPipe(mojo::ScopedMessagePipeHandle handle) {
111 binding_.Bind(handle.Pass());
112 }
113
114 void ClientChannelMojo::OnConnectionError() {
115 listener()->OnChannelError();
116 }
117
118 //------------------------------------------------------------------------------ 128 //------------------------------------------------------------------------------
119 129
120 class ServerChannelMojo : public ChannelMojo { 130 class ServerChannelMojo : public ChannelMojo {
121 public: 131 public:
122 ServerChannelMojo(scoped_refptr<base::TaskRunner> io_runner, 132 ServerChannelMojo(scoped_refptr<base::TaskRunner> io_runner,
123 const ChannelHandle& handle, 133 const ChannelHandle& handle,
124 Listener* listener, 134 Listener* listener,
125 AttachmentBroker* broker); 135 AttachmentBroker* broker)
126 ~ServerChannelMojo() override; 136 : ChannelMojo(io_runner, handle, Channel::MODE_SERVER, listener, broker),
137 weak_factory_(this) {
138 }
139 ~ServerChannelMojo() override {
140 Close();
141 }
127 142
128 // MojoBootstrap::Delegate implementation 143 // MojoBootstrap::Delegate implementation
129 void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle) override; 144 #if defined(USE_CHROME_EDK)
145 void OnPipeAvailable(mojo::edk::ScopedPlatformHandle handle,
146 int32 peer_pid) override {
147 message_pipe_ = mojo::edk::CreateMessagePipe(handle.Pass());
148 if (!message_pipe_.is_valid()) {
149 LOG(WARNING) << "mojo::CreateMessagePipe failed: ";
150 listener()->OnChannelError();
151 return;
152 }
153 InitMessageReader(message_pipe_.Pass(), peer_pid);
154 }
155 #else
156 void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle,
157 int32 peer_pid) override {
158 mojo::ScopedMessagePipeHandle peer;
159 MojoResult create_result =
160 mojo::CreateMessagePipe(nullptr, &message_pipe_, &peer);
161 if (create_result != MOJO_RESULT_OK) {
162 LOG(WARNING) << "mojo::CreateMessagePipe failed: " << create_result;
163 listener()->OnChannelError();
164 return;
165 }
166 CreateMessagingPipe(
167 handle.Pass(),
168 base::Bind(&ServerChannelMojo::InitClientChannel,
169 weak_factory_.GetWeakPtr(), base::Passed(&peer)));
170 }
171 #endif
130 // Channel override 172 // Channel override
131 void Close() override; 173 void Close() override {
174 #if !defined(USE_CHROME_EDK)
175 client_channel_.reset();
176 #endif
177 message_pipe_.reset();
178 ChannelMojo::Close();
179 }
132 180
133 private: 181 private:
182 #if !defined(USE_CHROME_EDK)
134 void InitClientChannel(mojo::ScopedMessagePipeHandle peer_handle, 183 void InitClientChannel(mojo::ScopedMessagePipeHandle peer_handle,
135 mojo::ScopedMessagePipeHandle handle); 184 mojo::ScopedMessagePipeHandle handle) {
136 void OnConnectionError(); 185 client_channel_.Bind(
186 mojo::InterfacePtrInfo<ClientChannel>(handle.Pass(), 0u));
187 client_channel_.set_connection_error_handler(base::Bind(
188 &ServerChannelMojo::OnConnectionError, base::Unretained(this)));
189 client_channel_->Init(
190 peer_handle.Pass(), static_cast<int32_t>(GetSelfPID()),
191 base::Bind(&ServerChannelMojo::ClientChannelWasInitialized,
192 base::Unretained(this)));
193 }
194 #endif
195 void OnConnectionError() {
196 listener()->OnChannelError();
197 }
137 198
199 #if !defined(USE_CHROME_EDK)
138 // ClientChannelClient implementation 200 // ClientChannelClient implementation
139 void ClientChannelWasInitialized(int32_t peer_pid); 201 void ClientChannelWasInitialized(int32_t peer_pid) {
202 InitMessageReader(message_pipe_.Pass(), peer_pid);
203 }
140 204
141 mojo::InterfacePtr<ClientChannel> client_channel_; 205 mojo::InterfacePtr<ClientChannel> client_channel_;
206 #endif
142 mojo::ScopedMessagePipeHandle message_pipe_; 207 mojo::ScopedMessagePipeHandle message_pipe_;
143 base::WeakPtrFactory<ServerChannelMojo> weak_factory_; 208 base::WeakPtrFactory<ServerChannelMojo> weak_factory_;
144 209
145 DISALLOW_COPY_AND_ASSIGN(ServerChannelMojo); 210 DISALLOW_COPY_AND_ASSIGN(ServerChannelMojo);
146 }; 211 };
147 212
148 ServerChannelMojo::ServerChannelMojo(scoped_refptr<base::TaskRunner> io_runner,
149 const ChannelHandle& handle,
150 Listener* listener,
151 AttachmentBroker* broker)
152 : ChannelMojo(io_runner, handle, Channel::MODE_SERVER, listener, broker),
153 weak_factory_(this) {
154 }
155
156 ServerChannelMojo::~ServerChannelMojo() {
157 Close();
158 }
159
160 void ServerChannelMojo::OnPipeAvailable(
161 mojo::embedder::ScopedPlatformHandle handle) {
162 mojo::ScopedMessagePipeHandle peer;
163 MojoResult create_result =
164 mojo::CreateMessagePipe(nullptr, &message_pipe_, &peer);
165 if (create_result != MOJO_RESULT_OK) {
166 LOG(WARNING) << "mojo::CreateMessagePipe failed: " << create_result;
167 listener()->OnChannelError();
168 return;
169 }
170 CreateMessagingPipe(
171 handle.Pass(),
172 base::Bind(&ServerChannelMojo::InitClientChannel,
173 weak_factory_.GetWeakPtr(), base::Passed(&peer)));
174 }
175
176 void ServerChannelMojo::Close() {
177 client_channel_.reset();
178 message_pipe_.reset();
179 ChannelMojo::Close();
180 }
181
182 void ServerChannelMojo::InitClientChannel(
183 mojo::ScopedMessagePipeHandle peer_handle,
184 mojo::ScopedMessagePipeHandle handle) {
185 client_channel_.Bind(
186 mojo::InterfacePtrInfo<ClientChannel>(handle.Pass(), 0u));
187 client_channel_.set_connection_error_handler(base::Bind(
188 &ServerChannelMojo::OnConnectionError, base::Unretained(this)));
189 client_channel_->Init(
190 peer_handle.Pass(), static_cast<int32_t>(GetSelfPID()),
191 base::Bind(&ServerChannelMojo::ClientChannelWasInitialized,
192 base::Unretained(this)));
193 }
194
195 void ServerChannelMojo::OnConnectionError() {
196 listener()->OnChannelError();
197 }
198
199 void ServerChannelMojo::ClientChannelWasInitialized(int32_t peer_pid) {
200 InitMessageReader(message_pipe_.Pass(), peer_pid);
201 }
202
203 #if defined(OS_POSIX) && !defined(OS_NACL) 213 #if defined(OS_POSIX) && !defined(OS_NACL)
204 214
205 base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) { 215 base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) {
206 return attachment->Owns() ? base::ScopedFD(attachment->TakePlatformFile()) 216 return attachment->Owns() ? base::ScopedFD(attachment->TakePlatformFile())
207 : base::ScopedFD(dup(attachment->file())); 217 : base::ScopedFD(dup(attachment->file()));
208 } 218 }
209 219
210 #endif 220 #endif
211 221
212 } // namespace 222 } // namespace
213 223
224 #if !defined(USE_CHROME_EDK)
214 //------------------------------------------------------------------------------ 225 //------------------------------------------------------------------------------
215 226
216 ChannelMojo::ChannelInfoDeleter::ChannelInfoDeleter( 227 ChannelMojo::ChannelInfoDeleter::ChannelInfoDeleter(
217 scoped_refptr<base::TaskRunner> io_runner) 228 scoped_refptr<base::TaskRunner> io_runner)
218 : io_runner(io_runner) { 229 : io_runner(io_runner) {
219 } 230 }
220 231
221 ChannelMojo::ChannelInfoDeleter::~ChannelInfoDeleter() { 232 ChannelMojo::ChannelInfoDeleter::~ChannelInfoDeleter() {
222 } 233 }
223 234
224 void ChannelMojo::ChannelInfoDeleter::operator()( 235 void ChannelMojo::ChannelInfoDeleter::operator()(
225 mojo::embedder::ChannelInfo* ptr) const { 236 mojo::embedder::ChannelInfo* ptr) const {
226 if (base::ThreadTaskRunnerHandle::Get() == io_runner) { 237 if (base::ThreadTaskRunnerHandle::Get() == io_runner) {
227 mojo::embedder::DestroyChannelOnIOThread(ptr); 238 mojo::embedder::DestroyChannelOnIOThread(ptr);
228 } else { 239 } else {
229 io_runner->PostTask( 240 io_runner->PostTask(
230 FROM_HERE, base::Bind(&mojo::embedder::DestroyChannelOnIOThread, ptr)); 241 FROM_HERE, base::Bind(&mojo::embedder::DestroyChannelOnIOThread, ptr));
231 } 242 }
232 } 243 }
233 244 #endif
234 //------------------------------------------------------------------------------ 245 //------------------------------------------------------------------------------
235 246
236 // static 247 // static
237 bool ChannelMojo::ShouldBeUsed() { 248 bool ChannelMojo::ShouldBeUsed() {
238 // TODO(rockot): Investigate performance bottlenecks and hopefully reenable 249 // TODO(rockot): Investigate performance bottlenecks and hopefully reenable
239 // this at some point. http://crbug.com/500019 250 // this at some point. http://crbug.com/500019
240 return false; 251 return false;
241 } 252 }
242 253
243 // static 254 // static
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 290 }
280 291
281 ChannelMojo::ChannelMojo(scoped_refptr<base::TaskRunner> io_runner, 292 ChannelMojo::ChannelMojo(scoped_refptr<base::TaskRunner> io_runner,
282 const ChannelHandle& handle, 293 const ChannelHandle& handle,
283 Mode mode, 294 Mode mode,
284 Listener* listener, 295 Listener* listener,
285 AttachmentBroker* broker) 296 AttachmentBroker* broker)
286 : listener_(listener), 297 : listener_(listener),
287 peer_pid_(base::kNullProcessId), 298 peer_pid_(base::kNullProcessId),
288 io_runner_(io_runner), 299 io_runner_(io_runner),
300 #if !defined(USE_CHROME_EDK)
289 channel_info_(nullptr, ChannelInfoDeleter(nullptr)), 301 channel_info_(nullptr, ChannelInfoDeleter(nullptr)),
302 #endif
290 waiting_connect_(true), 303 waiting_connect_(true),
291 weak_factory_(this) { 304 weak_factory_(this) {
292 // Create MojoBootstrap after all members are set as it touches 305 // Create MojoBootstrap after all members are set as it touches
293 // ChannelMojo from a different thread. 306 // ChannelMojo from a different thread.
294 bootstrap_ = MojoBootstrap::Create(handle, mode, this, broker); 307 bootstrap_ = MojoBootstrap::Create(handle, mode, this, broker);
295 if (io_runner == base::MessageLoop::current()->task_runner()) { 308 if (g_use_channel_on_io ||
309 io_runner == base::MessageLoop::current()->task_runner()) {
296 InitOnIOThread(); 310 InitOnIOThread();
297 } else { 311 } else {
298 io_runner->PostTask(FROM_HERE, base::Bind(&ChannelMojo::InitOnIOThread, 312 io_runner->PostTask(FROM_HERE, base::Bind(&ChannelMojo::InitOnIOThread,
299 base::Unretained(this))); 313 base::Unretained(this)));
300 } 314 }
301 } 315 }
302 316
303 ChannelMojo::~ChannelMojo() { 317 ChannelMojo::~ChannelMojo() {
304 Close(); 318 Close();
305 } 319 }
306 320
307 void ChannelMojo::InitOnIOThread() { 321 void ChannelMojo::InitOnIOThread() {
308 ipc_support_.reset( 322 ipc_support_.reset(
309 new ScopedIPCSupport(base::MessageLoop::current()->task_runner())); 323 new ScopedIPCSupport(base::MessageLoop::current()->task_runner()));
310 } 324 }
311 325
326 #if !defined(USE_CHROME_EDK)
312 void ChannelMojo::CreateMessagingPipe( 327 void ChannelMojo::CreateMessagingPipe(
313 mojo::embedder::ScopedPlatformHandle handle, 328 mojo::embedder::ScopedPlatformHandle handle,
314 const CreateMessagingPipeCallback& callback) { 329 const CreateMessagingPipeCallback& callback) {
315 auto return_callback = base::Bind(&ChannelMojo::OnMessagingPipeCreated, 330 auto return_callback = base::Bind(&ChannelMojo::OnMessagingPipeCreated,
316 weak_factory_.GetWeakPtr(), callback); 331 weak_factory_.GetWeakPtr(), callback);
317 if (base::ThreadTaskRunnerHandle::Get() == io_runner_) { 332 if (g_use_channel_on_io ||
333 base::ThreadTaskRunnerHandle::Get() == io_runner_) {
318 CreateMessagingPipeOnIOThread( 334 CreateMessagingPipeOnIOThread(
319 handle.Pass(), base::ThreadTaskRunnerHandle::Get(), return_callback); 335 handle.Pass(), base::ThreadTaskRunnerHandle::Get(), return_callback);
320 } else { 336 } else {
321 io_runner_->PostTask( 337 io_runner_->PostTask(
322 FROM_HERE, 338 FROM_HERE,
323 base::Bind(&ChannelMojo::CreateMessagingPipeOnIOThread, 339 base::Bind(&ChannelMojo::CreateMessagingPipeOnIOThread,
324 base::Passed(&handle), base::ThreadTaskRunnerHandle::Get(), 340 base::Passed(&handle), base::ThreadTaskRunnerHandle::Get(),
325 return_callback)); 341 return_callback));
326 } 342 }
327 } 343 }
(...skipping 16 matching lines...) Expand all
344 360
345 void ChannelMojo::OnMessagingPipeCreated( 361 void ChannelMojo::OnMessagingPipeCreated(
346 const CreateMessagingPipeCallback& callback, 362 const CreateMessagingPipeCallback& callback,
347 mojo::ScopedMessagePipeHandle handle, 363 mojo::ScopedMessagePipeHandle handle,
348 mojo::embedder::ChannelInfo* channel_info) { 364 mojo::embedder::ChannelInfo* channel_info) {
349 DCHECK(!channel_info_.get()); 365 DCHECK(!channel_info_.get());
350 channel_info_ = scoped_ptr<mojo::embedder::ChannelInfo, ChannelInfoDeleter>( 366 channel_info_ = scoped_ptr<mojo::embedder::ChannelInfo, ChannelInfoDeleter>(
351 channel_info, ChannelInfoDeleter(io_runner_)); 367 channel_info, ChannelInfoDeleter(io_runner_));
352 callback.Run(handle.Pass()); 368 callback.Run(handle.Pass());
353 } 369 }
370 #endif
354 371
355 bool ChannelMojo::Connect() { 372 bool ChannelMojo::Connect() {
356 DCHECK(!message_reader_); 373 DCHECK(!message_reader_);
357 return bootstrap_->Connect(); 374 return bootstrap_->Connect();
358 } 375 }
359 376
360 void ChannelMojo::Close() { 377 void ChannelMojo::Close() {
361 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> to_be_deleted; 378 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> to_be_deleted;
362 379
363 { 380 {
364 // |message_reader_| has to be cleared inside the lock, 381 // |message_reader_| has to be cleared inside the lock,
365 // but the instance has to be deleted outside. 382 // but the instance has to be deleted outside.
366 base::AutoLock l(lock_); 383 base::AutoLock l(lock_);
367 to_be_deleted = message_reader_.Pass(); 384 to_be_deleted = message_reader_.Pass();
368 // We might Close() before we Connect(). 385 // We might Close() before we Connect().
369 waiting_connect_ = false; 386 waiting_connect_ = false;
370 } 387 }
371 388
389 #if !defined(USE_CHROME_EDK)
372 channel_info_.reset(); 390 channel_info_.reset();
391 #endif
373 ipc_support_.reset(); 392 ipc_support_.reset();
374 to_be_deleted.reset(); 393 to_be_deleted.reset();
375 } 394 }
376 395
377 void ChannelMojo::OnBootstrapError() { 396 void ChannelMojo::OnBootstrapError() {
378 listener_->OnChannelError(); 397 listener_->OnChannelError();
379 } 398 }
380 399
381 namespace { 400 namespace {
382 401
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 base::ScopedFD file = 515 base::ScopedFD file =
497 TakeOrDupFile(static_cast<IPC::internal::PlatformFileAttachment*>( 516 TakeOrDupFile(static_cast<IPC::internal::PlatformFileAttachment*>(
498 attachment.get())); 517 attachment.get()));
499 if (!file.is_valid()) { 518 if (!file.is_valid()) {
500 DPLOG(WARNING) << "Failed to dup FD to transmit."; 519 DPLOG(WARNING) << "Failed to dup FD to transmit.";
501 set->CommitAll(); 520 set->CommitAll();
502 return MOJO_RESULT_UNKNOWN; 521 return MOJO_RESULT_UNKNOWN;
503 } 522 }
504 523
505 MojoHandle wrapped_handle; 524 MojoHandle wrapped_handle;
525 #if defined(USE_CHROME_EDK)
526 MojoResult wrap_result = CreatePlatformHandleWrapper(
527 mojo::edk::ScopedPlatformHandle(
528 mojo::edk::PlatformHandle(file.release())),
529 &wrapped_handle);
530 #else
506 MojoResult wrap_result = CreatePlatformHandleWrapper( 531 MojoResult wrap_result = CreatePlatformHandleWrapper(
507 mojo::embedder::ScopedPlatformHandle( 532 mojo::embedder::ScopedPlatformHandle(
508 mojo::embedder::PlatformHandle(file.release())), 533 mojo::embedder::PlatformHandle(file.release())),
509 &wrapped_handle); 534 &wrapped_handle);
535 #endif
510 if (MOJO_RESULT_OK != wrap_result) { 536 if (MOJO_RESULT_OK != wrap_result) {
511 LOG(WARNING) << "Pipe failed to wrap handles. Closing: " 537 LOG(WARNING) << "Pipe failed to wrap handles. Closing: "
512 << wrap_result; 538 << wrap_result;
513 set->CommitAll(); 539 set->CommitAll();
514 return wrap_result; 540 return wrap_result;
515 } 541 }
516 542
517 handles->push_back(wrapped_handle); 543 handles->push_back(wrapped_handle);
518 } 544 }
519 #else 545 #else
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 if (!ok) { 578 if (!ok) {
553 LOG(ERROR) << "Failed to add new Mojo handle."; 579 LOG(ERROR) << "Failed to add new Mojo handle.";
554 return MOJO_RESULT_UNKNOWN; 580 return MOJO_RESULT_UNKNOWN;
555 } 581 }
556 } 582 }
557 583
558 return MOJO_RESULT_OK; 584 return MOJO_RESULT_OK;
559 } 585 }
560 586
561 } // namespace IPC 587 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698