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

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

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