OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef PPAPI_PROXY_ENTER_PROXY_H_ | |
6 #define PPAPI_PROXY_ENTER_PROXY_H_ | |
7 | |
8 #include "base/logging.h" | |
9 #include "ppapi/proxy/host_dispatcher.h" | |
10 #include "ppapi/proxy/plugin_dispatcher.h" | |
11 #include "ppapi/proxy/plugin_resource_tracker.h" | |
12 #include "ppapi/thunk/enter.h" | |
13 | |
14 namespace pp { | |
15 namespace proxy { | |
16 | |
17 // Wrapper around EnterResourceNoLock that takes a host resource. This is used | |
18 // when handling messages in the plugin from the host and we need to convert to | |
19 // an object in the plugin side corresponding to that. | |
20 // | |
21 // This never locks since we assume the host Resource is coming from IPC, and | |
22 // never logs errors since we assume the host is doing reasonable things. | |
23 template<typename ResourceT> | |
24 class EnterPluginFromHostResource | |
25 : public ::ppapi::thunk::EnterResourceNoLock<ResourceT> { | |
26 public: | |
27 EnterPluginFromHostResource(const HostResource& host_resource) | |
28 : ::ppapi::thunk::EnterResourceNoLock<ResourceT>( | |
29 PluginResourceTracker::GetInstance()->PluginResourceForHostResource( | |
30 host_resource), | |
31 false) { | |
32 // Validate that we're in the plugin rather than the host. Otherwise this | |
33 // object will do the wrong thing. In the plugin, the instance should have | |
34 // a corresponding plugin dispatcher (assuming the resource is valid). | |
35 DCHECK(this->failed() || | |
36 PluginDispatcher::GetForInstance(host_resource.instance())); | |
37 } | |
38 }; | |
39 | |
40 template<typename ResourceT> | |
41 class EnterHostFromHostResource | |
42 : public ::ppapi::thunk::EnterResourceNoLock<ResourceT> { | |
43 public: | |
44 EnterHostFromHostResource(const HostResource& host_resource) | |
45 : ::ppapi::thunk::EnterResourceNoLock<ResourceT>( | |
46 host_resource.host_resource(), false) { | |
47 // Validate that we're in the host rather than the plugin. Otherwise this | |
48 // object will do the wrong thing. In the host, the instance should have | |
49 // a corresponding host disptacher (assuming the resource is valid). | |
50 DCHECK(this->failed() || | |
51 HostDispatcher::GetForInstance(host_resource.instance())); | |
52 } | |
53 }; | |
54 | |
55 } // namespace proxy | |
56 } // namespace pp | |
57 | |
58 #endif // PPAPI_PROXY_ENTER_PROXY_H_ | |
OLD | NEW |