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_PLUGIN_RESOURCE_TRACKER_H_ | 5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_ |
6 #define PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_ | 6 #define PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "ppapi/c/pp_completion_callback.h" | 12 #include "ppapi/c/pp_completion_callback.h" |
13 #include "ppapi/c/pp_instance.h" | 13 #include "ppapi/c/pp_instance.h" |
14 #include "ppapi/c/pp_stdint.h" | 14 #include "ppapi/c/pp_stdint.h" |
15 #include "ppapi/c/pp_resource.h" | 15 #include "ppapi/c/pp_resource.h" |
16 #include "ppapi/c/pp_var.h" | 16 #include "ppapi/c/pp_var.h" |
17 #include "ppapi/proxy/plugin_var_tracker.h" | 17 #include "ppapi/proxy/plugin_var_tracker.h" |
18 #include "ppapi/shared_impl/host_resource.h" | 18 #include "ppapi/shared_impl/host_resource.h" |
19 #include "ppapi/shared_impl/resource_tracker.h" | 19 #include "ppapi/shared_impl/resource_tracker.h" |
20 #include "ppapi/shared_impl/tracker_base.h" | 20 #include "ppapi/shared_impl/tracker_base.h" |
21 | 21 |
22 template<typename T> struct DefaultSingletonTraits; | 22 template<typename T> struct DefaultSingletonTraits; |
23 | 23 |
24 namespace ppapi { | 24 namespace ppapi { |
| 25 |
25 class Var; | 26 class Var; |
26 } | |
27 | 27 |
28 namespace pp { | |
29 namespace proxy { | 28 namespace proxy { |
30 | 29 |
31 class PluginDispatcher; | 30 class PluginDispatcher; |
32 | 31 |
33 class PluginResourceTracker : public ppapi::TrackerBase, | 32 class PluginResourceTracker : public TrackerBase, public ResourceTracker { |
34 public ppapi::ResourceTracker { | |
35 public: | 33 public: |
36 // Called by tests that want to specify a specific ResourceTracker. This | 34 // Called by tests that want to specify a specific ResourceTracker. This |
37 // allows them to use a unique one each time and avoids singletons sticking | 35 // allows them to use a unique one each time and avoids singletons sticking |
38 // around across tests. | 36 // around across tests. |
39 static void SetInstanceForTest(PluginResourceTracker* tracker); | 37 static void SetInstanceForTest(PluginResourceTracker* tracker); |
40 | 38 |
41 // Returns the global singleton resource tracker for the plugin. | 39 // Returns the global singleton resource tracker for the plugin. |
42 static PluginResourceTracker* GetInstance(); | 40 static PluginResourceTracker* GetInstance(); |
43 static ::ppapi::TrackerBase* GetTrackerBaseInstance(); | 41 static TrackerBase* GetTrackerBaseInstance(); |
44 | 42 |
45 // Given a host resource, maps it to an existing plugin resource ID if it | 43 // Given a host resource, maps it to an existing plugin resource ID if it |
46 // exists, or returns 0 on failure. | 44 // exists, or returns 0 on failure. |
47 PP_Resource PluginResourceForHostResource( | 45 PP_Resource PluginResourceForHostResource( |
48 const ppapi::HostResource& resource) const; | 46 const HostResource& resource) const; |
49 | 47 |
50 PluginVarTracker& var_tracker() { | 48 PluginVarTracker& var_tracker() { |
51 return var_tracker_test_override_ ? *var_tracker_test_override_ | 49 return var_tracker_test_override_ ? *var_tracker_test_override_ |
52 : var_tracker_; | 50 : var_tracker_; |
53 } | 51 } |
54 | 52 |
55 void set_var_tracker_test_override(PluginVarTracker* t) { | 53 void set_var_tracker_test_override(PluginVarTracker* t) { |
56 var_tracker_test_override_ = t; | 54 var_tracker_test_override_ = t; |
57 } | 55 } |
58 | 56 |
59 // TrackerBase. | 57 // TrackerBase. |
60 virtual ppapi::FunctionGroupBase* GetFunctionAPI( | 58 virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst, |
61 PP_Instance inst, | 59 InterfaceID id) OVERRIDE; |
62 pp::proxy::InterfaceID id) OVERRIDE; | 60 virtual VarTracker* GetVarTracker() OVERRIDE; |
63 virtual ppapi::VarTracker* GetVarTracker() OVERRIDE; | 61 virtual ResourceTracker* GetResourceTracker() OVERRIDE; |
64 virtual ppapi::ResourceTracker* GetResourceTracker() OVERRIDE; | |
65 | 62 |
66 protected: | 63 protected: |
67 // ResourceTracker overrides. | 64 // ResourceTracker overrides. |
68 virtual PP_Resource AddResource(ppapi::Resource* object) OVERRIDE; | 65 virtual PP_Resource AddResource(Resource* object) OVERRIDE; |
69 virtual void RemoveResource(ppapi::Resource* object) OVERRIDE; | 66 virtual void RemoveResource(Resource* object) OVERRIDE; |
70 | 67 |
71 private: | 68 private: |
72 friend struct DefaultSingletonTraits<PluginResourceTracker>; | 69 friend struct DefaultSingletonTraits<PluginResourceTracker>; |
73 friend class PluginResourceTrackerTest; | 70 friend class PluginResourceTrackerTest; |
74 friend class PluginProxyTestHarness; | 71 friend class PluginProxyTestHarness; |
75 | 72 |
76 PluginResourceTracker(); | 73 PluginResourceTracker(); |
77 virtual ~PluginResourceTracker(); | 74 virtual ~PluginResourceTracker(); |
78 | 75 |
79 // Use the var_tracker_test_override_ instead if it's non-NULL. | 76 // Use the var_tracker_test_override_ instead if it's non-NULL. |
80 // | 77 // |
81 // TODO(brettw) this should be somehow separated out from here. I'm thinking | 78 // TODO(brettw) this should be somehow separated out from here. I'm thinking |
82 // of some global object that manages PPAPI globals, including separate var | 79 // of some global object that manages PPAPI globals, including separate var |
83 // and resource trackers. | 80 // and resource trackers. |
84 PluginVarTracker var_tracker_; | 81 PluginVarTracker var_tracker_; |
85 | 82 |
86 // Non-owning pointer to a var tracker mock used by tests. NULL when no | 83 // Non-owning pointer to a var tracker mock used by tests. NULL when no |
87 // test implementation is provided. | 84 // test implementation is provided. |
88 PluginVarTracker* var_tracker_test_override_; | 85 PluginVarTracker* var_tracker_test_override_; |
89 | 86 |
90 // Map of host instance/resource pairs to a plugin resource ID. | 87 // Map of host instance/resource pairs to a plugin resource ID. |
91 typedef std::map<ppapi::HostResource, PP_Resource> HostResourceMap; | 88 typedef std::map<HostResource, PP_Resource> HostResourceMap; |
92 HostResourceMap host_resource_map_; | 89 HostResourceMap host_resource_map_; |
93 | 90 |
94 DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker); | 91 DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker); |
95 }; | 92 }; |
96 | 93 |
97 } // namespace proxy | 94 } // namespace proxy |
98 } // namespace pp | 95 } // namespace ppapi |
99 | 96 |
100 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_ | 97 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_ |
OLD | NEW |