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_PROXY_PLUGIN_RESOURCE_H_ | 5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
6 #define PPAPI_PROXY_PLUGIN_RESOURCE_H_ | 6 #define PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" |
9 #include "ppapi/c/pp_instance.h" | 10 #include "ppapi/c/pp_instance.h" |
10 #include "ppapi/proxy/host_resource.h" | 11 #include "ppapi/proxy/host_resource.h" |
11 #include "ppapi/proxy/plugin_dispatcher.h" | 12 #include "ppapi/proxy/plugin_dispatcher.h" |
12 #include "ppapi/proxy/plugin_resource_tracker.h" | 13 #include "ppapi/proxy/plugin_resource_tracker.h" |
13 #include "ppapi/shared_impl/resource_object_base.h" | 14 #include "ppapi/shared_impl/resource_object_base.h" |
14 | 15 |
15 // If you inherit from resource, make sure you add the class name here. | 16 // If you inherit from resource, make sure you add the class name here. |
16 #define FOR_ALL_PLUGIN_RESOURCES(F) \ | 17 #define FOR_ALL_PLUGIN_RESOURCES(F) \ |
17 F(Audio) \ | 18 F(Audio) \ |
18 F(AudioConfig) \ | 19 F(AudioConfig) \ |
(...skipping 19 matching lines...) Expand all Loading... |
38 F(VideoDecoder) | 39 F(VideoDecoder) |
39 | 40 |
40 namespace pp { | 41 namespace pp { |
41 namespace proxy { | 42 namespace proxy { |
42 | 43 |
43 // Forward declaration of Resource classes. | 44 // Forward declaration of Resource classes. |
44 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; | 45 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; |
45 FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS) | 46 FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS) |
46 #undef DECLARE_RESOURCE_CLASS | 47 #undef DECLARE_RESOURCE_CLASS |
47 | 48 |
48 class PluginResource : public ::ppapi::ResourceObjectBase { | 49 class PluginResource : public ::ppapi::ResourceObjectBase, |
| 50 public base::RefCounted<PluginResource> { |
49 public: | 51 public: |
50 PluginResource(const HostResource& resource); | 52 PluginResource(const HostResource& resource); |
51 virtual ~PluginResource(); | 53 virtual ~PluginResource(); |
52 | 54 |
53 // Returns NULL if the resource is invalid or is a different type. | 55 // Returns NULL if the resource is invalid or is a different type. |
54 template<typename T> static T* GetAs(PP_Resource res) { | 56 template<typename T> static T* GetAs(PP_Resource res) { |
55 PluginResource* resource = | 57 PluginResource* resource = |
56 PluginResourceTracker::GetInstance()->GetResourceObject(res); | 58 PluginResourceTracker::GetInstance()->GetResourceObject(res); |
57 return resource ? resource->Cast<T>() : NULL; | 59 return resource ? resource->Cast<T>() : NULL; |
58 } | 60 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 template <> inline Type* PluginResource::Cast<Type>() { \ | 93 template <> inline Type* PluginResource::Cast<Type>() { \ |
92 return As##Type(); \ | 94 return As##Type(); \ |
93 } | 95 } |
94 FOR_ALL_PLUGIN_RESOURCES(DEFINE_RESOURCE_CAST) | 96 FOR_ALL_PLUGIN_RESOURCES(DEFINE_RESOURCE_CAST) |
95 #undef DEFINE_RESOURCE_CAST | 97 #undef DEFINE_RESOURCE_CAST |
96 | 98 |
97 } // namespace proxy | 99 } // namespace proxy |
98 } // namespace pp | 100 } // namespace pp |
99 | 101 |
100 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ | 102 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
OLD | NEW |