1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
6 #define PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
11 #include "base/compiler_specific.h"
12 #include "base/containers/hash_tables.h"
13 #include "ppapi/c/pp_completion_callback.h"
14 #include "ppapi/c/pp_instance.h"
15 #include "ppapi/c/pp_stdint.h"
16 #include "ppapi/c/pp_resource.h"
17 #include "ppapi/c/pp_var.h"
18 #include "ppapi/proxy/ppapi_proxy_export.h"
19 #include "ppapi/shared_impl/host_resource.h"
20 #include "ppapi/shared_impl/resource_tracker.h"
23 template<typename T
> struct DefaultSingletonTraits
;
30 class PPAPI_PROXY_EXPORT PluginResourceTracker
: public ResourceTracker
{
32 PluginResourceTracker();
33 ~PluginResourceTracker() override
;
35 // Given a host resource, maps it to an existing plugin resource ID if it
36 // exists, or returns 0 on failure.
37 PP_Resource
PluginResourceForHostResource(
38 const HostResource
& resource
) const;
40 // "Abandons" a PP_Resource on the plugin side. This releases a reference to
41 // the resource and allows the plugin side of the resource (the proxy
42 // resource) to be destroyed without sending a message to the renderer
43 // notifing it that the plugin has released the resource. This is useful when
44 // the plugin sends a resource to the renderer in reply to a sync IPC. The
45 // plugin would want to release its reference to the reply resource straight
46 // away but doing so can sometimes cause the resource to be deleted in the
47 // renderer before the sync IPC reply has been received giving the renderer a
48 // chance to add a ref to it. (see e.g. crbug.com/490611). Instead the
49 // renderer assumes responsibility for the ref that the plugin created and
50 // this function can be called.
51 void AbandonResource(PP_Resource res
);
54 // ResourceTracker overrides.
55 PP_Resource
AddResource(Resource
* object
) override
;
56 void RemoveResource(Resource
* object
) override
;
59 // Map of host instance/resource pairs to a plugin resource ID.
60 typedef std::map
<HostResource
, PP_Resource
> HostResourceMap
;
61 HostResourceMap host_resource_map_
;
63 base::hash_set
<PP_Resource
> abandoned_resources_
;
65 DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker
);
71 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_