diff options
Diffstat (limited to 'webkit/glue/plugins/pepper_resource_tracker.cc')
-rw-r--r-- | webkit/glue/plugins/pepper_resource_tracker.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/webkit/glue/plugins/pepper_resource_tracker.cc b/webkit/glue/plugins/pepper_resource_tracker.cc index 9ee54f8..2e18cd8 100644 --- a/webkit/glue/plugins/pepper_resource_tracker.cc +++ b/webkit/glue/plugins/pepper_resource_tracker.cc @@ -8,6 +8,7 @@ #include <set> #include "base/logging.h" +#include "base/rand_util.h" #include "third_party/ppapi/c/pp_resource.h" #include "webkit/glue/plugins/pepper_resource.h" @@ -79,4 +80,78 @@ uint32 ResourceTracker::GetLiveObjectsForModule(PluginModule* module) const { return count; } +PP_Instance ResourceTracker::AddInstance(PluginInstance* instance) { +#ifndef NDEBUG + // Make sure we're not adding one more than once. + for (InstanceMap::const_iterator i = instance_map_.begin(); + i != instance_map_.end(); ++i) + DCHECK(i->second != instance); +#endif + + // Use a random 64-bit number for the instance ID. This helps prevent some + // mischeif where you could misallocate resources if you gave a different + // instance ID. + // + // See also AddModule below. + // + // Need to make sure the random number isn't a duplicate or 0. + PP_Instance new_instance; + do { + new_instance = static_cast<PP_Instance>(base::RandUint64()); + } while (!new_instance || + instance_map_.find(new_instance) != instance_map_.end()); + instance_map_[new_instance] = instance; + return new_instance; +} + +void ResourceTracker::InstanceDeleted(PP_Instance instance) { + InstanceMap::iterator found = instance_map_.find(instance); + if (found == instance_map_.end()) { + NOTREACHED(); + return; + } + instance_map_.erase(found); +} + +PluginInstance* ResourceTracker::GetInstance(PP_Instance instance) { + InstanceMap::iterator found = instance_map_.find(instance); + if (found == instance_map_.end()) + return NULL; + return found->second; +} + +PP_Module ResourceTracker::AddModule(PluginModule* module) { +#ifndef NDEBUG + // Make sure we're not adding one more than once. + for (ModuleMap::const_iterator i = module_map_.begin(); + i != module_map_.end(); ++i) + DCHECK(i->second != module); +#endif + + // See AddInstance above. + PP_Module new_module; + do { + new_module = static_cast<PP_Module>(base::RandUint64()); + } while (!new_module || + module_map_.find(new_module) != module_map_.end()); + module_map_[new_module] = module; + return new_module; +} + +void ResourceTracker::ModuleDeleted(PP_Module module) { + ModuleMap::iterator found = module_map_.find(module); + if (found == module_map_.end()) { + NOTREACHED(); + return; + } + module_map_.erase(found); +} + +PluginModule* ResourceTracker::GetModule(PP_Module module) { + ModuleMap::iterator found = module_map_.find(module); + if (found == module_map_.end()) + return NULL; + return found->second; +} + } // namespace pepper |