diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 15:41:01 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 15:41:01 +0000 |
commit | 7f8b26b5f223689de7af4803bc07e1e953ff5953 (patch) | |
tree | d6f3e574d97c6253b8b202264fe23dea1b489dc2 /ppapi/proxy/ppb_video_decoder_proxy.cc | |
parent | d8886526085a42874663be638be1421e78f6172c (diff) | |
download | chromium_src-7f8b26b5f223689de7af4803bc07e1e953ff5953.zip chromium_src-7f8b26b5f223689de7af4803bc07e1e953ff5953.tar.gz chromium_src-7f8b26b5f223689de7af4803bc07e1e953ff5953.tar.bz2 |
Add a unified resource tracker shared between the proxy and the impl.
This renames the old ResourceObjectBase to Resource and removes the old
PluginResource. It moves the resource tracker from the impl to the
shared_impl, and makes the proxy use it.
Some things become a little less neat because there's no proxy resource base
class. In particular GetDispatcher() is now gone. I considered whether to
add a helper base class that provides this function, but decided against it
and had individual resource classes implement this when their implementation
would find it useful. This is because ultimately I want more of this
functionality to move into the shared_impl, and it's easier to do that if
there are fewer proxy-specific things in the resources.
This changes the way that plugins are added to the tracker. Previously they
would only be in the tracker if the plugin had a reference to them, although
they could be alive if the impl had a scoped_ptr referencing an object. This
actually has the bug that if we then give the resource back to the plugin,
it wouldn't be refcounted properly and everything would get confused.
Now the tracker tracks all live resource objects whether or not the plugin
has a ref. This works basically like the var tracker (it would be nice if
the var and resource trackers shared more code, but that would further
complicate this already overcomplicated patch). The resource tracker takes an
extra ref whenever the plugin has one or more, and otherwise just tracks live
resources.
Review URL: http://codereview.chromium.org/7629017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97314 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/ppb_video_decoder_proxy.cc')
-rw-r--r-- | ppapi/proxy/ppb_video_decoder_proxy.cc | 48 |
1 files changed, 15 insertions, 33 deletions
diff --git a/ppapi/proxy/ppb_video_decoder_proxy.cc b/ppapi/proxy/ppb_video_decoder_proxy.cc index 85f6bff..bcc0fc94 100644 --- a/ppapi/proxy/ppb_video_decoder_proxy.cc +++ b/ppapi/proxy/ppb_video_decoder_proxy.cc @@ -16,6 +16,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::HostResource; +using ppapi::Resource; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Buffer_API; using ppapi::thunk::PPB_Context3D_API; @@ -24,16 +25,18 @@ using ppapi::thunk::PPB_VideoDecoder_API; namespace pp { namespace proxy { -class VideoDecoder : public PluginResource, +class VideoDecoder : public Resource, public ::ppapi::VideoDecoderImpl { public: + // You must call Init() before using this class. + explicit VideoDecoder(const HostResource& resource); virtual ~VideoDecoder(); static VideoDecoder* Create(const HostResource& resource, PP_Resource context3d_id, const PP_VideoConfigElement* config); - // ResourceObjectBase overrides. + // Resource overrides. virtual PPB_VideoDecoder_API* AsPPB_VideoDecoder_API() OVERRIDE; // PPB_VideoDecoder_API implementation. @@ -46,13 +49,10 @@ class VideoDecoder : public PluginResource, virtual int32_t Reset(PP_CompletionCallback callback) OVERRIDE; virtual void Destroy() OVERRIDE; - protected: - virtual void AddRefResource(PP_Resource resource) OVERRIDE; - virtual void UnrefResource(PP_Resource resource) OVERRIDE; - private: friend class PPB_VideoDecoder_Proxy; - explicit VideoDecoder(const HostResource& resource); + + PluginDispatcher* GetDispatcher() const; // Run the callbacks that were passed into the plugin interface. void FlushACK(int32_t result); @@ -62,24 +62,7 @@ class VideoDecoder : public PluginResource, DISALLOW_COPY_AND_ASSIGN(VideoDecoder); }; -VideoDecoder::VideoDecoder(const HostResource& decoder) - : PluginResource(decoder) { -} - -VideoDecoder* VideoDecoder::Create(const HostResource& resource, - PP_Resource context3d_id, - const PP_VideoConfigElement* config) { - if (!context3d_id) - return NULL; - - EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true); - if (enter_context.failed()) - return NULL; - - scoped_refptr<VideoDecoder> decoder(new VideoDecoder(resource)); - if (decoder->Init(context3d_id, enter_context.object(), config)) - return decoder.release(); - return NULL; +VideoDecoder::VideoDecoder(const HostResource& decoder) : Resource(decoder) { } VideoDecoder::~VideoDecoder() { @@ -155,12 +138,8 @@ void VideoDecoder::Destroy() { ::ppapi::VideoDecoderImpl::Destroy(); } -void VideoDecoder::AddRefResource(PP_Resource resource) { - PluginResourceTracker::GetInstance()->AddRefResource(resource); -} - -void VideoDecoder::UnrefResource(PP_Resource resource) { - PluginResourceTracker::GetInstance()->ReleaseResource(resource); +PluginDispatcher* VideoDecoder::GetDispatcher() const { + return PluginDispatcher::GetForResource(this); } void VideoDecoder::ResetACK(int32_t result) { @@ -257,8 +236,11 @@ PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource( if (result.is_null()) return 0; - return PluginResourceTracker::GetInstance()->AddResource( - VideoDecoder::Create(result, context3d_id, config)); + // Need a scoped_refptr to keep the object alive during the Init call. + scoped_refptr<VideoDecoder> decoder(new VideoDecoder(result)); + if (!decoder->Init(context3d_id, enter_context.object(), config)) + return 0; + return decoder->GetReference(); } void PPB_VideoDecoder_Proxy::OnMsgCreate( |