OLD | NEW |
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 DCHECK(resource_ || !instance); | 66 DCHECK(resource_ || !instance); |
67 if (!resource_) | 67 if (!resource_) |
68 retval_ = PP_ERROR_BADARGUMENT; | 68 retval_ = PP_ERROR_BADARGUMENT; |
69 callback_ = new TrackedCallback(resource_, callback); | 69 callback_ = new TrackedCallback(resource_, callback); |
70 } | 70 } |
71 | 71 |
72 EnterBase::~EnterBase() { | 72 EnterBase::~EnterBase() { |
73 // callback_ is cleared any time it is run, scheduled to be run, or once we | 73 // callback_ is cleared any time it is run, scheduled to be run, or once we |
74 // know it will be completed asynchronously. So by this point it should be | 74 // know it will be completed asynchronously. So by this point it should be |
75 // NULL. | 75 // NULL. |
76 DCHECK(!callback_) << "|callback_| is not NULL. Did you forget to call " | 76 DCHECK(!callback_.get()) |
77 "|EnterBase::SetResult| in the interface's thunk?"; | 77 << "|callback_| is not NULL. Did you forget to call " |
| 78 "|EnterBase::SetResult| in the interface's thunk?"; |
78 } | 79 } |
79 | 80 |
80 int32_t EnterBase::SetResult(int32_t result) { | 81 int32_t EnterBase::SetResult(int32_t result) { |
81 if (!callback_) { | 82 if (!callback_.get()) { |
82 // It doesn't make sense to call SetResult if there is no callback. | 83 // It doesn't make sense to call SetResult if there is no callback. |
83 NOTREACHED(); | 84 NOTREACHED(); |
84 retval_ = result; | 85 retval_ = result; |
85 return result; | 86 return result; |
86 } | 87 } |
87 if (result == PP_OK_COMPLETIONPENDING) { | 88 if (result == PP_OK_COMPLETIONPENDING) { |
88 retval_ = result; | 89 retval_ = result; |
89 if (callback_->is_blocking()) { | 90 if (callback_->is_blocking()) { |
90 DCHECK(!IsMainThread()); // We should have returned an error before this. | 91 DCHECK(!IsMainThread()); // We should have returned an error before this. |
91 retval_ = callback_->BlockUntilComplete(); | 92 retval_ = callback_->BlockUntilComplete(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 return NULL; | 126 return NULL; |
126 | 127 |
127 return ppb_instance->GetSingletonResource(instance, resource_id); | 128 return ppb_instance->GetSingletonResource(instance, resource_id); |
128 } | 129 } |
129 | 130 |
130 void EnterBase::SetStateForCallbackError(bool report_error) { | 131 void EnterBase::SetStateForCallbackError(bool report_error) { |
131 if (PpapiGlobals::Get()->IsHostGlobals()) { | 132 if (PpapiGlobals::Get()->IsHostGlobals()) { |
132 // In-process plugins can't make PPAPI calls off the main thread. | 133 // In-process plugins can't make PPAPI calls off the main thread. |
133 CHECK(IsMainThread()); | 134 CHECK(IsMainThread()); |
134 } | 135 } |
135 if (callback_) { | 136 if (callback_.get()) { |
136 if (callback_->is_blocking() && IsMainThread()) { | 137 if (callback_->is_blocking() && IsMainThread()) { |
137 // Blocking callbacks are never allowed on the main thread. | 138 // Blocking callbacks are never allowed on the main thread. |
138 callback_->MarkAsCompleted(); | 139 callback_->MarkAsCompleted(); |
139 callback_ = NULL; | 140 callback_ = NULL; |
140 retval_ = PP_ERROR_BLOCKS_MAIN_THREAD; | 141 retval_ = PP_ERROR_BLOCKS_MAIN_THREAD; |
141 if (report_error) { | 142 if (report_error) { |
142 std::string message( | 143 std::string message( |
143 "Blocking callbacks are not allowed on the main thread."); | 144 "Blocking callbacks are not allowed on the main thread."); |
144 PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR, | 145 PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR, |
145 std::string(), message); | 146 std::string(), message); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 bool report_error) { | 187 bool report_error) { |
187 // Check for callback errors. If we get any, SetStateForCallbackError will | 188 // Check for callback errors. If we get any, SetStateForCallbackError will |
188 // emit a log message. But we also want to check for resource errors. If there | 189 // emit a log message. But we also want to check for resource errors. If there |
189 // are both kinds of errors, we'll emit two log messages and return | 190 // are both kinds of errors, we'll emit two log messages and return |
190 // PP_ERROR_BADRESOURCE. | 191 // PP_ERROR_BADRESOURCE. |
191 SetStateForCallbackError(report_error); | 192 SetStateForCallbackError(report_error); |
192 | 193 |
193 if (object) | 194 if (object) |
194 return; // Everything worked. | 195 return; // Everything worked. |
195 | 196 |
196 if (callback_ && callback_->is_required()) { | 197 if (callback_.get() && callback_->is_required()) { |
197 callback_->PostRun(static_cast<int32_t>(PP_ERROR_BADRESOURCE)); | 198 callback_->PostRun(static_cast<int32_t>(PP_ERROR_BADRESOURCE)); |
198 callback_ = NULL; | 199 callback_ = NULL; |
199 retval_ = PP_OK_COMPLETIONPENDING; | 200 retval_ = PP_OK_COMPLETIONPENDING; |
200 } else { | 201 } else { |
201 if (callback_) | 202 if (callback_.get()) |
202 callback_->MarkAsCompleted(); | 203 callback_->MarkAsCompleted(); |
203 callback_ = NULL; | 204 callback_ = NULL; |
204 retval_ = PP_ERROR_BADRESOURCE; | 205 retval_ = PP_ERROR_BADRESOURCE; |
205 } | 206 } |
206 | 207 |
207 // We choose to silently ignore the error when the pp_resource is null | 208 // We choose to silently ignore the error when the pp_resource is null |
208 // because this is a pretty common case and we don't want to have lots | 209 // because this is a pretty common case and we don't want to have lots |
209 // of errors in the log. This should be an obvious case to debug. | 210 // of errors in the log. This should be an obvious case to debug. |
210 if (report_error && pp_resource) { | 211 if (report_error && pp_resource) { |
211 std::string message; | 212 std::string message; |
(...skipping 16 matching lines...) Expand all Loading... |
228 bool report_error) { | 229 bool report_error) { |
229 // Check for callback errors. If we get any, SetStateForCallbackError will | 230 // Check for callback errors. If we get any, SetStateForCallbackError will |
230 // emit a log message. But we also want to check for instance errors. If there | 231 // emit a log message. But we also want to check for instance errors. If there |
231 // are both kinds of errors, we'll emit two log messages and return | 232 // are both kinds of errors, we'll emit two log messages and return |
232 // PP_ERROR_BADARGUMENT. | 233 // PP_ERROR_BADARGUMENT. |
233 SetStateForCallbackError(report_error); | 234 SetStateForCallbackError(report_error); |
234 | 235 |
235 if (object) | 236 if (object) |
236 return; // Everything worked. | 237 return; // Everything worked. |
237 | 238 |
238 if (callback_ && callback_->is_required()) { | 239 if (callback_.get() && callback_->is_required()) { |
239 callback_->PostRun(static_cast<int32_t>(PP_ERROR_BADARGUMENT)); | 240 callback_->PostRun(static_cast<int32_t>(PP_ERROR_BADARGUMENT)); |
240 callback_ = NULL; | 241 callback_ = NULL; |
241 retval_ = PP_OK_COMPLETIONPENDING; | 242 retval_ = PP_OK_COMPLETIONPENDING; |
242 } else { | 243 } else { |
243 if (callback_) | 244 if (callback_.get()) |
244 callback_->MarkAsCompleted(); | 245 callback_->MarkAsCompleted(); |
245 callback_ = NULL; | 246 callback_ = NULL; |
246 retval_ = PP_ERROR_BADARGUMENT; | 247 retval_ = PP_ERROR_BADARGUMENT; |
247 } | 248 } |
248 | 249 |
249 // We choose to silently ignore the error when the pp_instance is null as | 250 // We choose to silently ignore the error when the pp_instance is null as |
250 // for PP_Resources above. | 251 // for PP_Resources above. |
251 if (report_error && pp_instance) { | 252 if (report_error && pp_instance) { |
252 std::string message; | 253 std::string message; |
253 message = base::StringPrintf( | 254 message = base::StringPrintf( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 : EnterBase(), | 313 : EnterBase(), |
313 functions_(PpapiGlobals::Get()->GetResourceCreationAPI(instance)) { | 314 functions_(PpapiGlobals::Get()->GetResourceCreationAPI(instance)) { |
314 SetStateForFunctionError(instance, functions_, true); | 315 SetStateForFunctionError(instance, functions_, true); |
315 } | 316 } |
316 | 317 |
317 EnterResourceCreationNoLock::~EnterResourceCreationNoLock() { | 318 EnterResourceCreationNoLock::~EnterResourceCreationNoLock() { |
318 } | 319 } |
319 | 320 |
320 } // namespace thunk | 321 } // namespace thunk |
321 } // namespace ppapi | 322 } // namespace ppapi |
OLD | NEW |