#ifndef CONTENT_RENDERER_PEPPER_HOST_VAR_TRACKER_H_
#define CONTENT_RENDERER_PEPPER_HOST_VAR_TRACKER_H_
#include <map>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/containers/hash_tables.h"
#include "base/gtest_prod_util.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/shared_impl/host_resource.h"
#include "ppapi/shared_impl/resource_tracker.h"
#include "ppapi/shared_impl/var_tracker.h"
typedef struct NPObject NPObject;
namespace ppapi {
class ArrayBufferVar;
class NPObjectVar;
class Var;
}
namespace content {
class HostVarTracker : public ppapi::VarTracker {
public:
HostVarTracker();
virtual ~HostVarTracker();
void AddNPObjectVar(ppapi::NPObjectVar* object_var);
void RemoveNPObjectVar(ppapi::NPObjectVar* object_var);
ppapi::NPObjectVar* NPObjectVarForNPObject(PP_Instance instance,
NPObject* np_object);
CONTENT_EXPORT int GetLiveNPObjectVarsForInstance(
PP_Instance instance) const;
virtual PP_Var MakeResourcePPVarFromMessage(
PP_Instance instance,
const IPC::Message& creation_message,
int pending_renderer_id,
int pending_browser_id) OVERRIDE;
virtual ppapi::ResourceVar* MakeResourceVar(PP_Resource pp_resource) OVERRIDE;
virtual void DidDeleteInstance(PP_Instance instance) OVERRIDE;
virtual int TrackSharedMemoryHandle(PP_Instance instance,
base::SharedMemoryHandle file,
uint32 size_in_bytes) OVERRIDE;
virtual bool StopTrackingSharedMemoryHandle(int id,
PP_Instance instance,
base::SharedMemoryHandle* handle,
uint32* size_in_bytes) OVERRIDE;
private:
virtual ppapi::ArrayBufferVar* CreateArrayBuffer(
uint32 size_in_bytes) OVERRIDE;
virtual ppapi::ArrayBufferVar* CreateShmArrayBuffer(
uint32 size_in_bytes, base::SharedMemoryHandle handle) OVERRIDE;
void ForceReleaseNPObject(ppapi::NPObjectVar* object_var);
typedef std::map<NPObject*, ppapi::NPObjectVar*> NPObjectToNPObjectVarMap;
typedef std::map<PP_Instance, linked_ptr<NPObjectToNPObjectVarMap> >
InstanceMap;
InstanceMap instance_map_;
struct SharedMemoryMapEntry {
PP_Instance instance;
base::SharedMemoryHandle handle;
uint32 size_in_bytes;
};
typedef std::map<int, SharedMemoryMapEntry> SharedMemoryMap;
SharedMemoryMap shared_memory_map_;
uint32_t last_shared_memory_map_id_;
DISALLOW_COPY_AND_ASSIGN(HostVarTracker);
};
}
#endif