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

Side by Side Diff: ppapi/proxy/plugin_resource.h

Issue 4229002: Core PPAPI proxy files. This includes the dispatcher which is the control poi... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_H_
6 #define PPAPI_PROXY_PLUGIN_RESOURCE_H_
7
8 #include "base/basictypes.h"
9 #include "ppapi/proxy/plugin_dispatcher.h"
10 #include "ppapi/proxy/plugin_resource_tracker.h"
11
12 // If you inherit from resource, make sure you add the class name here.
13 #define FOR_ALL_RESOURCES(F) \
14 F(Graphics2D) \
15 F(ImageData) \
16 F(URLLoader)
17
18 namespace pp {
19 namespace proxy {
20
21 // Forward declaration of Resource classes.
22 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE;
23 FOR_ALL_RESOURCES(DECLARE_RESOURCE_CLASS)
24 #undef DECLARE_RESOURCE_CLASS
25
26 class PluginResource {
27 public:
28 PluginResource();
29 virtual ~PluginResource();
30
31 // Returns NULL if the resource is invalid or is a different type.
32 template<typename T> static T* GetAs(PP_Resource res) {
33 PluginResource* resource =
34 PluginDispatcher::Get()->plugin_resource_tracker()->GetResourceObject(
35 res);
36 return resource ? resource->Cast<T>() : NULL;
37 }
38
39 template <typename T> T* Cast() { return NULL; }
40
41 private:
42 // Type-specific getters for individual resource types. These will return
43 // NULL if the resource does not match the specified type. Used by the Cast()
44 // function.
45 #define DEFINE_TYPE_GETTER(RESOURCE) \
46 virtual RESOURCE* As##RESOURCE() { return NULL; }
47 FOR_ALL_RESOURCES(DEFINE_TYPE_GETTER)
48 #undef DEFINE_TYPE_GETTER
49
50 DISALLOW_COPY_AND_ASSIGN(PluginResource);
51 };
52
53 // Cast() specializations.
54 #define DEFINE_RESOURCE_CAST(Type) \
55 template <> inline Type* PluginResource::Cast<Type>() { \
56 return As##Type(); \
57 }
58 FOR_ALL_RESOURCES(DEFINE_RESOURCE_CAST)
59 #undef DEFINE_RESOURCE_CAST
60
61 } // namespace proxy
62 } // namespace pp
63
64 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698