Index: ppapi/host/ppapi_host.h |
diff --git a/ppapi/host/ppapi_host.h b/ppapi/host/ppapi_host.h |
index 4280c3cb74553efe05481c54833d7d6ff6351af1..10040fcc5da437659eb594560ebaa9713a5e5bbc 100644 |
--- a/ppapi/host/ppapi_host.h |
+++ b/ppapi/host/ppapi_host.h |
@@ -91,6 +91,16 @@ class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener { |
// Returns null if the resource doesn't exist. |
host::ResourceHost* GetResourceHost(PP_Resource resource) const; |
+ // Pin |owned_host| in memory so long as |owner_host| still needs it. Even |
+ // if the plugin is done using |owned_host|, it will be kept alive until |
+ // |owner_host| calls UnpinHost. |
+ void PinHost(ResourceHost* owner_host, ResourceHost* owned_host); |
+ // Called to indicate that the |owner_host| no longer requires |owned_host|. |
+ // This may result in |owned_host| being deleted, if: |
+ // (a) The plugin has finished with it, and |
+ // (b) No other ResourceHosts have it pinned. |
+ void UnpinHost(ResourceHost* owner_host, ResourceHost* owned_host); |
+ |
private: |
friend class InstanceMessageFilter; |
@@ -116,6 +126,13 @@ class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener { |
void OnHostMsgAttachToPendingHost(PP_Resource resource, int pending_host_id); |
void OnHostMsgResourceDestroyed(PP_Resource resource); |
+ // Get a linked_ptr to the given ResourceHost. It's important to get at the |
+ // right one; if we just do: |
+ // linked_ptr<ResourceHost> ptr(raw_host_ptr); |
+ // ...we get a linked_ptr with its own separate reference tracking, and we'll |
+ // eventually double-delete |*raw_host_ptr|. |
+ linked_ptr<ResourceHost> RawToLinkedPtr(ResourceHost* host); |
+ |
// Non-owning pointer. |
IPC::Sender* sender_; |
@@ -143,6 +160,17 @@ class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener { |
PendingHostResourceMap pending_resource_hosts_; |
int next_pending_resource_host_id_; |
+ // Some hosts may need to Pin another host in memory for some amount of time. |
+ // The main example at the time of writing is PepperGraphics2DHost, which may |
+ // have a queue of ImageDataHosts that it requires for doing paints. This |
+ // needs to work even if the plugin deletes the ImageDataResource. So |
+ // owner_to_owned_map_ keeps a linked_ptr to any "pinned" hosts to make sure |
+ // that they live long enough, even when the plugin is done with the resource |
+ // and the host gets removed from resource_hosts_ or pending_resource_hosts_. |
+ typedef std::map<linked_ptr<ResourceHost>, int > PinCountMap; |
+ typedef std::map<ResourceHost*, PinCountMap> OwnerToOwnedHostMap; |
+ OwnerToOwnedHostMap owner_to_owned_map_; |
+ |
DISALLOW_COPY_AND_ASSIGN(PpapiHost); |
}; |