summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/plugins/ppapi')
-rw-r--r--webkit/plugins/ppapi/host_globals.h6
-rw-r--r--webkit/plugins/ppapi/host_resource_tracker.cc95
-rw-r--r--webkit/plugins/ppapi/host_resource_tracker.h29
-rw-r--r--webkit/plugins/ppapi/host_var_tracker.cc112
-rw-r--r--webkit/plugins/ppapi/host_var_tracker.h83
-rw-r--r--webkit/plugins/ppapi/host_var_tracker_unittest.cc (renamed from webkit/plugins/ppapi/host_resource_tracker_unittest.cc)16
-rw-r--r--webkit/plugins/ppapi/npapi_glue.cc4
-rw-r--r--webkit/plugins/ppapi/npobject_var.cc6
8 files changed, 217 insertions, 134 deletions
diff --git a/webkit/plugins/ppapi/host_globals.h b/webkit/plugins/ppapi/host_globals.h
index 4c6a7d0..a213d68 100644
--- a/webkit/plugins/ppapi/host_globals.h
+++ b/webkit/plugins/ppapi/host_globals.h
@@ -9,6 +9,7 @@
#include "ppapi/shared_impl/ppapi_globals.h"
#include "ppapi/shared_impl/var_tracker.h"
#include "webkit/plugins/ppapi/host_resource_tracker.h"
+#include "webkit/plugins/ppapi/host_var_tracker.h"
namespace webkit {
namespace ppapi {
@@ -30,12 +31,15 @@ class HostGlobals : public ::ppapi::PpapiGlobals {
HostResourceTracker* host_resource_tracker() {
return &host_resource_tracker_;
}
+ HostVarTracker* host_var_tracker() {
+ return &host_var_tracker_;
+ }
private:
static HostGlobals* host_globals_;
HostResourceTracker host_resource_tracker_;
- ::ppapi::VarTracker host_var_tracker_;
+ HostVarTracker host_var_tracker_;
DISALLOW_COPY_AND_ASSIGN(HostGlobals);
};
diff --git a/webkit/plugins/ppapi/host_resource_tracker.cc b/webkit/plugins/ppapi/host_resource_tracker.cc
index 63a37dd..69119e49 100644
--- a/webkit/plugins/ppapi/host_resource_tracker.cc
+++ b/webkit/plugins/ppapi/host_resource_tracker.cc
@@ -29,7 +29,6 @@ using ppapi::CheckIdType;
using ppapi::MakeTypedId;
using ppapi::NPObjectVar;
using ppapi::PPIdType;
-using ppapi::Var;
namespace webkit {
namespace ppapi {
@@ -42,8 +41,6 @@ namespace {
} // namespace
-typedef std::map<NPObject*, NPObjectVar*> NPObjectToNPObjectVarMap;
-
struct HostResourceTracker::InstanceData {
InstanceData() : instance(0) {}
@@ -51,12 +48,6 @@ struct HostResourceTracker::InstanceData {
// destroyed, it will notify us and we'll delete all associated data.
PluginInstance* instance;
- // Tracks all live NPObjectVars used by this module so we can map NPObjects
- // to the corresponding object, and also release these properly if the
- // instance goes away when there are still refs. These are non-owning
- // references.
- NPObjectToNPObjectVarMap np_object_to_object_var;
-
// Lazily allocated function proxies for the different interfaces.
scoped_ptr< ::ppapi::FunctionGroupBase >
function_proxies[::ppapi::proxy::INTERFACE_ID_COUNT];
@@ -70,39 +61,6 @@ HostResourceTracker::HostResourceTracker() {
HostResourceTracker::~HostResourceTracker() {
}
-void HostResourceTracker::CleanupInstanceData(PP_Instance instance,
- bool delete_instance) {
- DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE))
- << instance << " is not a PP_Instance.";
- InstanceMap::iterator found = instance_map_.find(instance);
- if (found == instance_map_.end()) {
- NOTREACHED();
- return;
- }
- InstanceData& data = *found->second;
-
- // Force delete all var references. Need to make a copy so we can iterate over
- // the map while deleting stuff from it.
- NPObjectToNPObjectVarMap np_object_map_copy = data.np_object_to_object_var;
- NPObjectToNPObjectVarMap::iterator cur_var =
- np_object_map_copy.begin();
- while (cur_var != np_object_map_copy.end()) {
- NPObjectToNPObjectVarMap::iterator current = cur_var++;
-
- // Clear the object from the var mapping and the live instance object list.
- int32 var_id = current->second->GetExistingVarID();
- if (var_id)
- live_vars_.erase(var_id);
-
- current->second->InstanceDeleted();
- data.np_object_to_object_var.erase(current->first);
- }
- DCHECK(data.np_object_to_object_var.empty());
-
- if (delete_instance)
- instance_map_.erase(found);
-}
-
::ppapi::FunctionGroupBase* HostResourceTracker::GetFunctionAPI(
PP_Instance pp_instance,
::ppapi::proxy::InterfaceID id) {
@@ -163,52 +121,6 @@ void HostResourceTracker::LastPluginRefWasDeleted(::ppapi::Resource* object) {
}
}
-void HostResourceTracker::AddNPObjectVar(NPObjectVar* object_var) {
- DCHECK(instance_map_.find(object_var->pp_instance()) != instance_map_.end());
- InstanceData& data = *instance_map_[object_var->pp_instance()].get();
-
- DCHECK(data.np_object_to_object_var.find(object_var->np_object()) ==
- data.np_object_to_object_var.end()) << "NPObjectVar already in map";
- data.np_object_to_object_var[object_var->np_object()] = object_var;
-}
-
-void HostResourceTracker::RemoveNPObjectVar(NPObjectVar* object_var) {
- DCHECK(instance_map_.find(object_var->pp_instance()) != instance_map_.end());
- InstanceData& data = *instance_map_[object_var->pp_instance()].get();
-
- NPObjectToNPObjectVarMap::iterator found =
- data.np_object_to_object_var.find(object_var->np_object());
- if (found == data.np_object_to_object_var.end()) {
- NOTREACHED() << "NPObjectVar not registered.";
- return;
- }
- if (found->second != object_var) {
- NOTREACHED() << "NPObjectVar doesn't match.";
- return;
- }
- data.np_object_to_object_var.erase(found);
-}
-
-NPObjectVar* HostResourceTracker::NPObjectVarForNPObject(PP_Instance instance,
- NPObject* np_object) {
- DCHECK(instance_map_.find(instance) != instance_map_.end());
- InstanceData& data = *instance_map_[instance].get();
-
- NPObjectToNPObjectVarMap::iterator found =
- data.np_object_to_object_var.find(np_object);
- if (found == data.np_object_to_object_var.end())
- return NULL;
- return found->second;
-}
-
-int HostResourceTracker::GetLiveNPObjectVarsForInstance(
- PP_Instance instance) const {
- InstanceMap::const_iterator found = instance_map_.find(instance);
- if (found == instance_map_.end())
- return 0;
- return static_cast<int>(found->second->np_object_to_object_var.size());
-}
-
PP_Instance HostResourceTracker::AddInstance(PluginInstance* instance) {
DCHECK(instance_map_.find(instance->pp_instance()) == instance_map_.end());
@@ -233,12 +145,15 @@ PP_Instance HostResourceTracker::AddInstance(PluginInstance* instance) {
void HostResourceTracker::InstanceDeleted(PP_Instance instance) {
DidDeleteInstance(instance);
- CleanupInstanceData(instance, true);
+ HostGlobals::Get()->host_var_tracker()->ForceFreeNPObjectsForInstance(
+ instance);
+ instance_map_.erase(instance);
}
void HostResourceTracker::InstanceCrashed(PP_Instance instance) {
DidDeleteInstance(instance);
- CleanupInstanceData(instance, false);
+ HostGlobals::Get()->host_var_tracker()->ForceFreeNPObjectsForInstance(
+ instance);
}
PluginInstance* HostResourceTracker::GetInstance(PP_Instance instance) {
diff --git a/webkit/plugins/ppapi/host_resource_tracker.h b/webkit/plugins/ppapi/host_resource_tracker.h
index 1883707..0c1e56f 100644
--- a/webkit/plugins/ppapi/host_resource_tracker.h
+++ b/webkit/plugins/ppapi/host_resource_tracker.h
@@ -59,25 +59,6 @@ class HostResourceTracker : public ::ppapi::TrackerBase,
// ppapi::ResourceTracker overrides.
virtual void LastPluginRefWasDeleted(::ppapi::Resource* object) OVERRIDE;
- // PP_Vars -------------------------------------------------------------------
-
- // Tracks all live NPObjectVar. This is so we can map between instance +
- // NPObject and get the NPObjectVar corresponding to it. This Add/Remove
- // function is called by the NPObjectVar when it is created and
- // destroyed.
- void AddNPObjectVar(::ppapi::NPObjectVar* object_var);
- void RemoveNPObjectVar(::ppapi::NPObjectVar* object_var);
-
- // Looks up a previously registered NPObjectVar for the given NPObject and
- // instance. Returns NULL if there is no NPObjectVar corresponding to the
- // given NPObject for the given instance. See AddNPObjectVar above.
- ::ppapi::NPObjectVar* NPObjectVarForNPObject(PP_Instance instance,
- NPObject* np_object);
-
- // Returns the number of NPObjectVar's associated with the given instance.
- // Returns 0 if the instance isn't known.
- int GetLiveNPObjectVarsForInstance(PP_Instance instance) const;
-
// PP_Modules ----------------------------------------------------------------
// Adds a new plugin module to the list of tracked module, and returns a new
@@ -117,16 +98,6 @@ class HostResourceTracker : public ::ppapi::TrackerBase,
// Per-instance data we track.
struct InstanceData;
- // Force frees all vars and resources associated with the given instance.
- // If delete_instance is true, the instance tracking information will also
- // be deleted.
- void CleanupInstanceData(PP_Instance instance, bool delete_instance);
-
- // Like ResourceAndRefCount but for vars, which are associated with modules.
- typedef std::pair<scoped_refptr< ::ppapi::Var>, size_t> VarAndRefCount;
- typedef base::hash_map<int32, VarAndRefCount> VarMap;
- VarMap live_vars_;
-
// Tracks all live instances and their associated data.
typedef std::map<PP_Instance, linked_ptr<InstanceData> > InstanceMap;
InstanceMap instance_map_;
diff --git a/webkit/plugins/ppapi/host_var_tracker.cc b/webkit/plugins/ppapi/host_var_tracker.cc
new file mode 100644
index 0000000..0508d2c
--- /dev/null
+++ b/webkit/plugins/ppapi/host_var_tracker.cc
@@ -0,0 +1,112 @@
+// 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 "webkit/plugins/ppapi/host_var_tracker.h"
+
+#include "base/logging.h"
+#include "ppapi/c/pp_var.h"
+#include "webkit/plugins/ppapi/npobject_var.h"
+#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+
+using ppapi::NPObjectVar;
+
+namespace webkit {
+namespace ppapi {
+
+HostVarTracker::HostVarTracker() {
+}
+
+HostVarTracker::~HostVarTracker() {
+}
+
+void HostVarTracker::AddNPObjectVar(NPObjectVar* object_var) {
+ InstanceMap::iterator found_instance = instance_map_.find(
+ object_var->pp_instance());
+ if (found_instance == instance_map_.end()) {
+ // Lazily create the instance map.
+ DCHECK(object_var->pp_instance() != 0);
+ found_instance = instance_map_.insert(std::make_pair(
+ object_var->pp_instance(),
+ linked_ptr<NPObjectToNPObjectVarMap>(new NPObjectToNPObjectVarMap))).
+ first;
+ }
+ NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get();
+
+ DCHECK(np_object_map->find(object_var->np_object()) ==
+ np_object_map->end()) << "NPObjectVar already in map";
+ np_object_map->insert(
+ std::make_pair(object_var->np_object(), object_var));
+}
+
+void HostVarTracker::RemoveNPObjectVar(NPObjectVar* object_var) {
+ InstanceMap::iterator found_instance = instance_map_.find(
+ object_var->pp_instance());
+ if (found_instance == instance_map_.end()) {
+ NOTREACHED() << "NPObjectVar has invalid instance.";
+ return;
+ }
+ NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get();
+
+ NPObjectToNPObjectVarMap::iterator found_object =
+ np_object_map->find(object_var->np_object());
+ if (found_object == np_object_map->end()) {
+ NOTREACHED() << "NPObjectVar not registered.";
+ return;
+ }
+ if (found_object->second != object_var) {
+ NOTREACHED() << "NPObjectVar doesn't match.";
+ return;
+ }
+ np_object_map->erase(found_object);
+
+ // Clean up when the map is empty.
+ if (np_object_map->empty())
+ instance_map_.erase(found_instance);
+}
+
+NPObjectVar* HostVarTracker::NPObjectVarForNPObject(PP_Instance instance,
+ NPObject* np_object) {
+ InstanceMap::iterator found_instance = instance_map_.find(instance);
+ if (found_instance == instance_map_.end())
+ return NULL; // No such instance.
+ NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get();
+
+ NPObjectToNPObjectVarMap::iterator found_object =
+ np_object_map->find(np_object);
+ if (found_object == np_object_map->end())
+ return NULL; // No such object.
+ return found_object->second;
+}
+
+int HostVarTracker::GetLiveNPObjectVarsForInstance(PP_Instance instance) const {
+ InstanceMap::const_iterator found = instance_map_.find(instance);
+ if (found == instance_map_.end())
+ return 0;
+ return static_cast<int>(found->second->size());
+}
+
+void HostVarTracker::ForceFreeNPObjectsForInstance(PP_Instance instance) {
+ InstanceMap::iterator found_instance = instance_map_.find(instance);
+ if (found_instance == instance_map_.end())
+ return; // Nothing to do.
+ NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get();
+
+ // Force delete all var references. Need to make a copy so we can iterate over
+ // the map while deleting stuff from it.
+ NPObjectToNPObjectVarMap np_object_map_copy = *np_object_map;
+ NPObjectToNPObjectVarMap::iterator cur_var =
+ np_object_map_copy.begin();
+ while (cur_var != np_object_map_copy.end()) {
+ NPObjectToNPObjectVarMap::iterator current = cur_var++;
+ current->second->InstanceDeleted();
+ np_object_map->erase(current->first);
+ }
+
+ // Remove the record for this instance since it should be empty.
+ DCHECK(np_object_map->empty());
+ instance_map_.erase(found_instance);
+}
+
+} // namespace ppapi
+} // namespace webkit
diff --git a/webkit/plugins/ppapi/host_var_tracker.h b/webkit/plugins/ppapi/host_var_tracker.h
new file mode 100644
index 0000000..dcb96c8
--- /dev/null
+++ b/webkit/plugins/ppapi/host_var_tracker.h
@@ -0,0 +1,83 @@
+// 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 WEBKIT_PLUGINS_PPAPI_HOST_VAR_TRACKER_H_
+#define WEBKIT_PLUGINS_PPAPI_HOST_VAR_TRACKER_H_
+
+#include <map>
+
+#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
+#include "base/hash_tables.h"
+#include "base/memory/linked_ptr.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_module.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/proxy/interface_id.h"
+#include "ppapi/shared_impl/function_group_base.h"
+#include "ppapi/shared_impl/resource_tracker.h"
+#include "ppapi/shared_impl/tracker_base.h"
+#include "ppapi/shared_impl/var_tracker.h"
+
+typedef struct NPObject NPObject;
+
+namespace ppapi {
+class NPObjectVar;
+class Var;
+}
+
+namespace webkit {
+namespace ppapi {
+
+// Adds NPObject var tracking to the standard PPAPI VarTracker for use in the
+// renderer.
+class HostVarTracker : public ::ppapi::VarTracker {
+ public:
+ HostVarTracker();
+ virtual ~HostVarTracker();
+
+ // Tracks all live NPObjectVar. This is so we can map between instance +
+ // NPObject and get the NPObjectVar corresponding to it. This Add/Remove
+ // function is called by the NPObjectVar when it is created and
+ // destroyed.
+ void AddNPObjectVar(::ppapi::NPObjectVar* object_var);
+ void RemoveNPObjectVar(::ppapi::NPObjectVar* object_var);
+
+ // Looks up a previously registered NPObjectVar for the given NPObject and
+ // instance. Returns NULL if there is no NPObjectVar corresponding to the
+ // given NPObject for the given instance. See AddNPObjectVar above.
+ ::ppapi::NPObjectVar* NPObjectVarForNPObject(PP_Instance instance,
+ NPObject* np_object);
+
+ // Returns the number of NPObjectVar's associated with the given instance.
+ // Returns 0 if the instance isn't known.
+ int GetLiveNPObjectVarsForInstance(PP_Instance instance) const;
+
+ // Forcibly deletes all np object vars for the given instance. Used for
+ // instance cleanup.
+ void ForceFreeNPObjectsForInstance(PP_Instance instance);
+
+ private:
+ typedef std::map<NPObject*, ::ppapi::NPObjectVar*> NPObjectToNPObjectVarMap;
+
+ // Lists all known NPObjects, first indexed by the corresponding instance,
+ // then by the NPObject*. This allows us to look up an NPObjectVar given
+ // these two pieces of information.
+ //
+ // The instance map is lazily managed, so we'll add the
+ // NPObjectToNPObjectVarMap lazily when the first NPObject var is created,
+ // and delete it when it's empty.
+ typedef std::map<PP_Instance, linked_ptr<NPObjectToNPObjectVarMap> >
+ InstanceMap;
+ InstanceMap instance_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(HostVarTracker);
+};
+
+} // namespace ppapi
+} // namespace webkit
+
+#endif // WEBKIT_PLUGINS_PPAPI_HOST_VAR_TRACKER_H_
diff --git a/webkit/plugins/ppapi/host_resource_tracker_unittest.cc b/webkit/plugins/ppapi/host_var_tracker_unittest.cc
index a02e066..bb6025e 100644
--- a/webkit/plugins/ppapi/host_resource_tracker_unittest.cc
+++ b/webkit/plugins/ppapi/host_var_tracker_unittest.cc
@@ -10,7 +10,7 @@
#include "third_party/npapi/bindings/npruntime.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
#include "webkit/plugins/ppapi/host_globals.h"
-#include "webkit/plugins/ppapi/host_resource_tracker.h"
+#include "webkit/plugins/ppapi/host_var_tracker.h"
#include "webkit/plugins/ppapi/mock_plugin_delegate.h"
#include "webkit/plugins/ppapi/mock_resource.h"
#include "webkit/plugins/ppapi/npapi_glue.h"
@@ -72,19 +72,17 @@ typedef scoped_ptr_malloc<NPObject, ReleaseNPObject> NPObjectReleaser;
} // namespace
-// HostResourceTrackerTest -----------------------------------------------------
-
-class HostResourceTrackerTest : public PpapiUnittest {
+class HostVarTrackerTest : public PpapiUnittest {
public:
- HostResourceTrackerTest() {
+ HostVarTrackerTest() {
}
- HostResourceTracker& tracker() {
- return *HostGlobals::Get()->host_resource_tracker();
+ HostVarTracker& tracker() {
+ return *HostGlobals::Get()->host_var_tracker();
}
};
-TEST_F(HostResourceTrackerTest, DeleteObjectVarWithInstance) {
+TEST_F(HostVarTrackerTest, DeleteObjectVarWithInstance) {
// Make a second instance (the test harness already creates & manages one).
scoped_refptr<PluginInstance> instance2(
PluginInstance::Create1_0(delegate(), module(),
@@ -105,7 +103,7 @@ TEST_F(HostResourceTrackerTest, DeleteObjectVarWithInstance) {
// Make sure that using the same NPObject should give the same PP_Var
// each time.
-TEST_F(HostResourceTrackerTest, ReuseVar) {
+TEST_F(HostVarTrackerTest, ReuseVar) {
NPObjectReleaser npobject(NewTrackedNPObject());
PP_Var pp_object1 = NPObjectToPPVar(instance(), npobject.get());
diff --git a/webkit/plugins/ppapi/npapi_glue.cc b/webkit/plugins/ppapi/npapi_glue.cc
index e8278d4..ecc5a41 100644
--- a/webkit/plugins/ppapi/npapi_glue.cc
+++ b/webkit/plugins/ppapi/npapi_glue.cc
@@ -8,7 +8,7 @@
#include "base/memory/ref_counted.h"
#include "base/string_util.h"
#include "webkit/plugins/ppapi/host_globals.h"
-#include "webkit/plugins/ppapi/host_resource_tracker.h"
+#include "webkit/plugins/ppapi/host_var_tracker.h"
#include "webkit/plugins/ppapi/npobject_var.h"
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/plugin_object.h"
@@ -134,7 +134,7 @@ PP_Var NPIdentifierToPPVar(PP_Module module, NPIdentifier id) {
PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) {
DCHECK(object);
scoped_refptr<NPObjectVar> object_var(
- HostGlobals::Get()->host_resource_tracker()->NPObjectVarForNPObject(
+ HostGlobals::Get()->host_var_tracker()->NPObjectVarForNPObject(
instance->pp_instance(), object));
if (!object_var) { // No object for this module yet, make a new one.
object_var = new NPObjectVar(instance->module()->pp_module(),
diff --git a/webkit/plugins/ppapi/npobject_var.cc b/webkit/plugins/ppapi/npobject_var.cc
index cb8a385..348e6ea 100644
--- a/webkit/plugins/ppapi/npobject_var.cc
+++ b/webkit/plugins/ppapi/npobject_var.cc
@@ -8,7 +8,7 @@
#include "ppapi/c/pp_var.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
#include "webkit/plugins/ppapi/host_globals.h"
-#include "webkit/plugins/ppapi/host_resource_tracker.h"
+#include "webkit/plugins/ppapi/host_var_tracker.h"
using webkit::ppapi::HostGlobals;
using WebKit::WebBindings;
@@ -24,12 +24,12 @@ NPObjectVar::NPObjectVar(PP_Module module,
pp_instance_(instance),
np_object_(np_object) {
WebBindings::retainObject(np_object_);
- HostGlobals::Get()->host_resource_tracker()->AddNPObjectVar(this);
+ HostGlobals::Get()->host_var_tracker()->AddNPObjectVar(this);
}
NPObjectVar::~NPObjectVar() {
if (pp_instance())
- HostGlobals::Get()->host_resource_tracker()->RemoveNPObjectVar(this);
+ HostGlobals::Get()->host_var_tracker()->RemoveNPObjectVar(this);
WebBindings::releaseObject(np_object_);
}