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

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

Issue 899993002: Add a thread-safe CreateChannel method to ChannelManager. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« mojo/edk/system/channel_manager.h ('K') | « 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: mojo/edk/system/channel_manager.cc
diff --git a/mojo/edk/system/channel_manager.cc b/mojo/edk/system/channel_manager.cc
index 320b8ce2107319a6e98241900a1f1944865c9929..c2fe8a5ceda15119968932bfee000707c3818910 100644
--- a/mojo/edk/system/channel_manager.cc
+++ b/mojo/edk/system/channel_manager.cc
@@ -5,8 +5,10 @@
#include "mojo/edk/system/channel_manager.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/message_loop/message_loop_proxy.h"
+#include "base/task_runner.h"
namespace mojo {
namespace system {
@@ -59,6 +61,25 @@ void ChannelManager::CreateChannelOnIOThread(
channel->SetChannelManager(this);
}
+void ChannelManager::CreateChannel(
+ ChannelId channel_id,
+ embedder::ScopedPlatformHandle platform_handle,
+ scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint,
+ scoped_refptr<base::TaskRunner> io_thread_task_runner,
+ base::Closure callback,
+ scoped_refptr<base::TaskRunner> callback_thread_task_runner) {
+ DCHECK(io_thread_task_runner);
+ DCHECK(!callback.is_null());
+ // (|callback_thread_task_runner| may be null.)
+
+ io_thread_task_runner->PostTask(
+ FROM_HERE,
+ base::Bind(&ChannelManager::CreateChannelHelper, base::Unretained(this),
+ channel_id, base::Passed(&platform_handle),
+ bootstrap_channel_endpoint, callback,
+ callback_thread_task_runner));
+}
+
scoped_refptr<Channel> ChannelManager::GetChannel(ChannelId channel_id) const {
base::AutoLock locker(lock_);
auto it = channel_infos_.find(channel_id);
@@ -82,5 +103,19 @@ void ChannelManager::ShutdownChannel(ChannelId channel_id) {
ShutdownChannelHelper(channel_info);
}
+void ChannelManager::CreateChannelHelper(
+ ChannelId channel_id,
+ embedder::ScopedPlatformHandle platform_handle,
+ scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint,
+ base::Closure callback,
+ scoped_refptr<base::TaskRunner> callback_thread_task_runner) {
+ CreateChannelOnIOThread(channel_id, platform_handle.Pass(),
+ bootstrap_channel_endpoint);
+ if (callback_thread_task_runner)
+ callback_thread_task_runner->PostTask(FROM_HERE, callback);
+ else
+ callback.Run();
+}
+
} // namespace system
} // namespace mojo
« mojo/edk/system/channel_manager.h ('K') | « mojo/edk/system/channel_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698