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