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

Unified Diff: third_party/mojo/src/mojo/edk/system/channel_manager.cc

Issue 1402453004: Use a WeakPtr to post a create channel task to the IO thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « third_party/mojo/src/mojo/edk/system/channel_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/mojo/src/mojo/edk/system/channel_manager.cc
diff --git a/third_party/mojo/src/mojo/edk/system/channel_manager.cc b/third_party/mojo/src/mojo/edk/system/channel_manager.cc
index bf3edb1edba60897ebe9a418f0011b39324ef857..bf70b02c061832698ba80fc6d0cf88571b7c14db 100644
--- a/third_party/mojo/src/mojo/edk/system/channel_manager.cc
+++ b/third_party/mojo/src/mojo/edk/system/channel_manager.cc
@@ -96,7 +96,7 @@ scoped_refptr<MessagePipeDispatcher> ChannelManager::CreateChannel(
&bootstrap_channel_endpoint);
bool ok = io_thread_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&ChannelManager::CreateChannelHelper, base::Unretained(this),
+ base::Bind(&ChannelManager::CreateChannelHelper, weak_ptr_,
channel_id, base::Passed(&platform_handle),
bootstrap_channel_endpoint, callback,
callback_thread_task_runner));
@@ -187,14 +187,21 @@ scoped_refptr<Channel> ChannelManager::CreateChannelOnIOThreadHelper(
return channel;
}
+// static
void ChannelManager::CreateChannelHelper(
+ base::WeakPtr<ChannelManager> channel_manager,
ChannelId channel_id,
embedder::ScopedPlatformHandle platform_handle,
scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint,
const base::Closure& callback,
scoped_refptr<base::TaskRunner> callback_thread_task_runner) {
- CreateChannelOnIOThreadHelper(channel_id, platform_handle.Pass(),
- bootstrap_channel_endpoint);
+ // TODO(amistry): Handle this gracefully after determining exactly what cases
+ // can cause this. There appear to be crashes caused by ChannelManager being
+ // destroyed before this point, which shouldn't be possible in the current
+ // uses of ChannelManager.
+ CHECK(channel_manager);
+ channel_manager->CreateChannelOnIOThreadHelper(
+ channel_id, platform_handle.Pass(), bootstrap_channel_endpoint);
if (callback_thread_task_runner) {
bool ok = callback_thread_task_runner->PostTask(FROM_HERE, callback);
DCHECK(ok);
« no previous file with comments | « third_party/mojo/src/mojo/edk/system/channel_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698