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

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

Issue 6282007: First pass at making the proxy handle multiple renderers. This associates the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 PPAPI_PROXY_PLUGIN_RESOURCE_H_ 5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_H_
6 #define PPAPI_PROXY_PLUGIN_RESOURCE_H_ 6 #define PPAPI_PROXY_PLUGIN_RESOURCE_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "ppapi/c/pp_instance.h"
9 #include "ppapi/proxy/plugin_dispatcher.h" 10 #include "ppapi/proxy/plugin_dispatcher.h"
10 #include "ppapi/proxy/plugin_resource_tracker.h" 11 #include "ppapi/proxy/plugin_resource_tracker.h"
11 12
12 // If you inherit from resource, make sure you add the class name here. 13 // If you inherit from resource, make sure you add the class name here.
13 #define FOR_ALL_PLUGIN_RESOURCES(F) \ 14 #define FOR_ALL_PLUGIN_RESOURCES(F) \
14 F(Audio) \ 15 F(Audio) \
15 F(AudioConfig) \ 16 F(AudioConfig) \
16 F(Buffer) \ 17 F(Buffer) \
17 F(Font) \ 18 F(Font) \
18 F(Graphics2D) \ 19 F(Graphics2D) \
19 F(ImageData) \ 20 F(ImageData) \
20 F(PrivateFontFile) \ 21 F(PrivateFontFile) \
21 F(URLLoader) \ 22 F(URLLoader) \
22 F(URLRequestInfo)\ 23 F(URLRequestInfo)\
23 F(URLResponseInfo) 24 F(URLResponseInfo)
24 25
25 namespace pp { 26 namespace pp {
26 namespace proxy { 27 namespace proxy {
27 28
28 // Forward declaration of Resource classes. 29 // Forward declaration of Resource classes.
29 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; 30 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE;
30 FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS) 31 FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS)
31 #undef DECLARE_RESOURCE_CLASS 32 #undef DECLARE_RESOURCE_CLASS
32 33
33 class PluginResource { 34 class PluginResource {
34 public: 35 public:
35 PluginResource(); 36 PluginResource(PP_Instance instance);
36 virtual ~PluginResource(); 37 virtual ~PluginResource();
37 38
38 // Returns NULL if the resource is invalid or is a different type. 39 // Returns NULL if the resource is invalid or is a different type.
39 template<typename T> static T* GetAs(PP_Resource res) { 40 template<typename T> static T* GetAs(PP_Resource res) {
40 PluginResource* resource = 41 PluginResource* resource =
41 PluginDispatcher::Get()->plugin_resource_tracker()->GetResourceObject( 42 PluginResourceTracker::GetInstance()->GetResourceObject(res);
42 res);
43 return resource ? resource->Cast<T>() : NULL; 43 return resource ? resource->Cast<T>() : NULL;
44 } 44 }
45 45
46 template <typename T> T* Cast() { return NULL; } 46 template <typename T> T* Cast() { return NULL; }
47 47
48 PP_Instance instance() const { return instance_; }
49
48 private: 50 private:
49 // Type-specific getters for individual resource types. These will return 51 // Type-specific getters for individual resource types. These will return
50 // NULL if the resource does not match the specified type. Used by the Cast() 52 // NULL if the resource does not match the specified type. Used by the Cast()
51 // function. 53 // function.
52 #define DEFINE_TYPE_GETTER(RESOURCE) \ 54 #define DEFINE_TYPE_GETTER(RESOURCE) \
53 virtual RESOURCE* As##RESOURCE(); 55 virtual RESOURCE* As##RESOURCE();
54 FOR_ALL_PLUGIN_RESOURCES(DEFINE_TYPE_GETTER) 56 FOR_ALL_PLUGIN_RESOURCES(DEFINE_TYPE_GETTER)
55 #undef DEFINE_TYPE_GETTER 57 #undef DEFINE_TYPE_GETTER
56 58
59 // Instance this resource is associated with.
60 PP_Instance instance_;
61
57 DISALLOW_COPY_AND_ASSIGN(PluginResource); 62 DISALLOW_COPY_AND_ASSIGN(PluginResource);
58 }; 63 };
59 64
60 // Cast() specializations. 65 // Cast() specializations.
61 #define DEFINE_RESOURCE_CAST(Type) \ 66 #define DEFINE_RESOURCE_CAST(Type) \
62 template <> inline Type* PluginResource::Cast<Type>() { \ 67 template <> inline Type* PluginResource::Cast<Type>() { \
63 return As##Type(); \ 68 return As##Type(); \
64 } 69 }
65 FOR_ALL_PLUGIN_RESOURCES(DEFINE_RESOURCE_CAST) 70 FOR_ALL_PLUGIN_RESOURCES(DEFINE_RESOURCE_CAST)
66 #undef DEFINE_RESOURCE_CAST 71 #undef DEFINE_RESOURCE_CAST
67 72
68 } // namespace proxy 73 } // namespace proxy
69 } // namespace pp 74 } // namespace pp
70 75
71 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ 76 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698