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

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

Issue 9391006: PPAPI: Add unlocking for PPP calls and callbacks. Add more locking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge 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 | « ppapi/proxy/ppb_testing_proxy.cc ('k') | ppapi/proxy/ppp_class_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/ppb_var_deprecated_proxy.h" 5 #include "ppapi/proxy/ppb_var_deprecated_proxy.h"
6 6
7 #include <stdlib.h> // For malloc 7 #include <stdlib.h> // For malloc
8 8
9 #include "base/bind.h" 9 #include "base/bind.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 "ppapi/c/dev/ppb_var_deprecated.h" 12 #include "ppapi/c/dev/ppb_var_deprecated.h"
13 #include "ppapi/c/pp_var.h" 13 #include "ppapi/c/pp_var.h"
14 #include "ppapi/c/ppb_var.h" 14 #include "ppapi/c/ppb_var.h"
15 #include "ppapi/c/ppb_core.h" 15 #include "ppapi/c/ppb_core.h"
16 #include "ppapi/proxy/host_dispatcher.h" 16 #include "ppapi/proxy/host_dispatcher.h"
17 #include "ppapi/proxy/plugin_dispatcher.h" 17 #include "ppapi/proxy/plugin_dispatcher.h"
18 #include "ppapi/proxy/plugin_globals.h" 18 #include "ppapi/proxy/plugin_globals.h"
19 #include "ppapi/proxy/plugin_resource_tracker.h" 19 #include "ppapi/proxy/plugin_resource_tracker.h"
20 #include "ppapi/proxy/plugin_var_tracker.h" 20 #include "ppapi/proxy/plugin_var_tracker.h"
21 #include "ppapi/proxy/ppapi_messages.h" 21 #include "ppapi/proxy/ppapi_messages.h"
22 #include "ppapi/proxy/ppp_class_proxy.h" 22 #include "ppapi/proxy/ppp_class_proxy.h"
23 #include "ppapi/proxy/serialized_var.h" 23 #include "ppapi/proxy/serialized_var.h"
24 #include "ppapi/shared_impl/ppb_var_shared.h" 24 #include "ppapi/shared_impl/ppb_var_shared.h"
25 #include "ppapi/shared_impl/proxy_lock.h"
25 #include "ppapi/shared_impl/var.h" 26 #include "ppapi/shared_impl/var.h"
26 27
27 namespace ppapi { 28 namespace ppapi {
28 namespace proxy { 29 namespace proxy {
29 30
30 namespace { 31 namespace {
31 32
32 // Used to do get the set-up information for calling a var object. If the 33 // Used to do get the set-up information for calling a var object. If the
33 // exception is set, returns NULL. Otherwise, computes the dispatcher for the 34 // exception is set, returns NULL. Otherwise, computes the dispatcher for the
34 // given var object. If the var is not a valid object, returns NULL and sets 35 // given var object. If the var is not a valid object, returns NULL and sets
(...skipping 22 matching lines...) Expand all
57 std::string("Attempting to use an invalid object")); 58 std::string("Attempting to use an invalid object"));
58 } 59 }
59 return NULL; 60 return NULL;
60 } 61 }
61 62
62 // PPB_Var_Deprecated plugin --------------------------------------------------- 63 // PPB_Var_Deprecated plugin ---------------------------------------------------
63 64
64 bool HasProperty(PP_Var var, 65 bool HasProperty(PP_Var var,
65 PP_Var name, 66 PP_Var name,
66 PP_Var* exception) { 67 PP_Var* exception) {
68 ProxyAutoLock lock;
67 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); 69 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception);
68 if (!dispatcher) 70 if (!dispatcher)
69 return false; 71 return false;
70 72
71 ReceiveSerializedException se(dispatcher, exception); 73 ReceiveSerializedException se(dispatcher, exception);
72 PP_Bool result = PP_FALSE; 74 PP_Bool result = PP_FALSE;
73 if (!se.IsThrown()) { 75 if (!se.IsThrown()) {
74 dispatcher->Send(new PpapiHostMsg_PPBVar_HasProperty( 76 dispatcher->Send(new PpapiHostMsg_PPBVar_HasProperty(
75 API_ID_PPB_VAR_DEPRECATED, 77 API_ID_PPB_VAR_DEPRECATED,
76 SerializedVarSendInput(dispatcher, var), 78 SerializedVarSendInput(dispatcher, var),
77 SerializedVarSendInput(dispatcher, name), &se, &result)); 79 SerializedVarSendInput(dispatcher, name), &se, &result));
78 } 80 }
79 return PP_ToBool(result); 81 return PP_ToBool(result);
80 } 82 }
81 83
82 bool HasMethod(PP_Var var, 84 bool HasMethod(PP_Var var,
83 PP_Var name, 85 PP_Var name,
84 PP_Var* exception) { 86 PP_Var* exception) {
87 ProxyAutoLock lock;
85 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); 88 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception);
86 if (!dispatcher) 89 if (!dispatcher)
87 return false; 90 return false;
88 91
89 ReceiveSerializedException se(dispatcher, exception); 92 ReceiveSerializedException se(dispatcher, exception);
90 PP_Bool result = PP_FALSE; 93 PP_Bool result = PP_FALSE;
91 if (!se.IsThrown()) { 94 if (!se.IsThrown()) {
92 dispatcher->Send(new PpapiHostMsg_PPBVar_HasMethodDeprecated( 95 dispatcher->Send(new PpapiHostMsg_PPBVar_HasMethodDeprecated(
93 API_ID_PPB_VAR_DEPRECATED, 96 API_ID_PPB_VAR_DEPRECATED,
94 SerializedVarSendInput(dispatcher, var), 97 SerializedVarSendInput(dispatcher, var),
95 SerializedVarSendInput(dispatcher, name), &se, &result)); 98 SerializedVarSendInput(dispatcher, name), &se, &result));
96 } 99 }
97 return PP_ToBool(result); 100 return PP_ToBool(result);
98 } 101 }
99 102
100 PP_Var GetProperty(PP_Var var, 103 PP_Var GetProperty(PP_Var var,
101 PP_Var name, 104 PP_Var name,
102 PP_Var* exception) { 105 PP_Var* exception) {
106 ProxyAutoLock lock;
103 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); 107 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception);
104 if (!dispatcher) 108 if (!dispatcher)
105 return PP_MakeUndefined(); 109 return PP_MakeUndefined();
106 110
107 ReceiveSerializedException se(dispatcher, exception); 111 ReceiveSerializedException se(dispatcher, exception);
108 ReceiveSerializedVarReturnValue result; 112 ReceiveSerializedVarReturnValue result;
109 if (!se.IsThrown()) { 113 if (!se.IsThrown()) {
110 dispatcher->Send(new PpapiHostMsg_PPBVar_GetProperty( 114 dispatcher->Send(new PpapiHostMsg_PPBVar_GetProperty(
111 API_ID_PPB_VAR_DEPRECATED, 115 API_ID_PPB_VAR_DEPRECATED,
112 SerializedVarSendInput(dispatcher, var), 116 SerializedVarSendInput(dispatcher, var),
113 SerializedVarSendInput(dispatcher, name), &se, &result)); 117 SerializedVarSendInput(dispatcher, name), &se, &result));
114 } 118 }
115 return result.Return(dispatcher); 119 return result.Return(dispatcher);
116 } 120 }
117 121
118 void EnumerateProperties(PP_Var var, 122 void EnumerateProperties(PP_Var var,
119 uint32_t* property_count, 123 uint32_t* property_count,
120 PP_Var** properties, 124 PP_Var** properties,
121 PP_Var* exception) { 125 PP_Var* exception) {
126 ProxyAutoLock lock;
122 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); 127 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception);
123 if (!dispatcher) { 128 if (!dispatcher) {
124 *property_count = 0; 129 *property_count = 0;
125 *properties = NULL; 130 *properties = NULL;
126 return; 131 return;
127 } 132 }
128 133
129 ReceiveSerializedVarVectorOutParam out_vector(dispatcher, 134 ReceiveSerializedVarVectorOutParam out_vector(dispatcher,
130 property_count, properties); 135 property_count, properties);
131 ReceiveSerializedException se(dispatcher, exception); 136 ReceiveSerializedException se(dispatcher, exception);
132 if (!se.IsThrown()) { 137 if (!se.IsThrown()) {
133 dispatcher->Send(new PpapiHostMsg_PPBVar_EnumerateProperties( 138 dispatcher->Send(new PpapiHostMsg_PPBVar_EnumerateProperties(
134 API_ID_PPB_VAR_DEPRECATED, 139 API_ID_PPB_VAR_DEPRECATED,
135 SerializedVarSendInput(dispatcher, var), 140 SerializedVarSendInput(dispatcher, var),
136 out_vector.OutParam(), &se)); 141 out_vector.OutParam(), &se));
137 } 142 }
138 } 143 }
139 144
140 void SetProperty(PP_Var var, 145 void SetProperty(PP_Var var,
141 PP_Var name, 146 PP_Var name,
142 PP_Var value, 147 PP_Var value,
143 PP_Var* exception) { 148 PP_Var* exception) {
149 ProxyAutoLock lock;
144 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); 150 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception);
145 if (!dispatcher) 151 if (!dispatcher)
146 return; 152 return;
147 153
148 ReceiveSerializedException se(dispatcher, exception); 154 ReceiveSerializedException se(dispatcher, exception);
149 if (!se.IsThrown()) { 155 if (!se.IsThrown()) {
150 dispatcher->Send(new PpapiHostMsg_PPBVar_SetPropertyDeprecated( 156 dispatcher->Send(new PpapiHostMsg_PPBVar_SetPropertyDeprecated(
151 API_ID_PPB_VAR_DEPRECATED, 157 API_ID_PPB_VAR_DEPRECATED,
152 SerializedVarSendInput(dispatcher, var), 158 SerializedVarSendInput(dispatcher, var),
153 SerializedVarSendInput(dispatcher, name), 159 SerializedVarSendInput(dispatcher, name),
154 SerializedVarSendInput(dispatcher, value), &se)); 160 SerializedVarSendInput(dispatcher, value), &se));
155 } 161 }
156 } 162 }
157 163
158 void RemoveProperty(PP_Var var, 164 void RemoveProperty(PP_Var var,
159 PP_Var name, 165 PP_Var name,
160 PP_Var* exception) { 166 PP_Var* exception) {
167 ProxyAutoLock lock;
161 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); 168 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception);
162 if (!dispatcher) 169 if (!dispatcher)
163 return; 170 return;
164 171
165 ReceiveSerializedException se(dispatcher, exception); 172 ReceiveSerializedException se(dispatcher, exception);
166 PP_Bool result = PP_FALSE; 173 PP_Bool result = PP_FALSE;
167 if (!se.IsThrown()) { 174 if (!se.IsThrown()) {
168 dispatcher->Send(new PpapiHostMsg_PPBVar_DeleteProperty( 175 dispatcher->Send(new PpapiHostMsg_PPBVar_DeleteProperty(
169 API_ID_PPB_VAR_DEPRECATED, 176 API_ID_PPB_VAR_DEPRECATED,
170 SerializedVarSendInput(dispatcher, var), 177 SerializedVarSendInput(dispatcher, var),
171 SerializedVarSendInput(dispatcher, name), &se, &result)); 178 SerializedVarSendInput(dispatcher, name), &se, &result));
172 } 179 }
173 } 180 }
174 181
175 PP_Var Call(PP_Var object, 182 PP_Var Call(PP_Var object,
176 PP_Var method_name, 183 PP_Var method_name,
177 uint32_t argc, 184 uint32_t argc,
178 PP_Var* argv, 185 PP_Var* argv,
179 PP_Var* exception) { 186 PP_Var* exception) {
187 ProxyAutoLock lock;
180 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(object, exception); 188 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(object, exception);
181 if (!dispatcher) 189 if (!dispatcher)
182 return PP_MakeUndefined(); 190 return PP_MakeUndefined();
183 191
184 ReceiveSerializedVarReturnValue result; 192 ReceiveSerializedVarReturnValue result;
185 ReceiveSerializedException se(dispatcher, exception); 193 ReceiveSerializedException se(dispatcher, exception);
186 if (!se.IsThrown()) { 194 if (!se.IsThrown()) {
187 std::vector<SerializedVar> argv_vect; 195 std::vector<SerializedVar> argv_vect;
188 SerializedVarSendInput::ConvertVector(dispatcher, argv, argc, &argv_vect); 196 SerializedVarSendInput::ConvertVector(dispatcher, argv, argc, &argv_vect);
189 197
190 dispatcher->Send(new PpapiHostMsg_PPBVar_CallDeprecated( 198 dispatcher->Send(new PpapiHostMsg_PPBVar_CallDeprecated(
191 API_ID_PPB_VAR_DEPRECATED, 199 API_ID_PPB_VAR_DEPRECATED,
192 SerializedVarSendInput(dispatcher, object), 200 SerializedVarSendInput(dispatcher, object),
193 SerializedVarSendInput(dispatcher, method_name), argv_vect, 201 SerializedVarSendInput(dispatcher, method_name), argv_vect,
194 &se, &result)); 202 &se, &result));
195 } 203 }
196 return result.Return(dispatcher); 204 return result.Return(dispatcher);
197 } 205 }
198 206
199 PP_Var Construct(PP_Var object, 207 PP_Var Construct(PP_Var object,
200 uint32_t argc, 208 uint32_t argc,
201 PP_Var* argv, 209 PP_Var* argv,
202 PP_Var* exception) { 210 PP_Var* exception) {
211 ProxyAutoLock lock;
203 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(object, exception); 212 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(object, exception);
204 if (!dispatcher) 213 if (!dispatcher)
205 return PP_MakeUndefined(); 214 return PP_MakeUndefined();
206 215
207 ReceiveSerializedVarReturnValue result; 216 ReceiveSerializedVarReturnValue result;
208 ReceiveSerializedException se(dispatcher, exception); 217 ReceiveSerializedException se(dispatcher, exception);
209 if (!se.IsThrown()) { 218 if (!se.IsThrown()) {
210 std::vector<SerializedVar> argv_vect; 219 std::vector<SerializedVar> argv_vect;
211 SerializedVarSendInput::ConvertVector(dispatcher, argv, argc, &argv_vect); 220 SerializedVarSendInput::ConvertVector(dispatcher, argv, argc, &argv_vect);
212 221
213 dispatcher->Send(new PpapiHostMsg_PPBVar_Construct( 222 dispatcher->Send(new PpapiHostMsg_PPBVar_Construct(
214 API_ID_PPB_VAR_DEPRECATED, 223 API_ID_PPB_VAR_DEPRECATED,
215 SerializedVarSendInput(dispatcher, object), 224 SerializedVarSendInput(dispatcher, object),
216 argv_vect, &se, &result)); 225 argv_vect, &se, &result));
217 } 226 }
218 return result.Return(dispatcher); 227 return result.Return(dispatcher);
219 } 228 }
220 229
221 bool IsInstanceOf(PP_Var var, 230 bool IsInstanceOf(PP_Var var,
222 const PPP_Class_Deprecated* ppp_class, 231 const PPP_Class_Deprecated* ppp_class,
223 void** ppp_class_data) { 232 void** ppp_class_data) {
233 ProxyAutoLock lock;
224 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, NULL); 234 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, NULL);
225 if (!dispatcher) 235 if (!dispatcher)
226 return false; 236 return false;
227 237
228 PP_Bool result = PP_FALSE; 238 PP_Bool result = PP_FALSE;
229 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class)); 239 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class));
230 int64 class_data_int = 0; 240 int64 class_data_int = 0;
231 dispatcher->Send(new PpapiHostMsg_PPBVar_IsInstanceOfDeprecated( 241 dispatcher->Send(new PpapiHostMsg_PPBVar_IsInstanceOfDeprecated(
232 API_ID_PPB_VAR_DEPRECATED, SerializedVarSendInput(dispatcher, var), 242 API_ID_PPB_VAR_DEPRECATED, SerializedVarSendInput(dispatcher, var),
233 class_int, &class_data_int, &result)); 243 class_int, &class_data_int, &result));
234 *ppp_class_data = 244 *ppp_class_data =
235 reinterpret_cast<void*>(static_cast<intptr_t>(class_data_int)); 245 reinterpret_cast<void*>(static_cast<intptr_t>(class_data_int));
236 return PP_ToBool(result); 246 return PP_ToBool(result);
237 } 247 }
238 248
239 PP_Var CreateObject(PP_Instance instance, 249 PP_Var CreateObject(PP_Instance instance,
240 const PPP_Class_Deprecated* ppp_class, 250 const PPP_Class_Deprecated* ppp_class,
241 void* ppp_class_data) { 251 void* ppp_class_data) {
252 ProxyAutoLock lock;
242 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 253 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
243 if (!dispatcher) 254 if (!dispatcher)
244 return PP_MakeUndefined(); 255 return PP_MakeUndefined();
245 256
246 ReceiveSerializedVarReturnValue result; 257 ReceiveSerializedVarReturnValue result;
247 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class)); 258 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class));
248 int64 data_int = 259 int64 data_int =
249 static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class_data)); 260 static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class_data));
250 dispatcher->Send(new PpapiHostMsg_PPBVar_CreateObjectDeprecated( 261 dispatcher->Send(new PpapiHostMsg_PPBVar_CreateObjectDeprecated(
251 API_ID_PPB_VAR_DEPRECATED, instance, class_int, data_int, 262 API_ID_PPB_VAR_DEPRECATED, instance, class_int, data_int,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 // release the object before it is AddRef'ed on the browser side. 371 // release the object before it is AddRef'ed on the browser side.
361 // To work around this, we post a task here, that will not execute before 372 // To work around this, we post a task here, that will not execute before
362 // control goes back to the main message loop, that will ensure the sync send 373 // control goes back to the main message loop, that will ensure the sync send
363 // has returned and the browser side can take its reference before we Release. 374 // has returned and the browser side can take its reference before we Release.
364 // Note: if the instance is gone by the time the task is executed, then it 375 // Note: if the instance is gone by the time the task is executed, then it
365 // will Release the objects itself and this Release will be a NOOP (aside of a 376 // will Release the objects itself and this Release will be a NOOP (aside of a
366 // spurious warning). 377 // spurious warning).
367 // TODO(piman): See if we can fix the IPC code to enforce strict ordering, and 378 // TODO(piman): See if we can fix the IPC code to enforce strict ordering, and
368 // then remove this. 379 // then remove this.
369 MessageLoop::current()->PostNonNestableTask(FROM_HERE, 380 MessageLoop::current()->PostNonNestableTask(FROM_HERE,
370 base::Bind(&PPB_Var_Deprecated_Proxy::DoReleaseObject, 381 RunWhileLocked(base::Bind(&PPB_Var_Deprecated_Proxy::DoReleaseObject,
371 task_factory_.GetWeakPtr(), 382 task_factory_.GetWeakPtr(),
372 object_id)); 383 object_id)));
373 } 384 }
374 385
375 void PPB_Var_Deprecated_Proxy::OnMsgHasProperty( 386 void PPB_Var_Deprecated_Proxy::OnMsgHasProperty(
376 SerializedVarReceiveInput var, 387 SerializedVarReceiveInput var,
377 SerializedVarReceiveInput name, 388 SerializedVarReceiveInput name,
378 SerializedVarOutParam exception, 389 SerializedVarOutParam exception,
379 PP_Bool* result) { 390 PP_Bool* result) {
380 SetAllowPluginReentrancy(); 391 SetAllowPluginReentrancy();
381 *result = PP_FromBool(ppb_var_impl_->HasProperty( 392 *result = PP_FromBool(ppb_var_impl_->HasProperty(
382 var.Get(dispatcher()), 393 var.Get(dispatcher()),
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 513 }
503 514
504 void PPB_Var_Deprecated_Proxy::DoReleaseObject(int64 object_id) { 515 void PPB_Var_Deprecated_Proxy::DoReleaseObject(int64 object_id) {
505 PP_Var var = { PP_VARTYPE_OBJECT }; 516 PP_Var var = { PP_VARTYPE_OBJECT };
506 var.value.as_id = object_id; 517 var.value.as_id = object_id;
507 ppb_var_impl_->Release(var); 518 ppb_var_impl_->Release(var);
508 } 519 }
509 520
510 } // namespace proxy 521 } // namespace proxy
511 } // namespace ppapi 522 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_testing_proxy.cc ('k') | ppapi/proxy/ppp_class_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698