OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/proxy/plugin_dispatcher.h" | 5 #include "ppapi/proxy/plugin_dispatcher.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 return true; | 122 return true; |
123 } | 123 } |
124 proxy = info->create_proxy(this, NULL); | 124 proxy = info->create_proxy(this, NULL); |
125 target_proxies_[info->id].reset(proxy); | 125 target_proxies_[info->id].reset(proxy); |
126 } | 126 } |
127 | 127 |
128 return proxy->OnMessageReceived(msg); | 128 return proxy->OnMessageReceived(msg); |
129 } | 129 } |
130 | 130 |
131 void PluginDispatcher::OnChannelError() { | 131 void PluginDispatcher::OnChannelError() { |
| 132 Dispatcher::OnChannelError(); |
| 133 |
132 // The renderer has crashed. This channel and all instances associated with | 134 // The renderer has crashed. This channel and all instances associated with |
133 // it are no longer valid. | 135 // it are no longer valid. |
134 ForceFreeAllInstances(); | 136 ForceFreeAllInstances(); |
135 // TODO(brettw) free resources too! | 137 // TODO(brettw) free resources too! |
136 delete this; | 138 delete this; |
137 } | 139 } |
138 | 140 |
139 void PluginDispatcher::DidCreateInstance(PP_Instance instance) { | 141 void PluginDispatcher::DidCreateInstance(PP_Instance instance) { |
140 if (!g_instance_to_dispatcher) | 142 if (!g_instance_to_dispatcher) |
141 g_instance_to_dispatcher = new InstanceToDispatcherMap; | 143 g_instance_to_dispatcher = new InstanceToDispatcherMap; |
(...skipping 19 matching lines...) Expand all Loading... |
161 } | 163 } |
162 } | 164 } |
163 | 165 |
164 InstanceData* PluginDispatcher::GetInstanceData(PP_Instance instance) { | 166 InstanceData* PluginDispatcher::GetInstanceData(PP_Instance instance) { |
165 InstanceDataMap::iterator it = instance_map_.find(instance); | 167 InstanceDataMap::iterator it = instance_map_.find(instance); |
166 return (it == instance_map_.end()) ? NULL : &it->second; | 168 return (it == instance_map_.end()) ? NULL : &it->second; |
167 } | 169 } |
168 | 170 |
169 #if defined(OS_POSIX) | 171 #if defined(OS_POSIX) |
170 int PluginDispatcher::GetRendererFD() { | 172 int PluginDispatcher::GetRendererFD() { |
171 if (renderer_fd_ == -1) | 173 if (renderer_fd_ == -1 && channel()) |
172 renderer_fd_ = channel()->GetClientFileDescriptor(); | 174 renderer_fd_ = channel()->GetClientFileDescriptor(); |
173 return renderer_fd_; | 175 return renderer_fd_; |
174 } | 176 } |
175 | 177 |
176 void PluginDispatcher::CloseRendererFD() { | 178 void PluginDispatcher::CloseRendererFD() { |
177 if (renderer_fd_ != -1) { | 179 if (renderer_fd_ != -1) { |
178 if (HANDLE_EINTR(close(renderer_fd_)) < 0) | 180 if (HANDLE_EINTR(close(renderer_fd_)) < 0) |
179 PLOG(ERROR) << "close"; | 181 PLOG(ERROR) << "close"; |
180 renderer_fd_ = -1; | 182 renderer_fd_ = -1; |
181 } | 183 } |
182 } | 184 } |
183 #endif | 185 #endif |
184 | 186 |
185 void PluginDispatcher::ForceFreeAllInstances() { | 187 void PluginDispatcher::ForceFreeAllInstances() { |
186 // TODO(brettw) implement freeing instances on crash. | 188 if (!g_instance_to_dispatcher) |
| 189 return; |
| 190 |
| 191 // Iterating will remove each item from the map, so we need to make a copy |
| 192 // to avoid things changing out from under is. |
| 193 InstanceToDispatcherMap temp_map = *g_instance_to_dispatcher; |
| 194 for (InstanceToDispatcherMap::iterator i = temp_map.begin(); |
| 195 i != temp_map.end(); ++i) { |
| 196 if (i->second == this) { |
| 197 // Synthesize an "instance destroyed" message, this will notify the |
| 198 // plugin and also remove it from our list of tracked plugins. |
| 199 OnMessageReceived( |
| 200 PpapiMsg_PPPInstance_DidDestroy(INTERFACE_ID_PPP_INSTANCE, i->first)); |
| 201 } |
| 202 } |
187 } | 203 } |
188 | 204 |
189 void PluginDispatcher::OnMsgSupportsInterface( | 205 void PluginDispatcher::OnMsgSupportsInterface( |
190 const std::string& interface_name, | 206 const std::string& interface_name, |
191 bool* result) { | 207 bool* result) { |
192 *result = false; | 208 *result = false; |
193 | 209 |
194 // Setup a proxy for receiving the messages from this interface. | 210 // Setup a proxy for receiving the messages from this interface. |
195 const InterfaceProxy::Info* info = GetPPPInterfaceInfo(interface_name); | 211 const InterfaceProxy::Info* info = GetPPPInterfaceInfo(interface_name); |
196 if (!info) | 212 if (!info) |
(...skipping 10 matching lines...) Expand all Loading... |
207 if (!interface_functions) | 223 if (!interface_functions) |
208 return; | 224 return; |
209 target_proxies_[info->id].reset( | 225 target_proxies_[info->id].reset( |
210 info->create_proxy(this, interface_functions)); | 226 info->create_proxy(this, interface_functions)); |
211 *result = true; | 227 *result = true; |
212 } | 228 } |
213 | 229 |
214 } // namespace proxy | 230 } // namespace proxy |
215 } // namespace pp | 231 } // namespace pp |
216 | 232 |
OLD | NEW |