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

Side by Side Diff: webkit/plugins/ppapi/resource_tracker.h

Issue 7578001: Unify var tracking between webkit and the proxy. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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
« no previous file with comments | « webkit/plugins/ppapi/ppb_var_impl.cc ('k') | webkit/plugins/ppapi/resource_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ 5 #ifndef WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_
6 #define WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ 6 #define WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/hash_tables.h" 14 #include "base/hash_tables.h"
15 #include "base/memory/linked_ptr.h" 15 #include "base/memory/linked_ptr.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "ppapi/c/pp_instance.h" 18 #include "ppapi/c/pp_instance.h"
19 #include "ppapi/c/pp_module.h" 19 #include "ppapi/c/pp_module.h"
20 #include "ppapi/c/pp_resource.h" 20 #include "ppapi/c/pp_resource.h"
21 #include "ppapi/proxy/interface_id.h" 21 #include "ppapi/proxy/interface_id.h"
22 #include "ppapi/shared_impl/function_group_base.h" 22 #include "ppapi/shared_impl/function_group_base.h"
23 #include "ppapi/shared_impl/tracker_base.h" 23 #include "ppapi/shared_impl/tracker_base.h"
24 #include "ppapi/shared_impl/var_tracker.h"
24 25
25 typedef struct NPObject NPObject; 26 typedef struct NPObject NPObject;
26 27
27 namespace ppapi { 28 namespace ppapi {
28 class NPObjectVar; 29 class NPObjectVar;
29 class Var; 30 class Var;
30 } 31 }
31 32
32 namespace webkit { 33 namespace webkit {
33 namespace ppapi { 34 namespace ppapi {
(...skipping 22 matching lines...) Expand all
56 scoped_refptr<Resource> GetResource(PP_Resource res) const; 57 scoped_refptr<Resource> GetResource(PP_Resource res) const;
57 58
58 // Increment resource's plugin refcount. See ResourceAndRefCount comments 59 // Increment resource's plugin refcount. See ResourceAndRefCount comments
59 // below. 60 // below.
60 bool AddRefResource(PP_Resource res); 61 bool AddRefResource(PP_Resource res);
61 bool UnrefResource(PP_Resource res); 62 bool UnrefResource(PP_Resource res);
62 63
63 // Returns the number of resources associated with this module. 64 // Returns the number of resources associated with this module.
64 uint32 GetLiveObjectsForInstance(PP_Instance instance) const; 65 uint32 GetLiveObjectsForInstance(PP_Instance instance) const;
65 66
66 // ResourceTrackerBase. 67 // TrackerBase.
67 virtual ::ppapi::ResourceObjectBase* GetResourceAPI( 68 virtual ::ppapi::ResourceObjectBase* GetResourceAPI(
68 PP_Resource res) OVERRIDE; 69 PP_Resource res) OVERRIDE;
69 virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( 70 virtual ::ppapi::FunctionGroupBase* GetFunctionAPI(
70 PP_Instance pp_instance, 71 PP_Instance pp_instance,
71 pp::proxy::InterfaceID id) OVERRIDE; 72 pp::proxy::InterfaceID id) OVERRIDE;
72 virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE; 73 virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE;
74 virtual ::ppapi::VarTracker* GetVarTracker() OVERRIDE;
73 75
74 // PP_Vars ------------------------------------------------------------------- 76 // PP_Vars -------------------------------------------------------------------
75 77
76 // TrackerBase implementation.
77 virtual int32 AddVar(::ppapi::Var* var) OVERRIDE;
78 virtual scoped_refptr< ::ppapi::Var > GetVar(int32 var_id) const OVERRIDE;
79 virtual bool AddRefVar(int32 var_id) OVERRIDE;
80 virtual bool UnrefVar(int32 var_id) OVERRIDE;
81
82 // Tracks all live NPObjectVar. This is so we can map between instance + 78 // Tracks all live NPObjectVar. This is so we can map between instance +
83 // NPObject and get the NPObjectVar corresponding to it. This Add/Remove 79 // NPObject and get the NPObjectVar corresponding to it. This Add/Remove
84 // function is called by the NPObjectVar when it is created and 80 // function is called by the NPObjectVar when it is created and
85 // destroyed. 81 // destroyed.
86 void AddNPObjectVar(::ppapi::NPObjectVar* object_var); 82 void AddNPObjectVar(::ppapi::NPObjectVar* object_var);
87 void RemoveNPObjectVar(::ppapi::NPObjectVar* object_var); 83 void RemoveNPObjectVar(::ppapi::NPObjectVar* object_var);
88 84
89 // Looks up a previously registered NPObjectVar for the given NPObject and 85 // Looks up a previously registered NPObjectVar for the given NPObject and
90 // instance. Returns NULL if there is no NPObjectVar corresponding to the 86 // instance. Returns NULL if there is no NPObjectVar corresponding to the
91 // given NPObject for the given instance. See AddNPObjectVar above. 87 // given NPObject for the given instance. See AddNPObjectVar above.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // layer via the delegate, which may be in a random state of shutdown. 171 // layer via the delegate, which may be in a random state of shutdown.
176 // 172 //
177 // So effectively our rule is: any resources still around at shutdown are 173 // So effectively our rule is: any resources still around at shutdown are
178 // associated with leaked plugins in WebKit, so it's also OK to leak those 174 // associated with leaked plugins in WebKit, so it's also OK to leak those
179 // resources from here (avoiding the shutdown race). 175 // resources from here (avoiding the shutdown race).
180 static ResourceTracker* global_tracker_; 176 static ResourceTracker* global_tracker_;
181 177
182 // See SetSingletonOverride above. 178 // See SetSingletonOverride above.
183 static ResourceTracker* singleton_override_; 179 static ResourceTracker* singleton_override_;
184 180
185 // Last assigned resource & var ID. 181 // Last assigned resource ID.
186 PP_Resource last_resource_id_; 182 PP_Resource last_resource_id_;
187 int32 last_var_id_; 183
184 ::ppapi::VarTracker var_tracker_;
188 185
189 // For each PP_Resource, keep the Resource* (as refptr) and plugin use count. 186 // For each PP_Resource, keep the Resource* (as refptr) and plugin use count.
190 // This use count is different then Resource's RefCount, and is manipulated 187 // This use count is different then Resource's RefCount, and is manipulated
191 // using this AddRefResource/UnrefResource. When it drops to zero, we just 188 // using this AddRefResource/UnrefResource. When it drops to zero, we just
192 // remove the resource from this resource tracker, but the resource object 189 // remove the resource from this resource tracker, but the resource object
193 // will be alive so long as some scoped_refptr still holds it's 190 // will be alive so long as some scoped_refptr still holds it's
194 // reference. This prevents plugins from forcing destruction of Resource 191 // reference. This prevents plugins from forcing destruction of Resource
195 // objects. 192 // objects.
196 typedef std::pair<scoped_refptr<Resource>, size_t> ResourceAndRefCount; 193 typedef std::pair<scoped_refptr<Resource>, size_t> ResourceAndRefCount;
197 typedef base::hash_map<PP_Resource, ResourceAndRefCount> ResourceMap; 194 typedef base::hash_map<PP_Resource, ResourceAndRefCount> ResourceMap;
(...skipping 13 matching lines...) Expand all
211 typedef std::map<PP_Module, PluginModule*> ModuleMap; 208 typedef std::map<PP_Module, PluginModule*> ModuleMap;
212 ModuleMap module_map_; 209 ModuleMap module_map_;
213 210
214 DISALLOW_COPY_AND_ASSIGN(ResourceTracker); 211 DISALLOW_COPY_AND_ASSIGN(ResourceTracker);
215 }; 212 };
216 213
217 } // namespace ppapi 214 } // namespace ppapi
218 } // namespace webkit 215 } // namespace webkit
219 216
220 #endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ 217 #endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_var_impl.cc ('k') | webkit/plugins/ppapi/resource_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698