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

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

Issue 9361065: reland 121901, PPAPI: Add unlocking for PPP calls and callbacks... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 | « no previous file | ppapi/proxy/ppb_core_proxy.cc » ('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/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"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "ipc/ipc_message.h" 12 #include "ipc/ipc_message.h"
13 #include "ipc/ipc_sync_channel.h" 13 #include "ipc/ipc_sync_channel.h"
14 #include "base/debug/trace_event.h" 14 #include "base/debug/trace_event.h"
15 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
16 #include "ppapi/c/ppp_instance.h" 16 #include "ppapi/c/ppp_instance.h"
17 #include "ppapi/proxy/interface_list.h" 17 #include "ppapi/proxy/interface_list.h"
18 #include "ppapi/proxy/interface_proxy.h" 18 #include "ppapi/proxy/interface_proxy.h"
19 #include "ppapi/proxy/plugin_message_filter.h" 19 #include "ppapi/proxy/plugin_message_filter.h"
20 #include "ppapi/proxy/plugin_resource_tracker.h" 20 #include "ppapi/proxy/plugin_resource_tracker.h"
21 #include "ppapi/proxy/plugin_var_serialization_rules.h" 21 #include "ppapi/proxy/plugin_var_serialization_rules.h"
22 #include "ppapi/proxy/ppapi_messages.h" 22 #include "ppapi/proxy/ppapi_messages.h"
23 #include "ppapi/proxy/ppb_cursor_control_proxy.h" 23 #include "ppapi/proxy/ppb_cursor_control_proxy.h"
24 #include "ppapi/proxy/ppb_font_proxy.h" 24 #include "ppapi/proxy/ppb_font_proxy.h"
25 #include "ppapi/proxy/ppb_instance_proxy.h" 25 #include "ppapi/proxy/ppb_instance_proxy.h"
26 #include "ppapi/proxy/ppp_class_proxy.h" 26 #include "ppapi/proxy/ppp_class_proxy.h"
27 #include "ppapi/proxy/resource_creation_proxy.h" 27 #include "ppapi/proxy/resource_creation_proxy.h"
28 #include "ppapi/shared_impl/proxy_lock.h"
28 #include "ppapi/shared_impl/resource.h" 29 #include "ppapi/shared_impl/resource.h"
29 30
30 #if defined(OS_POSIX) 31 #if defined(OS_POSIX)
31 #include "base/eintr_wrapper.h" 32 #include "base/eintr_wrapper.h"
32 #include "ipc/ipc_channel_posix.h" 33 #include "ipc/ipc_channel_posix.h"
33 #endif 34 #endif
34 35
35 namespace ppapi { 36 namespace ppapi {
36 namespace proxy { 37 namespace proxy {
37 38
38 namespace { 39 namespace {
39 40
40 typedef std::map<PP_Instance, PluginDispatcher*> InstanceToDispatcherMap; 41 typedef std::map<PP_Instance, PluginDispatcher*> InstanceToDispatcherMap;
41 InstanceToDispatcherMap* g_instance_to_dispatcher = NULL; 42 InstanceToDispatcherMap* g_instance_to_dispatcher = NULL;
42 43
43 typedef std::set<PluginDispatcher*> DispatcherSet; 44 typedef std::set<PluginDispatcher*> DispatcherSet;
44 DispatcherSet* g_live_dispatchers = NULL; 45 DispatcherSet* g_live_dispatchers = NULL;
45 46
46 } // namespace 47 } // namespace
47 48
48 InstanceData::InstanceData() 49 InstanceData::InstanceData()
49 : flash_fullscreen(PP_FALSE), 50 : flash_fullscreen(PP_FALSE),
50 mouse_lock_callback(PP_BlockUntilComplete()) { 51 mouse_lock_callback(PP_BlockUntilComplete()) {
51 } 52 }
52 53
53 InstanceData::~InstanceData() { 54 InstanceData::~InstanceData() {
54 // Run any pending mouse lock callback to prevent leaks. 55 // Run any pending mouse lock callback to prevent leaks.
55 if (mouse_lock_callback.func) 56 if (mouse_lock_callback.func) {
56 PP_RunAndClearCompletionCallback(&mouse_lock_callback, PP_ERROR_ABORTED); 57 CallWhileUnlocked(PP_RunAndClearCompletionCallback,
58 &mouse_lock_callback,
59 static_cast<int32_t>(PP_ERROR_ABORTED));
60 }
57 } 61 }
58 62
59 PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle, 63 PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle,
60 GetInterfaceFunc get_interface) 64 GetInterfaceFunc get_interface)
61 : Dispatcher(remote_process_handle, get_interface), 65 : Dispatcher(remote_process_handle, get_interface),
62 plugin_delegate_(NULL), 66 plugin_delegate_(NULL),
63 received_preferences_(false), 67 received_preferences_(false),
64 plugin_dispatcher_id_(0) { 68 plugin_dispatcher_id_(0) {
65 SetSerializationRules(new PluginVarSerializationRules); 69 SetSerializationRules(new PluginVarSerializationRules);
66 70
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 161
158 bool PluginDispatcher::IsPlugin() const { 162 bool PluginDispatcher::IsPlugin() const {
159 return true; 163 return true;
160 } 164 }
161 165
162 bool PluginDispatcher::Send(IPC::Message* msg) { 166 bool PluginDispatcher::Send(IPC::Message* msg) {
163 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::Send", 167 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::Send",
164 "Class", IPC_MESSAGE_ID_CLASS(msg->type()), 168 "Class", IPC_MESSAGE_ID_CLASS(msg->type()),
165 "Line", IPC_MESSAGE_ID_LINE(msg->type())); 169 "Line", IPC_MESSAGE_ID_LINE(msg->type()));
166 // We always want plugin->renderer messages to arrive in-order. If some sync 170 // We always want plugin->renderer messages to arrive in-order. If some sync
167 // and some async messages are send in response to a synchronous 171 // and some async messages are sent in response to a synchronous
168 // renderer->plugin call, the sync reply will be processed before the async 172 // renderer->plugin call, the sync reply will be processed before the async
169 // reply, and everything will be confused. 173 // reply, and everything will be confused.
170 // 174 //
171 // Allowing all async messages to unblock the renderer means more reentrancy 175 // Allowing all async messages to unblock the renderer means more reentrancy
172 // there but gives correct ordering. 176 // there but gives correct ordering.
173 msg->set_unblock(true); 177 msg->set_unblock(true);
178 if (msg->is_sync()) {
179 // Synchronous messages might be re-entrant, so we need to drop the lock.
180 ProxyAutoUnlock unlock;
181 return Dispatcher::Send(msg);
182 }
174 return Dispatcher::Send(msg); 183 return Dispatcher::Send(msg);
175 } 184 }
176 185
177 bool PluginDispatcher::OnMessageReceived(const IPC::Message& msg) { 186 bool PluginDispatcher::OnMessageReceived(const IPC::Message& msg) {
187 // We need to grab the proxy lock to ensure that we don't collide with the
188 // plugin making pepper calls on a different thread.
189 ProxyAutoLock lock;
178 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::OnMessageReceived", 190 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::OnMessageReceived",
179 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), 191 "Class", IPC_MESSAGE_ID_CLASS(msg.type()),
180 "Line", IPC_MESSAGE_ID_LINE(msg.type())); 192 "Line", IPC_MESSAGE_ID_LINE(msg.type()));
181 if (msg.routing_id() == MSG_ROUTING_CONTROL) { 193 if (msg.routing_id() == MSG_ROUTING_CONTROL) {
182 // Handle some plugin-specific control messages. 194 // Handle some plugin-specific control messages.
183 bool handled = true; 195 bool handled = true;
184 IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg) 196 IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg)
185 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) 197 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface)
186 IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnMsgSetPreferences) 198 IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnMsgSetPreferences)
187 IPC_MESSAGE_UNHANDLED(handled = false); 199 IPC_MESSAGE_UNHANDLED(handled = false);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // once they're set. The user will have to restart to get new font prefs 289 // once they're set. The user will have to restart to get new font prefs
278 // propogated to plugins. 290 // propogated to plugins.
279 if (!received_preferences_) { 291 if (!received_preferences_) {
280 received_preferences_ = true; 292 received_preferences_ = true;
281 preferences_ = prefs; 293 preferences_ = prefs;
282 } 294 }
283 } 295 }
284 296
285 } // namespace proxy 297 } // namespace proxy
286 } // namespace ppapi 298 } // namespace ppapi
OLDNEW
« no previous file with comments | « no previous file | ppapi/proxy/ppb_core_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698