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

Side by Side Diff: ppapi/proxy/ppb_testing_proxy.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 | « ppapi/proxy/ppb_message_loop_proxy.cc ('k') | ppapi/proxy/ppb_var_deprecated_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) 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/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) {
53 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); 55 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
56 // TODO(dmichael): We should probably assert that this is the main thread.
54 MessageLoop::current()->Run(); 57 MessageLoop::current()->Run();
55 } 58 }
56 59
57 void QuitMessageLoop(PP_Instance instance) { 60 void QuitMessageLoop(PP_Instance instance) {
61 // TODO(dmichael): We should probably assert that this is the main thread.
58 MessageLoop::current()->QuitNow(); 62 MessageLoop::current()->QuitNow();
59 } 63 }
60 64
61 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { 65 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) {
66 ProxyAutoLock lock;
62 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); 67 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
63 if (!dispatcher) 68 if (!dispatcher)
64 return static_cast<uint32_t>(-1); 69 return static_cast<uint32_t>(-1);
65 70
66 uint32_t result = 0; 71 uint32_t result = 0;
67 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance( 72 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance(
68 API_ID_PPB_TESTING, instance_id, &result)); 73 API_ID_PPB_TESTING, instance_id, &result));
69 return result; 74 return result;
70 } 75 }
71 76
72 PP_Bool IsOutOfProcess() { 77 PP_Bool IsOutOfProcess() {
73 return PP_TRUE; 78 return PP_TRUE;
74 } 79 }
75 80
76 void SimulateInputEvent(PP_Instance instance_id, PP_Resource input_event) { 81 void SimulateInputEvent(PP_Instance instance_id, PP_Resource input_event) {
82 ProxyAutoLock lock;
77 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); 83 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
78 if (!dispatcher) 84 if (!dispatcher)
79 return; 85 return;
80 EnterResource<PPB_InputEvent_API> enter(input_event, false); 86 EnterResourceNoLock<PPB_InputEvent_API> enter(input_event, false);
81 if (enter.failed()) 87 if (enter.failed())
82 return; 88 return;
83 89
84 const InputEventData& input_event_data = enter.object()->GetInputEventData(); 90 const InputEventData& input_event_data = enter.object()->GetInputEventData();
85 dispatcher->Send(new PpapiHostMsg_PPBTesting_SimulateInputEvent( 91 dispatcher->Send(new PpapiHostMsg_PPBTesting_SimulateInputEvent(
86 API_ID_PPB_TESTING, instance_id, input_event_data)); 92 API_ID_PPB_TESTING, instance_id, input_event_data));
87 } 93 }
88 94
89 PP_Var GetDocumentURL(PP_Instance instance, PP_URLComponents_Dev* components) { 95 PP_Var GetDocumentURL(PP_Instance instance, PP_URLComponents_Dev* components) {
90 EnterInstance enter(instance); 96 EnterInstance enter(instance);
91 if (enter.failed()) 97 if (enter.failed())
92 return PP_MakeUndefined(); 98 return PP_MakeUndefined();
93 return enter.functions()->GetDocumentURL(instance, components); 99 return enter.functions()->GetDocumentURL(instance, components);
94 } 100 }
95 101
96 // TODO(dmichael): Ideally we could get a way to check the number of vars in the 102 // TODO(dmichael): Ideally we could get a way to check the number of vars in the
97 // host-side tracker when running out-of-process, to make sure the proxy does 103 // host-side tracker when running out-of-process, to make sure the proxy does
98 // not leak host-side vars. 104 // not leak host-side vars.
99 uint32_t GetLiveVars(PP_Var live_vars[], uint32_t array_size) { 105 uint32_t GetLiveVars(PP_Var live_vars[], uint32_t array_size) {
106 ProxyAutoLock lock;
100 std::vector<PP_Var> vars = 107 std::vector<PP_Var> vars =
101 PpapiGlobals::Get()->GetVarTracker()->GetLiveVars(); 108 PpapiGlobals::Get()->GetVarTracker()->GetLiveVars();
102 for (size_t i = 0u; 109 for (size_t i = 0u;
103 i < std::min(static_cast<size_t>(array_size), vars.size()); 110 i < std::min(static_cast<size_t>(array_size), vars.size());
104 ++i) 111 ++i)
105 live_vars[i] = vars[i]; 112 live_vars[i] = vars[i];
106 return vars.size(); 113 return vars.size();
107 } 114 }
108 115
109 const PPB_Testing_Dev testing_interface = { 116 const PPB_Testing_Dev testing_interface = {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 PP_Instance instance, 194 PP_Instance instance,
188 const InputEventData& input_event) { 195 const InputEventData& input_event) {
189 scoped_refptr<PPB_InputEvent_Shared> input_event_impl( 196 scoped_refptr<PPB_InputEvent_Shared> input_event_impl(
190 new PPB_InputEvent_Shared(OBJECT_IS_PROXY, instance, input_event)); 197 new PPB_InputEvent_Shared(OBJECT_IS_PROXY, instance, input_event));
191 ppb_testing_impl_->SimulateInputEvent(instance, 198 ppb_testing_impl_->SimulateInputEvent(instance,
192 input_event_impl->pp_resource()); 199 input_event_impl->pp_resource());
193 } 200 }
194 201
195 } // namespace proxy 202 } // namespace proxy
196 } // namespace ppapi 203 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_message_loop_proxy.cc ('k') | ppapi/proxy/ppb_var_deprecated_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698