This source file includes following definitions.
- PluginResourceForHostResource
- AddResource
- RemoveResource
#include "ppapi/proxy/plugin_resource_tracker.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_globals.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_var.h"
#include "ppapi/shared_impl/proxy_lock.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/shared_impl/var.h"
namespace ppapi {
namespace proxy {
PluginResourceTracker::PluginResourceTracker() : ResourceTracker(THREAD_SAFE) {
UseOddResourceValueInDebugMode();
}
PluginResourceTracker::~PluginResourceTracker() {
}
PP_Resource PluginResourceTracker::PluginResourceForHostResource(
const HostResource& resource) const {
HostResourceMap::const_iterator found = host_resource_map_.find(resource);
if (found == host_resource_map_.end())
return 0;
return found->second;
}
PP_Resource PluginResourceTracker::AddResource(Resource* object) {
DCHECK(!object->host_resource().host_resource() ||
(host_resource_map_.find(object->host_resource()) ==
host_resource_map_.end()));
PP_Resource ret = ResourceTracker::AddResource(object);
if (object->host_resource().host_resource())
host_resource_map_.insert(std::make_pair(object->host_resource(), ret));
return ret;
}
void PluginResourceTracker::RemoveResource(Resource* object) {
ResourceTracker::RemoveResource(object);
if (!object->host_resource().is_null()) {
DCHECK(host_resource_map_.find(object->host_resource()) !=
host_resource_map_.end());
host_resource_map_.erase(object->host_resource());
PluginDispatcher* dispatcher =
PluginDispatcher::GetForInstance(object->pp_instance());
if (dispatcher) {
dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource(
API_ID_PPB_CORE, object->host_resource()));
}
}
}
}
}