[email protected] | 7309756 | 2012-01-12 19:38:55 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 2 | // 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 Ikuta | 8332bf9d | 2019-01-05 03:58:00 | [diff] [blame] | 9 | #include <unordered_set> |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 10 | #include <utility> |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 11 | |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 13 | #include "ppapi/c/pp_completion_callback.h" |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 14 | #include "ppapi/c/pp_instance.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 15 | #include "ppapi/c/pp_resource.h" |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 16 | #include "ppapi/c/pp_stdint.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 17 | #include "ppapi/c/pp_var.h" |
[email protected] | f0a04c4 | 2011-08-26 22:43:20 | [diff] [blame] | 18 | #include "ppapi/proxy/ppapi_proxy_export.h" |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 19 | #include "ppapi/shared_impl/host_resource.h" |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 20 | #include "ppapi/shared_impl/resource_tracker.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 21 | |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 22 | namespace base { |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 23 | template<typename T> struct DefaultSingletonTraits; |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 24 | } |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 25 | |
[email protected] | ce701cd | 2011-08-01 21:47:04 | [diff] [blame] | 26 | namespace ppapi { |
[email protected] | ce701cd | 2011-08-01 21:47:04 | [diff] [blame] | 27 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 28 | namespace proxy { |
29 | |||||
[email protected] | 2f59e38 | 2011-10-20 22:51:01 | [diff] [blame] | 30 | class PPAPI_PROXY_EXPORT PluginResourceTracker : public ResourceTracker { |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 31 | public: |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame] | 32 | PluginResourceTracker(); |
Peter Boström | 3d5b3cb | 2021-09-23 21:35:45 | [diff] [blame] | 33 | |
34 | PluginResourceTracker(const PluginResourceTracker&) = delete; | ||||
35 | PluginResourceTracker& operator=(const PluginResourceTracker&) = delete; | ||||
36 | |||||
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 37 | ~PluginResourceTracker() override; |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 38 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 39 | // 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] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 42 | const HostResource& resource) const; |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 43 | |
raymes | 1087a3e1 | 2015-05-22 04:34:05 | [diff] [blame] | 44 | // "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] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 57 | protected: |
58 | // ResourceTracker overrides. | ||||
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 59 | PP_Resource AddResource(Resource* object) override; |
60 | void RemoveResource(Resource* object) override; | ||||
[email protected] | 6239d34 | 2011-05-06 22:55:47 | [diff] [blame] | 61 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 62 | private: |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 63 | // Map of host instance/resource pairs to a plugin resource ID. |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 64 | typedef std::map<HostResource, PP_Resource> HostResourceMap; |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 65 | HostResourceMap host_resource_map_; |
66 | |||||
Takuto Ikuta | 8332bf9d | 2019-01-05 03:58:00 | [diff] [blame] | 67 | std::unordered_set<PP_Resource> abandoned_resources_; |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 68 | }; |
69 | |||||
70 | } // namespace proxy | ||||
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 71 | } // namespace ppapi |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 72 | |
73 | #endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_ |