| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_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 <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/lock.h" | 12 #include "base/lock.h" |
| 13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 #include "base/singleton.h" | 14 #include "base/singleton.h" |
| 15 #include "third_party/ppapi/c/pp_resource.h" | 15 #include "third_party/ppapi/c/pp_resource.h" |
| 16 | 16 |
| 17 namespace pepper { | 17 namespace pepper { |
| 18 | 18 |
| 19 class Buffer; | 19 class Buffer; |
| 20 class DeviceContext2D; | 20 class DeviceContext2D; |
| 21 class ImageData; | 21 class ImageData; |
| 22 class Resource; | 22 class Resource; |
| 23 class URLLoader; |
| 24 class URLRequestInfo; |
| 25 class URLResponseInfo; |
| 23 | 26 |
| 24 // This class maintains a global list of all live pepper resources. It allows | 27 // This class maintains a global list of all live pepper resources. It allows |
| 25 // us to check resource ID validity and to map them to a specific module. | 28 // us to check resource ID validity and to map them to a specific module. |
| 26 // | 29 // |
| 27 // This object is threadsafe. | 30 // This object is threadsafe. |
| 28 class ResourceTracker { | 31 class ResourceTracker { |
| 29 public: | 32 public: |
| 30 // Returns the pointer to the singleton object. | 33 // Returns the pointer to the singleton object. |
| 31 static ResourceTracker* Get(); | 34 static ResourceTracker* Get(); |
| 32 | 35 |
| 33 // The returned pointer will be NULL if there is no resource. Note that this | 36 // The returned pointer will be NULL if there is no resource. Note that this |
| 34 // return value is a scoped_refptr so that we ensure the resource is valid | 37 // return value is a scoped_refptr so that we ensure the resource is valid |
| 35 // from the point of the loopkup to the point that the calling code needs it. | 38 // from the point of the loopkup to the point that the calling code needs it. |
| 36 // Otherwise, the plugin could Release() the resource on another thread and | 39 // Otherwise, the plugin could Release() the resource on another thread and |
| 37 // the object will get deleted out from under us. | 40 // the object will get deleted out from under us. |
| 38 scoped_refptr<Resource> GetResource(PP_Resource res) const; | 41 scoped_refptr<Resource> GetResource(PP_Resource res) const; |
| 39 | 42 |
| 40 // Adds the given resource to the tracker and assigns it a resource ID. The | 43 // Adds the given resource to the tracker and assigns it a resource ID. The |
| 41 // assigned resource ID will be returned. | 44 // assigned resource ID will be returned. |
| 42 void AddResource(Resource* resource); | 45 void AddResource(Resource* resource); |
| 43 | 46 |
| 44 void DeleteResource(Resource* resource); | 47 void DeleteResource(Resource* resource); |
| 45 | 48 |
| 46 // Helpers for converting resources to a specific type. Returns NULL if the | 49 // Helpers for converting resources to a specific type. Returns NULL if the |
| 47 // resource is invalid or is a different type. | 50 // resource is invalid or is a different type. |
| 48 scoped_refptr<DeviceContext2D> GetAsDeviceContext2D(PP_Resource res) const; | 51 scoped_refptr<DeviceContext2D> GetAsDeviceContext2D(PP_Resource res) const; |
| 49 scoped_refptr<ImageData> GetAsImageData(PP_Resource res) const; | 52 scoped_refptr<ImageData> GetAsImageData(PP_Resource res) const; |
| 53 scoped_refptr<URLLoader> GetAsURLLoader(PP_Resource res) const; |
| 54 scoped_refptr<URLRequestInfo> GetAsURLRequestInfo(PP_Resource res) const; |
| 55 scoped_refptr<URLResponseInfo> GetAsURLResponseInfo(PP_Resource res) const; |
| 50 scoped_refptr<Buffer> GetAsBuffer(PP_Resource res) const; | 56 scoped_refptr<Buffer> GetAsBuffer(PP_Resource res) const; |
| 51 | 57 |
| 52 private: | 58 private: |
| 53 friend struct DefaultSingletonTraits<ResourceTracker>; | 59 friend struct DefaultSingletonTraits<ResourceTracker>; |
| 54 | 60 |
| 55 ResourceTracker(); | 61 ResourceTracker(); |
| 56 ~ResourceTracker(); | 62 ~ResourceTracker(); |
| 57 | 63 |
| 58 // Hold this lock when accessing this object's members. | 64 // Hold this lock when accessing this object's members. |
| 59 mutable Lock lock_; | 65 mutable Lock lock_; |
| 60 | 66 |
| 61 typedef std::set<Resource*> ResourceSet; | 67 typedef std::set<Resource*> ResourceSet; |
| 62 ResourceSet live_resources_; | 68 ResourceSet live_resources_; |
| 63 | 69 |
| 64 DISALLOW_COPY_AND_ASSIGN(ResourceTracker); | 70 DISALLOW_COPY_AND_ASSIGN(ResourceTracker); |
| 65 }; | 71 }; |
| 66 | 72 |
| 67 } // namespace pepper | 73 } // namespace pepper |
| 68 | 74 |
| 69 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_ | 75 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_ |
| OLD | NEW |