| 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 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | 12 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 ChannelInit::ChannelInit() |
| 16 ChannelInit::ChannelInit() : channel_info_(nullptr), weak_factory_(this) {} | 16 : channel_info_(nullptr), |
| 17 weak_factory_(this) {} |
| 17 | 18 |
| 18 ChannelInit::~ChannelInit() { | 19 ChannelInit::~ChannelInit() { |
| 19 if (channel_info_) | 20 if (channel_info_) |
| 20 mojo::embedder::DestroyChannel(channel_info_, | 21 mojo::embedder::DestroyChannel(channel_info_, |
| 21 base::Bind(&base::DoNothing), nullptr); | 22 base::Bind(&base::DoNothing), nullptr); |
| 22 } | 23 } |
| 23 | 24 |
| 24 mojo::ScopedMessagePipeHandle ChannelInit::Init( | 25 mojo::ScopedMessagePipeHandle ChannelInit::Init( |
| 25 base::PlatformFile file, | 26 base::PlatformFile file, |
| 26 scoped_refptr<base::TaskRunner> io_thread_task_runner) { | 27 scoped_refptr<base::TaskRunner> io_thread_task_runner) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 42 mojo::embedder::WillDestroyChannelSoon(channel_info_); | 43 mojo::embedder::WillDestroyChannelSoon(channel_info_); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void ChannelInit::ShutdownOnIOThread() { | 46 void ChannelInit::ShutdownOnIOThread() { |
| 46 if (channel_info_) | 47 if (channel_info_) |
| 47 mojo::embedder::DestroyChannelOnIOThread(channel_info_); | 48 mojo::embedder::DestroyChannelOnIOThread(channel_info_); |
| 48 channel_info_ = nullptr; | 49 channel_info_ = nullptr; |
| 49 ipc_support_.reset(); | 50 ipc_support_.reset(); |
| 50 } | 51 } |
| 51 | 52 |
| 53 |
| 52 // static | 54 // static |
| 53 void ChannelInit::OnCreatedChannel( | 55 void ChannelInit::OnCreatedChannel( |
| 54 base::WeakPtr<ChannelInit> self, | 56 base::WeakPtr<ChannelInit> self, |
| 55 scoped_ptr<IPC::ScopedIPCSupport> ipc_support, | 57 scoped_ptr<IPC::ScopedIPCSupport> ipc_support, |
| 56 mojo::embedder::ChannelInfo* channel) { | 58 mojo::embedder::ChannelInfo* channel) { |
| 57 // If |self| was already destroyed, shut the channel down. | 59 // If |self| was already destroyed, shut the channel down. |
| 58 if (!self) { | 60 if (!self) { |
| 59 mojo::embedder::DestroyChannel(channel, | 61 mojo::embedder::DestroyChannel(channel, |
| 60 base::Bind(&base::DoNothing), nullptr); | 62 base::Bind(&base::DoNothing), nullptr); |
| 61 return; | 63 return; |
| 62 } | 64 } |
| 63 | 65 |
| 64 DCHECK(!self->channel_info_); | 66 DCHECK(!self->channel_info_); |
| 65 self->channel_info_ = channel; | 67 self->channel_info_ = channel; |
| 66 self->ipc_support_ = ipc_support.Pass(); | 68 self->ipc_support_ = ipc_support.Pass(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 } // namespace content | 71 } // namespace content |
| OLD | NEW |