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

Side by Side Diff: ppapi/shared_impl/resource.h

Issue 174213003: PPAPI: Use clang-format on ppapi/shared_impl (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: remove DEPS Created 6 years, 10 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
« no previous file with comments | « ppapi/shared_impl/proxy_lock_unittest.cc ('k') | ppapi/shared_impl/resource.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_SHARED_IMPL_RESOURCE_H_ 5 #ifndef PPAPI_SHARED_IMPL_RESOURCE_H_
6 #define PPAPI_SHARED_IMPL_RESOURCE_H_ 6 #define PPAPI_SHARED_IMPL_RESOURCE_H_
7 7
8 #include <stddef.h> // For NULL. 8 #include <stddef.h> // For NULL.
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "ppapi/c/pp_instance.h" 14 #include "ppapi/c/pp_instance.h"
15 #include "ppapi/c/pp_resource.h" 15 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/c/ppb_console.h" 16 #include "ppapi/c/ppb_console.h"
17 #include "ppapi/shared_impl/host_resource.h" 17 #include "ppapi/shared_impl/host_resource.h"
18 18
19 // All resource types should be added here. This implements our hand-rolled 19 // All resource types should be added here. This implements our hand-rolled
20 // RTTI system since we don't compile with "real" RTTI. 20 // RTTI system since we don't compile with "real" RTTI.
21 #define FOR_ALL_PPAPI_RESOURCE_APIS(F) \ 21 #define FOR_ALL_PPAPI_RESOURCE_APIS(F) \
22 F(ExtensionsCommon_API) \ 22 F(ExtensionsCommon_API) \
23 F(PPB_Audio_API) \ 23 F(PPB_Audio_API) \
24 F(PPB_AudioBuffer_API) \ 24 F(PPB_AudioBuffer_API) \
25 F(PPB_AudioConfig_API) \ 25 F(PPB_AudioConfig_API) \
26 F(PPB_AudioInput_API) \ 26 F(PPB_AudioInput_API) \
27 F(PPB_AudioTrusted_API) \ 27 F(PPB_AudioTrusted_API) \
28 F(PPB_Broker_API) \ 28 F(PPB_Broker_API) \
29 F(PPB_Broker_Instance_API) \ 29 F(PPB_Broker_Instance_API) \
30 F(PPB_BrowserFont_Singleton_API) \ 30 F(PPB_BrowserFont_Singleton_API) \
31 F(PPB_BrowserFont_Trusted_API) \ 31 F(PPB_BrowserFont_Trusted_API) \
32 F(PPB_Buffer_API) \ 32 F(PPB_Buffer_API) \
33 F(PPB_DeviceRef_API) \ 33 F(PPB_DeviceRef_API) \
34 F(PPB_Ext_CrxFileSystem_Private_API) \ 34 F(PPB_Ext_CrxFileSystem_Private_API) \
35 F(PPB_FileChooser_API) \ 35 F(PPB_FileChooser_API) \
36 F(PPB_FileIO_API) \ 36 F(PPB_FileIO_API) \
37 F(PPB_FileMapping_API) \ 37 F(PPB_FileMapping_API) \
38 F(PPB_FileRef_API) \ 38 F(PPB_FileRef_API) \
39 F(PPB_FileSystem_API) \ 39 F(PPB_FileSystem_API) \
40 F(PPB_Find_API) \ 40 F(PPB_Find_API) \
41 F(PPB_Flash_Clipboard_API) \ 41 F(PPB_Flash_Clipboard_API) \
42 F(PPB_Flash_DRM_API) \ 42 F(PPB_Flash_DRM_API) \
43 F(PPB_Flash_File_API) \ 43 F(PPB_Flash_File_API) \
44 F(PPB_Flash_FontFile_API) \ 44 F(PPB_Flash_FontFile_API) \
45 F(PPB_Flash_Fullscreen_API) \ 45 F(PPB_Flash_Fullscreen_API) \
46 F(PPB_Flash_Functions_API) \ 46 F(PPB_Flash_Functions_API) \
47 F(PPB_Flash_Menu_API) \ 47 F(PPB_Flash_Menu_API) \
48 F(PPB_Flash_MessageLoop_API) \ 48 F(PPB_Flash_MessageLoop_API) \
49 F(PPB_Gamepad_API) \ 49 F(PPB_Gamepad_API) \
50 F(PPB_Graphics2D_API) \ 50 F(PPB_Graphics2D_API) \
51 F(PPB_Graphics3D_API) \ 51 F(PPB_Graphics3D_API) \
52 F(PPB_HostResolver_API) \ 52 F(PPB_HostResolver_API) \
53 F(PPB_HostResolver_Private_API) \ 53 F(PPB_HostResolver_Private_API) \
54 F(PPB_ImageData_API) \ 54 F(PPB_ImageData_API) \
55 F(PPB_InputEvent_API) \ 55 F(PPB_InputEvent_API) \
56 F(PPB_IsolatedFileSystem_Private_API) \ 56 F(PPB_IsolatedFileSystem_Private_API) \
57 F(PPB_LayerCompositor_API) \ 57 F(PPB_LayerCompositor_API) \
58 F(PPB_MediaStreamAudioTrack_API) \ 58 F(PPB_MediaStreamAudioTrack_API) \
59 F(PPB_MediaStreamVideoTrack_API) \ 59 F(PPB_MediaStreamVideoTrack_API) \
60 F(PPB_MessageLoop_API) \ 60 F(PPB_MessageLoop_API) \
61 F(PPB_NetAddress_API) \ 61 F(PPB_NetAddress_API) \
62 F(PPB_NetworkList_API) \ 62 F(PPB_NetworkList_API) \
63 F(PPB_NetworkMonitor_API) \ 63 F(PPB_NetworkMonitor_API) \
64 F(PPB_NetworkProxy_API) \ 64 F(PPB_NetworkProxy_API) \
65 F(PPB_OutputProtection_API) \ 65 F(PPB_OutputProtection_API) \
66 F(PPB_PDF_API) \ 66 F(PPB_PDF_API) \
67 F(PPB_PlatformVerification_API) \ 67 F(PPB_PlatformVerification_API) \
68 F(PPB_Printing_API) \ 68 F(PPB_Printing_API) \
69 F(PPB_Scrollbar_API) \ 69 F(PPB_Scrollbar_API) \
70 F(PPB_Talk_Private_API) \ 70 F(PPB_Talk_Private_API) \
71 F(PPB_TrueTypeFont_API) \ 71 F(PPB_TrueTypeFont_API) \
72 F(PPB_TrueTypeFont_Singleton_API) \ 72 F(PPB_TrueTypeFont_Singleton_API) \
73 F(PPB_TCPServerSocket_Private_API) \ 73 F(PPB_TCPServerSocket_Private_API) \
74 F(PPB_TCPSocket_API) \ 74 F(PPB_TCPSocket_API) \
75 F(PPB_TCPSocket_Private_API) \ 75 F(PPB_TCPSocket_Private_API) \
76 F(PPB_UDPSocket_API) \ 76 F(PPB_UDPSocket_API) \
77 F(PPB_UDPSocket_Private_API) \ 77 F(PPB_UDPSocket_Private_API) \
78 F(PPB_UMA_Singleton_API) \ 78 F(PPB_UMA_Singleton_API) \
79 F(PPB_URLLoader_API) \ 79 F(PPB_URLLoader_API) \
80 F(PPB_URLRequestInfo_API) \ 80 F(PPB_URLRequestInfo_API) \
81 F(PPB_URLResponseInfo_API) \ 81 F(PPB_URLResponseInfo_API) \
82 F(PPB_VideoCapture_API) \ 82 F(PPB_VideoCapture_API) \
83 F(PPB_VideoDecoder_API) \ 83 F(PPB_VideoDecoder_API) \
84 F(PPB_VideoDestination_Private_API) \ 84 F(PPB_VideoDestination_Private_API) \
85 F(PPB_VideoFrame_API) \ 85 F(PPB_VideoFrame_API) \
86 F(PPB_VideoLayer_API) \ 86 F(PPB_VideoLayer_API) \
87 F(PPB_VideoSource_Private_API) \ 87 F(PPB_VideoSource_Private_API) \
88 F(PPB_View_API) \ 88 F(PPB_View_API) \
89 F(PPB_WebSocket_API) \ 89 F(PPB_WebSocket_API) \
90 F(PPB_Widget_API) \ 90 F(PPB_Widget_API) \
91 F(PPB_X509Certificate_Private_API) 91 F(PPB_X509Certificate_Private_API)
92 92
93 namespace IPC { 93 namespace IPC {
94 class Message; 94 class Message;
95 } 95 }
96 96
97 namespace ppapi { 97 namespace ppapi {
98 98
99 // Normally we shouldn't reply on proxy here, but this is to support 99 // Normally we shouldn't reply on proxy here, but this is to support
100 // OnReplyReceived. See that comment. 100 // OnReplyReceived. See that comment.
101 namespace proxy { 101 namespace proxy {
102 class ResourceMessageReplyParams; 102 class ResourceMessageReplyParams;
103 } 103 }
104 104
105 // Forward declare all the resource APIs. 105 // Forward declare all the resource APIs.
106 namespace thunk { 106 namespace thunk {
107 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; 107 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE;
108 FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS) 108 FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS)
109 #undef DECLARE_RESOURCE_CLASS 109 #undef DECLARE_RESOURCE_CLASS
110 } // namespace thunk 110 } // namespace thunk
111 111
112 // Resources have slightly different registration behaviors when the're an 112 // Resources have slightly different registration behaviors when the're an
113 // in-process ("impl") resource in the host (renderer) process, or when they're 113 // in-process ("impl") resource in the host (renderer) process, or when they're
114 // a proxied resource in the plugin process. This enum differentiates those 114 // a proxied resource in the plugin process. This enum differentiates those
115 // cases. 115 // cases.
116 enum ResourceObjectType { 116 enum ResourceObjectType { OBJECT_IS_IMPL, OBJECT_IS_PROXY };
117 OBJECT_IS_IMPL,
118 OBJECT_IS_PROXY
119 };
120 117
121 class PPAPI_SHARED_EXPORT Resource : public base::RefCounted<Resource> { 118 class PPAPI_SHARED_EXPORT Resource : public base::RefCounted<Resource> {
122 public: 119 public:
123 // Constructor for impl and non-proxied, instance-only objects. 120 // Constructor for impl and non-proxied, instance-only objects.
124 // 121 //
125 // For constructing "impl" (non-proxied) objects, this just takes the 122 // For constructing "impl" (non-proxied) objects, this just takes the
126 // associated instance, and generates a new resource ID. The host resource 123 // associated instance, and generates a new resource ID. The host resource
127 // will be the same as the newly-generated resource ID. For all objects in 124 // will be the same as the newly-generated resource ID. For all objects in
128 // the renderer (host) process, you'll use this constructor and call it with 125 // the renderer (host) process, you'll use this constructor and call it with
129 // OBJECT_IS_IMPL. 126 // OBJECT_IS_IMPL.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // resource alive. 185 // resource alive.
189 // 186 //
190 // You will want to override this if your resource does some kind of 187 // You will want to override this if your resource does some kind of
191 // background processing (like maybe network loads) on behalf of the plugin 188 // background processing (like maybe network loads) on behalf of the plugin
192 // and you want to stop that when the plugin is deleted. 189 // and you want to stop that when the plugin is deleted.
193 // 190 //
194 // Note that subclasses except PluginResource should override 191 // Note that subclasses except PluginResource should override
195 // InstanceWasDeleted() to be notified. 192 // InstanceWasDeleted() to be notified.
196 virtual void NotifyInstanceWasDeleted(); 193 virtual void NotifyInstanceWasDeleted();
197 194
198 // Dynamic casting for this object. Returns the pointer to the given type if 195 // Dynamic casting for this object. Returns the pointer to the given type if
199 // it's supported. Derived classes override the functions they support to 196 // it's supported. Derived classes override the functions they support to
200 // return the interface. 197 // return the interface.
201 #define DEFINE_TYPE_GETTER(RESOURCE) \ 198 #define DEFINE_TYPE_GETTER(RESOURCE) virtual thunk::RESOURCE* As##RESOURCE();
202 virtual thunk::RESOURCE* As##RESOURCE();
203 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) 199 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER)
204 #undef DEFINE_TYPE_GETTER 200 #undef DEFINE_TYPE_GETTER
205 201
206 // Template-based dynamic casting. See specializations below. This is 202 // Template-based dynamic casting. See specializations below. This is
207 // unimplemented for the default case. This way, for anything that's not a 203 // unimplemented for the default case. This way, for anything that's not a
208 // resource (or if a developer forgets to add the resource to the list in 204 // resource (or if a developer forgets to add the resource to the list in
209 // this file), the result is a linker error. 205 // this file), the result is a linker error.
210 template <typename T> T* GetAs(); 206 template <typename T>
207 T* GetAs();
211 208
212 // Called when a PpapiPluginMsg_ResourceReply reply is received for a 209 // Called when a PpapiPluginMsg_ResourceReply reply is received for a
213 // previous CallRenderer. The message is the nested reply message, which may 210 // previous CallRenderer. The message is the nested reply message, which may
214 // be an empty message (depending on what the host sends). 211 // be an empty message (depending on what the host sends).
215 // 212 //
216 // The default implementation will assert (if you send a request, you should 213 // The default implementation will assert (if you send a request, you should
217 // override this function). 214 // override this function).
218 // 215 //
219 // (This function would make more conceptual sense on PluginResource but we 216 // (This function would make more conceptual sense on PluginResource but we
220 // need to call this function from general code that doesn't know how to 217 // need to call this function from general code that doesn't know how to
(...skipping 20 matching lines...) Expand all
241 private: 238 private:
242 // See the getters above. 239 // See the getters above.
243 PP_Resource pp_resource_; 240 PP_Resource pp_resource_;
244 HostResource host_resource_; 241 HostResource host_resource_;
245 242
246 DISALLOW_IMPLICIT_CONSTRUCTORS(Resource); 243 DISALLOW_IMPLICIT_CONSTRUCTORS(Resource);
247 }; 244 };
248 245
249 // Template-based dynamic casting. These specializations forward to the 246 // Template-based dynamic casting. These specializations forward to the
250 // AsXXX virtual functions to return whether the given type is supported. 247 // AsXXX virtual functions to return whether the given type is supported.
251 #define DEFINE_RESOURCE_CAST(RESOURCE) \ 248 #define DEFINE_RESOURCE_CAST(RESOURCE) \
252 template<> inline thunk::RESOURCE* Resource::GetAs() { \ 249 template <> \
253 return As##RESOURCE(); \ 250 inline thunk::RESOURCE* Resource::GetAs() { \
251 return As##RESOURCE(); \
254 } 252 }
255 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST) 253 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST)
256 #undef DEFINE_RESOURCE_CAST 254 #undef DEFINE_RESOURCE_CAST
257 255
258 } // namespace ppapi 256 } // namespace ppapi
259 257
260 #endif // PPAPI_SHARED_IMPL_RESOURCE_H_ 258 #endif // PPAPI_SHARED_IMPL_RESOURCE_H_
OLDNEW
« no previous file with comments | « ppapi/shared_impl/proxy_lock_unittest.cc ('k') | ppapi/shared_impl/resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698