| OLD | NEW |
| 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 "ppapi/proxy/host_dispatcher.h" | 5 #include "ppapi/proxy/host_dispatcher.h" |
| 6 | 6 |
| 7 #include <map> | |
| 8 | |
| 9 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 8 #include "base/logging.h" |
| 11 #include "ppapi/c/private/ppb_proxy_private.h" | 9 #include "ppapi/c/private/ppb_proxy_private.h" |
| 12 #include "ppapi/c/ppb_var.h" | 10 #include "ppapi/c/ppb_var.h" |
| 13 #include "ppapi/proxy/host_var_serialization_rules.h" | 11 #include "ppapi/proxy/host_var_serialization_rules.h" |
| 14 #include "ppapi/proxy/interface_list.h" | 12 #include "ppapi/proxy/interface_list.h" |
| 15 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
| 16 #include "ppapi/proxy/resource_creation_proxy.h" | 14 #include "ppapi/proxy/resource_creation_proxy.h" |
| 17 #include "ppapi/shared_impl/ppapi_globals.h" | 15 #include "ppapi/shared_impl/ppapi_globals.h" |
| 16 #include "ppapi/shared_impl/ppapi_message_tracker.h" |
| 18 | 17 |
| 19 namespace ppapi { | 18 namespace ppapi { |
| 20 namespace proxy { | 19 namespace proxy { |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 typedef std::map<PP_Instance, HostDispatcher*> InstanceToDispatcherMap; | 23 typedef std::map<PP_Instance, HostDispatcher*> InstanceToDispatcherMap; |
| 25 InstanceToDispatcherMap* g_instance_to_dispatcher = NULL; | 24 InstanceToDispatcherMap* g_instance_to_dispatcher = NULL; |
| 26 | 25 |
| 27 typedef std::map<PP_Module, HostDispatcher*> ModuleToDispatcherMap; | 26 typedef std::map<PP_Module, HostDispatcher*> ModuleToDispatcherMap; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 instance); | 125 instance); |
| 127 if (found != g_instance_to_dispatcher->end()) | 126 if (found != g_instance_to_dispatcher->end()) |
| 128 g_instance_to_dispatcher->erase(found); | 127 g_instance_to_dispatcher->erase(found); |
| 129 } | 128 } |
| 130 | 129 |
| 131 bool HostDispatcher::IsPlugin() const { | 130 bool HostDispatcher::IsPlugin() const { |
| 132 return false; | 131 return false; |
| 133 } | 132 } |
| 134 | 133 |
| 135 bool HostDispatcher::Send(IPC::Message* msg) { | 134 bool HostDispatcher::Send(IPC::Message* msg) { |
| 135 ScopedTrackPpapiMessage track_ppapi_message; |
| 136 |
| 136 TRACE_EVENT2("ppapi proxy", "HostDispatcher::Send", | 137 TRACE_EVENT2("ppapi proxy", "HostDispatcher::Send", |
| 137 "Class", IPC_MESSAGE_ID_CLASS(msg->type()), | 138 "Class", IPC_MESSAGE_ID_CLASS(msg->type()), |
| 138 "Line", IPC_MESSAGE_ID_LINE(msg->type())); | 139 "Line", IPC_MESSAGE_ID_LINE(msg->type())); |
| 139 | 140 |
| 140 // Normal sync messages are set to unblock, which would normally cause the | 141 // Normal sync messages are set to unblock, which would normally cause the |
| 141 // plugin to be reentered to process them. We only want to do this when we | 142 // plugin to be reentered to process them. We only want to do this when we |
| 142 // know the plugin is in a state to accept reentrancy. Since the plugin side | 143 // know the plugin is in a state to accept reentrancy. Since the plugin side |
| 143 // never clears this flag on messages it sends, we can't get deadlock, but we | 144 // never clears this flag on messages it sends, we can't get deadlock, but we |
| 144 // may still get reentrancy in the host as a result. | 145 // may still get reentrancy in the host as a result. |
| 145 if (!allow_plugin_reentrancy_) | 146 if (!allow_plugin_reentrancy_) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 164 } else { | 165 } else { |
| 165 // We don't want to have a scoped ref for async message cases since since | 166 // We don't want to have a scoped ref for async message cases since since |
| 166 // async messages are sent during module desruction. In this case, the | 167 // async messages are sent during module desruction. In this case, the |
| 167 // module will have a 0 refcount and addrefing and releasing it will | 168 // module will have a 0 refcount and addrefing and releasing it will |
| 168 // reenter the destructor and it will crash. | 169 // reenter the destructor and it will crash. |
| 169 return Dispatcher::Send(msg); | 170 return Dispatcher::Send(msg); |
| 170 } | 171 } |
| 171 } | 172 } |
| 172 | 173 |
| 173 bool HostDispatcher::OnMessageReceived(const IPC::Message& msg) { | 174 bool HostDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 175 ScopedTrackPpapiMessage track_ppapi_message; |
| 176 |
| 174 TRACE_EVENT2("ppapi proxy", "HostDispatcher::OnMessageReceived", | 177 TRACE_EVENT2("ppapi proxy", "HostDispatcher::OnMessageReceived", |
| 175 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), | 178 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), |
| 176 "Line", IPC_MESSAGE_ID_LINE(msg.type())); | 179 "Line", IPC_MESSAGE_ID_LINE(msg.type())); |
| 177 // We only want to allow reentrancy when the most recent message from the | 180 // We only want to allow reentrancy when the most recent message from the |
| 178 // plugin was a scripting message. We save the old state of the flag on the | 181 // plugin was a scripting message. We save the old state of the flag on the |
| 179 // stack in case we're (we are the host) being reentered ourselves. The flag | 182 // stack in case we're (we are the host) being reentered ourselves. The flag |
| 180 // is set to false here for all messages, and then the scripting API will | 183 // is set to false here for all messages, and then the scripting API will |
| 181 // explicitly set it to true during processing of those messages that can be | 184 // explicitly set it to true during processing of those messages that can be |
| 182 // reentered. | 185 // reentered. |
| 183 BoolRestorer restorer(&allow_plugin_reentrancy_); | 186 BoolRestorer restorer(&allow_plugin_reentrancy_); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 263 } |
| 261 } | 264 } |
| 262 | 265 |
| 263 ScopedModuleReference::~ScopedModuleReference() { | 266 ScopedModuleReference::~ScopedModuleReference() { |
| 264 if (dispatcher_) | 267 if (dispatcher_) |
| 265 dispatcher_->ppb_proxy()->ReleaseModule(dispatcher_->pp_module()); | 268 dispatcher_->ppb_proxy()->ReleaseModule(dispatcher_->pp_module()); |
| 266 } | 269 } |
| 267 | 270 |
| 268 } // namespace proxy | 271 } // namespace proxy |
| 269 } // namespace ppapi | 272 } // namespace ppapi |
| OLD | NEW |