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