summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp
diff options
context:
space:
mode:
authoryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-01 22:16:43 +0000
committeryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-01 22:16:43 +0000
commit60accc164fc11eb2b146cfaf009152ee1017d64b (patch)
tree9d9c151f06def929f5661e2d728a2a03a000eb96 /ppapi/cpp
parentec66d1efde8f062599447c1b74b656ac5449fd5d (diff)
downloadchromium_src-60accc164fc11eb2b146cfaf009152ee1017d64b.zip
chromium_src-60accc164fc11eb2b146cfaf009152ee1017d64b.tar.gz
chromium_src-60accc164fc11eb2b146cfaf009152ee1017d64b.tar.bz2
[PPAPI] Added pp::VarResource_Dev class.
This is a C++ wrapper for the C API PPB_VarResource_Dev. Also added methods to pp::FileSystem for converting a pp::Resource to a pp::FileSystem, which are necessary for making use of a resource extracted using pp::VarResource_Dev. (Committed by yzshen@chromium.org on behalf of mgiuca@chromium.org) BUG=177017 R=dmichael@chromium.org, noelallen@chromium.org, noelallen@google.com, yzshen@chromium.org Review URL: https://codereview.chromium.org/52233002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232482 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp')
-rw-r--r--ppapi/cpp/dev/var_resource_dev.cc70
-rw-r--r--ppapi/cpp/dev/var_resource_dev.h53
-rw-r--r--ppapi/cpp/file_system.cc18
-rw-r--r--ppapi/cpp/file_system.h13
-rw-r--r--ppapi/cpp/resource.cc7
-rw-r--r--ppapi/cpp/resource.h7
-rw-r--r--ppapi/cpp/var.h5
7 files changed, 173 insertions, 0 deletions
diff --git a/ppapi/cpp/dev/var_resource_dev.cc b/ppapi/cpp/dev/var_resource_dev.cc
new file mode 100644
index 0000000..69fb15b
--- /dev/null
+++ b/ppapi/cpp/dev/var_resource_dev.cc
@@ -0,0 +1,70 @@
+// Copyright 2013 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/cpp/dev/var_resource_dev.h"
+
+#include "ppapi/c/dev/ppb_var_resource_dev.h"
+#include "ppapi/cpp/logging.h"
+#include "ppapi/cpp/module_impl.h"
+
+namespace pp {
+
+namespace {
+
+template <> const char* interface_name<PPB_VarResource_Dev_0_1>() {
+ return PPB_VAR_RESOURCE_DEV_INTERFACE_0_1;
+}
+
+} // namespace
+
+VarResource_Dev::VarResource_Dev(const pp::Resource& resource) : Var(Null()) {
+ if (!has_interface<PPB_VarResource_Dev_0_1>()) {
+ PP_NOTREACHED();
+ return;
+ }
+
+ // Note: Var(Null()) sets is_managed_ to true, so |var_| will be properly
+ // released upon destruction.
+ var_ = get_interface<PPB_VarResource_Dev_0_1>()->VarFromResource(
+ resource.pp_resource());
+}
+
+VarResource_Dev::VarResource_Dev(const Var& var) : Var(var) {
+ if (!var.is_resource()) {
+ PP_NOTREACHED();
+
+ // This takes care of releasing the reference that this object holds.
+ Var::operator=(Var(Null()));
+ }
+}
+
+VarResource_Dev::VarResource_Dev(const VarResource_Dev& other) : Var(other) {}
+
+VarResource_Dev::~VarResource_Dev() {}
+
+VarResource_Dev& VarResource_Dev::operator=(const VarResource_Dev& other) {
+ Var::operator=(other);
+ return *this;
+}
+
+Var& VarResource_Dev::operator=(const Var& other) {
+ if (other.is_resource()) {
+ Var::operator=(other);
+ } else {
+ PP_NOTREACHED();
+ Var::operator=(Var(Null()));
+ }
+ return *this;
+}
+
+pp::Resource VarResource_Dev::AsResource() {
+ if (!has_interface<PPB_VarResource_Dev_0_1>())
+ return pp::Resource();
+
+ return pp::Resource(
+ pp::PASS_REF,
+ get_interface<PPB_VarResource_Dev_0_1>()->VarToResource(var_));
+}
+
+} // namespace pp
diff --git a/ppapi/cpp/dev/var_resource_dev.h b/ppapi/cpp/dev/var_resource_dev.h
new file mode 100644
index 0000000..ab879a5
--- /dev/null
+++ b/ppapi/cpp/dev/var_resource_dev.h
@@ -0,0 +1,53 @@
+// Copyright 2013 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_CPP_VAR_RESOURCE_DEV_H_
+#define PPAPI_CPP_VAR_RESOURCE_DEV_H_
+
+#include "ppapi/cpp/resource.h"
+#include "ppapi/cpp/var.h"
+
+/// @file
+/// This file defines the API for interacting with resource vars.
+
+namespace pp {
+
+class VarResource_Dev : public Var {
+ public:
+ /// Constructs a <code>VarResource_Dev</code> given a resource.
+ explicit VarResource_Dev(const pp::Resource& resource);
+
+ /// Constructs a <code>VarResource_Dev</code> given a var for which
+ /// is_resource() is true. This will refer to the same resource var, but allow
+ /// you to access methods specific to resources.
+ ///
+ /// @param[in] var A resource var.
+ explicit VarResource_Dev(const Var& var);
+
+ /// Copy constructor.
+ VarResource_Dev(const VarResource_Dev& other);
+
+ virtual ~VarResource_Dev();
+
+ /// Assignment operator.
+ VarResource_Dev& operator=(const VarResource_Dev& other);
+
+ /// The <code>Var</code> assignment operator is overridden here so that we can
+ /// check for assigning a non-resource var to a <code>VarResource_Dev</code>.
+ ///
+ /// @param[in] other The resource var to be assigned.
+ ///
+ /// @return The resulting <code>VarResource_Dev</code> (as a
+ /// <code>Var</code>&).
+ virtual Var& operator=(const Var& other);
+
+ /// Gets the resource contained in the var.
+ ///
+ /// @return The <code>pp::Resource</code> that is contained in the var.
+ pp::Resource AsResource();
+};
+
+} // namespace pp
+
+#endif // PPAPI_CPP_VAR_RESOURCE_DEV_H_
diff --git a/ppapi/cpp/file_system.cc b/ppapi/cpp/file_system.cc
index f993fda..8bd86d0 100644
--- a/ppapi/cpp/file_system.cc
+++ b/ppapi/cpp/file_system.cc
@@ -9,6 +9,7 @@
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/file_ref.h"
#include "ppapi/cpp/instance_handle.h"
+#include "ppapi/cpp/logging.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
@@ -28,6 +29,15 @@ FileSystem::FileSystem() {
FileSystem::FileSystem(const FileSystem& other) : Resource(other) {
}
+FileSystem::FileSystem(const Resource& resource) : Resource(resource) {
+ if (!IsFileSystem(resource)) {
+ PP_NOTREACHED();
+
+ // On release builds, set this to null.
+ Clear();
+ }
+}
+
FileSystem::FileSystem(PassRef, PP_Resource resource)
: Resource(PASS_REF, resource) {
}
@@ -48,4 +58,12 @@ int32_t FileSystem::Open(int64_t expected_size,
pp_resource(), expected_size, cc.pp_completion_callback());
}
+// static
+bool FileSystem::IsFileSystem(const Resource& resource) {
+ if (!has_interface<PPB_FileSystem_1_0>())
+ return false;
+ return get_interface<PPB_FileSystem_1_0>()->IsFileSystem(
+ resource.pp_resource()) == PP_TRUE;
+}
+
} // namespace pp
diff --git a/ppapi/cpp/file_system.h b/ppapi/cpp/file_system.h
index 9baa78e..96e88c1 100644
--- a/ppapi/cpp/file_system.h
+++ b/ppapi/cpp/file_system.h
@@ -33,6 +33,11 @@ class FileSystem : public Resource {
/// @param[in] other A reference to a <code>FileSystem</code>.
FileSystem(const FileSystem& other);
+ /// Constructs a <code>FileSystem</code> from a <code>Resource</code>.
+ ///
+ /// @param[in] resource A <code>Resource</code> containing a file system.
+ explicit FileSystem(const Resource& resource);
+
/// A constructor used when you have received a PP_Resource as a return
/// value that has already been reference counted.
///
@@ -63,6 +68,14 @@ class FileSystem : public Resource {
///
/// @return An int32_t containing an error code from <code>pp_errors.h</code>.
int32_t Open(int64_t expected_size, const CompletionCallback& cc);
+
+ /// Checks whether a <code>Resource</code> is a file system, to test whether
+ /// it is appropriate for use with the <code>FileSystem</code> constructor.
+ ///
+ /// @param[in] resource A <code>Resource</code> to test.
+ ///
+ /// @return True if <code>resource</code> is a file system.
+ static bool IsFileSystem(const Resource& resource);
};
} // namespace pp
diff --git a/ppapi/cpp/resource.cc b/ppapi/cpp/resource.cc
index 3ccc198..804d34d 100644
--- a/ppapi/cpp/resource.cc
+++ b/ppapi/cpp/resource.cc
@@ -52,4 +52,11 @@ void Resource::PassRefFromConstructor(PP_Resource resource) {
pp_resource_ = resource;
}
+void Resource::Clear() {
+ if (is_null())
+ return;
+ Module::Get()->core()->ReleaseResource(pp_resource_);
+ pp_resource_ = 0;
+}
+
} // namespace pp
diff --git a/ppapi/cpp/resource.h b/ppapi/cpp/resource.h
index 8f5a92d..311db6a 100644
--- a/ppapi/cpp/resource.h
+++ b/ppapi/cpp/resource.h
@@ -14,6 +14,8 @@
/// with the module.
namespace pp {
+class VarResource_Dev;
+
/// A reference counted module resource.
class Resource {
public:
@@ -81,7 +83,12 @@ class Resource {
/// resource.
void PassRefFromConstructor(PP_Resource resource);
+ /// Sets this resource to null. This releases ownership of the resource.
+ void Clear();
+
private:
+ friend class VarResource_Dev;
+
PP_Resource pp_resource_;
};
diff --git a/ppapi/cpp/var.h b/ppapi/cpp/var.h
index fe30e10..5cb26d9 100644
--- a/ppapi/cpp/var.h
+++ b/ppapi/cpp/var.h
@@ -135,6 +135,11 @@ class Var {
/// @return true if this <code>Var</code> is a dictionary, otherwise false.
bool is_dictionary() const { return var_.type == PP_VARTYPE_DICTIONARY; }
+ /// This function determines if this <code>Var</code> is a resource.
+ ///
+ /// @return true if this <code>Var</code> is a resource, otherwise false.
+ bool is_resource() const { return var_.type == PP_VARTYPE_RESOURCE; }
+
/// This function determines if this <code>Var</code> is an integer value.
/// The <code>is_int</code> function returns the internal representation.
/// The JavaScript runtime may convert between the two as needed, so the