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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
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_GLUE_PLUGINS_PEPPER_RESOURCE_H_
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_ 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_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 "third_party/ppapi/c/pp_resource.h" 10 #include "third_party/ppapi/c/pp_resource.h"
11 #include "webkit/glue/plugins/pepper_resource_tracker.h"
11 12
12 namespace pepper { 13 namespace pepper {
13 14
14 class Buffer; 15 class Buffer;
15 class DeviceContext2D; 16 class DeviceContext2D;
16 class DirectoryReader; 17 class DirectoryReader;
17 class FileChooser; 18 class FileChooser;
18 class FileIO; 19 class FileIO;
19 class FileRef; 20 class FileRef;
20 class ImageData; 21 class ImageData;
21 class PluginModule; 22 class PluginModule;
22 class URLLoader; 23 class URLLoader;
23 class URLRequestInfo; 24 class URLRequestInfo;
24 class URLResponseInfo; 25 class URLResponseInfo;
25 26
26 class Resource : public base::RefCountedThreadSafe<Resource> { 27 class Resource : public base::RefCountedThreadSafe<Resource> {
27 public: 28 public:
28 explicit Resource(PluginModule* module); 29 explicit Resource(PluginModule* module);
29 virtual ~Resource(); 30 virtual ~Resource();
30 31
32 // Returns NULL if the resource is invalid or is a different type.
33 template<typename T>
34 static scoped_refptr<T> GetAs(PP_Resource res) {
35 scoped_refptr<Resource> resource = ResourceTracker::Get()->GetResource(res);
36 return resource ? resource->Cast<T>() : NULL;
37 }
38
31 PP_Resource GetResource() const; 39 PP_Resource GetResource() const;
32 40
33 PluginModule* module() const { return module_; } 41 PluginModule* module() const { return module_; }
34 42
43 // Cast the resource into a specified type. This will return NULL if the
44 // resource does not match the specified type. Specializations of this
45 // template call into As* functions.
46 template <typename T> T* Cast() { return NULL; }
47
48 private:
35 // Type-specific getters for individual resource types. These will return 49 // Type-specific getters for individual resource types. These will return
36 // NULL if the resource does not match the specified type. 50 // NULL if the resource does not match the specified type. Used by the Cast()
51 // function.
37 virtual Buffer* AsBuffer() { return NULL; } 52 virtual Buffer* AsBuffer() { return NULL; }
38 virtual DeviceContext2D* AsDeviceContext2D() { return NULL; } 53 virtual DeviceContext2D* AsDeviceContext2D() { return NULL; }
39 virtual DirectoryReader* AsDirectoryReader() { return NULL; } 54 virtual DirectoryReader* AsDirectoryReader() { return NULL; }
40 virtual FileChooser* AsFileChooser() { return NULL; } 55 virtual FileChooser* AsFileChooser() { return NULL; }
41 virtual FileIO* AsFileIO() { return NULL; } 56 virtual FileIO* AsFileIO() { return NULL; }
42 virtual FileRef* AsFileRef() { return NULL; } 57 virtual FileRef* AsFileRef() { return NULL; }
43 virtual ImageData* AsImageData() { return NULL; } 58 virtual ImageData* AsImageData() { return NULL; }
44 virtual URLLoader* AsURLLoader() { return NULL; } 59 virtual URLLoader* AsURLLoader() { return NULL; }
45 virtual URLRequestInfo* AsURLRequestInfo() { return NULL; } 60 virtual URLRequestInfo* AsURLRequestInfo() { return NULL; }
46 virtual URLResponseInfo* AsURLResponseInfo() { return NULL; } 61 virtual URLResponseInfo* AsURLResponseInfo() { return NULL; }
47 62
48 private:
49 PluginModule* module_; // Non-owning pointer to our module. 63 PluginModule* module_; // Non-owning pointer to our module.
50 64
51 DISALLOW_COPY_AND_ASSIGN(Resource); 65 DISALLOW_COPY_AND_ASSIGN(Resource);
52 }; 66 };
53 67
68 // Cast() specializations.
69 #define DEFINE_RESOURCE_CAST(Type) \
70 template <> inline Type* Resource::Cast<Type>() { \
71 return As##Type(); \
72 }
73
74 DEFINE_RESOURCE_CAST(Buffer)
75 DEFINE_RESOURCE_CAST(DeviceContext2D)
76 DEFINE_RESOURCE_CAST(DirectoryReader)
77 DEFINE_RESOURCE_CAST(FileChooser)
78 DEFINE_RESOURCE_CAST(FileIO)
79 DEFINE_RESOURCE_CAST(FileRef)
80 DEFINE_RESOURCE_CAST(ImageData)
81 DEFINE_RESOURCE_CAST(URLLoader)
82 DEFINE_RESOURCE_CAST(URLRequestInfo)
83 DEFINE_RESOURCE_CAST(URLResponseInfo)
84
85 #undef DEFINE_RESOURCE_CAST
54 } // namespace pepper 86 } // namespace pepper
darin (slow to review) 2010/06/28 19:57:07 nit: add a new line above the close of the namespa
55 87
56 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_ 88 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_
OLDNEW
« 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