| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef PPAPI_PROXY_ENTER_PROXY_H_ | 5 #ifndef PPAPI_PROXY_ENTER_PROXY_H_ |
| 6 #define PPAPI_PROXY_ENTER_PROXY_H_ | 6 #define PPAPI_PROXY_ENTER_PROXY_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/proxy/host_dispatcher.h" | 10 #include "ppapi/proxy/host_dispatcher.h" |
| 11 #include "ppapi/proxy/plugin_dispatcher.h" | 11 #include "ppapi/proxy/plugin_dispatcher.h" |
| 12 #include "ppapi/proxy/plugin_resource_tracker.h" | 12 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 13 #include "ppapi/thunk/enter.h" | 13 #include "ppapi/thunk/enter.h" |
| 14 | 14 |
| 15 namespace pp { | 15 namespace ppapi { |
| 16 namespace proxy { | 16 namespace proxy { |
| 17 | 17 |
| 18 // Wrapper around EnterResourceNoLock that takes a host resource. This is used | 18 // Wrapper around EnterResourceNoLock that takes a host resource. This is used |
| 19 // when handling messages in the plugin from the host and we need to convert to | 19 // when handling messages in the plugin from the host and we need to convert to |
| 20 // an object in the plugin side corresponding to that. | 20 // an object in the plugin side corresponding to that. |
| 21 // | 21 // |
| 22 // This never locks since we assume the host Resource is coming from IPC, and | 22 // This never locks since we assume the host Resource is coming from IPC, and |
| 23 // never logs errors since we assume the host is doing reasonable things. | 23 // never logs errors since we assume the host is doing reasonable things. |
| 24 template<typename ResourceT> | 24 template<typename ResourceT> |
| 25 class EnterPluginFromHostResource | 25 class EnterPluginFromHostResource |
| 26 : public ::ppapi::thunk::EnterResourceNoLock<ResourceT> { | 26 : public thunk::EnterResourceNoLock<ResourceT> { |
| 27 public: | 27 public: |
| 28 EnterPluginFromHostResource(const ppapi::HostResource& host_resource) | 28 EnterPluginFromHostResource(const HostResource& host_resource) |
| 29 : ::ppapi::thunk::EnterResourceNoLock<ResourceT>( | 29 : thunk::EnterResourceNoLock<ResourceT>( |
| 30 PluginResourceTracker::GetInstance()->PluginResourceForHostResource( | 30 PluginResourceTracker::GetInstance()->PluginResourceForHostResource( |
| 31 host_resource), | 31 host_resource), |
| 32 false) { | 32 false) { |
| 33 // Validate that we're in the plugin rather than the host. Otherwise this | 33 // Validate that we're in the plugin rather than the host. Otherwise this |
| 34 // object will do the wrong thing. In the plugin, the instance should have | 34 // object will do the wrong thing. In the plugin, the instance should have |
| 35 // a corresponding plugin dispatcher (assuming the resource is valid). | 35 // a corresponding plugin dispatcher (assuming the resource is valid). |
| 36 DCHECK(this->failed() || | 36 DCHECK(this->failed() || |
| 37 PluginDispatcher::GetForInstance(host_resource.instance())); | 37 PluginDispatcher::GetForInstance(host_resource.instance())); |
| 38 } | 38 } |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 template<typename ResourceT> | 41 template<typename ResourceT> |
| 42 class EnterHostFromHostResource | 42 class EnterHostFromHostResource |
| 43 : public ::ppapi::thunk::EnterResourceNoLock<ResourceT> { | 43 : public thunk::EnterResourceNoLock<ResourceT> { |
| 44 public: | 44 public: |
| 45 EnterHostFromHostResource(const ppapi::HostResource& host_resource) | 45 EnterHostFromHostResource(const HostResource& host_resource) |
| 46 : ::ppapi::thunk::EnterResourceNoLock<ResourceT>( | 46 : thunk::EnterResourceNoLock<ResourceT>( |
| 47 host_resource.host_resource(), false) { | 47 host_resource.host_resource(), false) { |
| 48 // Validate that we're in the host rather than the plugin. Otherwise this | 48 // Validate that we're in the host rather than the plugin. Otherwise this |
| 49 // object will do the wrong thing. In the host, the instance should have | 49 // object will do the wrong thing. In the host, the instance should have |
| 50 // a corresponding host disptacher (assuming the resource is valid). | 50 // a corresponding host disptacher (assuming the resource is valid). |
| 51 DCHECK(this->failed() || | 51 DCHECK(this->failed() || |
| 52 HostDispatcher::GetForInstance(host_resource.instance())); | 52 HostDispatcher::GetForInstance(host_resource.instance())); |
| 53 } | 53 } |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // Enters a resource and forces a completion callback to be issued. | 56 // Enters a resource and forces a completion callback to be issued. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 84 // Send(new FooMsg_FooComplete(..., result, res)); | 84 // Send(new FooMsg_FooComplete(..., result, res)); |
| 85 // } | 85 // } |
| 86 template<typename ResourceT> | 86 template<typename ResourceT> |
| 87 class EnterHostFromHostResourceForceCallback | 87 class EnterHostFromHostResourceForceCallback |
| 88 : public EnterHostFromHostResource<ResourceT> { | 88 : public EnterHostFromHostResource<ResourceT> { |
| 89 public: | 89 public: |
| 90 // For callbacks that take no parameters except the "int32_t result". Most | 90 // For callbacks that take no parameters except the "int32_t result". Most |
| 91 // implementations will use the 1-extra-argument constructor below. | 91 // implementations will use the 1-extra-argument constructor below. |
| 92 template<class CallbackFactory, typename Method> | 92 template<class CallbackFactory, typename Method> |
| 93 EnterHostFromHostResourceForceCallback( | 93 EnterHostFromHostResourceForceCallback( |
| 94 const ppapi::HostResource& host_resource, | 94 const HostResource& host_resource, |
| 95 CallbackFactory& factory, | 95 CallbackFactory& factory, |
| 96 Method method) | 96 Method method) |
| 97 : EnterHostFromHostResource<ResourceT>(host_resource), | 97 : EnterHostFromHostResource<ResourceT>(host_resource), |
| 98 needs_running_(true), | 98 needs_running_(true), |
| 99 callback_(factory.NewOptionalCallback(method)) { | 99 callback_(factory.NewOptionalCallback(method)) { |
| 100 if (this->failed()) | 100 if (this->failed()) |
| 101 RunCallback(PP_ERROR_BADRESOURCE); | 101 RunCallback(PP_ERROR_BADRESOURCE); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // For callbacks that take an extra parameter as a closure. | 104 // For callbacks that take an extra parameter as a closure. |
| 105 template<class CallbackFactory, typename Method, typename A> | 105 template<class CallbackFactory, typename Method, typename A> |
| 106 EnterHostFromHostResourceForceCallback( | 106 EnterHostFromHostResourceForceCallback( |
| 107 const ppapi::HostResource& host_resource, | 107 const HostResource& host_resource, |
| 108 CallbackFactory& factory, | 108 CallbackFactory& factory, |
| 109 Method method, | 109 Method method, |
| 110 const A& a) | 110 const A& a) |
| 111 : EnterHostFromHostResource<ResourceT>(host_resource), | 111 : EnterHostFromHostResource<ResourceT>(host_resource), |
| 112 needs_running_(true), | 112 needs_running_(true), |
| 113 callback_(factory.NewOptionalCallback(method, a)) { | 113 callback_(factory.NewOptionalCallback(method, a)) { |
| 114 if (this->failed()) | 114 if (this->failed()) |
| 115 RunCallback(PP_ERROR_BADRESOURCE); | 115 RunCallback(PP_ERROR_BADRESOURCE); |
| 116 } | 116 } |
| 117 | 117 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 139 DCHECK(needs_running_); | 139 DCHECK(needs_running_); |
| 140 needs_running_ = false; | 140 needs_running_ = false; |
| 141 callback_.Run(result); | 141 callback_.Run(result); |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool needs_running_; | 144 bool needs_running_; |
| 145 pp::CompletionCallback callback_; | 145 pp::CompletionCallback callback_; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 } // namespace proxy | 148 } // namespace proxy |
| 149 } // namespace pp | 149 } // namespace ppapi |
| 150 | 150 |
| 151 #endif // PPAPI_PROXY_ENTER_PROXY_H_ | 151 #endif // PPAPI_PROXY_ENTER_PROXY_H_ |
| OLD | NEW |