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