Chromium Code Reviews| 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 "ipc/mojo/ipc_channel_mojo_host.h" | 5 #include "ipc/mojo/ipc_channel_mojo_host.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 "ipc/mojo/ipc_channel_mojo.h" | 9 #include "ipc/mojo/ipc_channel_mojo.h" |
| 10 | 10 |
| 11 namespace IPC { | 11 namespace IPC { |
| 12 | 12 |
| 13 namespace { | |
| 14 | |
| 15 void DeleteChannelMojoHost(IPC::ChannelMojoHost* ptr) { | |
|
viettrungluu
2014/09/25 19:38:34
Can't you use DeletePointer (from bind_helpers.h)
Hajime Morrita
2014/09/25 22:00:03
Done.
| |
| 16 delete ptr; | |
| 17 } | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 13 ChannelMojoHost::ChannelMojoHost(scoped_refptr<base::TaskRunner> task_runner) | 21 ChannelMojoHost::ChannelMojoHost(scoped_refptr<base::TaskRunner> task_runner) |
| 14 : weak_factory_(this), task_runner_(task_runner), channel_(NULL) { | 22 : weak_factory_(this), task_runner_(task_runner) { |
| 15 } | 23 } |
| 16 | 24 |
| 17 ChannelMojoHost::~ChannelMojoHost() { | 25 ChannelMojoHost::~ChannelMojoHost() { |
| 18 } | 26 } |
|
viettrungluu
2014/09/25 19:38:34
DCHECK_EQ(base::MessageLoop::current()->message_lo
Hajime Morrita
2014/09/25 22:00:03
Done.
| |
| 19 | 27 |
| 20 void ChannelMojoHost::OnClientLaunched(base::ProcessHandle process) { | 28 void ChannelMojoHost::OnClientLaunched(base::ProcessHandle process) { |
| 21 if (task_runner_ == base::MessageLoop::current()->message_loop_proxy()) { | 29 if (task_runner_ == base::MessageLoop::current()->message_loop_proxy()) { |
| 22 InvokeOnClientLaunched(process); | 30 if (channel_) |
| 31 channel_->OnClientLaunched(process); | |
| 23 } else { | 32 } else { |
| 24 task_runner_->PostTask(FROM_HERE, | 33 // Don't check |channel_| here as it is safe only on IO thread. |
| 25 base::Bind(&ChannelMojoHost::InvokeOnClientLaunched, | 34 task_runner_->PostTask( |
| 26 weak_factory_.GetWeakPtr(), | 35 FROM_HERE, |
| 27 process)); | 36 base::Bind(&ChannelMojo::OnClientLaunched, channel_, process)); |
| 28 } | 37 } |
| 29 } | 38 } |
| 30 | 39 |
| 31 void ChannelMojoHost::InvokeOnClientLaunched(base::ProcessHandle process) { | 40 void ChannelMojoHost::DeleteThisSoon() { |
| 32 if (!channel_) | 41 task_runner_->PostTask(FROM_HERE, base::Bind(&DeleteChannelMojoHost, this)); |
| 33 return; | |
| 34 channel_->OnClientLaunched(process); | |
| 35 } | 42 } |
| 36 | 43 |
| 37 void ChannelMojoHost::OnChannelCreated(ChannelMojo* channel) { | 44 base::WeakPtr<ChannelMojoHost> ChannelMojoHost::ToWeakPtr() { |
| 38 DCHECK(channel_ == NULL); | 45 return weak_factory_.GetWeakPtr(); |
| 46 } | |
| 47 | |
| 48 void ChannelMojoHost::OnChannelCreated(base::WeakPtr<ChannelMojo> channel) { | |
| 49 DCHECK(!channel_); | |
| 39 channel_ = channel; | 50 channel_ = channel; |
| 40 } | 51 } |
| 41 | 52 |
| 42 void ChannelMojoHost::OnChannelDestroyed() { | 53 void ChannelMojoHostDeleter::operator()(ChannelMojoHost* ptr) const { |
| 43 DCHECK(channel_ != NULL); | 54 ptr->DeleteThisSoon(); |
| 44 channel_ = NULL; | |
| 45 } | 55 } |
| 46 | 56 |
| 47 } // namespace IPC | 57 } // namespace IPC |
| OLD | NEW |