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 pp { |
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 ::ppapi::thunk::EnterResourceNoLock<ResourceT> { |
27 public: | 27 public: |
28 EnterPluginFromHostResource(const HostResource& host_resource) | 28 EnterPluginFromHostResource(const ppapi::HostResource& host_resource) |
29 : ::ppapi::thunk::EnterResourceNoLock<ResourceT>( | 29 : ::ppapi::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 ::ppapi::thunk::EnterResourceNoLock<ResourceT> { |
44 public: | 44 public: |
45 EnterHostFromHostResource(const HostResource& host_resource) | 45 EnterHostFromHostResource(const ppapi::HostResource& host_resource) |
46 : ::ppapi::thunk::EnterResourceNoLock<ResourceT>( | 46 : ::ppapi::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 |
(...skipping 27 matching lines...) Expand all Loading... |
83 // void MyClass::SendResult(int32_t result, const HostResource& res) { | 83 // void MyClass::SendResult(int32_t result, const HostResource& res) { |
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(const HostResource& host_resource, | 93 EnterHostFromHostResourceForceCallback( |
94 CallbackFactory& factory, | 94 const ppapi::HostResource& host_resource, |
95 Method method) | 95 CallbackFactory& factory, |
| 96 Method method) |
96 : EnterHostFromHostResource<ResourceT>(host_resource), | 97 : EnterHostFromHostResource<ResourceT>(host_resource), |
97 needs_running_(true), | 98 needs_running_(true), |
98 callback_(factory.NewOptionalCallback(method)) { | 99 callback_(factory.NewOptionalCallback(method)) { |
99 if (this->failed()) | 100 if (this->failed()) |
100 RunCallback(PP_ERROR_BADRESOURCE); | 101 RunCallback(PP_ERROR_BADRESOURCE); |
101 } | 102 } |
102 | 103 |
103 // For callbacks that take an extra parameter as a closure. | 104 // For callbacks that take an extra parameter as a closure. |
104 template<class CallbackFactory, typename Method, typename A> | 105 template<class CallbackFactory, typename Method, typename A> |
105 EnterHostFromHostResourceForceCallback(const HostResource& host_resource, | 106 EnterHostFromHostResourceForceCallback( |
106 CallbackFactory& factory, | 107 const ppapi::HostResource& host_resource, |
107 Method method, | 108 CallbackFactory& factory, |
108 const A& a) | 109 Method method, |
| 110 const A& a) |
109 : EnterHostFromHostResource<ResourceT>(host_resource), | 111 : EnterHostFromHostResource<ResourceT>(host_resource), |
110 needs_running_(true), | 112 needs_running_(true), |
111 callback_(factory.NewOptionalCallback(method, a)) { | 113 callback_(factory.NewOptionalCallback(method, a)) { |
112 if (this->failed()) | 114 if (this->failed()) |
113 RunCallback(PP_ERROR_BADRESOURCE); | 115 RunCallback(PP_ERROR_BADRESOURCE); |
114 } | 116 } |
115 | 117 |
116 ~EnterHostFromHostResourceForceCallback() { | 118 ~EnterHostFromHostResourceForceCallback() { |
117 if (needs_running_) { | 119 if (needs_running_) { |
118 NOTREACHED() << "Should always call SetResult except in the " | 120 NOTREACHED() << "Should always call SetResult except in the " |
(...skipping 21 matching lines...) Expand all Loading... |
140 } | 142 } |
141 | 143 |
142 bool needs_running_; | 144 bool needs_running_; |
143 pp::CompletionCallback callback_; | 145 pp::CompletionCallback callback_; |
144 }; | 146 }; |
145 | 147 |
146 } // namespace proxy | 148 } // namespace proxy |
147 } // namespace pp | 149 } // namespace pp |
148 | 150 |
149 #endif // PPAPI_PROXY_ENTER_PROXY_H_ | 151 #endif // PPAPI_PROXY_ENTER_PROXY_H_ |
OLD | NEW |