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

Side by Side Diff: ppapi/thunk/enter.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/thunk/enter.h ('k') | no next file » | 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/thunk/enter.h" 5 #include "ppapi/thunk/enter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 22 matching lines...) Expand all
33 : callback_(CallbackIsRequired(callback) ? callback 33 : callback_(CallbackIsRequired(callback) ? callback
34 : PP_BlockUntilComplete()), 34 : PP_BlockUntilComplete()),
35 retval_(PP_OK) { 35 retval_(PP_OK) {
36 // TODO(brettw) validate threads. 36 // TODO(brettw) validate threads.
37 } 37 }
38 38
39 EnterBase::~EnterBase() { 39 EnterBase::~EnterBase() {
40 if (callback_.func) { 40 if (callback_.func) {
41 // All async completions should have cleared the callback in SetResult(). 41 // All async completions should have cleared the callback in SetResult().
42 DCHECK(retval_ != PP_OK_COMPLETIONPENDING && retval_ != PP_OK); 42 DCHECK(retval_ != PP_OK_COMPLETIONPENDING && retval_ != PP_OK);
43 MessageLoop::current()->PostTask(FROM_HERE, RunWhileLocked(base::Bind( 43 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
44 callback_.func, callback_.user_data, retval_))); 44 callback_.func, callback_.user_data, retval_));
45 } 45 }
46 } 46 }
47 47
48 int32_t EnterBase::SetResult(int32_t result) { 48 int32_t EnterBase::SetResult(int32_t result) {
49 if (!callback_.func || result == PP_OK_COMPLETIONPENDING) { 49 if (!callback_.func || result == PP_OK_COMPLETIONPENDING) {
50 // Easy case, we don't need to issue the callback (either none is 50 // Easy case, we don't need to issue the callback (either none is
51 // required, or the implementation will asynchronously issue it 51 // required, or the implementation will asynchronously issue it
52 // for us), just store the result. 52 // for us), just store the result.
53 callback_ = PP_BlockUntilComplete(); 53 callback_ = PP_BlockUntilComplete();
54 retval_ = result; 54 retval_ = result;
55 return retval_; 55 return retval_;
56 } 56 }
57 57
58 // This is a required callback, asynchronously issue it. 58 // This is a required callback, asynchronously issue it.
59 // TODO(brettw) make this work on different threads, etc. 59 // TODO(brettw) make this work on different threads, etc.
60 MessageLoop::current()->PostTask(FROM_HERE, RunWhileLocked(base::Bind( 60 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
61 callback_.func, callback_.user_data, result))); 61 callback_.func, callback_.user_data, result));
62 62
63 // Now that the callback will be issued in the future, we should return 63 // Now that the callback will be issued in the future, we should return
64 // "pending" to the caller, and not issue the callback again. 64 // "pending" to the caller, and not issue the callback again.
65 callback_ = PP_BlockUntilComplete(); 65 callback_ = PP_BlockUntilComplete();
66 retval_ = PP_OK_COMPLETIONPENDING; 66 retval_ = PP_OK_COMPLETIONPENDING;
67 return retval_; 67 return retval_;
68 } 68 }
69 69
70 FunctionGroupBase* EnterBase::GetFunctions(PP_Instance instance, 70 FunctionGroupBase* EnterBase::GetFunctions(PP_Instance instance,
71 ApiID id) const { 71 ApiID id) const {
72 return PpapiGlobals::Get()->GetFunctionAPI(instance, id); 72 return PpapiGlobals::Get()->GetFunctionAPI(instance, id);
73 } 73 }
74 74
75 Resource* EnterBase::GetResource(PP_Resource resource) const { 75 Resource* EnterBase::GetResource(PP_Resource resource) const {
76 return PpapiGlobals::Get()->GetResourceTracker()->GetResource(resource); 76 return PpapiGlobals::Get()->GetResourceTracker()->GetResource(resource);
77 } 77 }
78 78
79 void EnterBase::SetStateForResourceError(PP_Resource pp_resource, 79 void EnterBase::SetStateForResourceError(PP_Resource pp_resource,
80 Resource* resource_base, 80 Resource* resource_base,
81 void* object, 81 void* object,
82 bool report_error) { 82 bool report_error) {
83 if (object) 83 if (object)
84 return; // Everything worked. 84 return; // Everything worked.
85 85
86 if (callback_.func) { 86 if (callback_.func) {
87 // Required callback, issue the async completion. 87 // Required callback, issue the async completion.
88 MessageLoop::current()->PostTask(FROM_HERE, RunWhileLocked(base::Bind( 88 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
89 callback_.func, callback_.user_data, 89 callback_.func, callback_.user_data,
90 static_cast<int32_t>(PP_ERROR_BADRESOURCE)))); 90 static_cast<int32_t>(PP_ERROR_BADRESOURCE)));
91 callback_ = PP_BlockUntilComplete(); 91 callback_ = PP_BlockUntilComplete();
92 retval_ = PP_OK_COMPLETIONPENDING; 92 retval_ = PP_OK_COMPLETIONPENDING;
93 } else { 93 } else {
94 retval_ = PP_ERROR_BADRESOURCE; 94 retval_ = PP_ERROR_BADRESOURCE;
95 } 95 }
96 96
97 // We choose to silently ignore the error when the pp_resource is null 97 // We choose to silently ignore the error when the pp_resource is null
98 // because this is a pretty common case and we don't want to have lots 98 // because this is a pretty common case and we don't want to have lots
99 // of errors in the log. This should be an obvious case to debug. 99 // of errors in the log. This should be an obvious case to debug.
100 if (report_error && pp_resource) { 100 if (report_error && pp_resource) {
(...skipping 13 matching lines...) Expand all
114 } 114 }
115 115
116 void EnterBase::SetStateForFunctionError(PP_Instance pp_instance, 116 void EnterBase::SetStateForFunctionError(PP_Instance pp_instance,
117 void* object, 117 void* object,
118 bool report_error) { 118 bool report_error) {
119 if (object) 119 if (object)
120 return; // Everything worked. 120 return; // Everything worked.
121 121
122 if (callback_.func) { 122 if (callback_.func) {
123 // Required callback, issue the async completion. 123 // Required callback, issue the async completion.
124 MessageLoop::current()->PostTask(FROM_HERE, RunWhileLocked(base::Bind( 124 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
125 callback_.func, callback_.user_data, 125 callback_.func, callback_.user_data,
126 static_cast<int32_t>(PP_ERROR_BADARGUMENT)))); 126 static_cast<int32_t>(PP_ERROR_BADARGUMENT)));
127 callback_ = PP_BlockUntilComplete(); 127 callback_ = PP_BlockUntilComplete();
128 retval_ = PP_OK_COMPLETIONPENDING; 128 retval_ = PP_OK_COMPLETIONPENDING;
129 } else { 129 } else {
130 retval_ = PP_ERROR_BADARGUMENT; 130 retval_ = PP_ERROR_BADARGUMENT;
131 } 131 }
132 132
133 // We choose to silently ignore the error when the pp_instance is null as 133 // We choose to silently ignore the error when the pp_instance is null as
134 // for PP_Resources above. 134 // for PP_Resources above.
135 if (report_error && pp_instance) { 135 if (report_error && pp_instance) {
136 std::string message; 136 std::string message;
137 message = base::StringPrintf( 137 message = base::StringPrintf(
138 "0x%X is not a valid instance ID.", 138 "0x%X is not a valid instance ID.",
139 pp_instance); 139 pp_instance);
140 PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR, 140 PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR,
141 std::string(), message); 141 std::string(), message);
142 } 142 }
143 } 143 }
144 144
145 } // namespace subtle 145 } // namespace subtle
146 146
147 EnterResourceCreation::EnterResourceCreation(PP_Instance instance) 147 EnterResourceCreation::EnterResourceCreation(PP_Instance instance)
148 : EnterFunction<ResourceCreationAPI>(instance, true) { 148 : EnterFunctionNoLock<ResourceCreationAPI>(instance, true) {
149 } 149 }
150 150
151 EnterResourceCreation::~EnterResourceCreation() { 151 EnterResourceCreation::~EnterResourceCreation() {
152 } 152 }
153 153
154 EnterInstance::EnterInstance(PP_Instance instance) 154 EnterInstance::EnterInstance(PP_Instance instance)
155 : EnterFunction<PPB_Instance_FunctionAPI>(instance, true) { 155 : EnterFunction<PPB_Instance_FunctionAPI>(instance, true) {
156 } 156 }
157 157
158 EnterInstance::EnterInstance(PP_Instance instance, 158 EnterInstance::EnterInstance(PP_Instance instance,
159 const PP_CompletionCallback& callback) 159 const PP_CompletionCallback& callback)
160 : EnterFunction<PPB_Instance_FunctionAPI>(instance, callback, true) { 160 : EnterFunction<PPB_Instance_FunctionAPI>(instance, callback, true) {
161 } 161 }
162 162
163 EnterInstance::~EnterInstance() { 163 EnterInstance::~EnterInstance() {
164 } 164 }
165 165
166 } // namespace thunk 166 } // namespace thunk
167 } // namespace ppapi 167 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/thunk/enter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698