OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/child/np_channel_base.h" | 5 #include "content/child/np_channel_base.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 iter->second->Send(new IPC::Message(*message)); | 65 iter->second->Send(new IPC::Message(*message)); |
66 } | 66 } |
67 delete message; | 67 delete message; |
68 } | 68 } |
69 | 69 |
70 NPChannelBase::NPChannelBase() | 70 NPChannelBase::NPChannelBase() |
71 : mode_(IPC::Channel::MODE_NONE), | 71 : mode_(IPC::Channel::MODE_NONE), |
72 non_npobject_count_(0), | 72 non_npobject_count_(0), |
73 peer_pid_(0), | 73 peer_pid_(0), |
74 in_remove_route_(false), | 74 in_remove_route_(false), |
| 75 default_owner_(NULL), |
75 channel_valid_(false), | 76 channel_valid_(false), |
76 in_unblock_dispatch_(0), | 77 in_unblock_dispatch_(0), |
77 send_unblocking_only_during_unblock_dispatch_(false) { | 78 send_unblocking_only_during_unblock_dispatch_(false) { |
78 } | 79 } |
79 | 80 |
80 NPChannelBase::~NPChannelBase() { | 81 NPChannelBase::~NPChannelBase() { |
| 82 // TODO(wez): Establish why these would ever be non-empty at teardown. |
| 83 //DCHECK(npobject_listeners_.empty()); |
| 84 //DCHECK(proxy_map_.empty()); |
| 85 //DCHECK(stub_map_.empty()); |
| 86 DCHECK(owner_to_route_.empty()); |
| 87 DCHECK(route_to_owner_.empty()); |
81 } | 88 } |
82 | 89 |
83 NPChannelBase* NPChannelBase::GetCurrentChannel() { | 90 NPChannelBase* NPChannelBase::GetCurrentChannel() { |
84 return g_lazy_channel_stack.Pointer()->top().get(); | 91 return g_lazy_channel_stack.Pointer()->top().get(); |
85 } | 92 } |
86 | 93 |
87 void NPChannelBase::CleanupChannels() { | 94 void NPChannelBase::CleanupChannels() { |
88 // Make a copy of the references as we can't iterate the map since items will | 95 // Make a copy of the references as we can't iterate the map since items will |
89 // be removed from it as we clean them up. | 96 // be removed from it as we clean them up. |
90 std::vector<scoped_refptr<NPChannelBase> > channels; | 97 std::vector<scoped_refptr<NPChannelBase> > channels; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 iter != g_channels.Get().end(); ++iter) { | 271 iter != g_channels.Get().end(); ++iter) { |
265 if (iter->second.get() == this) { | 272 if (iter->second.get() == this) { |
266 // Insert new element before invalidating |iter|. | 273 // Insert new element before invalidating |iter|. |
267 g_channels.Get()[iter->first + "-error"] = iter->second; | 274 g_channels.Get()[iter->first + "-error"] = iter->second; |
268 g_channels.Get().erase(iter); | 275 g_channels.Get().erase(iter); |
269 break; | 276 break; |
270 } | 277 } |
271 } | 278 } |
272 } | 279 } |
273 | 280 |
274 NPObject* NPChannelBase::GetExistingNPObjectProxy(int route_id) { | |
275 ProxyMap::iterator iter = proxy_map_.find(route_id); | |
276 return iter != proxy_map_.end() ? iter->second : NULL; | |
277 } | |
278 | |
279 int NPChannelBase::GetExistingRouteForNPObjectStub(NPObject* npobject) { | |
280 StubMap::iterator iter = stub_map_.find(npobject); | |
281 return iter != stub_map_.end() ? iter->second : MSG_ROUTING_NONE; | |
282 } | |
283 | |
284 void NPChannelBase::AddMappingForNPObjectProxy(int route_id, | 281 void NPChannelBase::AddMappingForNPObjectProxy(int route_id, |
285 NPObject* object) { | 282 NPObject* object) { |
286 proxy_map_[route_id] = object; | 283 proxy_map_[route_id] = object; |
287 } | 284 } |
288 | 285 |
| 286 void NPChannelBase::RemoveMappingForNPObjectProxy(int route_id) { |
| 287 proxy_map_.erase(route_id); |
| 288 } |
| 289 |
289 void NPChannelBase::AddMappingForNPObjectStub(int route_id, | 290 void NPChannelBase::AddMappingForNPObjectStub(int route_id, |
290 NPObject* object) { | 291 NPObject* object) { |
291 DCHECK(object != NULL); | 292 DCHECK(object != NULL); |
292 stub_map_[object] = route_id; | 293 stub_map_[object] = route_id; |
293 } | 294 } |
294 | 295 |
295 void NPChannelBase::RemoveMappingForNPObjectStub(int route_id, | 296 void NPChannelBase::RemoveMappingForNPObjectStub(int route_id, |
296 NPObject* object) { | 297 NPObject* object) { |
297 DCHECK(object != NULL); | 298 DCHECK(object != NULL); |
298 stub_map_.erase(object); | 299 stub_map_.erase(object); |
299 } | 300 } |
300 | 301 |
301 void NPChannelBase::RemoveMappingForNPObjectProxy(int route_id) { | 302 void NPChannelBase::AddMappingForNPObjectOwner(int route_id, |
302 proxy_map_.erase(route_id); | 303 struct _NPP* owner) { |
| 304 DCHECK(owner != NULL); |
| 305 route_to_owner_[route_id] = owner; |
| 306 owner_to_route_[owner] = route_id; |
| 307 } |
| 308 |
| 309 void NPChannelBase::SetDefaultNPObjectOwner(struct _NPP* owner) { |
| 310 DCHECK(owner != NULL); |
| 311 default_owner_ = owner; |
| 312 } |
| 313 |
| 314 void NPChannelBase::RemoveMappingForNPObjectOwner(int route_id) { |
| 315 DCHECK(route_to_owner_.find(route_id) != route_to_owner_.end()); |
| 316 owner_to_route_.erase(route_to_owner_[route_id]); |
| 317 route_to_owner_.erase(route_id); |
| 318 } |
| 319 |
| 320 NPObject* NPChannelBase::GetExistingNPObjectProxy(int route_id) { |
| 321 ProxyMap::iterator iter = proxy_map_.find(route_id); |
| 322 return iter != proxy_map_.end() ? iter->second : NULL; |
| 323 } |
| 324 |
| 325 int NPChannelBase::GetExistingRouteForNPObjectStub(NPObject* npobject) { |
| 326 StubMap::iterator iter = stub_map_.find(npobject); |
| 327 return iter != stub_map_.end() ? iter->second : MSG_ROUTING_NONE; |
| 328 } |
| 329 |
| 330 NPP NPChannelBase::GetExistingNPObjectOwner(int route_id) { |
| 331 RouteToOwnerMap::iterator iter = route_to_owner_.find(route_id); |
| 332 return iter != route_to_owner_.end() ? iter->second : default_owner_; |
| 333 } |
| 334 |
| 335 int NPChannelBase::GetExistingRouteForNPObjectOwner(NPP owner) { |
| 336 OwnerToRouteMap::iterator iter = owner_to_route_.find(owner); |
| 337 return iter != owner_to_route_.end() ? iter->second : MSG_ROUTING_NONE; |
303 } | 338 } |
304 | 339 |
305 } // namespace content | 340 } // namespace content |
OLD | NEW |