| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/plugin/plugin_channel_base.h" | 5 #include "chrome/plugin/plugin_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" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "chrome/common/child_process.h" | 12 #include "chrome/common/child_process.h" |
| 13 #include "ipc/ipc_sync_message.h" | 13 #include "ipc/ipc_sync_message.h" |
| 14 | 14 |
| 15 #if defined(OS_POSIX) | 15 #if defined(OS_POSIX) |
| 16 #include "ipc/ipc_channel_posix.h" | 16 #include "ipc/ipc_channel_posix.h" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 typedef base::hash_map<std::string, scoped_refptr<PluginChannelBase> > | 19 typedef base::hash_map<std::string, scoped_refptr<PluginChannelBase> > |
| 20 PluginChannelMap; | 20 PluginChannelMap; |
| 21 | 21 |
| 22 static PluginChannelMap g_plugin_channels_; | 22 static PluginChannelMap g_plugin_channels_; |
| 23 | 23 |
| 24 static base::LazyInstance<std::stack<scoped_refptr<PluginChannelBase> > > | 24 static base::LazyInstance<std::stack<PluginChannelBase*> > |
| 25 lazy_plugin_channel_stack_(base::LINKER_INITIALIZED); | 25 lazy_plugin_channel_stack_(base::LINKER_INITIALIZED); |
| 26 | 26 |
| 27 PluginChannelBase* PluginChannelBase::GetChannel( | 27 PluginChannelBase* PluginChannelBase::GetChannel( |
| 28 const std::string& channel_name, IPC::Channel::Mode mode, | 28 const std::string& channel_name, IPC::Channel::Mode mode, |
| 29 PluginChannelFactory factory, MessageLoop* ipc_message_loop, | 29 PluginChannelFactory factory, MessageLoop* ipc_message_loop, |
| 30 bool create_pipe_now) { | 30 bool create_pipe_now) { |
| 31 scoped_refptr<PluginChannelBase> channel; | 31 scoped_refptr<PluginChannelBase> channel; |
| 32 | 32 |
| 33 PluginChannelMap::const_iterator iter = g_plugin_channels_.find(channel_name); | 33 PluginChannelMap::const_iterator iter = g_plugin_channels_.find(channel_name); |
| 34 if (iter == g_plugin_channels_.end()) { | 34 if (iter == g_plugin_channels_.end()) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 return channel_->Send(message); | 118 return channel_->Send(message); |
| 119 } | 119 } |
| 120 | 120 |
| 121 int PluginChannelBase::Count() { | 121 int PluginChannelBase::Count() { |
| 122 return static_cast<int>(g_plugin_channels_.size()); | 122 return static_cast<int>(g_plugin_channels_.size()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void PluginChannelBase::OnMessageReceived(const IPC::Message& message) { | 125 void PluginChannelBase::OnMessageReceived(const IPC::Message& message) { |
| 126 // This call might cause us to be deleted, so keep an extra reference to | 126 // This call might cause us to be deleted, so keep an extra reference to |
| 127 // ourself so that we can send the reply and decrement back in_dispatch_. | 127 // ourself so that we can send the reply and decrement back in_dispatch_. |
| 128 lazy_plugin_channel_stack_.Pointer()->push( | 128 scoped_refptr<PluginChannelBase> me(this); |
| 129 scoped_refptr<PluginChannelBase>(this)); | 129 lazy_plugin_channel_stack_.Pointer()->push(this); |
| 130 | 130 |
| 131 if (message.is_sync()) | 131 if (message.is_sync()) |
| 132 in_sync_dispatch_++; | 132 in_sync_dispatch_++; |
| 133 if (message.routing_id() == MSG_ROUTING_CONTROL) { | 133 if (message.routing_id() == MSG_ROUTING_CONTROL) { |
| 134 OnControlMessageReceived(message); | 134 OnControlMessageReceived(message); |
| 135 } else { | 135 } else { |
| 136 bool routed = router_.RouteMessage(message); | 136 bool routed = router_.RouteMessage(message); |
| 137 if (!routed && message.is_sync()) { | 137 if (!routed && message.is_sync()) { |
| 138 // The listener has gone away, so we must respond or else the caller will | 138 // The listener has gone away, so we must respond or else the caller will |
| 139 // hang waiting for a reply. | 139 // hang waiting for a reply. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 if (channel_valid()) { | 221 if (channel_valid()) { |
| 222 IPC::RemoveAndCloseChannelSocket(channel_name()); | 222 IPC::RemoveAndCloseChannelSocket(channel_name()); |
| 223 } | 223 } |
| 224 #endif | 224 #endif |
| 225 channel_valid_ = false; | 225 channel_valid_ = false; |
| 226 } | 226 } |
| 227 | 227 |
| 228 void PluginChannelBase::SendUnblockingOnlyDuringSyncDispatch() { | 228 void PluginChannelBase::SendUnblockingOnlyDuringSyncDispatch() { |
| 229 send_unblocking_only_during_sync_dispatch_ = true; | 229 send_unblocking_only_during_sync_dispatch_ = true; |
| 230 } | 230 } |
| OLD | NEW |