summaryrefslogtreecommitdiffstats
path: root/ppapi/shared_impl/scoped_pp_resource.h
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-24 15:19:37 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-24 15:19:37 +0000
commitbbf076f18dbb27fba74de06f4994aa1480690ea3 (patch)
tree6dcabc6d408c997b18f8762fee0fac8470770fb4 /ppapi/shared_impl/scoped_pp_resource.h
parent081c03452bb7d97b138bed3ccc7cbe0903eae05c (diff)
downloadchromium_src-bbf076f18dbb27fba74de06f4994aa1480690ea3.zip
chromium_src-bbf076f18dbb27fba74de06f4994aa1480690ea3.tar.gz
chromium_src-bbf076f18dbb27fba74de06f4994aa1480690ea3.tar.bz2
Remove webkit::ppapi::Resource.
This makes all resource _impl's derive directly from ppapi::Resource so we can share code better. This means removing PluginInstances and converting them to PP_Instances. This adds a new ResourceHelper static class to help in the conversion of resources to PluginInstances for the _impl classes. Overall the new code is in general slightly worse than the old because using the ResourceHelper is more annoying than just calling instance() on the old webkit::ppapi::Resource object. However, I'm hoping that, because this will allow us to move more code into shared_impl and reduce duplicate logic, it will eventually have a net positive effect. This also adds a ScopedPPResource class that works just like a scoped_refptr. We need this in a few places. Most of the places that used the old ScopedResourceId class could be removed now since resources have PP_Resource IDs generated even when there's no plugin reference (this didn't use to be the case) so we can pass resources as input params to the plugin even when there's no plugin ref, as long as there's a scoped_refptr to the Resource. Review URL: http://codereview.chromium.org/7669055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98047 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl/scoped_pp_resource.h')
-rw-r--r--ppapi/shared_impl/scoped_pp_resource.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/ppapi/shared_impl/scoped_pp_resource.h b/ppapi/shared_impl/scoped_pp_resource.h
new file mode 100644
index 0000000..74cb9eb
--- /dev/null
+++ b/ppapi/shared_impl/scoped_pp_resource.h
@@ -0,0 +1,53 @@
+// 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.
+
+#ifndef PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_
+#define PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_
+
+#include "ppapi/c/pp_resource.h"
+
+namespace ppapi {
+
+class Resource;
+
+// This is a version of scoped_refptr but for PP_Resources.
+class ScopedPPResource {
+ public:
+ ScopedPPResource();
+
+ // Takes one reference to the given resource.
+ explicit ScopedPPResource(PP_Resource resource);
+
+ // Helper to get the PP_Resource out of the given object and take a reference
+ // to it.
+ explicit ScopedPPResource(Resource* resource);
+
+ // Implicit copy constructor allowed.
+ ScopedPPResource(const ScopedPPResource& other);
+
+ ~ScopedPPResource();
+
+ ScopedPPResource& operator=(PP_Resource resource);
+ ScopedPPResource& operator=(const ScopedPPResource& resource);
+
+ // Returns the PP_Resource without affecting the refcounting.
+ PP_Resource get() const { return id_; }
+ operator PP_Resource() const { return id_; }
+
+ // Returns the PP_Resource, passing the reference to the caller. This class
+ // will no longer hold the resource.
+ PP_Resource Release();
+
+ private:
+ // Helpers to addref or release the id_ if it's non-NULL. The id_ value will
+ // be unchanged.
+ void CallAddRef();
+ void CallRelease();
+
+ PP_Resource id_;
+};
+
+} // namespace ppapi
+
+#endif // PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_