| OLD | NEW |
| 1 // Copyright (c) 2010 The Native Client Authors. All rights reserved. | 1 // Copyright (c) 2011 The Native Client 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_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_ | 5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_ |
| 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_ | 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "native_client/src/include/nacl_base.h" | 11 #include "native_client/src/include/nacl_base.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 36 // Increment resource's plugin refcount. See ResourceAndRefCount. | 36 // Increment resource's plugin refcount. See ResourceAndRefCount. |
| 37 bool AddRefResource(PP_Resource res); | 37 bool AddRefResource(PP_Resource res); |
| 38 bool UnrefResource(PP_Resource res); | 38 bool UnrefResource(PP_Resource res); |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 friend class PluginResource; | 41 friend class PluginResource; |
| 42 | 42 |
| 43 // Prohibit creation other then by the Singleton class. | 43 // Prohibit creation other then by the Singleton class. |
| 44 PluginResourceTracker(); | 44 PluginResourceTracker(); |
| 45 | 45 |
| 46 // Adds the given resource to the tracker and assigns it a resource ID and | 46 // Adds the given resource to the tracker and assigns it a resource ID, local |
| 47 // refcount of 1. Used only by the Resource class. | 47 // refcount of 1, and initializes the browser reference count to |
| 48 void AddResource(PluginResource* resource, PP_Resource id); | 48 // |browser_refcount|. Used only by the Resource class. |
| 49 void AddResource(PluginResource* resource, PP_Resource id, |
| 50 size_t browser_refcount); |
| 49 | 51 |
| 50 // The returned pointer will be NULL if there is no resource. Note that this | 52 // The returned pointer will be NULL if there is no resource. Note that this |
| 51 // return value is a scoped_refptr so that we ensure the resource is valid | 53 // return value is a scoped_refptr so that we ensure the resource is valid |
| 52 // from the point of the lookup to the point that the calling code needs it. | 54 // from the point of the lookup to the point that the calling code needs it. |
| 53 // Otherwise, the plugin could Release() the resource on another thread and | 55 // Otherwise, the plugin could Release() the resource on another thread and |
| 54 // the object will get deleted out from under us. | 56 // the object will get deleted out from under us. |
| 55 scoped_refptr<PluginResource> GetExistingResource(PP_Resource res) const; | 57 scoped_refptr<PluginResource> GetExistingResource(PP_Resource res) const; |
| 56 | 58 |
| 57 // Get or create a new PluginResource from a browser resource. | 59 // Get or create a new PluginResource from a browser resource. |
| 58 // If we are already tracking this resource, we bump its browser_refcount to | 60 // If we are already tracking this resource, we bump its browser_refcount to |
| 59 // reflect that we took ownership of it. If this is a new resource, we create | 61 // reflect that we took ownership of it. If this is a new resource, we create |
| 60 // a PluginResource for it with browser_refcount 1. | 62 // a PluginResource for it with the given browser_refcount. |
| 61 template<typename T> scoped_refptr<T> AdoptBrowserResource(PP_Resource res); | 63 template<typename T> scoped_refptr<T> AdoptBrowserResource( |
| 64 PP_Resource res, size_t browser_refcount); |
| 62 | 65 |
| 63 // Try to get a browser-side refcount for an existing resource. | 66 // Try to get a browser-side refcount for an existing resource. |
| 64 void ObtainBrowserResource(PP_Resource res); | 67 void ObtainBrowserResource(PP_Resource res); |
| 65 | 68 |
| 66 // Release browser-side refcount. | 69 // Release browser-side refcount. |
| 67 void ReleaseBrowserResource(PP_Resource res, size_t refcount); | 70 void ReleaseBrowserResource(PP_Resource res, size_t refcount); |
| 68 | 71 |
| 69 // Last assigned resource ID. | 72 // Last assigned resource ID. |
| 70 PP_Resource last_id_; | 73 PP_Resource last_id_; |
| 71 | 74 |
| 72 struct ResourceAndRefCounts { | 75 struct ResourceAndRefCounts { |
| 73 scoped_refptr<PluginResource> resource; | 76 scoped_refptr<PluginResource> resource; |
| 74 size_t browser_refcount; | 77 size_t browser_refcount; |
| 75 size_t plugin_refcount; | 78 size_t plugin_refcount; |
| 76 explicit ResourceAndRefCounts(PluginResource* r); | 79 ResourceAndRefCounts(PluginResource* r, size_t browser_refcount); |
| 77 ~ResourceAndRefCounts(); | 80 ~ResourceAndRefCounts(); |
| 78 }; | 81 }; |
| 79 typedef std::map<PP_Resource, ResourceAndRefCounts> ResourceMap; | 82 typedef std::map<PP_Resource, ResourceAndRefCounts> ResourceMap; |
| 80 ResourceMap live_resources_; | 83 ResourceMap live_resources_; |
| 81 | 84 |
| 82 DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker); | 85 DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker); |
| 83 }; | 86 }; |
| 84 | 87 |
| 85 } // namespace ppapi_proxy | 88 } // namespace ppapi_proxy |
| 86 | 89 |
| 87 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_ | 90 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_ |
| 88 | 91 |
| OLD | NEW |