Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: webkit/plugins/ppapi/resource_tracker.cc

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/plugins/ppapi/resource_tracker.cc
diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc
index 5e15103037531ca0f768c39782947e7fca3d1cb0..1405a302d7a3f7158f87e016853ff2eb6ac9bfb4 100644
--- a/webkit/plugins/ppapi/resource_tracker.cc
+++ b/webkit/plugins/ppapi/resource_tracker.cc
@@ -50,10 +50,6 @@ struct ResourceTracker::InstanceData {
// destroyed, it will notify us and we'll delete all associated data.
PluginInstance* instance;
- // Resources associated with the instance.
- ResourceSet ref_resources;
- std::set<Resource*> assoc_resources;
-
// 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
@@ -65,16 +61,6 @@ struct ResourceTracker::InstanceData {
function_proxies[::pp::proxy::INTERFACE_ID_COUNT];
};
-scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const {
- DLOG_IF(ERROR, !CheckIdType(res, ::ppapi::PP_ID_TYPE_RESOURCE))
- << res << " is not a PP_Resource.";
- ResourceMap::const_iterator result = live_resources_.find(res);
- if (result == live_resources_.end()) {
- return scoped_refptr<Resource>();
- }
- return result->second.first;
-}
-
// static
ResourceTracker* ResourceTracker::global_tracker_ = NULL;
ResourceTracker* ResourceTracker::singleton_override_ = NULL;
@@ -97,81 +83,6 @@ ResourceTracker* ResourceTracker::Get() {
return global_tracker_;
}
-void ResourceTracker::ResourceCreated(Resource* resource,
- PluginInstance* instance) {
- if (!instance)
- return;
- PP_Instance pp_instance = instance->pp_instance();
- DCHECK(pp_instance);
- DCHECK(instance_map_.find(pp_instance) != instance_map_.end());
- instance_map_[pp_instance]->assoc_resources.insert(resource);
-}
-
-void ResourceTracker::ResourceDestroyed(Resource* resource) {
- if (!resource->instance())
- return;
-
- PP_Instance pp_instance = resource->instance()->pp_instance();
- DCHECK(pp_instance);
- DCHECK(instance_map_.find(pp_instance) != instance_map_.end());
-
- instance_map_[pp_instance]->assoc_resources.erase(resource);
-}
-
-PP_Resource ResourceTracker::AddResource(Resource* resource) {
- // If the plugin manages to create 1 billion resources, don't do crazy stuff.
- if (last_resource_id_ ==
- (std::numeric_limits<PP_Resource>::max() >> ::ppapi::kPPIdTypeBits))
- return 0;
-
- // Add the resource with plugin use-count 1.
- PP_Resource new_id = MakeTypedId(++last_resource_id_,
- ::ppapi::PP_ID_TYPE_RESOURCE);
- live_resources_.insert(std::make_pair(new_id, std::make_pair(resource, 1)));
-
- // Track associated with the instance.
- PP_Instance pp_instance = resource->instance()->pp_instance();
- DCHECK(instance_map_.find(pp_instance) != instance_map_.end());
- instance_map_[pp_instance]->ref_resources.insert(new_id);
- return new_id;
-}
-
-bool ResourceTracker::AddRefResource(PP_Resource res) {
- DLOG_IF(ERROR, !CheckIdType(res, ::ppapi::PP_ID_TYPE_RESOURCE))
- << res << " is not a PP_Resource.";
- ResourceMap::iterator i = live_resources_.find(res);
- if (i != live_resources_.end()) {
- // We don't protect against overflow, since a plugin as malicious as to ref
- // once per every byte in the address space could have just as well unrefed
- // one time too many.
- ++i->second.second;
- return true;
- } else {
- return false;
- }
-}
-
-bool ResourceTracker::UnrefResource(PP_Resource res) {
- DLOG_IF(ERROR, !CheckIdType(res, ::ppapi::PP_ID_TYPE_RESOURCE))
- << res << " is not a PP_Resource.";
- ResourceMap::iterator i = live_resources_.find(res);
- if (i != live_resources_.end()) {
- if (!--i->second.second) {
- Resource* to_release = i->second.first;
- // LastPluginRefWasDeleted will clear the instance pointer, so save it
- // first.
- PP_Instance instance = to_release->instance()->pp_instance();
- to_release->LastPluginRefWasDeleted();
-
- instance_map_[instance]->ref_resources.erase(res);
- live_resources_.erase(i);
- }
- return true;
- } else {
- return false;
- }
-}
-
void ResourceTracker::CleanupInstanceData(PP_Instance instance,
bool delete_instance) {
DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE))
@@ -183,30 +94,6 @@ void ResourceTracker::CleanupInstanceData(PP_Instance instance,
}
InstanceData& data = *found->second;
- // Force release all plugin references to resources associated with the
- // deleted instance.
- ResourceSet::iterator cur_res = data.ref_resources.begin();
- while (cur_res != data.ref_resources.end()) {
- ResourceMap::iterator found_resource = live_resources_.find(*cur_res);
- if (found_resource == live_resources_.end()) {
- NOTREACHED();
- } else {
- Resource* resource = found_resource->second.first;
-
- // Must delete from the resource set first since the resource's instance
- // pointer will get zeroed out in LastPluginRefWasDeleted.
- resource->LastPluginRefWasDeleted();
- live_resources_.erase(*cur_res);
- }
-
- // Iterators to a set are stable so we can iterate the set while the items
- // are being deleted as long as we're careful not to delete the item we're
- // holding an iterator to.
- ResourceSet::iterator current = cur_res++;
- data.ref_resources.erase(current);
- }
- DCHECK(data.ref_resources.empty());
-
// 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;
@@ -225,36 +112,10 @@ void ResourceTracker::CleanupInstanceData(PP_Instance instance,
}
DCHECK(data.np_object_to_object_var.empty());
- // Clear any resources that still reference this instance.
- for (std::set<Resource*>::iterator res = data.assoc_resources.begin();
- res != data.assoc_resources.end();
- ++res)
- (*res)->ClearInstance();
- data.assoc_resources.clear();
-
if (delete_instance)
instance_map_.erase(found);
}
-uint32 ResourceTracker::GetLiveObjectsForInstance(
- PP_Instance instance) const {
- InstanceMap::const_iterator found = instance_map_.find(instance);
- if (found == instance_map_.end())
- return 0;
- return static_cast<uint32>(found->second->ref_resources.size() +
- found->second->np_object_to_object_var.size());
-}
-
-::ppapi::ResourceObjectBase* ResourceTracker::GetResourceAPI(
- PP_Resource res) {
- DLOG_IF(ERROR, !CheckIdType(res, ::ppapi::PP_ID_TYPE_RESOURCE))
- << res << " is not a PP_Resource.";
- ResourceMap::const_iterator result = live_resources_.find(res);
- if (result == live_resources_.end())
- return NULL;
- return result->second.first.get();
-}
-
::ppapi::FunctionGroupBase* ResourceTracker::GetFunctionAPI(
PP_Instance pp_instance,
pp::proxy::InterfaceID id) {
@@ -297,17 +158,14 @@ uint32 ResourceTracker::GetLiveObjectsForInstance(
return proxy.get();
}
-PP_Instance ResourceTracker::GetInstanceForResource(PP_Resource pp_resource) {
- scoped_refptr<Resource> resource(GetResource(pp_resource));
- if (!resource.get())
- return 0;
- return resource->instance()->pp_instance();
-}
-
::ppapi::VarTracker* ResourceTracker::GetVarTracker() {
return &var_tracker_;
}
+::ppapi::ResourceTracker* ResourceTracker::GetResourceTracker() {
+ return this;
+}
+
void ResourceTracker::AddNPObjectVar(NPObjectVar* object_var) {
DCHECK(instance_map_.find(object_var->pp_instance()) != instance_map_.end());
InstanceData& data = *instance_map_[object_var->pp_instance()].get();
@@ -346,6 +204,14 @@ NPObjectVar* ResourceTracker::NPObjectVarForNPObject(PP_Instance instance,
return found->second;
}
+int ResourceTracker::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 ResourceTracker::AddInstance(PluginInstance* instance) {
DCHECK(instance_map_.find(instance->pp_instance()) == instance_map_.end());
@@ -363,14 +229,18 @@ PP_Instance ResourceTracker::AddInstance(PluginInstance* instance) {
instance_map_[new_instance] = linked_ptr<InstanceData>(new InstanceData);
instance_map_[new_instance]->instance = instance;
+
+ DidCreateInstance(new_instance);
return new_instance;
}
void ResourceTracker::InstanceDeleted(PP_Instance instance) {
+ DidDeleteInstance(instance);
CleanupInstanceData(instance, true);
}
void ResourceTracker::InstanceCrashed(PP_Instance instance) {
+ DidDeleteInstance(instance);
CleanupInstanceData(instance, false);
}

Powered by Google App Engine
This is Rietveld 408576698