| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" |
| 16 #include "ppapi/c/pp_instance.h" | 17 #include "ppapi/c/pp_instance.h" |
| 17 #include "ppapi/c/pp_module.h" | 18 #include "ppapi/c/pp_module.h" |
| 18 #include "ppapi/c/pp_resource.h" | 19 #include "ppapi/c/pp_resource.h" |
| 20 #include "ppapi/proxy/interface_id.h" |
| 21 #include "ppapi/shared_impl/function_group_base.h" |
| 22 #include "ppapi/shared_impl/tracker_base.h" |
| 19 | 23 |
| 20 namespace webkit { | 24 namespace webkit { |
| 21 namespace ppapi { | 25 namespace ppapi { |
| 22 | 26 |
| 23 class PluginInstance; | 27 class PluginInstance; |
| 24 class PluginModule; | 28 class PluginModule; |
| 25 class Resource; | 29 class Resource; |
| 26 class ResourceTrackerTest; | 30 class ResourceTrackerTest; |
| 27 class Var; | 31 class Var; |
| 28 | 32 |
| 29 // This class maintains a global list of all live pepper resources. It allows | 33 // This class maintains a global list of all live pepper resources. It allows |
| 30 // us to check resource ID validity and to map them to a specific module. | 34 // us to check resource ID validity and to map them to a specific module. |
| 31 // | 35 // |
| 32 // This object is NOT threadsafe. | 36 // This object is NOT threadsafe. |
| 33 class ResourceTracker { | 37 class ResourceTracker : public ::ppapi::shared_impl::TrackerBase { |
| 34 public: | 38 public: |
| 35 // Returns the pointer to the singleton object. | 39 // Returns the pointer to the singleton object. |
| 36 static ResourceTracker* Get(); | 40 static ResourceTracker* Get(); |
| 37 | 41 |
| 38 // PP_Resources -------------------------------------------------------------- | 42 // PP_Resources -------------------------------------------------------------- |
| 39 | 43 |
| 40 // The returned pointer will be NULL if there is no resource. Note that this | 44 // The returned pointer will be NULL if there is no resource. Note that this |
| 41 // return value is a scoped_refptr so that we ensure the resource is valid | 45 // return value is a scoped_refptr so that we ensure the resource is valid |
| 42 // from the point of the lookup to the point that the calling code needs it. | 46 // from the point of the lookup to the point that the calling code needs it. |
| 43 // Otherwise, the plugin could Release() the resource on another thread and | 47 // Otherwise, the plugin could Release() the resource on another thread and |
| 44 // the object will get deleted out from under us. | 48 // the object will get deleted out from under us. |
| 45 scoped_refptr<Resource> GetResource(PP_Resource res) const; | 49 scoped_refptr<Resource> GetResource(PP_Resource res) const; |
| 46 | 50 |
| 47 // Increment resource's plugin refcount. See ResourceAndRefCount comments | 51 // Increment resource's plugin refcount. See ResourceAndRefCount comments |
| 48 // below. | 52 // below. |
| 49 bool AddRefResource(PP_Resource res); | 53 bool AddRefResource(PP_Resource res); |
| 50 bool UnrefResource(PP_Resource res); | 54 bool UnrefResource(PP_Resource res); |
| 51 | 55 |
| 52 // Returns the number of resources associated with this module. | 56 // Returns the number of resources associated with this module. |
| 53 uint32 GetLiveObjectsForInstance(PP_Instance instance) const; | 57 uint32 GetLiveObjectsForInstance(PP_Instance instance) const; |
| 54 | 58 |
| 59 // ResourceTrackerBase. |
| 60 virtual ::ppapi::shared_impl::ResourceObjectBase* GetResourceAPI( |
| 61 PP_Resource res); |
| 62 virtual ::ppapi::shared_impl::FunctionGroupBase* GetFunctionAPI( |
| 63 PP_Instance inst, |
| 64 pp::proxy::InterfaceID id); |
| 65 |
| 55 // PP_Vars ------------------------------------------------------------------- | 66 // PP_Vars ------------------------------------------------------------------- |
| 56 | 67 |
| 57 scoped_refptr<Var> GetVar(int32 var_id) const; | 68 scoped_refptr<Var> GetVar(int32 var_id) const; |
| 58 | 69 |
| 59 bool AddRefVar(int32 var_id); | 70 bool AddRefVar(int32 var_id); |
| 60 bool UnrefVar(int32 var_id); | 71 bool UnrefVar(int32 var_id); |
| 61 | 72 |
| 62 // PP_Modules ---------------------------------------------------------------- | 73 // PP_Modules ---------------------------------------------------------------- |
| 63 | 74 |
| 64 // Adds a new plugin module to the list of tracked module, and returns a new | 75 // Adds a new plugin module to the list of tracked module, and returns a new |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 181 |
| 171 // Tracks all live instances and their associated data. | 182 // Tracks all live instances and their associated data. |
| 172 typedef std::map<PP_Instance, InstanceData> InstanceMap; | 183 typedef std::map<PP_Instance, InstanceData> InstanceMap; |
| 173 InstanceMap instance_map_; | 184 InstanceMap instance_map_; |
| 174 | 185 |
| 175 // Tracks all live modules. The pointers are non-owning, the PluginModule | 186 // Tracks all live modules. The pointers are non-owning, the PluginModule |
| 176 // destructor will notify us when the module is deleted. | 187 // destructor will notify us when the module is deleted. |
| 177 typedef std::map<PP_Module, PluginModule*> ModuleMap; | 188 typedef std::map<PP_Module, PluginModule*> ModuleMap; |
| 178 ModuleMap module_map_; | 189 ModuleMap module_map_; |
| 179 | 190 |
| 191 scoped_ptr< ::ppapi::shared_impl::FunctionGroupBase > |
| 192 function_proxies_[::pp::proxy::INTERFACE_ID_COUNT]; |
| 193 |
| 180 DISALLOW_COPY_AND_ASSIGN(ResourceTracker); | 194 DISALLOW_COPY_AND_ASSIGN(ResourceTracker); |
| 181 }; | 195 }; |
| 182 | 196 |
| 183 } // namespace ppapi | 197 } // namespace ppapi |
| 184 } // namespace webkit | 198 } // namespace webkit |
| 185 | 199 |
| 186 #endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ | 200 #endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ |
| OLD | NEW |