Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: content/common/mojo/mojo_channel_init.cc

Issue 213313004: Add creation of ServiceManager to Content (2nd try) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add shell_client to mojo_pepper_container_app Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/mojo/mojo_channel_init.h ('k') | content/content_app.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
9 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
10 #include "base/synchronization/lock.h"
11 #include "mojo/embedder/embedder.h" 9 #include "mojo/embedder/embedder.h"
12 10
13 namespace content { 11 namespace content {
14 12
15 namespace {
16
17 struct Initializer {
18 Initializer() {
19 mojo::embedder::Init();
20 }
21 };
22
23
24 } // namespace
25
26 MojoChannelInit::MojoChannelInit() 13 MojoChannelInit::MojoChannelInit()
27 : channel_info_(NULL), 14 : channel_info_(NULL),
28 weak_factory_(this) { 15 weak_factory_(this) {
29 } 16 }
30 17
31 MojoChannelInit::~MojoChannelInit() { 18 MojoChannelInit::~MojoChannelInit() {
32 bootstrap_message_pipe_.reset(); 19 bootstrap_message_pipe_.reset();
33 if (channel_info_) { 20 if (channel_info_) {
34 io_thread_task_runner_->PostTask( 21 io_thread_task_runner_->PostTask(
35 FROM_HERE, 22 FROM_HERE,
36 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel_info_)); 23 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel_info_));
37 } 24 }
38 } 25 }
39 26
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
50 void MojoChannelInit::Init( 27 void MojoChannelInit::Init(
51 base::PlatformFile file, 28 base::PlatformFile file,
52 scoped_refptr<base::TaskRunner> io_thread_task_runner) { 29 scoped_refptr<base::TaskRunner> io_thread_task_runner) {
53 DCHECK(!io_thread_task_runner_.get()); // Should only init once. 30 DCHECK(!io_thread_task_runner_.get()); // Should only init once.
54 io_thread_task_runner_ = io_thread_task_runner; 31 io_thread_task_runner_ = io_thread_task_runner;
55 InitMojo();
56 bootstrap_message_pipe_ = mojo::embedder::CreateChannel( 32 bootstrap_message_pipe_ = mojo::embedder::CreateChannel(
57 mojo::embedder::ScopedPlatformHandle( 33 mojo::embedder::ScopedPlatformHandle(
58 mojo::embedder::PlatformHandle(file)), 34 mojo::embedder::PlatformHandle(file)),
59 io_thread_task_runner, 35 io_thread_task_runner,
60 base::Bind(&MojoChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(), 36 base::Bind(&MojoChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(),
61 io_thread_task_runner), 37 io_thread_task_runner),
62 base::MessageLoop::current()->message_loop_proxy()).Pass(); 38 base::MessageLoop::current()->message_loop_proxy()).Pass();
63 } 39 }
64 40
65 // static 41 // static
66 void MojoChannelInit::OnCreatedChannel( 42 void MojoChannelInit::OnCreatedChannel(
67 base::WeakPtr<MojoChannelInit> host, 43 base::WeakPtr<MojoChannelInit> host,
68 scoped_refptr<base::TaskRunner> io_thread, 44 scoped_refptr<base::TaskRunner> io_thread,
69 mojo::embedder::ChannelInfo* channel) { 45 mojo::embedder::ChannelInfo* channel) {
70 // By the time we get here |host| may have been destroyed. If so, shutdown the 46 // By the time we get here |host| may have been destroyed. If so, shutdown the
71 // channel. 47 // channel.
72 if (!host.get()) { 48 if (!host.get()) {
73 io_thread->PostTask( 49 io_thread->PostTask(
74 FROM_HERE, 50 FROM_HERE,
75 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel)); 51 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel));
76 return; 52 return;
77 } 53 }
78 host->channel_info_ = channel; 54 host->channel_info_ = channel;
79 } 55 }
80 56
81 57
82 } // namespace content 58 } // namespace content
OLDNEW
« no previous file with comments | « content/common/mojo/mojo_channel_init.h ('k') | content/content_app.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698