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 WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ |
6 #define WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 18 matching lines...) Expand all Loading... |
29 namespace ppapi { | 29 namespace ppapi { |
30 class NPObjectVar; | 30 class NPObjectVar; |
31 class Var; | 31 class Var; |
32 } | 32 } |
33 | 33 |
34 namespace webkit { | 34 namespace webkit { |
35 namespace ppapi { | 35 namespace ppapi { |
36 | 36 |
37 class PluginInstance; | 37 class PluginInstance; |
38 class PluginModule; | 38 class PluginModule; |
39 class Resource; | |
40 class ResourceTrackerTest; | 39 class ResourceTrackerTest; |
41 | 40 |
42 // This class maintains a global list of all live pepper resources. It allows | 41 // This class maintains a global list of all live pepper resources. It allows |
43 // us to check resource ID validity and to map them to a specific module. | 42 // us to check resource ID validity and to map them to a specific module. |
44 // | 43 // |
45 // This object is NOT threadsafe. | 44 // This object is NOT threadsafe. |
46 class ResourceTracker : public ::ppapi::TrackerBase, | 45 class ResourceTracker : public ::ppapi::TrackerBase, |
47 public ::ppapi::ResourceTracker { | 46 public ::ppapi::ResourceTracker { |
48 public: | 47 public: |
49 // Returns the pointer to the singleton object. | 48 // Returns the pointer to the singleton object. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 void InstanceDeleted(PP_Instance instance); | 101 void InstanceDeleted(PP_Instance instance); |
103 | 102 |
104 void InstanceCrashed(PP_Instance instance); | 103 void InstanceCrashed(PP_Instance instance); |
105 | 104 |
106 // Returns a pointer to the plugin instance object associated with the given | 105 // Returns a pointer to the plugin instance object associated with the given |
107 // instance handle. The return value will be NULL if the handle is invalid or | 106 // instance handle. The return value will be NULL if the handle is invalid or |
108 // if the instance has crashed. | 107 // if the instance has crashed. |
109 PluginInstance* GetInstance(PP_Instance instance); | 108 PluginInstance* GetInstance(PP_Instance instance); |
110 | 109 |
111 private: | 110 private: |
112 friend class Resource; | |
113 friend class ResourceTrackerTest; | 111 friend class ResourceTrackerTest; |
114 | 112 |
115 typedef std::set<PP_Resource> ResourceSet; | 113 typedef std::set<PP_Resource> ResourceSet; |
116 | 114 |
117 // Per-instance data we track. | 115 // Per-instance data we track. |
118 struct InstanceData; | 116 struct InstanceData; |
119 | 117 |
120 // Prohibit creation other then by the Singleton class. | 118 // Prohibit creation other then by the Singleton class. |
121 ResourceTracker(); | 119 ResourceTracker(); |
122 virtual ~ResourceTracker(); | 120 virtual ~ResourceTracker(); |
(...skipping 25 matching lines...) Expand all Loading... |
148 // layer via the delegate, which may be in a random state of shutdown. | 146 // layer via the delegate, which may be in a random state of shutdown. |
149 // | 147 // |
150 // So effectively our rule is: any resources still around at shutdown are | 148 // So effectively our rule is: any resources still around at shutdown are |
151 // associated with leaked plugins in WebKit, so it's also OK to leak those | 149 // associated with leaked plugins in WebKit, so it's also OK to leak those |
152 // resources from here (avoiding the shutdown race). | 150 // resources from here (avoiding the shutdown race). |
153 static ResourceTracker* global_tracker_; | 151 static ResourceTracker* global_tracker_; |
154 | 152 |
155 // See SetSingletonOverride above. | 153 // See SetSingletonOverride above. |
156 static ResourceTracker* singleton_override_; | 154 static ResourceTracker* singleton_override_; |
157 | 155 |
158 // Last assigned resource ID. | |
159 PP_Resource last_resource_id_; | |
160 | |
161 ::ppapi::VarTracker var_tracker_; | 156 ::ppapi::VarTracker var_tracker_; |
162 | 157 |
163 // For each PP_Resource, keep the Resource* (as refptr) and plugin use count. | |
164 // This use count is different then Resource's RefCount, and is manipulated | |
165 // using this AddRefResource/UnrefResource. When it drops to zero, we just | |
166 // remove the resource from this resource tracker, but the resource object | |
167 // will be alive so long as some scoped_refptr still holds it's | |
168 // reference. This prevents plugins from forcing destruction of Resource | |
169 // objects. | |
170 typedef std::pair<scoped_refptr<Resource>, size_t> ResourceAndRefCount; | |
171 typedef base::hash_map<PP_Resource, ResourceAndRefCount> ResourceMap; | |
172 ResourceMap live_resources_; | |
173 | |
174 // Like ResourceAndRefCount but for vars, which are associated with modules. | 158 // Like ResourceAndRefCount but for vars, which are associated with modules. |
175 typedef std::pair<scoped_refptr< ::ppapi::Var>, size_t> VarAndRefCount; | 159 typedef std::pair<scoped_refptr< ::ppapi::Var>, size_t> VarAndRefCount; |
176 typedef base::hash_map<int32, VarAndRefCount> VarMap; | 160 typedef base::hash_map<int32, VarAndRefCount> VarMap; |
177 VarMap live_vars_; | 161 VarMap live_vars_; |
178 | 162 |
179 // Tracks all live instances and their associated data. | 163 // Tracks all live instances and their associated data. |
180 typedef std::map<PP_Instance, linked_ptr<InstanceData> > InstanceMap; | 164 typedef std::map<PP_Instance, linked_ptr<InstanceData> > InstanceMap; |
181 InstanceMap instance_map_; | 165 InstanceMap instance_map_; |
182 | 166 |
183 // Tracks all live modules. The pointers are non-owning, the PluginModule | 167 // Tracks all live modules. The pointers are non-owning, the PluginModule |
184 // destructor will notify us when the module is deleted. | 168 // destructor will notify us when the module is deleted. |
185 typedef std::map<PP_Module, PluginModule*> ModuleMap; | 169 typedef std::map<PP_Module, PluginModule*> ModuleMap; |
186 ModuleMap module_map_; | 170 ModuleMap module_map_; |
187 | 171 |
188 DISALLOW_COPY_AND_ASSIGN(ResourceTracker); | 172 DISALLOW_COPY_AND_ASSIGN(ResourceTracker); |
189 }; | 173 }; |
190 | 174 |
191 } // namespace ppapi | 175 } // namespace ppapi |
192 } // namespace webkit | 176 } // namespace webkit |
193 | 177 |
194 #endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ | 178 #endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ |
OLD | NEW |