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

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

Issue 728043002: Revert of Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
10 namespace mojo {
11 namespace system {
12
13 namespace {
14
15 void ShutdownChannelHelper(const ChannelInfo& channel_info) {
16 channel_info.channel->WillShutdownSoon();
17 channel_info.channel_thread_task_runner->PostTask(
18 FROM_HERE, base::Bind(&Channel::Shutdown, channel_info.channel));
19 }
20
21 } // namespace
22
23 ChannelManager::ChannelManager() {
24 }
25
26 ChannelManager::~ChannelManager() {
27 // No need to take the lock.
28 for (const auto& map_elem : channel_infos_)
29 ShutdownChannelHelper(map_elem.second);
30 }
31
32 ChannelId ChannelManager::AddChannel(
33 scoped_refptr<Channel> channel,
34 scoped_refptr<base::TaskRunner> channel_thread_task_runner) {
35 ChannelId channel_id = GetChannelId(channel.get());
36
37 {
38 base::AutoLock locker(lock_);
39 DCHECK(channel_infos_.find(channel_id) == channel_infos_.end());
40 channel_infos_[channel_id] =
41 ChannelInfo(channel, channel_thread_task_runner);
42 }
43 channel->SetChannelManager(this);
44
45 return channel_id;
46 }
47
48 void ChannelManager::ShutdownChannel(ChannelId channel_id) {
49 ChannelInfo channel_info;
50 {
51 base::AutoLock locker(lock_);
52
53 auto it = channel_infos_.find(channel_id);
54 DCHECK(it != channel_infos_.end());
55 channel_info.Swap(&it->second);
56 channel_infos_.erase(it);
57 }
58 ShutdownChannelHelper(channel_info);
59 }
60
61 } // namespace system
62 } // 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