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