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

Unified Diff: ppapi/proxy/enter_proxy.h

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up for review. Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ppapi/proxy/plugin_dispatcher.h » ('j') | ppapi/shared_impl/api_callback_type.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/enter_proxy.h
diff --git a/ppapi/proxy/enter_proxy.h b/ppapi/proxy/enter_proxy.h
index 86ee7a0f0fd80d8a518a78c323186f7ffe0cc16d..ea74436323ee5306b7e1923f1c2c0f2bd8a1c673 100644
--- a/ppapi/proxy/enter_proxy.h
+++ b/ppapi/proxy/enter_proxy.h
@@ -45,8 +45,19 @@ class EnterHostFromHostResource
: public thunk::EnterResourceNoLock<ResourceT> {
public:
explicit EnterHostFromHostResource(const HostResource& host_resource)
- : thunk::EnterResourceNoLock<ResourceT>(
- host_resource.host_resource(), false) {
+ : thunk::EnterResourceNoLock<ResourceT>(host_resource.host_resource(),
+ false) {
+ // Validate that we're in the host rather than the plugin. Otherwise this
+ // object will do the wrong thing. In the host, the instance should have
+ // a corresponding host disptacher (assuming the resource is valid).
+ DCHECK(this->failed() ||
+ HostDispatcher::GetForInstance(host_resource.instance()));
+ }
+ EnterHostFromHostResource(const HostResource& host_resource,
+ const pp::CompletionCallback& callback)
+ : thunk::EnterResourceNoLock<ResourceT>(host_resource.host_resource(),
+ callback.pp_completion_callback(),
+ false) {
// Validate that we're in the host rather than the plugin. Otherwise this
// object will do the wrong thing. In the host, the instance should have
// a corresponding host disptacher (assuming the resource is valid).
@@ -92,9 +103,8 @@ class EnterHostFromHostResourceForceCallback
EnterHostFromHostResourceForceCallback(
const HostResource& host_resource,
const pp::CompletionCallback& callback)
- : EnterHostFromHostResource<ResourceT>(host_resource),
- needs_running_(true),
- callback_(callback) {
+ : EnterHostFromHostResource<ResourceT>(host_resource, callback),
+ needs_running_(true) {
}
// For callbacks that take no parameters except the "int32_t result". Most
@@ -104,9 +114,9 @@ class EnterHostFromHostResourceForceCallback
const HostResource& host_resource,
CallbackFactory& factory,
Method method)
- : EnterHostFromHostResource<ResourceT>(host_resource),
- needs_running_(true),
- callback_(factory.NewOptionalCallback(method)) {
+ : EnterHostFromHostResource<ResourceT>(host_resource,
+ factory.NewOptionalCallback(method)),
+ needs_running_(true) {
if (this->failed())
RunCallback(PP_ERROR_BADRESOURCE);
}
@@ -118,9 +128,9 @@ class EnterHostFromHostResourceForceCallback
CallbackFactory& factory,
Method method,
const A& a)
- : EnterHostFromHostResource<ResourceT>(host_resource),
- needs_running_(true),
- callback_(factory.NewOptionalCallback(method, a)) {
+ : EnterHostFromHostResource<ResourceT>(host_resource,
+ factory.NewOptionalCallback(method, a)),
+ needs_running_(true) {
if (this->failed())
RunCallback(PP_ERROR_BADRESOURCE);
}
@@ -133,9 +143,9 @@ class EnterHostFromHostResourceForceCallback
Method method,
const A& a,
const B& b)
- : EnterHostFromHostResource<ResourceT>(host_resource),
- needs_running_(true),
- callback_(factory.NewOptionalCallback(method, a, b)) {
+ : EnterHostFromHostResource<ResourceT>(host_resource,
+ factory.NewOptionalCallback(method, a, b)),
+ needs_running_(true) {
if (this->failed())
RunCallback(PP_ERROR_BADRESOURCE);
}
@@ -150,24 +160,21 @@ class EnterHostFromHostResourceForceCallback
void SetResult(int32_t result) {
DCHECK(needs_running_) << "Don't call SetResult when there already is one.";
- needs_running_ = false;
if (result != PP_OK_COMPLETIONPENDING)
- callback_.Run(result);
- }
-
- PP_CompletionCallback callback() {
- return callback_.pp_completion_callback();
+ RunCallback(result);
+ needs_running_ = false;
+ this->ClearCallback();
}
private:
void RunCallback(int32_t result) {
DCHECK(needs_running_);
needs_running_ = false;
- callback_.Run(result);
+ this->callback()->Run(result);
+ this->ClearCallback();
}
bool needs_running_;
- pp::CompletionCallback callback_;
};
// Like EnterHostFromHostResourceForceCallback but for Function APIs. It takes
@@ -180,8 +187,7 @@ class EnterHostFunctionForceCallback
PP_Instance instance,
const pp::CompletionCallback& callback)
: thunk::EnterFunctionNoLock<FunctionT>(instance, false),
- needs_running_(true),
- callback_(callback) {
+ needs_running_(true) {
if (this->failed())
RunCallback(PP_ERROR_BADARGUMENT);
}
@@ -196,24 +202,21 @@ class EnterHostFunctionForceCallback
void SetResult(int32_t result) {
DCHECK(needs_running_) << "Don't call SetResult when there already is one.";
- needs_running_ = false;
if (result != PP_OK_COMPLETIONPENDING)
- callback_.Run(result);
- }
-
- PP_CompletionCallback callback() {
- return callback_.pp_completion_callback();
+ RunCallback(result);
+ needs_running_ = false;
+ this->ClearCallback();
}
private:
void RunCallback(int32_t result) {
DCHECK(needs_running_);
needs_running_ = false;
- callback_.Run(result);
+ this->callback()->Run(result);
+ this->ClearCallback();
}
bool needs_running_;
- pp::CompletionCallback callback_;
};
} // namespace proxy
« no previous file with comments | « no previous file | ppapi/proxy/plugin_dispatcher.h » ('j') | ppapi/shared_impl/api_callback_type.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698