Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Unified Diff: webkit/glue/plugins/pepper_resource.h

Issue 2800028: Simplfy Pepepr2 bolierplate code. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Updated. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/glue/plugins/pepper_plugin_module.cc ('k') | webkit/glue/plugins/pepper_resource_tracker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/plugins/pepper_resource.h
diff --git a/webkit/glue/plugins/pepper_resource.h b/webkit/glue/plugins/pepper_resource.h
index efcc2115d52b0e944602c4e194101f6eacb6a82a..fdb9d012ec66f7713c6c33f06c25db6dd8c0a5ac 100644
--- a/webkit/glue/plugins/pepper_resource.h
+++ b/webkit/glue/plugins/pepper_resource.h
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/ref_counted.h"
#include "third_party/ppapi/c/pp_resource.h"
+#include "webkit/glue/plugins/pepper_resource_tracker.h"
namespace pepper {
@@ -28,12 +29,26 @@ class Resource : public base::RefCountedThreadSafe<Resource> {
explicit Resource(PluginModule* module);
virtual ~Resource();
+ // Returns NULL if the resource is invalid or is a different type.
+ template<typename T>
+ static scoped_refptr<T> GetAs(PP_Resource res) {
+ scoped_refptr<Resource> resource = ResourceTracker::Get()->GetResource(res);
+ return resource ? resource->Cast<T>() : NULL;
+ }
+
PP_Resource GetResource() const;
PluginModule* module() const { return module_; }
+ // Cast the resource into a specified type. This will return NULL if the
+ // resource does not match the specified type. Specializations of this
+ // template call into As* functions.
+ template <typename T> T* Cast() { return NULL; }
+
+ private:
// Type-specific getters for individual resource types. These will return
- // NULL if the resource does not match the specified type.
+ // NULL if the resource does not match the specified type. Used by the Cast()
+ // function.
virtual Buffer* AsBuffer() { return NULL; }
virtual DeviceContext2D* AsDeviceContext2D() { return NULL; }
virtual DirectoryReader* AsDirectoryReader() { return NULL; }
@@ -45,12 +60,29 @@ class Resource : public base::RefCountedThreadSafe<Resource> {
virtual URLRequestInfo* AsURLRequestInfo() { return NULL; }
virtual URLResponseInfo* AsURLResponseInfo() { return NULL; }
- private:
PluginModule* module_; // Non-owning pointer to our module.
DISALLOW_COPY_AND_ASSIGN(Resource);
};
+// Cast() specializations.
+#define DEFINE_RESOURCE_CAST(Type) \
+ template <> inline Type* Resource::Cast<Type>() { \
+ return As##Type(); \
+ }
+
+DEFINE_RESOURCE_CAST(Buffer)
+DEFINE_RESOURCE_CAST(DeviceContext2D)
+DEFINE_RESOURCE_CAST(DirectoryReader)
+DEFINE_RESOURCE_CAST(FileChooser)
+DEFINE_RESOURCE_CAST(FileIO)
+DEFINE_RESOURCE_CAST(FileRef)
+DEFINE_RESOURCE_CAST(ImageData)
+DEFINE_RESOURCE_CAST(URLLoader)
+DEFINE_RESOURCE_CAST(URLRequestInfo)
+DEFINE_RESOURCE_CAST(URLResponseInfo)
+
+#undef DEFINE_RESOURCE_CAST
} // namespace pepper
darin (slow to review) 2010/06/28 19:57:07 nit: add a new line above the close of the namespa
#endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_
« no previous file with comments | « webkit/glue/plugins/pepper_plugin_module.cc ('k') | webkit/glue/plugins/pepper_resource_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698