Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: ppapi/proxy/plugin_resource_tracker.h

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_ 5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
6 #define PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_ 6 #define PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "ppapi/c/pp_completion_callback.h" 12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_instance.h" 13 #include "ppapi/c/pp_instance.h"
14 #include "ppapi/c/pp_stdint.h" 14 #include "ppapi/c/pp_stdint.h"
15 #include "ppapi/c/pp_resource.h" 15 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/c/pp_var.h" 16 #include "ppapi/c/pp_var.h"
17 #include "ppapi/proxy/plugin_var_tracker.h" 17 #include "ppapi/proxy/plugin_var_tracker.h"
18 #include "ppapi/shared_impl/host_resource.h" 18 #include "ppapi/shared_impl/host_resource.h"
19 #include "ppapi/shared_impl/resource_tracker.h"
19 #include "ppapi/shared_impl/tracker_base.h" 20 #include "ppapi/shared_impl/tracker_base.h"
20 21
21 template<typename T> struct DefaultSingletonTraits; 22 template<typename T> struct DefaultSingletonTraits;
22 23
23 namespace ppapi { 24 namespace ppapi {
24 class Var; 25 class Var;
25 } 26 }
26 27
27 namespace pp { 28 namespace pp {
28 namespace proxy { 29 namespace proxy {
29 30
30 class PluginDispatcher; 31 class PluginDispatcher;
31 class PluginResource;
32 32
33 class PluginResourceTracker : public ::ppapi::TrackerBase { 33 class PluginResourceTracker : public ppapi::TrackerBase,
34 public ppapi::ResourceTracker {
34 public: 35 public:
35 // Called by tests that want to specify a specific ResourceTracker. This 36 // Called by tests that want to specify a specific ResourceTracker. This
36 // allows them to use a unique one each time and avoids singletons sticking 37 // allows them to use a unique one each time and avoids singletons sticking
37 // around across tests. 38 // around across tests.
38 static void SetInstanceForTest(PluginResourceTracker* tracker); 39 static void SetInstanceForTest(PluginResourceTracker* tracker);
39 40
40 // Returns the global singleton resource tracker for the plugin. 41 // Returns the global singleton resource tracker for the plugin.
41 static PluginResourceTracker* GetInstance(); 42 static PluginResourceTracker* GetInstance();
42 static ::ppapi::TrackerBase* GetTrackerBaseInstance(); 43 static ::ppapi::TrackerBase* GetTrackerBaseInstance();
43 44
44 // Returns the object associated with the given resource ID, or NULL if
45 // there isn't one.
46 PluginResource* GetResourceObject(PP_Resource pp_resource);
47
48 // Adds the given resource object to the tracked list, and returns the
49 // plugin-local PP_Resource ID that identifies the resource. Note that this
50 // PP_Resource is not valid to send to the host, use
51 // PluginResource.host_resource() to get that.
52 //
53 // The resource tracker will take a reference to the given object.
54 PP_Resource AddResource(PluginResource* object);
55
56 void AddRefResource(PP_Resource resource);
57 void ReleaseResource(PP_Resource resource);
58
59 // Given a host resource, maps it to an existing plugin resource ID if it 45 // Given a host resource, maps it to an existing plugin resource ID if it
60 // exists, or returns 0 on failure. 46 // exists, or returns 0 on failure.
61 PP_Resource PluginResourceForHostResource( 47 PP_Resource PluginResourceForHostResource(
62 const ppapi::HostResource& resource) const; 48 const ppapi::HostResource& resource) const;
63 49
64 PluginVarTracker& var_tracker() { 50 PluginVarTracker& var_tracker() {
65 return var_tracker_test_override_ ? *var_tracker_test_override_ 51 return var_tracker_test_override_ ? *var_tracker_test_override_
66 : var_tracker_; 52 : var_tracker_;
67 } 53 }
68 54
69 void set_var_tracker_test_override(PluginVarTracker* t) { 55 void set_var_tracker_test_override(PluginVarTracker* t) {
70 var_tracker_test_override_ = t; 56 var_tracker_test_override_ = t;
71 } 57 }
72 58
73 // TrackerBase. 59 // TrackerBase.
74 virtual ppapi::ResourceObjectBase* GetResourceAPI(
75 PP_Resource res) OVERRIDE;
76 virtual ppapi::FunctionGroupBase* GetFunctionAPI( 60 virtual ppapi::FunctionGroupBase* GetFunctionAPI(
77 PP_Instance inst, 61 PP_Instance inst,
78 pp::proxy::InterfaceID id) OVERRIDE; 62 pp::proxy::InterfaceID id) OVERRIDE;
79 virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE;
80 virtual ppapi::VarTracker* GetVarTracker() OVERRIDE; 63 virtual ppapi::VarTracker* GetVarTracker() OVERRIDE;
64 virtual ppapi::ResourceTracker* GetResourceTracker() OVERRIDE;
65
66 protected:
67 // ResourceTracker overrides.
68 virtual PP_Resource AddResource(ppapi::Resource* object) OVERRIDE;
69 virtual void RemoveResource(ppapi::Resource* object) OVERRIDE;
81 70
82 private: 71 private:
83 friend struct DefaultSingletonTraits<PluginResourceTracker>; 72 friend struct DefaultSingletonTraits<PluginResourceTracker>;
84 friend class PluginResourceTrackerTest; 73 friend class PluginResourceTrackerTest;
85 friend class PluginProxyTestHarness; 74 friend class PluginProxyTestHarness;
86 75
87 PluginResourceTracker(); 76 PluginResourceTracker();
88 virtual ~PluginResourceTracker(); 77 virtual ~PluginResourceTracker();
89 78
90 struct ResourceInfo {
91 ResourceInfo();
92 ResourceInfo(int ref_count, PluginResource* r);
93 ResourceInfo(const ResourceInfo& other);
94 ~ResourceInfo();
95
96 ResourceInfo& operator=(const ResourceInfo& other);
97
98 int ref_count;
99 scoped_refptr<PluginResource> resource; // May be NULL.
100 };
101
102 void ReleasePluginResourceRef(const PP_Resource& var,
103 bool notify_browser_on_release);
104
105 // Use the var_tracker_test_override_ instead if it's non-NULL. 79 // Use the var_tracker_test_override_ instead if it's non-NULL.
106 // 80 //
107 // TODO(brettw) this should be somehow separated out from here. I'm thinking 81 // TODO(brettw) this should be somehow separated out from here. I'm thinking
108 // of some global object that manages PPAPI globals, including separate var 82 // of some global object that manages PPAPI globals, including separate var
109 // and resource trackers. 83 // and resource trackers.
110 PluginVarTracker var_tracker_; 84 PluginVarTracker var_tracker_;
111 85
112 // Non-owning pointer to a var tracker mock used by tests. NULL when no 86 // Non-owning pointer to a var tracker mock used by tests. NULL when no
113 // test implementation is provided. 87 // test implementation is provided.
114 PluginVarTracker* var_tracker_test_override_; 88 PluginVarTracker* var_tracker_test_override_;
115 89
116 // Map of plugin resource IDs to the information tracking that resource.
117 typedef std::map<PP_Resource, ResourceInfo> ResourceMap;
118 ResourceMap resource_map_;
119
120 // Map of host instance/resource pairs to a plugin resource ID. 90 // Map of host instance/resource pairs to a plugin resource ID.
121 typedef std::map<ppapi::HostResource, PP_Resource> HostResourceMap; 91 typedef std::map<ppapi::HostResource, PP_Resource> HostResourceMap;
122 HostResourceMap host_resource_map_; 92 HostResourceMap host_resource_map_;
123 93
124 // Tracks the last ID we've sent out as a plugin resource so we don't send
125 // duplicates.
126 PP_Resource last_resource_id_;
127
128 DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker); 94 DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker);
129 }; 95 };
130 96
131 } // namespace proxy 97 } // namespace proxy
132 } // namespace pp 98 } // namespace pp
133 99
134 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_ 100 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698