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"
22 template<typename T
> struct DefaultSingletonTraits
;
28 class PPAPI_PROXY_EXPORT PluginResourceTracker
: public ResourceTracker
{
30 PluginResourceTracker();
31 ~PluginResourceTracker() override
;
33 // Given a host resource, maps it to an existing plugin resource ID if it
34 // exists, or returns 0 on failure.
35 PP_Resource
PluginResourceForHostResource(
36 const HostResource
& resource
) const;
38 // "Abandons" a PP_Resource on the plugin side. This releases a reference to
39 // the resource and allows the plugin side of the resource (the proxy
40 // resource) to be destroyed without sending a message to the renderer
41 // notifing it that the plugin has released the resource. This is useful when
42 // the plugin sends a resource to the renderer in reply to a sync IPC. The
43 // plugin would want to release its reference to the reply resource straight
44 // away but doing so can sometimes cause the resource to be deleted in the
45 // renderer before the sync IPC reply has been received giving the renderer a
46 // chance to add a ref to it. (see e.g. crbug.com/490611). Instead the
47 // renderer assumes responsibility for the ref that the plugin created and
48 // this function can be called.
49 void AbandonResource(PP_Resource res
);
52 // ResourceTracker overrides.
53 PP_Resource
AddResource(Resource
* object
) override
;
54 void RemoveResource(Resource
* object
) override
;
57 // Map of host instance/resource pairs to a plugin resource ID.
58 typedef std::map
<HostResource
, PP_Resource
> HostResourceMap
;
59 HostResourceMap host_resource_map_
;
61 base::hash_set
<PP_Resource
> abandoned_resources_
;
63 DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker
);
69 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_