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

Unified Diff: ipc/mojo/ipc_channel_mojo_host.cc

Issue 599333002: ChannelMojo: Handle when ChannelMojo outlives ChannelMojoHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« ipc/mojo/ipc_channel_mojo_host.h ('K') | « ipc/mojo/ipc_channel_mojo_host.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« ipc/mojo/ipc_channel_mojo_host.h ('K') | « ipc/mojo/ipc_channel_mojo_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698