| 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_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ |
| 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "ppapi/c/pp_resource.h" | 10 #include "ppapi/c/pp_resource.h" |
| 11 #include "webkit/glue/plugins/pepper_resource_tracker.h" | 11 #include "webkit/plugins/ppapi/resource_tracker.h" |
| 12 | 12 |
| 13 namespace pepper { | 13 namespace webkit { |
| 14 namespace plugins { |
| 15 namespace ppapi { |
| 14 | 16 |
| 15 // If you inherit from resource, make sure you add the class name here. | 17 // If you inherit from resource, make sure you add the class name here. |
| 16 #define FOR_ALL_RESOURCES(F) \ | 18 #define FOR_ALL_RESOURCES(F) \ |
| 17 F(Audio) \ | |
| 18 F(AudioConfig) \ | |
| 19 F(Buffer) \ | |
| 20 F(DirectoryReader) \ | |
| 21 F(FileChooser) \ | |
| 22 F(FileIO) \ | |
| 23 F(FileRef) \ | |
| 24 F(FileSystem) \ | |
| 25 F(Font) \ | |
| 26 F(Graphics2D) \ | |
| 27 F(Graphics3D) \ | |
| 28 F(ImageData) \ | |
| 29 F(MockResource) \ | 19 F(MockResource) \ |
| 30 F(ObjectVar) \ | 20 F(ObjectVar) \ |
| 31 F(PluginModule) \ | 21 F(PPB_AudioConfig_Impl) \ |
| 32 F(PrivateFontFile) \ | 22 F(PPB_Audio_Impl) \ |
| 33 F(Scrollbar) \ | 23 F(PPB_Buffer_Impl) \ |
| 34 F(StringVar) \ | 24 F(PPB_DirectoryReader_Impl) \ |
| 35 F(Transport) \ | 25 F(PPB_FileChooser_Impl) \ |
| 36 F(URLLoader) \ | 26 F(PPB_FileIO_Impl) \ |
| 37 F(URLRequestInfo) \ | 27 F(PPB_FileRef_Impl) \ |
| 38 F(URLResponseInfo) \ | 28 F(PPB_FileSystem_Impl) \ |
| 29 F(PPB_Font_Impl) \ |
| 30 F(PPB_Graphics2D_Impl) \ |
| 31 F(PPB_Graphics3D_Impl) \ |
| 32 F(PPB_ImageData_Impl) \ |
| 33 F(PPB_PrivateFontFile_Impl) \ |
| 34 F(PPB_Scrollbar_Impl) \ |
| 35 F(PPB_StringVar_Impl) \ |
| 36 F(PPB_Transport_Impl) \ |
| 37 F(PPB_URLLoader_Impl) \ |
| 38 F(PPB_URLRequestInfo_Impl) \ |
| 39 F(PPB_URLResponseInfo_Impl) \ |
| 40 F(PPB_VideoDecoder_Impl) \ |
| 41 F(PPB_Widget_Impl) \ |
| 39 F(Var) \ | 42 F(Var) \ |
| 40 F(VarObjectClass) \ | 43 F(VarObjectClass) |
| 41 F(VideoDecoder) \ | |
| 42 F(Widget) | |
| 43 | 44 |
| 44 // Forward declaration of Resource classes. | 45 // Forward declaration of Resource classes. |
| 45 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; | 46 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; |
| 46 FOR_ALL_RESOURCES(DECLARE_RESOURCE_CLASS) | 47 FOR_ALL_RESOURCES(DECLARE_RESOURCE_CLASS) |
| 47 #undef DECLARE_RESOURCE_CLASS | 48 #undef DECLARE_RESOURCE_CLASS |
| 48 | 49 |
| 49 class Resource : public base::RefCountedThreadSafe<Resource> { | 50 class Resource : public base::RefCountedThreadSafe<Resource> { |
| 50 public: | 51 public: |
| 51 explicit Resource(PluginModule* module); | 52 explicit Resource(PluginModule* module); |
| 52 virtual ~Resource(); | 53 virtual ~Resource(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ResourceTracker::Get()->UnrefResource(id); | 97 ResourceTracker::Get()->UnrefResource(id); |
| 97 } | 98 } |
| 98 const PP_Resource id; | 99 const PP_Resource id; |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 private: | 102 private: |
| 102 // Type-specific getters for individual resource types. These will return | 103 // Type-specific getters for individual resource types. These will return |
| 103 // NULL if the resource does not match the specified type. Used by the Cast() | 104 // NULL if the resource does not match the specified type. Used by the Cast() |
| 104 // function. | 105 // function. |
| 105 #define DEFINE_TYPE_GETTER(RESOURCE) \ | 106 #define DEFINE_TYPE_GETTER(RESOURCE) \ |
| 106 virtual RESOURCE* As##RESOURCE() { return NULL; } | 107 virtual RESOURCE* As##RESOURCE(); |
| 107 FOR_ALL_RESOURCES(DEFINE_TYPE_GETTER) | 108 FOR_ALL_RESOURCES(DEFINE_TYPE_GETTER) |
| 108 #undef DEFINE_TYPE_GETTER | 109 #undef DEFINE_TYPE_GETTER |
| 109 | 110 |
| 110 // If referenced by a plugin, holds the id of this resource object. Do not | 111 // If referenced by a plugin, holds the id of this resource object. Do not |
| 111 // access this member directly, because it is possible that the plugin holds | 112 // access this member directly, because it is possible that the plugin holds |
| 112 // no references to the object, and therefore the resource_id_ is zero. Use | 113 // no references to the object, and therefore the resource_id_ is zero. Use |
| 113 // either GetReference() to obtain a new resource_id and increase the | 114 // either GetReference() to obtain a new resource_id and increase the |
| 114 // refcount, or TemporaryReference when you do not want to increase the | 115 // refcount, or TemporaryReference when you do not want to increase the |
| 115 // refcount. | 116 // refcount. |
| 116 PP_Resource resource_id_; | 117 PP_Resource resource_id_; |
| 117 | 118 |
| 118 // Non-owning pointer to our module. | 119 // Non-owning pointer to our module. |
| 119 PluginModule* module_; | 120 PluginModule* module_; |
| 120 | 121 |
| 121 // Called by the resource tracker when the last plugin reference has been | 122 // Called by the resource tracker when the last plugin reference has been |
| 122 // dropped. | 123 // dropped. |
| 123 friend class ResourceTracker; | 124 friend class ResourceTracker; |
| 124 void StoppedTracking(); | 125 void StoppedTracking(); |
| 125 | 126 |
| 126 DISALLOW_COPY_AND_ASSIGN(Resource); | 127 DISALLOW_COPY_AND_ASSIGN(Resource); |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 // Cast() specializations. | 130 // Cast() specializations. |
| 130 #define DEFINE_RESOURCE_CAST(Type) \ | 131 #define DEFINE_RESOURCE_CAST(Type) \ |
| 131 template <> inline Type* Resource::Cast<Type>() { \ | 132 template <> inline Type* Resource::Cast<Type>() { \ |
| 132 return As##Type(); \ | 133 return As##Type(); \ |
| 133 } | 134 } |
| 134 | 135 |
| 135 FOR_ALL_RESOURCES(DEFINE_RESOURCE_CAST) | 136 FOR_ALL_RESOURCES(DEFINE_RESOURCE_CAST) |
| 136 #undef DEFINE_RESOURCE_CAST | 137 #undef DEFINE_RESOURCE_CAST |
| 137 | 138 |
| 138 #undef FOR_ALL_RESOURCES | 139 } // namespace ppapi |
| 139 } // namespace pepper | 140 } // namespace plugins |
| 141 } // namespace webkit |
| 140 | 142 |
| 141 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_ | 143 #endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ |
| OLD | NEW |