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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 PluginChannelMap; | 21 PluginChannelMap; |
22 | 22 |
23 static PluginChannelMap g_plugin_channels_; | 23 static PluginChannelMap g_plugin_channels_; |
24 | 24 |
25 static base::LazyInstance<std::stack<scoped_refptr<PluginChannelBase> > > | 25 static base::LazyInstance<std::stack<scoped_refptr<PluginChannelBase> > > |
26 lazy_plugin_channel_stack_(base::LINKER_INITIALIZED); | 26 lazy_plugin_channel_stack_(base::LINKER_INITIALIZED); |
27 | 27 |
28 static int next_pipe_id = 0; | 28 static int next_pipe_id = 0; |
29 | 29 |
30 PluginChannelBase* PluginChannelBase::GetChannel( | 30 PluginChannelBase* PluginChannelBase::GetChannel( |
31 const std::string& channel_key, IPC::Channel::Mode mode, | 31 const IPC::ChannelHandle& channel_handle, IPC::Channel::Mode mode, |
32 PluginChannelFactory factory, MessageLoop* ipc_message_loop, | 32 PluginChannelFactory factory, MessageLoop* ipc_message_loop, |
33 bool create_pipe_now) { | 33 bool create_pipe_now) { |
34 scoped_refptr<PluginChannelBase> channel; | 34 scoped_refptr<PluginChannelBase> channel; |
35 | 35 std::string channel_key = channel_handle.name; |
36 PluginChannelMap::const_iterator iter = g_plugin_channels_.find(channel_key); | 36 PluginChannelMap::const_iterator iter = g_plugin_channels_.find(channel_key); |
37 if (iter == g_plugin_channels_.end()) { | 37 if (iter == g_plugin_channels_.end()) { |
38 channel = factory(); | 38 channel = factory(); |
39 } else { | 39 } else { |
40 channel = iter->second; | 40 channel = iter->second; |
41 } | 41 } |
42 | 42 |
43 DCHECK(channel != NULL); | 43 DCHECK(channel != NULL); |
44 | 44 |
45 if (!channel->channel_valid()) { | 45 if (!channel->channel_valid()) { |
46 channel->channel_name_ = channel_key; | 46 channel->channel_handle_ = channel_handle; |
47 if (mode == IPC::Channel::MODE_SERVER) { | 47 if (mode == IPC::Channel::MODE_SERVER) { |
48 channel->channel_name_.append("."); | 48 channel->channel_handle_.name.append("."); |
49 channel->channel_name_.append(base::IntToString(next_pipe_id++)); | 49 channel->channel_handle_.name.append(base::IntToString(next_pipe_id++)); |
50 } | 50 } |
51 channel->mode_ = mode; | 51 channel->mode_ = mode; |
52 if (channel->Init(ipc_message_loop, create_pipe_now)) { | 52 if (channel->Init(ipc_message_loop, create_pipe_now)) { |
53 g_plugin_channels_[channel_key] = channel; | 53 g_plugin_channels_[channel_key] = channel; |
54 } else { | 54 } else { |
55 channel = NULL; | 55 channel = NULL; |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 return channel; | 59 return channel; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 if (iter == npobject_listeners_.end()) { | 108 if (iter == npobject_listeners_.end()) { |
109 DLOG(WARNING) << "Invalid route id passed in:" << route_id; | 109 DLOG(WARNING) << "Invalid route id passed in:" << route_id; |
110 return NULL; | 110 return NULL; |
111 } | 111 } |
112 return iter->second; | 112 return iter->second; |
113 } | 113 } |
114 | 114 |
115 bool PluginChannelBase::Init(MessageLoop* ipc_message_loop, | 115 bool PluginChannelBase::Init(MessageLoop* ipc_message_loop, |
116 bool create_pipe_now) { | 116 bool create_pipe_now) { |
117 channel_.reset(new IPC::SyncChannel( | 117 channel_.reset(new IPC::SyncChannel( |
118 channel_name_, mode_, this, ipc_message_loop, create_pipe_now, | 118 channel_handle_, mode_, this, ipc_message_loop, create_pipe_now, |
119 ChildProcess::current()->GetShutDownEvent())); | 119 ChildProcess::current()->GetShutDownEvent())); |
120 channel_valid_ = true; | 120 channel_valid_ = true; |
121 return true; | 121 return true; |
122 } | 122 } |
123 | 123 |
124 bool PluginChannelBase::Send(IPC::Message* message) { | 124 bool PluginChannelBase::Send(IPC::Message* message) { |
125 if (!channel_.get()) { | 125 if (!channel_.get()) { |
126 delete message; | 126 delete message; |
127 return false; | 127 return false; |
128 } | 128 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 IPC::Channel::Listener* channel_listener = | 212 IPC::Channel::Listener* channel_listener = |
213 npobj_iter->second->GetChannelListener(); | 213 npobj_iter->second->GetChannelListener(); |
214 DCHECK(channel_listener != NULL); | 214 DCHECK(channel_listener != NULL); |
215 channel_listener->OnChannelError(); | 215 channel_listener->OnChannelError(); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 for (PluginChannelMap::iterator iter = g_plugin_channels_.begin(); | 219 for (PluginChannelMap::iterator iter = g_plugin_channels_.begin(); |
220 iter != g_plugin_channels_.end(); ++iter) { | 220 iter != g_plugin_channels_.end(); ++iter) { |
221 if (iter->second == this) { | 221 if (iter->second == this) { |
222 #if defined(OS_POSIX) | |
223 if (channel_valid()) { | |
224 IPC::RemoveAndCloseChannelSocket(channel_name()); | |
225 } | |
226 #endif | |
227 g_plugin_channels_.erase(iter); | 222 g_plugin_channels_.erase(iter); |
228 return; | 223 return; |
229 } | 224 } |
230 } | 225 } |
231 | 226 |
232 NOTREACHED(); | 227 NOTREACHED(); |
233 } | 228 } |
234 } | 229 } |
235 | 230 |
236 void PluginChannelBase::OnControlMessageReceived(const IPC::Message& msg) { | 231 void PluginChannelBase::OnControlMessageReceived(const IPC::Message& msg) { |
237 NOTREACHED() << | 232 NOTREACHED() << |
238 "should override in subclass if you care about control messages"; | 233 "should override in subclass if you care about control messages"; |
239 } | 234 } |
240 | 235 |
241 void PluginChannelBase::OnChannelError() { | 236 void PluginChannelBase::OnChannelError() { |
242 #if defined(OS_POSIX) | |
243 if (channel_valid()) { | |
244 IPC::RemoveAndCloseChannelSocket(channel_name()); | |
245 } | |
246 #endif | |
247 channel_valid_ = false; | 237 channel_valid_ = false; |
248 } | 238 } |
OLD | NEW |