blob: 743496ef65db1eba48740f01b322fecba9ede10d [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"
avie029c4132015-12-23 06:45:2213#include "base/macros.h"
[email protected]c2932f5e2010-11-03 03:22:3314#include "ppapi/c/pp_completion_callback.h"
[email protected]f24448db2011-01-27 20:40:3915#include "ppapi/c/pp_instance.h"
[email protected]c2932f5e2010-11-03 03:22:3316#include "ppapi/c/pp_resource.h"
avie029c4132015-12-23 06:45:2217#include "ppapi/c/pp_stdint.h"
[email protected]c2932f5e2010-11-03 03:22:3318#include "ppapi/c/pp_var.h"
[email protected]f0a04c42011-08-26 22:43:2019#include "ppapi/proxy/ppapi_proxy_export.h"
[email protected]be0a84b2011-08-13 04:18:4420#include "ppapi/shared_impl/host_resource.h"
[email protected]7f8b26b2011-08-18 15:41:0121#include "ppapi/shared_impl/resource_tracker.h"
[email protected]c2932f5e2010-11-03 03:22:3322
olli.raula36aa8be2015-09-10 11:14:2223namespace base {
[email protected]4614f192011-01-21 00:26:4324template<typename T> struct DefaultSingletonTraits;
olli.raula36aa8be2015-09-10 11:14:2225}
[email protected]4614f192011-01-21 00:26:4326
[email protected]ce701cd2011-08-01 21:47:0427namespace ppapi {
[email protected]ce701cd2011-08-01 21:47:0428
[email protected]c2932f5e2010-11-03 03:22:3329namespace proxy {
30
[email protected]2f59e382011-10-20 22:51:0131class PPAPI_PROXY_EXPORT PluginResourceTracker : public ResourceTracker {
[email protected]c2932f5e2010-11-03 03:22:3332 public:
[email protected]794d83cd2011-10-20 19:09:2033 PluginResourceTracker();
Peter Boström3d5b3cb2021-09-23 21:35:4534
35 PluginResourceTracker(const PluginResourceTracker&) = delete;
36 PluginResourceTracker& operator=(const PluginResourceTracker&) = delete;
37
nicke4784432015-04-23 14:01:4838 ~PluginResourceTracker() override;
[email protected]f24448db2011-01-27 20:40:3939
[email protected]f24448db2011-01-27 20:40:3940 // Given a host resource, maps it to an existing plugin resource ID if it
41 // exists, or returns 0 on failure.
42 PP_Resource PluginResourceForHostResource(
[email protected]4d2efd22011-08-18 21:58:0243 const HostResource& resource) const;
[email protected]799d1ab2010-11-09 17:16:2844
raymes1087a3e12015-05-22 04:34:0545 // "Abandons" a PP_Resource on the plugin side. This releases a reference to
46 // the resource and allows the plugin side of the resource (the proxy
47 // resource) to be destroyed without sending a message to the renderer
48 // notifing it that the plugin has released the resource. This is useful when
49 // the plugin sends a resource to the renderer in reply to a sync IPC. The
50 // plugin would want to release its reference to the reply resource straight
51 // away but doing so can sometimes cause the resource to be deleted in the
52 // renderer before the sync IPC reply has been received giving the renderer a
53 // chance to add a ref to it. (see e.g. crbug.com/490611). Instead the
54 // renderer assumes responsibility for the ref that the plugin created and
55 // this function can be called.
56 void AbandonResource(PP_Resource res);
57
[email protected]7f8b26b2011-08-18 15:41:0158 protected:
59 // ResourceTracker overrides.
nicke4784432015-04-23 14:01:4860 PP_Resource AddResource(Resource* object) override;
61 void RemoveResource(Resource* object) override;
[email protected]6239d342011-05-06 22:55:4762
[email protected]c2932f5e2010-11-03 03:22:3363 private:
[email protected]f24448db2011-01-27 20:40:3964 // Map of host instance/resource pairs to a plugin resource ID.
[email protected]4d2efd22011-08-18 21:58:0265 typedef std::map<HostResource, PP_Resource> HostResourceMap;
[email protected]f24448db2011-01-27 20:40:3966 HostResourceMap host_resource_map_;
67
Takuto Ikuta8332bf9d2019-01-05 03:58:0068 std::unordered_set<PP_Resource> abandoned_resources_;
[email protected]c2932f5e2010-11-03 03:22:3369};
70
71} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:0272} // namespace ppapi
[email protected]c2932f5e2010-11-03 03:22:3373
74#endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_