diff options
author | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-23 15:09:21 +0000 |
---|---|---|
committer | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-23 15:09:21 +0000 |
commit | c82b014311d37cc8c4ea0c54e41d1925fd7a3df4 (patch) | |
tree | e055d0451d810f83b107b13d8c9569c7eea13ed8 /ppapi/shared_impl | |
parent | eb856a5fc49d6efbf06118d43b453b1be4859540 (diff) | |
download | chromium_src-c82b014311d37cc8c4ea0c54e41d1925fd7a3df4.zip chromium_src-c82b014311d37cc8c4ea0c54e41d1925fd7a3df4.tar.gz chromium_src-c82b014311d37cc8c4ea0c54e41d1925fd7a3df4.tar.bz2 |
[PPAPI] ResourceVar now reference counts its Resource in the plugin.
ResourceVar is now an abstract base class with subclasses
HostResourceVar and PluginResourceVar. The PluginResourceVar has a
reference counted Resource instead of a PP_Resource.
VarTracker has MakeResourceVar and MakeResourcePPVar methods, to
abstract over the creation of a resource var of the correct subclass.
Also, the creation_message is now NULL when empty, instead of being an
empty message object.
BUG=290713
Review URL: https://chromiumcodereview.appspot.com/23809016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224717 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl')
-rw-r--r-- | ppapi/shared_impl/resource_var.cc | 18 | ||||
-rw-r--r-- | ppapi/shared_impl/resource_var.h | 48 | ||||
-rw-r--r-- | ppapi/shared_impl/test_globals.h | 3 | ||||
-rw-r--r-- | ppapi/shared_impl/unittest_utils.cc | 32 | ||||
-rw-r--r-- | ppapi/shared_impl/var.cc | 4 | ||||
-rw-r--r-- | ppapi/shared_impl/var_tracker.cc | 8 | ||||
-rw-r--r-- | ppapi/shared_impl/var_tracker.h | 9 |
7 files changed, 64 insertions, 58 deletions
diff --git a/ppapi/shared_impl/resource_var.cc b/ppapi/shared_impl/resource_var.cc index c5719aa..3e34c38 100644 --- a/ppapi/shared_impl/resource_var.cc +++ b/ppapi/shared_impl/resource_var.cc @@ -9,18 +9,8 @@ namespace ppapi { -ResourceVar::ResourceVar() : pp_resource_(0) {} - -ResourceVar::ResourceVar(PP_Resource pp_resource) : pp_resource_(pp_resource) {} - -ResourceVar::ResourceVar(const IPC::Message& creation_message) - : pp_resource_(0), - creation_message_(creation_message) {} - -ResourceVar::~ResourceVar() {} - -bool ResourceVar::IsPending() const { - return pp_resource_ == 0 && creation_message_.type() != 0; +const IPC::Message* ResourceVar::GetCreationMessage() const { + return NULL; } ResourceVar* ResourceVar::AsResourceVar() { @@ -42,4 +32,8 @@ ResourceVar* ResourceVar::FromPPVar(PP_Var var) { return var_object->AsResourceVar(); } +ResourceVar::ResourceVar() {} + +ResourceVar::~ResourceVar() {} + } // namespace ppapi diff --git a/ppapi/shared_impl/resource_var.h b/ppapi/shared_impl/resource_var.h index 70eabc6..0b8bab2 100644 --- a/ppapi/shared_impl/resource_var.h +++ b/ppapi/shared_impl/resource_var.h @@ -5,42 +5,34 @@ #ifndef PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ #define PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ -#include "ipc/ipc_message.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_var.h" #include "ppapi/shared_impl/ppapi_shared_export.h" #include "ppapi/shared_impl/var.h" +namespace IPC { +class Message; +} + namespace ppapi { // Represents a resource Var. class PPAPI_SHARED_EXPORT ResourceVar : public Var { public: - // Makes a null resource var. - ResourceVar(); - - // Makes a resource var with an existing plugin-side resource. - explicit ResourceVar(PP_Resource pp_resource); - - // Makes a resource var with a pending resource host. - // The |creation_message| contains instructions on how to create the - // plugin-side resource. Its type depends on the type of resource. - explicit ResourceVar(const IPC::Message& creation_message); - - virtual ~ResourceVar(); - // Gets the resource ID associated with this var. - // This is 0 if a resource is still pending. - PP_Resource pp_resource() const { return pp_resource_; } + // This is 0 if a resource is still pending (only possible on the host side). + // NOTE: This can return a PP_Resource with a reference count of 0 on the + // plugin side. It should be AddRef'd if the resource is passed to the user. + virtual PP_Resource GetPPResource() const = 0; - // Gets the message for creating a plugin-side resource. - // May be an empty message. - const IPC::Message& creation_message() const { return creation_message_; } + // Gets the message for creating a plugin-side resource. Returns NULL if the + // message is empty (which is always true on the plugin side). + virtual const IPC::Message* GetCreationMessage() const; // Determines whether this is a pending resource. - // This is true if the pp_resource is 0 and there is a non-empty - // creation_message. - bool IsPending() const; + // This is true if, on the host side, the there is a creation_message and no + // PP_Resource. + virtual bool IsPending() const = 0; // Var override. virtual ResourceVar* AsResourceVar() OVERRIDE; @@ -50,16 +42,12 @@ class PPAPI_SHARED_EXPORT ResourceVar : public Var { // return NULL if the PP_Var is not of Resource type. static ResourceVar* FromPPVar(PP_Var var); - private: - // Real resource ID in the plugin. 0 if one has not yet been created - // (indicating that there is a pending host resource). - PP_Resource pp_resource_; + protected: + ResourceVar(); - // If the plugin-side resource has not yet been created, carries a message to - // create a resource of the specific type on the plugin side. - // Otherwise, carries an empty message. - IPC::Message creation_message_; + virtual ~ResourceVar(); + private: DISALLOW_COPY_AND_ASSIGN(ResourceVar); }; diff --git a/ppapi/shared_impl/test_globals.h b/ppapi/shared_impl/test_globals.h index 709438e..2a0ece3 100644 --- a/ppapi/shared_impl/test_globals.h +++ b/ppapi/shared_impl/test_globals.h @@ -18,6 +18,9 @@ class TestVarTracker : public VarTracker { public: TestVarTracker() : VarTracker(THREAD_SAFE) {} virtual ~TestVarTracker() {} + virtual ResourceVar* MakeResourceVar(PP_Resource pp_resource) OVERRIDE { + return NULL; + } virtual ArrayBufferVar* CreateArrayBuffer(uint32 size_in_bytes) OVERRIDE { return NULL; } diff --git a/ppapi/shared_impl/unittest_utils.cc b/ppapi/shared_impl/unittest_utils.cc index f613882..6974bd2 100644 --- a/ppapi/shared_impl/unittest_utils.cc +++ b/ppapi/shared_impl/unittest_utils.cc @@ -8,6 +8,7 @@ #include "base/containers/hash_tables.h" #include "base/logging.h" +#include "ipc/ipc_message.h" #include "ppapi/shared_impl/array_var.h" #include "ppapi/shared_impl/dictionary_var.h" #include "ppapi/shared_impl/resource_var.h" @@ -156,17 +157,19 @@ bool Equals(const PP_Var& expected, ResourceVar* expected_var = ResourceVar::FromPPVar(expected); ResourceVar* actual_var = ResourceVar::FromPPVar(actual); DCHECK(expected_var && actual_var); - if (expected_var->pp_resource() != actual_var->pp_resource()) { - LOG(ERROR) << "expected: " << expected_var->pp_resource() << " actual: " - << actual_var->pp_resource(); + if (expected_var->GetPPResource() != actual_var->GetPPResource()) { + LOG(ERROR) << "expected: " << expected_var->GetPPResource() + << " actual: " << actual_var->GetPPResource(); return false; } - IPC::Message actual_message(actual_var->creation_message()); - const IPC::Message& expected_message = expected_var->creation_message(); - if (expected_message.size() != actual_message.size()) { + + const IPC::Message* actual_message = actual_var->GetCreationMessage(); + const IPC::Message* expected_message = + expected_var->GetCreationMessage(); + if (expected_message->size() != actual_message->size()) { LOG(ERROR) << "expected creation message size: " - << expected_message.size() << " actual: " - << actual_message.size(); + << expected_message->size() << " actual: " + << actual_message->size(); return false; } @@ -174,12 +177,13 @@ bool Equals(const PP_Var& expected, // expected. This is an unpredictable reference number that changes // between serialization/deserialization, and we do not want it to cause // the comparison to fail. - actual_message.SetHeaderValues(actual_message.routing_id(), - actual_message.type(), - (expected_message.flags() & 0xffffff00) | - (actual_message.flags() & 0xff)); - if (memcmp(expected_message.data(), actual_message.data(), - expected_message.size()) != 0) { + IPC::Message local_actual_message(*actual_message); + local_actual_message.SetHeaderValues( + actual_message->routing_id(), actual_message->type(), + (expected_message->flags() & 0xffffff00) | + (actual_message->flags() & 0xff)); + if (memcmp(expected_message->data(), local_actual_message.data(), + expected_message->size()) != 0) { LOG(ERROR) << "expected creation message does not match actual."; return false; } diff --git a/ppapi/shared_impl/var.cc b/ppapi/shared_impl/var.cc index 9644a44..d128d90 100644 --- a/ppapi/shared_impl/var.cc +++ b/ppapi/shared_impl/var.cc @@ -71,8 +71,8 @@ std::string Var::PPVarToLogString(PP_Var var) { if (resource->IsPending()) { return base::StringPrintf("[Pending resource]"); - } else if (resource->pp_resource()) { - return base::StringPrintf("[Resource %d]", resource->pp_resource()); + } else if (resource->GetPPResource()) { + return base::StringPrintf("[Resource %d]", resource->GetPPResource()); } else { return "[Null resource]"; } diff --git a/ppapi/shared_impl/var_tracker.cc b/ppapi/shared_impl/var_tracker.cc index 254c51a..bada0ab 100644 --- a/ppapi/shared_impl/var_tracker.cc +++ b/ppapi/shared_impl/var_tracker.cc @@ -13,6 +13,7 @@ #include "ppapi/shared_impl/host_resource.h" #include "ppapi/shared_impl/id_assignment.h" #include "ppapi/shared_impl/proxy_lock.h" +#include "ppapi/shared_impl/resource_var.h" #include "ppapi/shared_impl/var.h" namespace ppapi { @@ -234,6 +235,13 @@ PP_Var VarTracker::MakeArrayBufferPPVar(uint32 size_in_bytes, return array_buffer->GetPPVar(); } +PP_Var VarTracker::MakeResourcePPVar(PP_Resource pp_resource) { + CheckThreadingPreconditions(); + + ResourceVar* resource_var = MakeResourceVar(pp_resource); + return resource_var ? resource_var->GetPPVar() : PP_MakeNull(); +} + std::vector<PP_Var> VarTracker::GetLiveVars() { CheckThreadingPreconditions(); diff --git a/ppapi/shared_impl/var_tracker.h b/ppapi/shared_impl/var_tracker.h index d7fb49c..379f645 100644 --- a/ppapi/shared_impl/var_tracker.h +++ b/ppapi/shared_impl/var_tracker.h @@ -85,6 +85,15 @@ class PPAPI_SHARED_EXPORT VarTracker { // usually immediately put this in a scoped_refptr). ArrayBufferVar* MakeArrayBufferVar(uint32 size_in_bytes, const void* data); + // Creates a new resource var that points to a given resource ID. Returns a + // PP_Var that references it and has an initial reference count of 1. + PP_Var MakeResourcePPVar(PP_Resource pp_resource); + + // Creates a new resource var that points to a given resource ID. This is + // implemented by the host and plugin tracker separately, because the plugin + // keeps a reference to the resource, and the host does not. + virtual ResourceVar* MakeResourceVar(PP_Resource pp_resource) = 0; + // Return a vector containing all PP_Vars that are in the tracker. This is // to help implement PPB_Testing_Dev.GetLiveVars and should generally not be // used in production code. The PP_Vars are returned in no particular order, |