| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/common/mojo/channel_init.h" | 5 #include "content/common/mojo/channel_init.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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 |
| 13 #if defined(USE_CHROME_EDK) |
| 14 #include "mojo/edk/embedder/embedder.h" |
| 15 #else |
| 12 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | 16 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
| 17 #endif |
| 13 | 18 |
| 14 namespace content { | 19 namespace content { |
| 15 | 20 |
| 21 #if !defined(USE_CHROME_EDK) |
| 16 ChannelInit::ChannelInit() : channel_info_(nullptr), weak_factory_(this) {} | 22 ChannelInit::ChannelInit() : channel_info_(nullptr), weak_factory_(this) {} |
| 17 | 23 |
| 18 ChannelInit::~ChannelInit() { | 24 ChannelInit::~ChannelInit() { |
| 19 if (channel_info_) | 25 if (channel_info_) |
| 20 mojo::embedder::DestroyChannel(channel_info_, | 26 mojo::embedder::DestroyChannel(channel_info_, |
| 21 base::Bind(&base::DoNothing), nullptr); | 27 base::Bind(&base::DoNothing), nullptr); |
| 22 } | 28 } |
| 29 #endif |
| 23 | 30 |
| 24 mojo::ScopedMessagePipeHandle ChannelInit::Init( | 31 mojo::ScopedMessagePipeHandle ChannelInit::Init( |
| 25 base::PlatformFile file, | 32 base::PlatformFile file, |
| 26 scoped_refptr<base::TaskRunner> io_thread_task_runner) { | 33 scoped_refptr<base::TaskRunner> io_thread_task_runner) { |
| 27 scoped_ptr<IPC::ScopedIPCSupport> ipc_support( | 34 scoped_ptr<IPC::ScopedIPCSupport> ipc_support( |
| 28 new IPC::ScopedIPCSupport(io_thread_task_runner)); | 35 new IPC::ScopedIPCSupport(io_thread_task_runner)); |
| 36 |
| 37 #if defined(USE_CHROME_EDK) |
| 38 mojo::ScopedMessagePipeHandle message_pipe( |
| 39 mojo::edk::CreateMessagePipe(mojo::edk::ScopedPlatformHandle( |
| 40 mojo::edk::PlatformHandle(file)))); |
| 41 return message_pipe.Pass(); |
| 42 #else |
| 29 mojo::ScopedMessagePipeHandle message_pipe = | 43 mojo::ScopedMessagePipeHandle message_pipe = |
| 30 mojo::embedder::CreateChannel( | 44 mojo::embedder::CreateChannel( |
| 31 mojo::embedder::ScopedPlatformHandle( | 45 mojo::embedder::ScopedPlatformHandle( |
| 32 mojo::embedder::PlatformHandle(file)), | 46 mojo::embedder::PlatformHandle(file)), |
| 33 base::Bind(&ChannelInit::OnCreatedChannel, | 47 base::Bind(&ChannelInit::OnCreatedChannel, |
| 34 weak_factory_.GetWeakPtr(), | 48 weak_factory_.GetWeakPtr(), |
| 35 base::Passed(&ipc_support)), | 49 base::Passed(&ipc_support)), |
| 36 base::ThreadTaskRunnerHandle::Get()).Pass(); | 50 base::ThreadTaskRunnerHandle::Get()).Pass(); |
| 37 return message_pipe.Pass(); | 51 return message_pipe.Pass(); |
| 52 #endif |
| 38 } | 53 } |
| 39 | 54 |
| 40 void ChannelInit::WillDestroySoon() { | 55 void ChannelInit::WillDestroySoon() { |
| 56 #if !defined(USE_CHROME_EDK) |
| 41 if (channel_info_) | 57 if (channel_info_) |
| 42 mojo::embedder::WillDestroyChannelSoon(channel_info_); | 58 mojo::embedder::WillDestroyChannelSoon(channel_info_); |
| 59 #endif |
| 43 } | 60 } |
| 44 | 61 |
| 45 void ChannelInit::ShutdownOnIOThread() { | 62 void ChannelInit::ShutdownOnIOThread() { |
| 63 #if !defined(USE_CHROME_EDK) |
| 46 if (channel_info_) | 64 if (channel_info_) |
| 47 mojo::embedder::DestroyChannelOnIOThread(channel_info_); | 65 mojo::embedder::DestroyChannelOnIOThread(channel_info_); |
| 48 channel_info_ = nullptr; | 66 channel_info_ = nullptr; |
| 67 #endif |
| 49 ipc_support_.reset(); | 68 ipc_support_.reset(); |
| 50 } | 69 } |
| 51 | 70 |
| 71 |
| 72 #if !defined(USE_CHROME_EDK) |
| 52 // static | 73 // static |
| 53 void ChannelInit::OnCreatedChannel( | 74 void ChannelInit::OnCreatedChannel( |
| 54 base::WeakPtr<ChannelInit> self, | 75 base::WeakPtr<ChannelInit> self, |
| 55 scoped_ptr<IPC::ScopedIPCSupport> ipc_support, | 76 scoped_ptr<IPC::ScopedIPCSupport> ipc_support, |
| 56 mojo::embedder::ChannelInfo* channel) { | 77 mojo::embedder::ChannelInfo* channel) { |
| 57 // If |self| was already destroyed, shut the channel down. | 78 // If |self| was already destroyed, shut the channel down. |
| 58 if (!self) { | 79 if (!self) { |
| 59 mojo::embedder::DestroyChannel(channel, | 80 mojo::embedder::DestroyChannel(channel, |
| 60 base::Bind(&base::DoNothing), nullptr); | 81 base::Bind(&base::DoNothing), nullptr); |
| 61 return; | 82 return; |
| 62 } | 83 } |
| 63 | 84 |
| 64 DCHECK(!self->channel_info_); | 85 DCHECK(!self->channel_info_); |
| 65 self->channel_info_ = channel; | 86 self->channel_info_ = channel; |
| 66 self->ipc_support_ = ipc_support.Pass(); | 87 self->ipc_support_ = ipc_support.Pass(); |
| 67 } | 88 } |
| 89 #endif |
| 68 | 90 |
| 69 } // namespace content | 91 } // namespace content |
| OLD | NEW |