Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: ppapi/proxy/host_dispatcher.cc

Issue 8222021: Prevent reentrant destructors in the PluginModule. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/c/private/ppb_proxy_private.h ('k') | webkit/plugins/ppapi/plugin_module.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/host_dispatcher.h" 5 #include "ppapi/proxy/host_dispatcher.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 127 }
128 128
129 bool HostDispatcher::IsPlugin() const { 129 bool HostDispatcher::IsPlugin() const {
130 return false; 130 return false;
131 } 131 }
132 132
133 bool HostDispatcher::Send(IPC::Message* msg) { 133 bool HostDispatcher::Send(IPC::Message* msg) {
134 TRACE_EVENT2("ppapi proxy", "HostDispatcher::Send", 134 TRACE_EVENT2("ppapi proxy", "HostDispatcher::Send",
135 "Class", IPC_MESSAGE_ID_CLASS(msg->type()), 135 "Class", IPC_MESSAGE_ID_CLASS(msg->type()),
136 "Line", IPC_MESSAGE_ID_LINE(msg->type())); 136 "Line", IPC_MESSAGE_ID_LINE(msg->type()));
137 // Prevent the dispatcher from going away during the call. Scenarios
138 // where this could happen include a Send for a sync message which while
139 // waiting for the reply, dispatches an incoming ExecuteScript call which
140 // destroys the plugin module and in turn the dispatcher.
141 ScopedModuleReference ref(this);
142 137
143 // 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
144 // 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
145 // 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
146 // 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
147 // may still get reentrancy in the host as a result. 142 // may still get reentrancy in the host as a result.
148
149 if (!allow_plugin_reentrancy_) 143 if (!allow_plugin_reentrancy_)
150 msg->set_unblock(false); 144 msg->set_unblock(false);
151 return Dispatcher::Send(msg); 145
146 if (msg->is_sync()) {
147 // Don't allow sending sync messages during module shutdown. Seee the "else"
148 // block below for why.
149 CHECK(!PP_ToBool(ppb_proxy()->IsInModuleDestructor(pp_module())));
150
151 // Prevent the dispatcher from going away during sync calls. Scenarios
152 // where this could happen include a Send for a sync message which while
153 // waiting for the reply, dispatches an incoming ExecuteScript call which
154 // destroys the plugin module and in turn the dispatcher.
155 ScopedModuleReference scoped_ref(this);
156 return Dispatcher::Send(msg);
157 } else {
158 // We don't want to have a scoped ref for async message cases since since
159 // async messages are sent during module desruction. In this case, the
160 // module will have a 0 refcount and addrefing and releasing it will
161 // reenter the destructor and it will crash.
162 return Dispatcher::Send(msg);
163 }
152 } 164 }
153 165
154 bool HostDispatcher::OnMessageReceived(const IPC::Message& msg) { 166 bool HostDispatcher::OnMessageReceived(const IPC::Message& msg) {
155 TRACE_EVENT2("ppapi proxy", "HostDispatcher::OnMessageReceived", 167 TRACE_EVENT2("ppapi proxy", "HostDispatcher::OnMessageReceived",
156 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), 168 "Class", IPC_MESSAGE_ID_CLASS(msg.type()),
157 "Line", IPC_MESSAGE_ID_LINE(msg.type())); 169 "Line", IPC_MESSAGE_ID_LINE(msg.type()));
158 // We only want to allow reentrancy when the most recent message from the 170 // We only want to allow reentrancy when the most recent message from the
159 // plugin was a scripting message. We save the old state of the flag on the 171 // plugin was a scripting message. We save the old state of the flag on the
160 // stack in case we're (we are the host) being reentered ourselves. The flag 172 // stack in case we're (we are the host) being reentered ourselves. The flag
161 // is set to false here for all messages, and then the scripting API will 173 // is set to false here for all messages, and then the scripting API will
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 dispatcher_ = static_cast<HostDispatcher*>(dispatcher); 224 dispatcher_ = static_cast<HostDispatcher*>(dispatcher);
213 dispatcher_->ppb_proxy()->AddRefModule(dispatcher_->pp_module()); 225 dispatcher_->ppb_proxy()->AddRefModule(dispatcher_->pp_module());
214 } 226 }
215 227
216 ScopedModuleReference::~ScopedModuleReference() { 228 ScopedModuleReference::~ScopedModuleReference() {
217 dispatcher_->ppb_proxy()->ReleaseModule(dispatcher_->pp_module()); 229 dispatcher_->ppb_proxy()->ReleaseModule(dispatcher_->pp_module());
218 } 230 }
219 231
220 } // namespace proxy 232 } // namespace proxy
221 } // namespace ppapi 233 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/c/private/ppb_proxy_private.h ('k') | webkit/plugins/ppapi/plugin_module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698