OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/edk/system/channel_manager.h" | 5 #include "mojo/edk/system/channel_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 DCHECK_NE(channel_id, kInvalidChannelId); | 43 DCHECK_NE(channel_id, kInvalidChannelId); |
44 DCHECK(platform_handle.is_valid()); | 44 DCHECK(platform_handle.is_valid()); |
45 DCHECK(bootstrap_channel_endpoint); | 45 DCHECK(bootstrap_channel_endpoint); |
46 | 46 |
47 // Create and initialize a |system::Channel|. | 47 // Create and initialize a |system::Channel|. |
48 scoped_refptr<system::Channel> channel = | 48 scoped_refptr<system::Channel> channel = |
49 new system::Channel(platform_support_); | 49 new system::Channel(platform_support_); |
50 channel->Init(system::RawChannel::Create(platform_handle.Pass())); | 50 channel->Init(system::RawChannel::Create(platform_handle.Pass())); |
51 channel->SetBootstrapEndpoint(bootstrap_channel_endpoint); | 51 channel->SetBootstrapEndpoint(bootstrap_channel_endpoint); |
52 | 52 |
53 AddChannel(channel_id, channel, base::MessageLoopProxy::current()); | |
54 } | |
55 | |
56 void ChannelManager::AddChannel( | |
57 ChannelId channel_id, | |
58 scoped_refptr<Channel> channel, | |
59 scoped_refptr<base::TaskRunner> channel_thread_task_runner) { | |
60 { | 53 { |
61 base::AutoLock locker(lock_); | 54 base::AutoLock locker(lock_); |
62 CHECK(channel_infos_.find(channel_id) == channel_infos_.end()); | 55 CHECK(channel_infos_.find(channel_id) == channel_infos_.end()); |
63 channel_infos_[channel_id] = | 56 channel_infos_[channel_id] = |
64 ChannelInfo(channel, channel_thread_task_runner); | 57 ChannelInfo(channel, base::MessageLoopProxy::current()); |
65 } | 58 } |
66 channel->SetChannelManager(this); | 59 channel->SetChannelManager(this); |
67 } | 60 } |
68 | 61 |
| 62 scoped_refptr<Channel> ChannelManager::GetChannel(ChannelId channel_id) const { |
| 63 base::AutoLock locker(lock_); |
| 64 auto it = channel_infos_.find(channel_id); |
| 65 DCHECK(it != channel_infos_.end()); |
| 66 return it->second.channel; |
| 67 } |
| 68 |
69 void ChannelManager::WillShutdownChannel(ChannelId channel_id) { | 69 void ChannelManager::WillShutdownChannel(ChannelId channel_id) { |
70 GetChannelInfo(channel_id).channel->WillShutdownSoon(); | 70 GetChannel(channel_id)->WillShutdownSoon(); |
71 } | 71 } |
72 | 72 |
73 void ChannelManager::ShutdownChannel(ChannelId channel_id) { | 73 void ChannelManager::ShutdownChannel(ChannelId channel_id) { |
74 ChannelInfo channel_info; | 74 ChannelInfo channel_info; |
75 { | 75 { |
76 base::AutoLock locker(lock_); | 76 base::AutoLock locker(lock_); |
77 auto it = channel_infos_.find(channel_id); | 77 auto it = channel_infos_.find(channel_id); |
78 DCHECK(it != channel_infos_.end()); | 78 DCHECK(it != channel_infos_.end()); |
79 channel_info.Swap(&it->second); | 79 channel_info.Swap(&it->second); |
80 channel_infos_.erase(it); | 80 channel_infos_.erase(it); |
81 } | 81 } |
82 ShutdownChannelHelper(channel_info); | 82 ShutdownChannelHelper(channel_info); |
83 } | 83 } |
84 | 84 |
85 ChannelInfo ChannelManager::GetChannelInfo(ChannelId channel_id) { | |
86 base::AutoLock locker(lock_); | |
87 auto it = channel_infos_.find(channel_id); | |
88 DCHECK(it != channel_infos_.end()); | |
89 return it->second; | |
90 } | |
91 | |
92 } // namespace system | 85 } // namespace system |
93 } // namespace mojo | 86 } // namespace mojo |
OLD | NEW |