diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 22:51:01 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 22:51:01 +0000 |
commit | 2f59e3827f5bf5dc1cad0a0a393feef965abc6bc (patch) | |
tree | 156a9acb7570a78e31256f03726bd0b8984c8f3e /webkit/plugins/ppapi/host_resource_tracker.cc | |
parent | 7969c78bba2a31c8b50f4e19e497bf81694f6388 (diff) | |
download | chromium_src-2f59e3827f5bf5dc1cad0a0a393feef965abc6bc.zip chromium_src-2f59e3827f5bf5dc1cad0a0a393feef965abc6bc.tar.gz chromium_src-2f59e3827f5bf5dc1cad0a0a393feef965abc6bc.tar.bz2 |
Remove TrackerBase.
Fold the methods it provided into the PpapiGlobals base class. Move the
instance and module tracking in the webkit/plugins/ppapi dir out of the
HostResourceTracker (since it has nothing to do with resources) and into the
HostGlobals object (which provides general global object tracking).
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/8335001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106612 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins/ppapi/host_resource_tracker.cc')
-rw-r--r-- | webkit/plugins/ppapi/host_resource_tracker.cc | 174 |
1 files changed, 1 insertions, 173 deletions
diff --git a/webkit/plugins/ppapi/host_resource_tracker.cc b/webkit/plugins/ppapi/host_resource_tracker.cc index 69119e49..70b5157 100644 --- a/webkit/plugins/ppapi/host_resource_tracker.cc +++ b/webkit/plugins/ppapi/host_resource_tracker.cc @@ -4,109 +4,20 @@ #include "webkit/plugins/ppapi/host_resource_tracker.h" -#include <limits> -#include <set> - -#include "base/logging.h" -#include "base/rand_util.h" -#include "ppapi/c/pp_resource.h" -#include "ppapi/c/pp_var.h" -#include "ppapi/shared_impl/function_group_base.h" -#include "ppapi/shared_impl/id_assignment.h" -#include "ppapi/shared_impl/tracker_base.h" +#include "ppapi/shared_impl/resource.h" #include "webkit/plugins/ppapi/callbacks.h" -#include "webkit/plugins/ppapi/host_globals.h" -#include "webkit/plugins/ppapi/npobject_var.h" #include "webkit/plugins/ppapi/plugin_module.h" -#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/ppb_cursor_control_impl.h" -#include "webkit/plugins/ppapi/ppb_font_impl.h" -#include "webkit/plugins/ppapi/ppb_text_input_impl.h" -#include "webkit/plugins/ppapi/resource_creation_impl.h" #include "webkit/plugins/ppapi/resource_helper.h" -using ppapi::CheckIdType; -using ppapi::MakeTypedId; -using ppapi::NPObjectVar; -using ppapi::PPIdType; - namespace webkit { namespace ppapi { -namespace { - -::ppapi::TrackerBase* GetTrackerBase() { - return HostGlobals::Get()->host_resource_tracker(); -} - -} // namespace - -struct HostResourceTracker::InstanceData { - InstanceData() : instance(0) {} - - // Non-owning pointer to the instance object. When a PluginInstance is - // destroyed, it will notify us and we'll delete all associated data. - PluginInstance* instance; - - // Lazily allocated function proxies for the different interfaces. - scoped_ptr< ::ppapi::FunctionGroupBase > - function_proxies[::ppapi::proxy::INTERFACE_ID_COUNT]; -}; - HostResourceTracker::HostResourceTracker() { - // Wire up the new shared resource tracker base to use our implementation. - ::ppapi::TrackerBase::Init(&GetTrackerBase); } HostResourceTracker::~HostResourceTracker() { } -::ppapi::FunctionGroupBase* HostResourceTracker::GetFunctionAPI( - PP_Instance pp_instance, - ::ppapi::proxy::InterfaceID id) { - // Get the instance object. This also ensures that the instance data is in - // the map, since we need it below. - PluginInstance* instance = GetInstance(pp_instance); - if (!instance) - return NULL; - - // The instance one is special, since it's just implemented by the instance - // object. - if (id == ::ppapi::proxy::INTERFACE_ID_PPB_INSTANCE) - return instance; - - scoped_ptr< ::ppapi::FunctionGroupBase >& proxy = - instance_map_[pp_instance]->function_proxies[id]; - if (proxy.get()) - return proxy.get(); - - switch (id) { - case ::ppapi::proxy::INTERFACE_ID_PPB_CURSORCONTROL: - proxy.reset(new PPB_CursorControl_Impl(instance)); - break; - case ::ppapi::proxy::INTERFACE_ID_PPB_FONT: - proxy.reset(new PPB_Font_FunctionImpl(instance)); - break; - case ::ppapi::proxy::INTERFACE_ID_PPB_TEXT_INPUT: - proxy.reset(new PPB_TextInput_Impl(instance)); - break; - case ::ppapi::proxy::INTERFACE_ID_RESOURCE_CREATION: - proxy.reset(new ResourceCreationImpl(instance)); - break; - default: - NOTREACHED(); - } - - return proxy.get(); -} - -PP_Module HostResourceTracker::GetModuleForInstance(PP_Instance instance) { - PluginInstance* inst = GetInstance(instance); - if (!inst) - return 0; - return inst->module()->pp_module(); -} - void HostResourceTracker::LastPluginRefWasDeleted(::ppapi::Resource* object) { ::ppapi::ResourceTracker::LastPluginRefWasDeleted(object); @@ -121,88 +32,5 @@ void HostResourceTracker::LastPluginRefWasDeleted(::ppapi::Resource* object) { } } -PP_Instance HostResourceTracker::AddInstance(PluginInstance* instance) { - DCHECK(instance_map_.find(instance->pp_instance()) == instance_map_.end()); - - // Use a random number for the instance ID. This helps prevent some - // accidents. See also AddModule below. - // - // Need to make sure the random number isn't a duplicate or 0. - PP_Instance new_instance; - do { - new_instance = MakeTypedId(static_cast<PP_Instance>(base::RandUint64()), - ::ppapi::PP_ID_TYPE_INSTANCE); - } while (!new_instance || - instance_map_.find(new_instance) != instance_map_.end() || - !instance->module()->ReserveInstanceID(new_instance)); - - instance_map_[new_instance] = linked_ptr<InstanceData>(new InstanceData); - instance_map_[new_instance]->instance = instance; - - DidCreateInstance(new_instance); - return new_instance; -} - -void HostResourceTracker::InstanceDeleted(PP_Instance instance) { - DidDeleteInstance(instance); - HostGlobals::Get()->host_var_tracker()->ForceFreeNPObjectsForInstance( - instance); - instance_map_.erase(instance); -} - -void HostResourceTracker::InstanceCrashed(PP_Instance instance) { - DidDeleteInstance(instance); - HostGlobals::Get()->host_var_tracker()->ForceFreeNPObjectsForInstance( - instance); -} - -PluginInstance* HostResourceTracker::GetInstance(PP_Instance 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()) - return NULL; - return found->second->instance; -} - -PP_Module HostResourceTracker::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 = MakeTypedId(static_cast<PP_Module>(base::RandUint64()), - ::ppapi::PP_ID_TYPE_MODULE); - } while (!new_module || - module_map_.find(new_module) != module_map_.end()); - module_map_[new_module] = module; - return new_module; -} - -void HostResourceTracker::ModuleDeleted(PP_Module module) { - DLOG_IF(ERROR, !CheckIdType(module, ::ppapi::PP_ID_TYPE_MODULE)) - << module << " is not a PP_Module."; - ModuleMap::iterator found = module_map_.find(module); - if (found == module_map_.end()) { - NOTREACHED(); - return; - } - module_map_.erase(found); -} - -PluginModule* HostResourceTracker::GetModule(PP_Module module) { - DLOG_IF(ERROR, !CheckIdType(module, ::ppapi::PP_ID_TYPE_MODULE)) - << module << " is not a PP_Module."; - ModuleMap::iterator found = module_map_.find(module); - if (found == module_map_.end()) - return NULL; - return found->second; -} - } // namespace ppapi } // namespace webkit |