Index: ipc/mojo/ipc_channel_mojo_host.cc |
diff --git a/ipc/mojo/ipc_channel_mojo_host.cc b/ipc/mojo/ipc_channel_mojo_host.cc |
index 4318a15f54379e5fb568ebd15735eb313b2ebf14..590032a9e64bd37638f7dca57967bbc1fc7d96b7 100644 |
--- a/ipc/mojo/ipc_channel_mojo_host.cc |
+++ b/ipc/mojo/ipc_channel_mojo_host.cc |
@@ -10,8 +10,16 @@ |
namespace IPC { |
+namespace { |
+ |
+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.
|
+ delete ptr; |
+} |
+ |
+} // namespace |
+ |
ChannelMojoHost::ChannelMojoHost(scoped_refptr<base::TaskRunner> task_runner) |
- : weak_factory_(this), task_runner_(task_runner), channel_(NULL) { |
+ : weak_factory_(this), task_runner_(task_runner) { |
} |
ChannelMojoHost::~ChannelMojoHost() { |
@@ -19,29 +27,31 @@ ChannelMojoHost::~ChannelMojoHost() { |
void ChannelMojoHost::OnClientLaunched(base::ProcessHandle process) { |
if (task_runner_ == base::MessageLoop::current()->message_loop_proxy()) { |
- InvokeOnClientLaunched(process); |
+ if (channel_) |
+ channel_->OnClientLaunched(process); |
} else { |
- task_runner_->PostTask(FROM_HERE, |
- base::Bind(&ChannelMojoHost::InvokeOnClientLaunched, |
- weak_factory_.GetWeakPtr(), |
- process)); |
+ // Don't check |channel_| here as it is safe only on IO thread. |
+ task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ChannelMojo::OnClientLaunched, channel_, process)); |
} |
} |
-void ChannelMojoHost::InvokeOnClientLaunched(base::ProcessHandle process) { |
- if (!channel_) |
- return; |
- channel_->OnClientLaunched(process); |
+void ChannelMojoHost::DeleteThisSoon() { |
+ task_runner_->PostTask(FROM_HERE, base::Bind(&DeleteChannelMojoHost, this)); |
+} |
+ |
+base::WeakPtr<ChannelMojoHost> ChannelMojoHost::ToWeakPtr() { |
+ return weak_factory_.GetWeakPtr(); |
} |
-void ChannelMojoHost::OnChannelCreated(ChannelMojo* channel) { |
- DCHECK(channel_ == NULL); |
+void ChannelMojoHost::OnChannelCreated(base::WeakPtr<ChannelMojo> channel) { |
+ DCHECK(!channel_); |
channel_ = channel; |
} |
-void ChannelMojoHost::OnChannelDestroyed() { |
- DCHECK(channel_ != NULL); |
- channel_ = NULL; |
+void ChannelMojoHostDeleter::operator()(ChannelMojoHost* ptr) const { |
+ ptr->DeleteThisSoon(); |
} |
} // namespace IPC |