OLD | NEW |
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 "mojo/common/mojo_channel_init.h" | 5 #include "mojo/common/channel_init.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "mojo/embedder/embedder.h" | 9 #include "mojo/embedder/embedder.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 namespace common { | 12 namespace common { |
13 | 13 |
14 MojoChannelInit::MojoChannelInit() | 14 ChannelInit::ChannelInit() |
15 : channel_info_(NULL), | 15 : channel_info_(NULL), |
16 weak_factory_(this) { | 16 weak_factory_(this) { |
17 } | 17 } |
18 | 18 |
19 MojoChannelInit::~MojoChannelInit() { | 19 ChannelInit::~ChannelInit() { |
20 bootstrap_message_pipe_.reset(); | |
21 if (channel_info_) { | 20 if (channel_info_) { |
22 io_thread_task_runner_->PostTask( | 21 io_thread_task_runner_->PostTask( |
23 FROM_HERE, | 22 FROM_HERE, |
24 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel_info_)); | 23 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel_info_)); |
25 } | 24 } |
26 } | 25 } |
27 | 26 |
28 void MojoChannelInit::Init( | 27 mojo::ScopedMessagePipeHandle ChannelInit::Init( |
29 base::PlatformFile file, | 28 base::PlatformFile file, |
30 scoped_refptr<base::TaskRunner> io_thread_task_runner) { | 29 scoped_refptr<base::TaskRunner> io_thread_task_runner) { |
31 DCHECK(!io_thread_task_runner_.get()); // Should only init once. | 30 DCHECK(!io_thread_task_runner_.get()); // Should only init once. |
32 io_thread_task_runner_ = io_thread_task_runner; | 31 io_thread_task_runner_ = io_thread_task_runner; |
33 bootstrap_message_pipe_ = mojo::embedder::CreateChannel( | 32 mojo::ScopedMessagePipeHandle message_pipe = mojo::embedder::CreateChannel( |
34 mojo::embedder::ScopedPlatformHandle( | 33 mojo::embedder::ScopedPlatformHandle( |
35 mojo::embedder::PlatformHandle(file)), | 34 mojo::embedder::PlatformHandle(file)), |
36 io_thread_task_runner, | 35 io_thread_task_runner, |
37 base::Bind(&MojoChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(), | 36 base::Bind(&ChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(), |
38 io_thread_task_runner), | 37 io_thread_task_runner), |
39 base::MessageLoop::current()->message_loop_proxy()).Pass(); | 38 base::MessageLoop::current()->message_loop_proxy()).Pass(); |
| 39 return message_pipe.Pass(); |
40 } | 40 } |
41 | 41 |
42 // static | 42 // static |
43 void MojoChannelInit::OnCreatedChannel( | 43 void ChannelInit::OnCreatedChannel( |
44 base::WeakPtr<MojoChannelInit> host, | 44 base::WeakPtr<ChannelInit> host, |
45 scoped_refptr<base::TaskRunner> io_thread, | 45 scoped_refptr<base::TaskRunner> io_thread, |
46 embedder::ChannelInfo* channel) { | 46 embedder::ChannelInfo* channel) { |
47 // By the time we get here |host| may have been destroyed. If so, shutdown the | 47 // By the time we get here |host| may have been destroyed. If so, shutdown the |
48 // channel. | 48 // channel. |
49 if (!host.get()) { | 49 if (!host.get()) { |
50 io_thread->PostTask( | 50 io_thread->PostTask( |
51 FROM_HERE, | 51 FROM_HERE, |
52 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel)); | 52 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel)); |
53 return; | 53 return; |
54 } | 54 } |
55 host->channel_info_ = channel; | 55 host->channel_info_ = channel; |
56 } | 56 } |
57 | 57 |
58 } // namespace common | 58 } // namespace common |
59 } // namespace mojo | 59 } // namespace mojo |
OLD | NEW |