ChannelMojo: Handle when ChannelMojo outlives ChannelMojoHost

In some case ChannelMojo outlives ChannelMojoHost because
two objects are living in diffent thread.
Instead of using lifecycle callbacks, this CL relies on
WeakPtr. See comment on ipc_channel_mojo_host.h for
more details.

This CL also fixes a crash on --single-process mode.

R=viettrungluu@chromium.org
TBR=jam@chromium.org
TEST=content_browsertests (with --enable-renderer-mojo-channel on)
BUG=377980

Review URL: https://codereview.chromium.org/599333002

Cr-Commit-Position: refs/heads/master@{#296871}


CrOS-Libchrome-Original-Commit: e9453ea69cbb3d52e67394e75c747b0b2d970621
diff --git a/ipc/mojo/ipc_channel_mojo_unittest.cc b/ipc/mojo/ipc_channel_mojo_unittest.cc
index e1adecd..ac1efd1 100644
--- a/ipc/mojo/ipc_channel_mojo_unittest.cc
+++ b/ipc/mojo/ipc_channel_mojo_unittest.cc
@@ -83,7 +83,8 @@
       const IPC::ChannelHandle& handle,
       base::TaskRunner* runner) OVERRIDE {
     host_.reset(new IPC::ChannelMojoHost(task_runner()));
-    return IPC::ChannelMojo::CreateServerFactory(host_.get(), handle);
+    return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(),
+                                                 handle);
   }
 
   virtual bool DidStartClient() OVERRIDE {
@@ -190,7 +191,8 @@
       const IPC::ChannelHandle& handle,
       base::TaskRunner* runner) OVERRIDE {
     host_.reset(new IPC::ChannelMojoHost(task_runner()));
-    return IPC::ChannelMojo::CreateServerFactory(host_.get(), handle);
+    return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(),
+                                                 handle);
   }
 
   virtual bool DidStartClient() OVERRIDE {