| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | 14 #include "mojo/edk/embedder/embedder.h" |
| 15 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 ChannelInit::ChannelInit() : channel_info_(nullptr), weak_factory_(this) {} | 19 ChannelInit::ChannelInit() { |
| 20 } |
| 19 | 21 |
| 20 ChannelInit::~ChannelInit() { | 22 ChannelInit::~ChannelInit() { |
| 21 if (channel_info_) | |
| 22 mojo::embedder::DestroyChannel(channel_info_, | |
| 23 base::Bind(&base::DoNothing), nullptr); | |
| 24 } | 23 } |
| 25 | 24 |
| 26 mojo::ScopedMessagePipeHandle ChannelInit::Init( | 25 mojo::ScopedMessagePipeHandle ChannelInit::Init( |
| 27 base::PlatformFile file, | 26 base::PlatformFile file, |
| 28 scoped_refptr<base::TaskRunner> io_thread_task_runner) { | 27 scoped_refptr<base::TaskRunner> io_thread_task_runner) { |
| 29 scoped_ptr<IPC::ScopedIPCSupport> ipc_support( | 28 ipc_support_.reset(new IPC::ScopedIPCSupport(io_thread_task_runner)); |
| 30 new IPC::ScopedIPCSupport(io_thread_task_runner)); | 29 return mojo::edk::CreateMessagePipe( |
| 31 mojo::ScopedMessagePipeHandle message_pipe = mojo::embedder::CreateChannel( | 30 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle(file))); |
| 32 mojo::embedder::ScopedPlatformHandle( | |
| 33 mojo::embedder::PlatformHandle(file)), | |
| 34 base::Bind(&ChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(), | |
| 35 base::Passed(&ipc_support)), | |
| 36 base::ThreadTaskRunnerHandle::Get()); | |
| 37 return message_pipe; | |
| 38 } | |
| 39 | |
| 40 void ChannelInit::WillDestroySoon() { | |
| 41 if (channel_info_) | |
| 42 mojo::embedder::WillDestroyChannelSoon(channel_info_); | |
| 43 } | |
| 44 | |
| 45 // static | |
| 46 void ChannelInit::OnCreatedChannel( | |
| 47 base::WeakPtr<ChannelInit> self, | |
| 48 scoped_ptr<IPC::ScopedIPCSupport> ipc_support, | |
| 49 mojo::embedder::ChannelInfo* channel) { | |
| 50 // If |self| was already destroyed, shut the channel down. | |
| 51 if (!self) { | |
| 52 mojo::embedder::DestroyChannel(channel, | |
| 53 base::Bind(&base::DoNothing), nullptr); | |
| 54 return; | |
| 55 } | |
| 56 | |
| 57 DCHECK(!self->channel_info_); | |
| 58 self->channel_info_ = channel; | |
| 59 self->ipc_support_ = std::move(ipc_support); | |
| 60 } | 31 } |
| 61 | 32 |
| 62 } // namespace content | 33 } // namespace content |
| OLD | NEW |