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

Side by Side Diff: ppapi/proxy/ppb_testing_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: added documentation 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
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_testing_proxy.h" 5 #include "ppapi/proxy/ppb_testing_proxy.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "ppapi/c/dev/ppb_testing_dev.h" 8 #include "ppapi/c/dev/ppb_testing_dev.h"
9 #include "ppapi/proxy/enter_proxy.h" 9 #include "ppapi/proxy/enter_proxy.h"
10 #include "ppapi/proxy/plugin_dispatcher.h" 10 #include "ppapi/proxy/plugin_dispatcher.h"
11 #include "ppapi/proxy/ppapi_messages.h" 11 #include "ppapi/proxy/ppapi_messages.h"
12 #include "ppapi/shared_impl/ppapi_globals.h" 12 #include "ppapi/shared_impl/ppapi_globals.h"
13 #include "ppapi/shared_impl/proxy_lock.h"
13 #include "ppapi/shared_impl/resource.h" 14 #include "ppapi/shared_impl/resource.h"
14 #include "ppapi/shared_impl/resource_tracker.h" 15 #include "ppapi/shared_impl/resource_tracker.h"
15 #include "ppapi/thunk/enter.h" 16 #include "ppapi/thunk/enter.h"
16 #include "ppapi/thunk/ppb_input_event_api.h" 17 #include "ppapi/thunk/ppb_input_event_api.h"
17 18
18 using ppapi::thunk::EnterInstance; 19 using ppapi::thunk::EnterInstance;
19 using ppapi::thunk::EnterResource; 20 using ppapi::thunk::EnterResourceNoLock;
20 using ppapi::thunk::PPB_InputEvent_API; 21 using ppapi::thunk::PPB_InputEvent_API;
21 22
22 namespace ppapi { 23 namespace ppapi {
23 namespace proxy { 24 namespace proxy {
24 25
25 namespace { 26 namespace {
26 27
27 PP_Bool ReadImageData(PP_Resource graphics_2d, 28 PP_Bool ReadImageData(PP_Resource graphics_2d,
28 PP_Resource image, 29 PP_Resource image,
29 const PP_Point* top_left) { 30 const PP_Point* top_left) {
31 ProxyAutoLock lock;
30 Resource* image_object = 32 Resource* image_object =
31 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image); 33 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image);
32 if (!image_object) 34 if (!image_object)
33 return PP_FALSE; 35 return PP_FALSE;
34 Resource* graphics_2d_object = 36 Resource* graphics_2d_object =
35 PpapiGlobals::Get()->GetResourceTracker()->GetResource(graphics_2d); 37 PpapiGlobals::Get()->GetResourceTracker()->GetResource(graphics_2d);
36 if (!graphics_2d_object || 38 if (!graphics_2d_object ||
37 image_object->pp_instance() != graphics_2d_object->pp_instance()) 39 image_object->pp_instance() != graphics_2d_object->pp_instance())
38 return PP_FALSE; 40 return PP_FALSE;
39 41
40 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( 42 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
41 image_object->pp_instance()); 43 image_object->pp_instance());
42 if (!dispatcher) 44 if (!dispatcher)
43 return PP_FALSE; 45 return PP_FALSE;
44 46
45 PP_Bool result = PP_FALSE; 47 PP_Bool result = PP_FALSE;
46 dispatcher->Send(new PpapiHostMsg_PPBTesting_ReadImageData( 48 dispatcher->Send(new PpapiHostMsg_PPBTesting_ReadImageData(
47 API_ID_PPB_TESTING, graphics_2d_object->host_resource(), 49 API_ID_PPB_TESTING, graphics_2d_object->host_resource(),
48 image_object->host_resource(), *top_left, &result)); 50 image_object->host_resource(), *top_left, &result));
49 return result; 51 return result;
50 } 52 }
51 53
52 void RunMessageLoop(PP_Instance instance) { 54 void RunMessageLoop(PP_Instance instance) {
55 // TODO(dmichael): We should probably assert that this is the main thread.
53 bool old_state = MessageLoop::current()->NestableTasksAllowed(); 56 bool old_state = MessageLoop::current()->NestableTasksAllowed();
54 MessageLoop::current()->SetNestableTasksAllowed(true); 57 MessageLoop::current()->SetNestableTasksAllowed(true);
55 MessageLoop::current()->Run(); 58 MessageLoop::current()->Run();
56 MessageLoop::current()->SetNestableTasksAllowed(old_state); 59 MessageLoop::current()->SetNestableTasksAllowed(old_state);
57 } 60 }
58 61
59 void QuitMessageLoop(PP_Instance instance) { 62 void QuitMessageLoop(PP_Instance instance) {
63 // TODO(dmichael): We should probably assert that this is the main thread.
60 MessageLoop::current()->QuitNow(); 64 MessageLoop::current()->QuitNow();
61 } 65 }
62 66
63 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { 67 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) {
68 ProxyAutoLock lock;
64 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); 69 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
65 if (!dispatcher) 70 if (!dispatcher)
66 return static_cast<uint32_t>(-1); 71 return static_cast<uint32_t>(-1);
67 72
68 uint32_t result = 0; 73 uint32_t result = 0;
69 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance( 74 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance(
70 API_ID_PPB_TESTING, instance_id, &result)); 75 API_ID_PPB_TESTING, instance_id, &result));
71 return result; 76 return result;
72 } 77 }
73 78
74 PP_Bool IsOutOfProcess() { 79 PP_Bool IsOutOfProcess() {
75 return PP_TRUE; 80 return PP_TRUE;
76 } 81 }
77 82
78 void SimulateInputEvent(PP_Instance instance_id, PP_Resource input_event) { 83 void SimulateInputEvent(PP_Instance instance_id, PP_Resource input_event) {
84 ProxyAutoLock lock;
79 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); 85 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
80 if (!dispatcher) 86 if (!dispatcher)
81 return; 87 return;
82 EnterResource<PPB_InputEvent_API> enter(input_event, false); 88 EnterResourceNoLock<PPB_InputEvent_API> enter(input_event, false);
83 if (enter.failed()) 89 if (enter.failed())
84 return; 90 return;
85 91
86 const InputEventData& input_event_data = enter.object()->GetInputEventData(); 92 const InputEventData& input_event_data = enter.object()->GetInputEventData();
87 dispatcher->Send(new PpapiHostMsg_PPBTesting_SimulateInputEvent( 93 dispatcher->Send(new PpapiHostMsg_PPBTesting_SimulateInputEvent(
88 API_ID_PPB_TESTING, instance_id, input_event_data)); 94 API_ID_PPB_TESTING, instance_id, input_event_data));
89 } 95 }
90 96
91 PP_Var GetDocumentURL(PP_Instance instance, PP_URLComponents_Dev* components) { 97 PP_Var GetDocumentURL(PP_Instance instance, PP_URLComponents_Dev* components) {
92 EnterInstance enter(instance); 98 EnterInstance enter(instance);
93 if (enter.failed()) 99 if (enter.failed())
94 return PP_MakeUndefined(); 100 return PP_MakeUndefined();
95 return enter.functions()->GetDocumentURL(instance, components); 101 return enter.functions()->GetDocumentURL(instance, components);
96 } 102 }
97 103
98 // TODO(dmichael): Ideally we could get a way to check the number of vars in the 104 // TODO(dmichael): Ideally we could get a way to check the number of vars in the
99 // host-side tracker when running out-of-process, to make sure the proxy does 105 // host-side tracker when running out-of-process, to make sure the proxy does
100 // not leak host-side vars. 106 // not leak host-side vars.
101 uint32_t GetLiveVars(PP_Var live_vars[], uint32_t array_size) { 107 uint32_t GetLiveVars(PP_Var live_vars[], uint32_t array_size) {
108 ProxyAutoLock lock;
102 std::vector<PP_Var> vars = 109 std::vector<PP_Var> vars =
103 PpapiGlobals::Get()->GetVarTracker()->GetLiveVars(); 110 PpapiGlobals::Get()->GetVarTracker()->GetLiveVars();
104 for (size_t i = 0u; 111 for (size_t i = 0u;
105 i < std::min(static_cast<size_t>(array_size), vars.size()); 112 i < std::min(static_cast<size_t>(array_size), vars.size());
106 ++i) 113 ++i)
107 live_vars[i] = vars[i]; 114 live_vars[i] = vars[i];
108 return vars.size(); 115 return vars.size();
109 } 116 }
110 117
111 const PPB_Testing_Dev testing_interface = { 118 const PPB_Testing_Dev testing_interface = {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 scoped_refptr<PPB_InputEvent_Shared> input_event_impl( 198 scoped_refptr<PPB_InputEvent_Shared> input_event_impl(
192 new PPB_InputEvent_Shared(PPB_InputEvent_Shared::InitAsProxy(), 199 new PPB_InputEvent_Shared(PPB_InputEvent_Shared::InitAsProxy(),
193 instance, 200 instance,
194 input_event)); 201 input_event));
195 ppb_testing_impl_->SimulateInputEvent(instance, 202 ppb_testing_impl_->SimulateInputEvent(instance,
196 input_event_impl->pp_resource()); 203 input_event_impl->pp_resource());
197 } 204 }
198 205
199 } // namespace proxy 206 } // namespace proxy
200 } // namespace ppapi 207 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698