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

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

Issue 728613002: Make the embedder API use the ChannelManager. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: update comment Created 6 years, 1 month 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 | « 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 e673299cb6c1b785791451ca5282f20ae14b56ac..89f515579d7e36eeb4812c6d4484053bb504a914 100644
--- a/mojo/edk/system/channel_manager.cc
+++ b/mojo/edk/system/channel_manager.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/location.h"
+#include "base/message_loop/message_loop_proxy.h"
namespace mojo {
namespace system {
@@ -13,9 +14,14 @@ namespace system {
namespace {
void ShutdownChannelHelper(const ChannelInfo& channel_info) {
- channel_info.channel->WillShutdownSoon();
- channel_info.channel_thread_task_runner->PostTask(
- FROM_HERE, base::Bind(&Channel::Shutdown, channel_info.channel));
+ if (base::MessageLoopProxy::current() ==
+ channel_info.channel_thread_task_runner) {
+ channel_info.channel->Shutdown();
+ } else {
+ channel_info.channel->WillShutdownSoon();
+ channel_info.channel_thread_task_runner->PostTask(
+ FROM_HERE, base::Bind(&Channel::Shutdown, channel_info.channel));
+ }
}
} // namespace
@@ -45,17 +51,22 @@ ChannelId ChannelManager::AddChannel(
return channel_id;
}
+void ChannelManager::WillShutdownChannel(ChannelId channel_id) {
+ GetChannelInfo(channel_id).channel->WillShutdownSoon();
+}
+
void ChannelManager::ShutdownChannel(ChannelId channel_id) {
- ChannelInfo channel_info;
- {
- base::AutoLock locker(lock_);
+ ShutdownChannelHelper(GetChannelInfo(channel_id));
+}
- auto it = channel_infos_.find(channel_id);
- DCHECK(it != channel_infos_.end());
- channel_info.Swap(&it->second);
- channel_infos_.erase(it);
- }
- ShutdownChannelHelper(channel_info);
+ChannelInfo ChannelManager::GetChannelInfo(ChannelId channel_id) {
+ ChannelInfo rv;
+ base::AutoLock locker(lock_);
+ auto it = channel_infos_.find(channel_id);
+ DCHECK(it != channel_infos_.end());
+ rv.Swap(&it->second);
+ channel_infos_.erase(it);
+ return rv;
}
} // namespace system
« no previous file with comments | « mojo/edk/system/channel_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698