summaryrefslogtreecommitdiffstats
path: root/ppapi/shared_impl
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-01 07:19:31 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-01 07:19:31 +0000
commitcd910b93160f754297e51b27bdbc5f98cf52a743 (patch)
tree098dd0816260568abeae1662fa7de759e8372c49 /ppapi/shared_impl
parent20da3817eb403599ec87537bf2bc862446a13abf (diff)
downloadchromium_src-cd910b93160f754297e51b27bdbc5f98cf52a743.zip
chromium_src-cd910b93160f754297e51b27bdbc5f98cf52a743.tar.gz
chromium_src-cd910b93160f754297e51b27bdbc5f98cf52a743.tar.bz2
Convert more interfaces to the new thunk system. This goes up to and including
the ones starting with "F". Since this adds a lot more interfaces, I added the macro stuff we used for the old system to generate the various template specializations. This involded a lot of renaming since the As* needs to match the name (I was previously leaving off the "PPB_" part). I did other misc cleanup to the infrastructure. Review URL: http://codereview.chromium.org/7082036 Reland 87415 Review URL: http://codereview.chromium.org/7105013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87444 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl')
-rw-r--r--ppapi/shared_impl/audio_impl.cc2
-rw-r--r--ppapi/shared_impl/audio_impl.h2
-rw-r--r--ppapi/shared_impl/function_group_base.cc17
-rw-r--r--ppapi/shared_impl/function_group_base.h68
-rw-r--r--ppapi/shared_impl/resource_object_base.cc18
-rw-r--r--ppapi/shared_impl/resource_object_base.h94
-rw-r--r--ppapi/shared_impl/tracker_base.h4
7 files changed, 116 insertions, 89 deletions
diff --git a/ppapi/shared_impl/audio_impl.cc b/ppapi/shared_impl/audio_impl.cc
index 0173d6e..09d4589 100644
--- a/ppapi/shared_impl/audio_impl.cc
+++ b/ppapi/shared_impl/audio_impl.cc
@@ -25,7 +25,7 @@ AudioImpl::~AudioImpl() {
}
}
-::ppapi::thunk::PPB_Audio_API* AudioImpl::AsAudio_API() {
+::ppapi::thunk::PPB_Audio_API* AudioImpl::AsPPB_Audio_API() {
return this;
}
diff --git a/ppapi/shared_impl/audio_impl.h b/ppapi/shared_impl/audio_impl.h
index ba7c780..4916cd6 100644
--- a/ppapi/shared_impl/audio_impl.h
+++ b/ppapi/shared_impl/audio_impl.h
@@ -26,7 +26,7 @@ class AudioImpl : public ResourceObjectBase,
virtual ~AudioImpl();
// ResourceObjectBase implementation.
- virtual ::ppapi::thunk::PPB_Audio_API* AsAudio_API() OVERRIDE;
+ virtual ::ppapi::thunk::PPB_Audio_API* AsPPB_Audio_API() OVERRIDE;
bool playing() const { return playing_; }
diff --git a/ppapi/shared_impl/function_group_base.cc b/ppapi/shared_impl/function_group_base.cc
new file mode 100644
index 0000000..8fb7ad5
--- /dev/null
+++ b/ppapi/shared_impl/function_group_base.cc
@@ -0,0 +1,17 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/shared_impl/function_group_base.h"
+
+namespace ppapi {
+
+FunctionGroupBase::~FunctionGroupBase() {
+}
+
+#define DEFINE_TYPE_GETTER(FUNCTIONS) \
+ thunk::FUNCTIONS* FunctionGroupBase::As##FUNCTIONS() { return NULL; }
+FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_TYPE_GETTER)
+#undef DEFINE_TYPE_GETTER
+
+} // namespace ppapi
diff --git a/ppapi/shared_impl/function_group_base.h b/ppapi/shared_impl/function_group_base.h
index 4f98396..6f828ae 100644
--- a/ppapi/shared_impl/function_group_base.h
+++ b/ppapi/shared_impl/function_group_base.h
@@ -5,53 +5,49 @@
#ifndef PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_
#define PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_
+#include <stddef.h> // For NULL.
+
+#define FOR_ALL_PPAPI_FUNCTION_APIS(F) \
+ F(PPB_CharSet_FunctionAPI) \
+ F(PPB_CursorControl_FunctionAPI) \
+ F(PPB_Find_FunctionAPI) \
+ F(PPB_Font_FunctionAPI) \
+ F(ResourceCreationAPI)
+
namespace ppapi {
+// Forward declare all the function APIs.
namespace thunk {
-class PPB_CharSet_FunctionAPI;
-class PPB_CursorControl_FunctionAPI;
-class PPB_Font_FunctionAPI;
-class ResourceCreationAPI;
-}
+#define DECLARE_FUNCTION_CLASS(FUNCTIONS) class FUNCTIONS;
+FOR_ALL_PPAPI_FUNCTION_APIS(DECLARE_FUNCTION_CLASS)
+#undef DECLARE_FUNCTION_CLASS
+} // namespace thunk
class FunctionGroupBase {
public:
- virtual ~FunctionGroupBase() {}
+ virtual ~FunctionGroupBase();
// Dynamic casting for this object. Returns the pointer to the given type if
- // it's supported.
- virtual thunk::PPB_CharSet_FunctionAPI* AsCharSet_FunctionAPI() {
- return NULL;
- }
- virtual thunk::PPB_CursorControl_FunctionAPI* AsCursorControl_FunctionAPI() {
- return NULL;
- }
- virtual thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() {
- return NULL;
- }
- virtual thunk::ResourceCreationAPI* AsResourceCreation() {
- return NULL;
- }
-
+ // Inheritance-based dynamic casting for this object. Returns the pointer to
+ // the given type if it's supported. Derived classes override the functions
+ // they support to return the interface.
+ #define DEFINE_TYPE_GETTER(FUNCTIONS) \
+ virtual thunk::FUNCTIONS* As##FUNCTIONS();
+ FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_TYPE_GETTER)
+ #undef DEFINE_TYPE_GETTER
+
+ // Template-based dynamic casting. See specializations below.
template <typename T> T* GetAs() { return NULL; }
};
-template<>
-inline thunk::PPB_CharSet_FunctionAPI* FunctionGroupBase::GetAs() {
- return AsCharSet_FunctionAPI();
-}
-template<>
-inline thunk::PPB_CursorControl_FunctionAPI* FunctionGroupBase::GetAs() {
- return AsCursorControl_FunctionAPI();
-}
-template<>
-inline thunk::PPB_Font_FunctionAPI* FunctionGroupBase::GetAs() {
- return AsFont_FunctionAPI();
-}
-template<>
-inline ppapi::thunk::ResourceCreationAPI* FunctionGroupBase::GetAs() {
- return AsResourceCreation();
-}
+// Template-based dynamic casting. These specializations forward to the
+// AsXXX virtual functions to return whether the given type is supported.
+#define DEFINE_FUNCTION_CAST(FUNCTIONS) \
+ template<> inline thunk::FUNCTIONS* FunctionGroupBase::GetAs() { \
+ return As##FUNCTIONS(); \
+ }
+FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_FUNCTION_CAST)
+#undef DEFINE_FUNCTION_CAST
} // namespace ppapi
diff --git a/ppapi/shared_impl/resource_object_base.cc b/ppapi/shared_impl/resource_object_base.cc
new file mode 100644
index 0000000..4c0a9af
--- /dev/null
+++ b/ppapi/shared_impl/resource_object_base.cc
@@ -0,0 +1,18 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/shared_impl/resource_object_base.h"
+
+namespace ppapi {
+
+ResourceObjectBase::~ResourceObjectBase() {
+}
+
+#define DEFINE_TYPE_GETTER(RESOURCE) \
+ thunk::RESOURCE* ResourceObjectBase::As##RESOURCE() { return NULL; }
+FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER)
+#undef DEFINE_TYPE_GETTER
+
+} // namespace ppapi
+
diff --git a/ppapi/shared_impl/resource_object_base.h b/ppapi/shared_impl/resource_object_base.h
index c8d88c1..00ac498 100644
--- a/ppapi/shared_impl/resource_object_base.h
+++ b/ppapi/shared_impl/resource_object_base.h
@@ -5,66 +5,58 @@
#ifndef PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_
#define PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_
+#include <stddef.h> // For NULL.
+
+#define FOR_ALL_PPAPI_RESOURCE_APIS(F) \
+ F(PPB_Audio_API) \
+ F(PPB_AudioConfig_API) \
+ F(PPB_AudioTrusted_API) \
+ F(PPB_Broker_API) \
+ F(PPB_Buffer_API) \
+ F(PPB_DirectoryReader_API) \
+ F(PPB_FileChooser_API) \
+ F(PPB_FileIO_API) \
+ F(PPB_FileRef_API) \
+ F(PPB_FileSystem_API) \
+ F(PPB_Find_API) \
+ F(PPB_Font_API) \
+ F(PPB_Graphics2D_API) \
+ F(PPB_ImageData_API)
+
namespace ppapi {
+// Forward declare all the resource APIs.
namespace thunk {
-class PPB_Audio_API;
-class PPB_AudioConfig_API;
-class PPB_AudioTrusted_API;
-class PPB_Broker_API;
-class PPB_Buffer_API;
-class PPB_Font_API;
-class PPB_Graphics2D_API;
-class PPB_ImageData_API;
-}
+#define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE;
+FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS)
+#undef DECLARE_RESOURCE_CLASS
+} // namespace thunk
class ResourceObjectBase {
public:
-
- virtual thunk::PPB_Audio_API* AsAudio_API() { return NULL; }
- virtual thunk::PPB_AudioConfig_API* AsAudioConfig_API() { return NULL; }
- virtual thunk::PPB_AudioTrusted_API* AsAudioTrusted_API() { return NULL; }
- virtual thunk::PPB_Buffer_API* AsBuffer_API() { return NULL; }
- virtual thunk::PPB_Broker_API* AsBroker_API() { return NULL; }
- virtual thunk::PPB_Font_API* AsFont_API() { return NULL; }
- virtual thunk::PPB_Graphics2D_API* AsGraphics2D_API() { return NULL; }
- virtual thunk::PPB_ImageData_API* AsImageData_API() { return NULL; }
-
+ virtual ~ResourceObjectBase();
+
+ // Dynamic casting for this object. Returns the pointer to the given type if
+ // Inheritance-based dynamic casting for this object. Returns the pointer to
+ // the given type if it's supported. Derived classes override the functions
+ // they support to return the interface.
+ #define DEFINE_TYPE_GETTER(RESOURCE) \
+ virtual thunk::RESOURCE* As##RESOURCE();
+ FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER)
+ #undef DEFINE_TYPE_GETTER
+
+ // Template-based dynamic casting. See specializations below.
template <typename T> T* GetAs() { return NULL; }
};
-template<>
-inline thunk::PPB_Audio_API* ResourceObjectBase::GetAs() {
- return AsAudio_API();
-}
-template<>
-inline thunk::PPB_AudioConfig_API* ResourceObjectBase::GetAs() {
- return AsAudioConfig_API();
-}
-template<>
-inline thunk::PPB_AudioTrusted_API* ResourceObjectBase::GetAs() {
- return AsAudioTrusted_API();
-}
-template<>
-inline thunk::PPB_Broker_API* ResourceObjectBase::GetAs() {
- return AsBroker_API();
-}
-template<>
-inline thunk::PPB_Buffer_API* ResourceObjectBase::GetAs() {
- return AsBuffer_API();
-}
-template<>
-inline thunk::PPB_Font_API* ResourceObjectBase::GetAs() {
- return AsFont_API();
-}
-template<>
-inline thunk::PPB_Graphics2D_API* ResourceObjectBase::GetAs() {
- return AsGraphics2D_API();
-}
-template<>
-inline thunk::PPB_ImageData_API* ResourceObjectBase::GetAs() {
- return AsImageData_API();
-}
+// Template-based dynamic casting. These specializations forward to the
+// AsXXX virtual functions to return whether the given type is supported.
+#define DEFINE_RESOURCE_CAST(RESOURCE) \
+ template<> inline thunk::RESOURCE* ResourceObjectBase::GetAs() { \
+ return As##RESOURCE(); \
+ }
+FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST)
+#undef DEFINE_RESOURCE_CAST
} // namespace ppapi
diff --git a/ppapi/shared_impl/tracker_base.h b/ppapi/shared_impl/tracker_base.h
index 4b7e447..28cd442 100644
--- a/ppapi/shared_impl/tracker_base.h
+++ b/ppapi/shared_impl/tracker_base.h
@@ -40,6 +40,10 @@ class TrackerBase {
// there isn't one.
virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst,
pp::proxy::InterfaceID id) = 0;
+
+ // Returns the instance corresponding to the given resource, or 0 if the
+ // resource is invalid.
+ virtual PP_Instance GetInstanceForResource(PP_Resource resource) = 0;
};
} // namespace ppapi