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

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

Issue 236813002: Move Mojo channel initialization closer to IPC::Channel setup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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/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 content { 11 namespace content {
12 12
13 MojoChannelInit::MojoChannelInit() 13 MojoChannelInit::MojoChannelInit()
14 : channel_info_(NULL), 14 : channel_info_(NULL),
15 weak_factory_(this) { 15 weak_factory_(this) {
16 } 16 }
17 17
18 MojoChannelInit::~MojoChannelInit() { 18 MojoChannelInit::~MojoChannelInit() {
19 bootstrap_message_pipe_.reset();
20 if (channel_info_) { 19 if (channel_info_) {
21 io_thread_task_runner_->PostTask( 20 io_thread_task_runner_->PostTask(
22 FROM_HERE, 21 FROM_HERE,
23 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel_info_)); 22 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel_info_));
24 } 23 }
25 } 24 }
26 25
27 void MojoChannelInit::Init( 26 mojo::ScopedMessagePipeHandle MojoChannelInit::Init(
28 base::PlatformFile file, 27 base::PlatformFile file,
29 scoped_refptr<base::TaskRunner> io_thread_task_runner) { 28 scoped_refptr<base::TaskRunner> io_thread_task_runner) {
30 DCHECK(!io_thread_task_runner_.get()); // Should only init once. 29 DCHECK(!io_thread_task_runner_.get()); // Should only init once.
31 io_thread_task_runner_ = io_thread_task_runner; 30 io_thread_task_runner_ = io_thread_task_runner;
32 bootstrap_message_pipe_ = mojo::embedder::CreateChannel( 31 mojo::ScopedMessagePipeHandle message_pipe = mojo::embedder::CreateChannel(
33 mojo::embedder::ScopedPlatformHandle( 32 mojo::embedder::ScopedPlatformHandle(
34 mojo::embedder::PlatformHandle(file)), 33 mojo::embedder::PlatformHandle(file)),
35 io_thread_task_runner, 34 io_thread_task_runner,
36 base::Bind(&MojoChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(), 35 base::Bind(&MojoChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(),
37 io_thread_task_runner), 36 io_thread_task_runner),
38 base::MessageLoop::current()->message_loop_proxy()).Pass(); 37 base::MessageLoop::current()->message_loop_proxy()).Pass();
38 return message_pipe.Pass();
39 } 39 }
40 40
41 // static 41 // static
42 void MojoChannelInit::OnCreatedChannel( 42 void MojoChannelInit::OnCreatedChannel(
43 base::WeakPtr<MojoChannelInit> host, 43 base::WeakPtr<MojoChannelInit> host,
44 scoped_refptr<base::TaskRunner> io_thread, 44 scoped_refptr<base::TaskRunner> io_thread,
45 mojo::embedder::ChannelInfo* channel) { 45 mojo::embedder::ChannelInfo* channel) {
46 // 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
47 // channel. 47 // channel.
48 if (!host.get()) { 48 if (!host.get()) {
49 io_thread->PostTask( 49 io_thread->PostTask(
50 FROM_HERE, 50 FROM_HERE,
51 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel)); 51 base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel));
52 return; 52 return;
53 } 53 }
54 host->channel_info_ = channel; 54 host->channel_info_ = channel;
55 } 55 }
56 56
57 57
58 } // namespace content 58 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698