blob: ca58ebb88f4cf431b500ee0b7e4abb80e16b70c6 [file] [log] [blame]
[email protected]73097562012-01-12 19:38:551// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c2932f5e2010-11-03 03:22:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
6#define PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
7
8#include <map>
Takuto Ikuta8332bf9d2019-01-05 03:58:009#include <unordered_set>
[email protected]f24448db2011-01-27 20:40:3910#include <utility>
[email protected]c2932f5e2010-11-03 03:22:3311
[email protected]cd910b92011-06-01 07:19:3112#include "base/compiler_specific.h"
[email protected]c2932f5e2010-11-03 03:22:3313#include "ppapi/c/pp_completion_callback.h"
[email protected]f24448db2011-01-27 20:40:3914#include "ppapi/c/pp_instance.h"
[email protected]c2932f5e2010-11-03 03:22:3315#include "ppapi/c/pp_resource.h"
avie029c4132015-12-23 06:45:2216#include "ppapi/c/pp_stdint.h"
[email protected]c2932f5e2010-11-03 03:22:3317#include "ppapi/c/pp_var.h"
[email protected]f0a04c42011-08-26 22:43:2018#include "ppapi/proxy/ppapi_proxy_export.h"
[email protected]be0a84b2011-08-13 04:18:4419#include "ppapi/shared_impl/host_resource.h"
[email protected]7f8b26b2011-08-18 15:41:0120#include "ppapi/shared_impl/resource_tracker.h"
[email protected]c2932f5e2010-11-03 03:22:3321
olli.raula36aa8be2015-09-10 11:14:2222namespace base {
[email protected]4614f192011-01-21 00:26:4323template<typename T> struct DefaultSingletonTraits;
olli.raula36aa8be2015-09-10 11:14:2224}
[email protected]4614f192011-01-21 00:26:4325
[email protected]ce701cd2011-08-01 21:47:0426namespace ppapi {
[email protected]ce701cd2011-08-01 21:47:0427
[email protected]c2932f5e2010-11-03 03:22:3328namespace proxy {
29
[email protected]2f59e382011-10-20 22:51:0130class PPAPI_PROXY_EXPORT PluginResourceTracker : public ResourceTracker {
[email protected]c2932f5e2010-11-03 03:22:3331 public:
[email protected]794d83cd2011-10-20 19:09:2032 PluginResourceTracker();
Peter Boström3d5b3cb2021-09-23 21:35:4533
34 PluginResourceTracker(const PluginResourceTracker&) = delete;
35 PluginResourceTracker& operator=(const PluginResourceTracker&) = delete;
36
nicke4784432015-04-23 14:01:4837 ~PluginResourceTracker() override;
[email protected]f24448db2011-01-27 20:40:3938
[email protected]f24448db2011-01-27 20:40:3939 // Given a host resource, maps it to an existing plugin resource ID if it
40 // exists, or returns 0 on failure.
41 PP_Resource PluginResourceForHostResource(
[email protected]4d2efd22011-08-18 21:58:0242 const HostResource& resource) const;
[email protected]799d1ab2010-11-09 17:16:2843
raymes1087a3e12015-05-22 04:34:0544 // "Abandons" a PP_Resource on the plugin side. This releases a reference to
45 // the resource and allows the plugin side of the resource (the proxy
46 // resource) to be destroyed without sending a message to the renderer
47 // notifing it that the plugin has released the resource. This is useful when
48 // the plugin sends a resource to the renderer in reply to a sync IPC. The
49 // plugin would want to release its reference to the reply resource straight
50 // away but doing so can sometimes cause the resource to be deleted in the
51 // renderer before the sync IPC reply has been received giving the renderer a
52 // chance to add a ref to it. (see e.g. crbug.com/490611). Instead the
53 // renderer assumes responsibility for the ref that the plugin created and
54 // this function can be called.
55 void AbandonResource(PP_Resource res);
56
[email protected]7f8b26b2011-08-18 15:41:0157 protected:
58 // ResourceTracker overrides.
nicke4784432015-04-23 14:01:4859 PP_Resource AddResource(Resource* object) override;
60 void RemoveResource(Resource* object) override;
[email protected]6239d342011-05-06 22:55:4761
[email protected]c2932f5e2010-11-03 03:22:3362 private:
[email protected]f24448db2011-01-27 20:40:3963 // Map of host instance/resource pairs to a plugin resource ID.
[email protected]4d2efd22011-08-18 21:58:0264 typedef std::map<HostResource, PP_Resource> HostResourceMap;
[email protected]f24448db2011-01-27 20:40:3965 HostResourceMap host_resource_map_;
66
Takuto Ikuta8332bf9d2019-01-05 03:58:0067 std::unordered_set<PP_Resource> abandoned_resources_;
[email protected]c2932f5e2010-11-03 03:22:3368};
69
70} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:0271} // namespace ppapi
[email protected]c2932f5e2010-11-03 03:22:3372
73#endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_