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

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

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 4 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
(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_OBJECT_BASE_H_
6 #define PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_
7
8 #include <stddef.h> // For NULL.
9
10 #include "base/memory/ref_counted.h"
11 #include "ppapi/c/pp_instance.h"
12
13 #define FOR_ALL_PPAPI_RESOURCE_APIS(F) \
14 F(PPB_AudioConfig_API) \
15 F(PPB_AudioTrusted_API) \
16 F(PPB_Audio_API) \
17 F(PPB_Broker_API) \
18 F(PPB_Buffer_API) \
19 F(PPB_BufferTrusted_API) \
20 F(PPB_Context3D_API) \
21 F(PPB_DirectoryReader_API) \
22 F(PPB_FileChooser_API) \
23 F(PPB_FileIO_API) \
24 F(PPB_FileRef_API) \
25 F(PPB_FileSystem_API) \
26 F(PPB_Find_API) \
27 F(PPB_Flash_Menu_API) \
28 F(PPB_Flash_NetConnector_API) \
29 F(PPB_Flash_TCPSocket_API) \
30 F(PPB_Font_API) \
31 F(PPB_Graphics2D_API) \
32 F(PPB_Graphics3D_API) \
33 F(PPB_ImageData_API) \
34 F(PPB_InputEvent_API) \
35 F(PPB_LayerCompositor_API) \
36 F(PPB_PDFFont_API) \
37 F(PPB_Scrollbar_API) \
38 F(PPB_Surface3D_API) \
39 F(PPB_Transport_API) \
40 F(PPB_URLLoader_API) \
41 F(PPB_URLRequestInfo_API) \
42 F(PPB_URLResponseInfo_API) \
43 F(PPB_VideoCapture_API) \
44 F(PPB_VideoDecoder_API) \
45 F(PPB_VideoLayer_API) \
46 F(PPB_Widget_API)
47
48 namespace ppapi {
49
50 // Forward declare all the resource APIs.
51 namespace thunk {
52 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE;
53 FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS)
54 #undef DECLARE_RESOURCE_CLASS
55 } // namespace thunk
56
57 class ResourceObjectBase : public base::RefCounted<ResourceObjectBase> {
58 public:
59 ResourceObjectBase(PP_Instance instance);
60 virtual ~ResourceObjectBase();
61
62 PP_Instance pp_instance() const { return pp_instance_; }
63
64 // Dynamic casting for this object. Returns the pointer to the given type if
65 // Inheritance-based dynamic casting for this object. Returns the pointer to
66 // the given type if it's supported. Derived classes override the functions
67 // they support to return the interface.
68 #define DEFINE_TYPE_GETTER(RESOURCE) \
69 virtual thunk::RESOURCE* As##RESOURCE();
70 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER)
71 #undef DEFINE_TYPE_GETTER
72
73 // Template-based dynamic casting. See specializations below.
74 template <typename T> T* GetAs() { return NULL; }
75
76 private:
77 PP_Instance pp_instance_;
78
79 DISALLOW_IMPLICIT_CONSTRUCTORS(ResourceObjectBase);
80 };
81
82 // Template-based dynamic casting. These specializations forward to the
83 // AsXXX virtual functions to return whether the given type is supported.
84 #define DEFINE_RESOURCE_CAST(RESOURCE) \
85 template<> inline thunk::RESOURCE* ResourceObjectBase::GetAs() { \
86 return As##RESOURCE(); \
87 }
88 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST)
89 #undef DEFINE_RESOURCE_CAST
90
91 } // namespace ppapi
92
93 #endif // PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698