| 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
|
|
|