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

Side by Side Diff: mojo/edk/system/channel_manager.cc

Issue 728133002: Update mojo sdk to rev e01f9a49449381a5eb430c1fd88bf2cae73ec35a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android + ios gyp fixes 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 unified diff | Download patch
« no previous file with comments | « mojo/edk/system/channel_manager.h ('k') | mojo/edk/system/channel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/edk/system/channel_manager.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h"
10
11 namespace mojo {
12 namespace system {
13
14 namespace {
15
16 void ShutdownChannelHelper(const ChannelInfo& channel_info) {
17 if (base::MessageLoopProxy::current() ==
18 channel_info.channel_thread_task_runner) {
19 channel_info.channel->Shutdown();
20 } else {
21 channel_info.channel->WillShutdownSoon();
22 channel_info.channel_thread_task_runner->PostTask(
23 FROM_HERE, base::Bind(&Channel::Shutdown, channel_info.channel));
24 }
25 }
26
27 } // namespace
28
29 ChannelManager::ChannelManager() {
30 }
31
32 ChannelManager::~ChannelManager() {
33 // No need to take the lock.
34 for (const auto& map_elem : channel_infos_)
35 ShutdownChannelHelper(map_elem.second);
36 }
37
38 ChannelId ChannelManager::AddChannel(
39 scoped_refptr<Channel> channel,
40 scoped_refptr<base::TaskRunner> channel_thread_task_runner) {
41 ChannelId channel_id = GetChannelId(channel.get());
42
43 {
44 base::AutoLock locker(lock_);
45 DCHECK(channel_infos_.find(channel_id) == channel_infos_.end());
46 channel_infos_[channel_id] =
47 ChannelInfo(channel, channel_thread_task_runner);
48 }
49 channel->SetChannelManager(this);
50
51 return channel_id;
52 }
53
54 void ChannelManager::WillShutdownChannel(ChannelId channel_id) {
55 GetChannelInfo(channel_id).channel->WillShutdownSoon();
56 }
57
58 void ChannelManager::ShutdownChannel(ChannelId channel_id) {
59 ChannelInfo channel_info;
60 {
61 base::AutoLock locker(lock_);
62 auto it = channel_infos_.find(channel_id);
63 DCHECK(it != channel_infos_.end());
64 channel_info.Swap(&it->second);
65 channel_infos_.erase(it);
66 }
67 ShutdownChannelHelper(channel_info);
68 }
69
70 ChannelInfo ChannelManager::GetChannelInfo(ChannelId channel_id) {
71 base::AutoLock locker(lock_);
72 auto it = channel_infos_.find(channel_id);
73 DCHECK(it != channel_infos_.end());
74 return it->second;
75 }
76
77 } // namespace system
78 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel_manager.h ('k') | mojo/edk/system/channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698