| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/common/mojo/mojo_channel_init.h" | 5 #include "content/common/mojo/mojo_channel_init.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "mojo/embedder/embedder.h" | 11 #include "mojo/embedder/embedder.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 struct Initializer { | 17 struct Initializer { |
| 18 Initializer() { | 18 Initializer() { |
| 19 mojo::embedder::Init(); | 19 mojo::embedder::Init(); |
| 20 } | 20 } |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 static base::LazyInstance<Initializer>::Leaky initializer = | |
| 24 LAZY_INSTANCE_INITIALIZER; | |
| 25 | |
| 26 // Initializes mojo. Use a lazy instance to ensure we only do this once. | |
| 27 // TODO(sky): this likely wants to move to a more central location, such as | |
| 28 // startup. | |
| 29 void InitMojo() { | |
| 30 initializer.Get(); | |
| 31 } | |
| 32 | 23 |
| 33 } // namespace | 24 } // namespace |
| 34 | 25 |
| 35 MojoChannelInit::MojoChannelInit() | 26 MojoChannelInit::MojoChannelInit() |
| 36 : channel_info_(NULL), | 27 : channel_info_(NULL), |
| 37 weak_factory_(this) { | 28 weak_factory_(this) { |
| 38 } | 29 } |
| 39 | 30 |
| 40 MojoChannelInit::~MojoChannelInit() { | 31 MojoChannelInit::~MojoChannelInit() { |
| 41 bootstrap_message_pipe_.reset(); | 32 bootstrap_message_pipe_.reset(); |
| 42 if (channel_info_) { | 33 if (channel_info_) { |
| 43 io_thread_task_runner_->PostTask( | 34 io_thread_task_runner_->PostTask( |
| 44 FROM_HERE, | 35 FROM_HERE, |
| 45 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel_info_)); | 36 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel_info_)); |
| 46 } | 37 } |
| 47 } | 38 } |
| 48 | 39 |
| 40 // static |
| 41 void MojoChannelInit::InitMojo() { |
| 42 static base::LazyInstance<Initializer>::Leaky initializer = |
| 43 LAZY_INSTANCE_INITIALIZER; |
| 44 // Initializes mojo. Use a lazy instance to ensure we only do this once. |
| 45 // TODO(sky): this likely wants to move to a more central location, such as |
| 46 // startup. |
| 47 initializer.Get(); |
| 48 } |
| 49 |
| 49 void MojoChannelInit::Init( | 50 void MojoChannelInit::Init( |
| 50 base::PlatformFile file, | 51 base::PlatformFile file, |
| 51 scoped_refptr<base::TaskRunner> io_thread_task_runner) { | 52 scoped_refptr<base::TaskRunner> io_thread_task_runner) { |
| 52 DCHECK(!io_thread_task_runner_.get()); // Should only init once. | 53 DCHECK(!io_thread_task_runner_.get()); // Should only init once. |
| 53 io_thread_task_runner_ = io_thread_task_runner; | 54 io_thread_task_runner_ = io_thread_task_runner; |
| 54 InitMojo(); | 55 InitMojo(); |
| 55 bootstrap_message_pipe_ = mojo::embedder::CreateChannel( | 56 bootstrap_message_pipe_ = mojo::embedder::CreateChannel( |
| 56 mojo::embedder::ScopedPlatformHandle( | 57 mojo::embedder::ScopedPlatformHandle( |
| 57 mojo::embedder::PlatformHandle(file)), | 58 mojo::embedder::PlatformHandle(file)), |
| 58 io_thread_task_runner, | 59 io_thread_task_runner, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 72 io_thread->PostTask( | 73 io_thread->PostTask( |
| 73 FROM_HERE, | 74 FROM_HERE, |
| 74 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel)); | 75 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel)); |
| 75 return; | 76 return; |
| 76 } | 77 } |
| 77 host->channel_info_ = channel; | 78 host->channel_info_ = channel; |
| 78 } | 79 } |
| 79 | 80 |
| 80 | 81 |
| 81 } // namespace content | 82 } // namespace content |
| OLD | NEW |