OLD | NEW |
1 // Copyright (c) 2011 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_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ | 5 #ifndef PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ |
6 #define PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ | 6 #define PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ |
7 | 7 |
8 #include <stddef.h> // For NULL. | 8 #include <stddef.h> // For NULL. |
9 | 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 |
10 #define FOR_ALL_PPAPI_RESOURCE_APIS(F) \ | 12 #define FOR_ALL_PPAPI_RESOURCE_APIS(F) \ |
11 F(PPB_AudioConfig_API) \ | 13 F(PPB_AudioConfig_API) \ |
12 F(PPB_AudioTrusted_API) \ | 14 F(PPB_AudioTrusted_API) \ |
13 F(PPB_Audio_API) \ | 15 F(PPB_Audio_API) \ |
14 F(PPB_Broker_API) \ | 16 F(PPB_Broker_API) \ |
15 F(PPB_Buffer_API) \ | 17 F(PPB_Buffer_API) \ |
16 F(PPB_BufferTrusted_API) \ | 18 F(PPB_BufferTrusted_API) \ |
17 F(PPB_Context3D_API) \ | 19 F(PPB_Context3D_API) \ |
18 F(PPB_DirectoryReader_API) \ | 20 F(PPB_DirectoryReader_API) \ |
19 F(PPB_FileChooser_API) \ | 21 F(PPB_FileChooser_API) \ |
(...skipping 24 matching lines...) Expand all Loading... |
44 | 46 |
45 namespace ppapi { | 47 namespace ppapi { |
46 | 48 |
47 // Forward declare all the resource APIs. | 49 // Forward declare all the resource APIs. |
48 namespace thunk { | 50 namespace thunk { |
49 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; | 51 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; |
50 FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS) | 52 FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS) |
51 #undef DECLARE_RESOURCE_CLASS | 53 #undef DECLARE_RESOURCE_CLASS |
52 } // namespace thunk | 54 } // namespace thunk |
53 | 55 |
54 class ResourceObjectBase { | 56 class ResourceObjectBase : public base::RefCounted<ResourceObjectBase> { |
55 public: | 57 public: |
56 virtual ~ResourceObjectBase(); | 58 virtual ~ResourceObjectBase(); |
57 | 59 |
58 // Dynamic casting for this object. Returns the pointer to the given type if | 60 // Dynamic casting for this object. Returns the pointer to the given type if |
59 // Inheritance-based dynamic casting for this object. Returns the pointer to | 61 // Inheritance-based dynamic casting for this object. Returns the pointer to |
60 // the given type if it's supported. Derived classes override the functions | 62 // the given type if it's supported. Derived classes override the functions |
61 // they support to return the interface. | 63 // they support to return the interface. |
62 #define DEFINE_TYPE_GETTER(RESOURCE) \ | 64 #define DEFINE_TYPE_GETTER(RESOURCE) \ |
63 virtual thunk::RESOURCE* As##RESOURCE(); | 65 virtual thunk::RESOURCE* As##RESOURCE(); |
64 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) | 66 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) |
65 #undef DEFINE_TYPE_GETTER | 67 #undef DEFINE_TYPE_GETTER |
66 | 68 |
67 // Template-based dynamic casting. See specializations below. | 69 // Template-based dynamic casting. See specializations below. |
68 template <typename T> T* GetAs() { return NULL; } | 70 template <typename T> T* GetAs() { return NULL; } |
69 }; | 71 }; |
70 | 72 |
71 // Template-based dynamic casting. These specializations forward to the | 73 // Template-based dynamic casting. These specializations forward to the |
72 // AsXXX virtual functions to return whether the given type is supported. | 74 // AsXXX virtual functions to return whether the given type is supported. |
73 #define DEFINE_RESOURCE_CAST(RESOURCE) \ | 75 #define DEFINE_RESOURCE_CAST(RESOURCE) \ |
74 template<> inline thunk::RESOURCE* ResourceObjectBase::GetAs() { \ | 76 template<> inline thunk::RESOURCE* ResourceObjectBase::GetAs() { \ |
75 return As##RESOURCE(); \ | 77 return As##RESOURCE(); \ |
76 } | 78 } |
77 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST) | 79 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST) |
78 #undef DEFINE_RESOURCE_CAST | 80 #undef DEFINE_RESOURCE_CAST |
79 | 81 |
80 } // namespace ppapi | 82 } // namespace ppapi |
81 | 83 |
82 #endif // PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ | 84 #endif // PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ |
OLD | NEW |