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

Side by Side Diff: content/common_child/np_channel_base.cc

Issue 16294003: Update content/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « content/common/resource_messages.cc ('k') | content/common_child/npobject_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common_child/np_channel_base.h" 5 #include "content/common_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/hash_tables.h" 10 #include "base/hash_tables.h"
(...skipping 21 matching lines...) Expand all
32 bool create_pipe_now, base::WaitableEvent* shutdown_event) { 32 bool create_pipe_now, base::WaitableEvent* shutdown_event) {
33 scoped_refptr<NPChannelBase> channel; 33 scoped_refptr<NPChannelBase> channel;
34 std::string channel_key = channel_handle.name; 34 std::string channel_key = channel_handle.name;
35 ChannelMap::const_iterator iter = g_channels.Get().find(channel_key); 35 ChannelMap::const_iterator iter = g_channels.Get().find(channel_key);
36 if (iter == g_channels.Get().end()) { 36 if (iter == g_channels.Get().end()) {
37 channel = factory(); 37 channel = factory();
38 } else { 38 } else {
39 channel = iter->second; 39 channel = iter->second;
40 } 40 }
41 41
42 DCHECK(channel != NULL); 42 DCHECK(channel.get() != NULL);
43 43
44 if (!channel->channel_valid()) { 44 if (!channel->channel_valid()) {
45 channel->channel_handle_ = channel_handle; 45 channel->channel_handle_ = channel_handle;
46 if (mode & IPC::Channel::MODE_SERVER_FLAG) { 46 if (mode & IPC::Channel::MODE_SERVER_FLAG) {
47 channel->channel_handle_.name = 47 channel->channel_handle_.name =
48 IPC::Channel::GenerateVerifiedChannelID(channel_key); 48 IPC::Channel::GenerateVerifiedChannelID(channel_key);
49 } 49 }
50 channel->mode_ = mode; 50 channel->mode_ = mode;
51 if (channel->Init(ipc_message_loop, create_pipe_now, shutdown_event)) { 51 if (channel->Init(ipc_message_loop, create_pipe_now, shutdown_event)) {
52 g_channels.Get()[channel_key] = channel; 52 g_channels.Get()[channel_key] = channel;
53 } else { 53 } else {
54 channel = NULL; 54 channel = NULL;
55 } 55 }
56 } 56 }
57 57
58 return channel; 58 return channel.get();
59 } 59 }
60 60
61 void NPChannelBase::Broadcast(IPC::Message* message) { 61 void NPChannelBase::Broadcast(IPC::Message* message) {
62 for (ChannelMap::iterator iter = g_channels.Get().begin(); 62 for (ChannelMap::iterator iter = g_channels.Get().begin();
63 iter != g_channels.Get().end(); 63 iter != g_channels.Get().end();
64 ++iter) { 64 ++iter) {
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 channel_valid_(false), 75 channel_valid_(false),
76 in_unblock_dispatch_(0), 76 in_unblock_dispatch_(0),
77 send_unblocking_only_during_unblock_dispatch_(false) { 77 send_unblocking_only_during_unblock_dispatch_(false) {
78 } 78 }
79 79
80 NPChannelBase::~NPChannelBase() { 80 NPChannelBase::~NPChannelBase() {
81 } 81 }
82 82
83 NPChannelBase* NPChannelBase::GetCurrentChannel() { 83 NPChannelBase* NPChannelBase::GetCurrentChannel() {
84 return g_lazy_channel_stack.Pointer()->top(); 84 return g_lazy_channel_stack.Pointer()->top().get();
85 } 85 }
86 86
87 void NPChannelBase::CleanupChannels() { 87 void NPChannelBase::CleanupChannels() {
88 // Make a copy of the references as we can't iterate the map since items will 88 // 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. 89 // be removed from it as we clean them up.
90 std::vector<scoped_refptr<NPChannelBase> > channels; 90 std::vector<scoped_refptr<NPChannelBase> > channels;
91 for (ChannelMap::const_iterator iter = g_channels.Get().begin(); 91 for (ChannelMap::const_iterator iter = g_channels.Get().begin();
92 iter != g_channels.Get().end(); 92 iter != g_channels.Get().end();
93 ++iter) { 93 ++iter) {
94 channels.push_back(iter->second); 94 channels.push_back(iter->second);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 base::AutoReset<bool> auto_reset_in_remove_route(&in_remove_route_, true); 230 base::AutoReset<bool> auto_reset_in_remove_route(&in_remove_route_, true);
231 for (ListenerMap::iterator npobj_iter = npobject_listeners_.begin(); 231 for (ListenerMap::iterator npobj_iter = npobject_listeners_.begin();
232 npobj_iter != npobject_listeners_.end(); ++npobj_iter) { 232 npobj_iter != npobject_listeners_.end(); ++npobj_iter) {
233 if (npobj_iter->second) { 233 if (npobj_iter->second) {
234 npobj_iter->second->GetChannelListener()->OnChannelError(); 234 npobj_iter->second->GetChannelListener()->OnChannelError();
235 } 235 }
236 } 236 }
237 237
238 for (ChannelMap::iterator iter = g_channels.Get().begin(); 238 for (ChannelMap::iterator iter = g_channels.Get().begin();
239 iter != g_channels.Get().end(); ++iter) { 239 iter != g_channels.Get().end(); ++iter) {
240 if (iter->second == this) { 240 if (iter->second.get() == this) {
241 g_channels.Get().erase(iter); 241 g_channels.Get().erase(iter);
242 return; 242 return;
243 } 243 }
244 } 244 }
245 245
246 NOTREACHED(); 246 NOTREACHED();
247 } 247 }
248 } 248 }
249 249
250 bool NPChannelBase::OnControlMessageReceived(const IPC::Message& msg) { 250 bool NPChannelBase::OnControlMessageReceived(const IPC::Message& msg) {
251 NOTREACHED() << 251 NOTREACHED() <<
252 "should override in subclass if you care about control messages"; 252 "should override in subclass if you care about control messages";
253 return false; 253 return false;
254 } 254 }
255 255
256 void NPChannelBase::OnChannelError() { 256 void NPChannelBase::OnChannelError() {
257 channel_valid_ = false; 257 channel_valid_ = false;
258 258
259 // TODO(shess): http://crbug.com/97285 259 // TODO(shess): http://crbug.com/97285
260 // Once an error is seen on a channel, remap the channel to prevent 260 // Once an error is seen on a channel, remap the channel to prevent
261 // it from being vended again. Keep the channel in the map so 261 // it from being vended again. Keep the channel in the map so
262 // RemoveRoute() can clean things up correctly. 262 // RemoveRoute() can clean things up correctly.
263 for (ChannelMap::iterator iter = g_channels.Get().begin(); 263 for (ChannelMap::iterator iter = g_channels.Get().begin();
264 iter != g_channels.Get().end(); ++iter) { 264 iter != g_channels.Get().end(); ++iter) {
265 if (iter->second == this) { 265 if (iter->second.get() == this) {
266 // Insert new element before invalidating |iter|. 266 // Insert new element before invalidating |iter|.
267 g_channels.Get()[iter->first + "-error"] = iter->second; 267 g_channels.Get()[iter->first + "-error"] = iter->second;
268 g_channels.Get().erase(iter); 268 g_channels.Get().erase(iter);
269 break; 269 break;
270 } 270 }
271 } 271 }
272 } 272 }
273 273
274 NPObject* NPChannelBase::GetExistingNPObjectProxy(int route_id) { 274 NPObject* NPChannelBase::GetExistingNPObjectProxy(int route_id) {
275 ProxyMap::iterator iter = proxy_map_.find(route_id); 275 ProxyMap::iterator iter = proxy_map_.find(route_id);
(...skipping 20 matching lines...) Expand all
296 NPObject* object) { 296 NPObject* object) {
297 DCHECK(object != NULL); 297 DCHECK(object != NULL);
298 stub_map_.erase(object); 298 stub_map_.erase(object);
299 } 299 }
300 300
301 void NPChannelBase::RemoveMappingForNPObjectProxy(int route_id) { 301 void NPChannelBase::RemoveMappingForNPObjectProxy(int route_id) {
302 proxy_map_.erase(route_id); 302 proxy_map_.erase(route_id);
303 } 303 }
304 304
305 } // namespace content 305 } // namespace content
OLDNEW
« no previous file with comments | « content/common/resource_messages.cc ('k') | content/common_child/npobject_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698