OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef PPAPI_SHARED_IMPL_RESOURCE_H_ | |
6 #define PPAPI_SHARED_IMPL_RESOURCE_H_ | |
7 | |
8 #include <stddef.h> // For NULL. | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "ppapi/c/pp_instance.h" | |
13 #include "ppapi/c/pp_resource.h" | |
14 #include "ppapi/shared_impl/host_resource.h" | |
15 | |
16 #define FOR_ALL_PPAPI_RESOURCE_APIS(F) \ | |
dmichael (off chromium)
2011/08/17 19:02:54
I guess it's obvious, but it maybe good to comment
| |
17 F(PPB_AudioConfig_API) \ | |
18 F(PPB_AudioTrusted_API) \ | |
19 F(PPB_Audio_API) \ | |
20 F(PPB_Broker_API) \ | |
21 F(PPB_Buffer_API) \ | |
22 F(PPB_BufferTrusted_API) \ | |
23 F(PPB_Context3D_API) \ | |
24 F(PPB_DirectoryReader_API) \ | |
25 F(PPB_FileChooser_API) \ | |
26 F(PPB_FileIO_API) \ | |
27 F(PPB_FileRef_API) \ | |
28 F(PPB_FileSystem_API) \ | |
29 F(PPB_Find_API) \ | |
30 F(PPB_Flash_Menu_API) \ | |
31 F(PPB_Flash_NetConnector_API) \ | |
32 F(PPB_Flash_TCPSocket_API) \ | |
33 F(PPB_Font_API) \ | |
34 F(PPB_Graphics2D_API) \ | |
35 F(PPB_Graphics3D_API) \ | |
36 F(PPB_ImageData_API) \ | |
37 F(PPB_InputEvent_API) \ | |
38 F(PPB_LayerCompositor_API) \ | |
39 F(PPB_PDFFont_API) \ | |
40 F(PPB_Scrollbar_API) \ | |
41 F(PPB_Surface3D_API) \ | |
42 F(PPB_Transport_API) \ | |
43 F(PPB_URLLoader_API) \ | |
44 F(PPB_URLRequestInfo_API) \ | |
45 F(PPB_URLResponseInfo_API) \ | |
46 F(PPB_VideoCapture_API) \ | |
47 F(PPB_VideoDecoder_API) \ | |
48 F(PPB_VideoLayer_API) \ | |
49 F(PPB_Widget_API) | |
50 | |
51 namespace ppapi { | |
52 | |
53 // Forward declare all the resource APIs. | |
54 namespace thunk { | |
55 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; | |
56 FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS) | |
57 #undef DECLARE_RESOURCE_CLASS | |
58 } // namespace thunk | |
59 | |
60 class Resource : public base::RefCounted<Resource> { | |
61 public: | |
62 // For constructing non-proxied objects. This just takes the associated | |
63 // instance, and generates a new resource ID. The host resource will be the | |
64 // same as the newly-generated resource ID. | |
65 Resource(PP_Instance instance); | |
dmichael (off chromium)
2011/08/17 19:02:54
explicit
| |
66 | |
67 // For constructing proxied objects. This takes the resource generated in | |
68 // the host side, stores it, and allocates a "local" resource ID for use in | |
69 // the current process. | |
70 Resource(const HostResource& host_resource); | |
dmichael (off chromium)
2011/08/17 19:02:54
explicit
| |
71 | |
72 virtual ~Resource(); | |
73 | |
74 PP_Instance pp_instance() const { return host_resource_.instance(); } | |
75 | |
76 // Returns the resource ID for this object in the current process without | |
77 // adjusting the refcount. See also GetReference(). | |
78 PP_Resource pp_resource() const { return pp_resource_; } | |
79 | |
80 // Returns the host resource which identifies the resource in the host side | |
81 // of the process in the case of proxied objects. For in-process objects, | |
82 // this just identifies the in-process resource ID & instance. | |
83 const HostResource& host_resource() { return host_resource_; } | |
84 | |
85 // Adds a ref on behalf of the plugin and returns the resource ID. This is | |
86 // normally used when returning a resource to the plugin, where it's | |
87 // expecting the returned resource to have ownership of a ref passed. | |
88 // See also pp_resource() to avoid the AddRef. | |
89 PP_Resource GetReference(); | |
90 | |
91 // Called by the resource tracker when the last reference from the plugin | |
92 // was released. For a few types of resources, the resource could still | |
93 // stay alive if there are other references held by the PPAPI implementation | |
94 // (possibly for callbacks and things). | |
95 virtual void LastPluginRefWasDeleted(); | |
96 | |
97 // Called by the resource tracker when the instance is going away but the | |
98 // object is still alive (this is not the common case, since it requires | |
99 // something in the implementation to be keeping a ref that keeps the | |
100 // resource alive. | |
101 // | |
102 // You will want to override this if your resource does some kind of | |
103 // background processing (like maybe network loads) on behalf of the plugin | |
104 // and you want to stop that when the plugin is deleted. | |
105 // | |
106 // Be sure to call this version which clears the instance ID. | |
107 virtual void InstanceWasDeleted(); | |
108 | |
109 // Dynamic casting for this object. Returns the pointer to the given type if | |
dmichael (off chromium)
2011/08/17 19:02:54
I think you meant to delete this line^^^^
| |
110 // Inheritance-based dynamic casting for this object. Returns the pointer to | |
111 // the given type if it's supported. Derived classes override the functions | |
112 // they support to return the interface. | |
113 #define DEFINE_TYPE_GETTER(RESOURCE) \ | |
114 virtual thunk::RESOURCE* As##RESOURCE(); | |
115 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) | |
116 #undef DEFINE_TYPE_GETTER | |
117 | |
118 // Template-based dynamic casting. See specializations below. | |
119 template <typename T> T* GetAs() { return NULL; } | |
120 | |
121 private: | |
122 // See the getters above. | |
123 PP_Resource pp_resource_; | |
124 HostResource host_resource_; | |
125 | |
126 DISALLOW_IMPLICIT_CONSTRUCTORS(Resource); | |
127 }; | |
128 | |
129 // Template-based dynamic casting. These specializations forward to the | |
130 // AsXXX virtual functions to return whether the given type is supported. | |
131 #define DEFINE_RESOURCE_CAST(RESOURCE) \ | |
132 template<> inline thunk::RESOURCE* Resource::GetAs() { \ | |
133 return As##RESOURCE(); \ | |
134 } | |
135 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST) | |
136 #undef DEFINE_RESOURCE_CAST | |
137 | |
138 } // namespace ppapi | |
139 | |
140 #endif // PPAPI_SHARED_IMPL_RESOURCE_H_ | |
OLD | NEW |