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

Side by Side Diff: webkit/plugins/ppapi/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 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/resource_tracker.h"
23 #include "ppapi/shared_impl/tracker_base.h" 24 #include "ppapi/shared_impl/tracker_base.h"
24 #include "ppapi/shared_impl/var_tracker.h" 25 #include "ppapi/shared_impl/var_tracker.h"
25 26
26 typedef struct NPObject NPObject; 27 typedef struct NPObject NPObject;
27 28
28 namespace ppapi { 29 namespace ppapi {
29 class NPObjectVar; 30 class NPObjectVar;
30 class Var; 31 class Var;
31 } 32 }
32 33
33 namespace webkit { 34 namespace webkit {
34 namespace ppapi { 35 namespace ppapi {
35 36
36 class PluginInstance; 37 class PluginInstance;
37 class PluginModule; 38 class PluginModule;
38 class Resource; 39 class Resource;
39 class ResourceTrackerTest; 40 class ResourceTrackerTest;
40 41
41 // This class maintains a global list of all live pepper resources. It allows 42 // This class maintains a global list of all live pepper resources. It allows
42 // us to check resource ID validity and to map them to a specific module. 43 // us to check resource ID validity and to map them to a specific module.
43 // 44 //
44 // This object is NOT threadsafe. 45 // This object is NOT threadsafe.
45 class ResourceTracker : public ::ppapi::TrackerBase { 46 class ResourceTracker : public ::ppapi::TrackerBase,
47 public ::ppapi::ResourceTracker {
46 public: 48 public:
47 // Returns the pointer to the singleton object. 49 // Returns the pointer to the singleton object.
48 static ResourceTracker* Get(); 50 static ResourceTracker* Get();
49 51
50 // PP_Resources -------------------------------------------------------------- 52 // PP_Resources --------------------------------------------------------------
51 53
52 // The returned pointer will be NULL if there is no resource. Note that this
53 // return value is a scoped_refptr so that we ensure the resource is valid
54 // from the point of the lookup to the point that the calling code needs it.
55 // Otherwise, the plugin could Release() the resource on another thread and
56 // the object will get deleted out from under us.
57 scoped_refptr<Resource> GetResource(PP_Resource res) const;
58
59 // Increment resource's plugin refcount. See ResourceAndRefCount comments
60 // below.
61 bool AddRefResource(PP_Resource res);
62 bool UnrefResource(PP_Resource res);
63
64 // Returns the number of resources associated with this module.
65 uint32 GetLiveObjectsForInstance(PP_Instance instance) const;
66
67 // TrackerBase. 54 // TrackerBase.
68 virtual ::ppapi::ResourceObjectBase* GetResourceAPI(
69 PP_Resource res) OVERRIDE;
70 virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( 55 virtual ::ppapi::FunctionGroupBase* GetFunctionAPI(
71 PP_Instance pp_instance, 56 PP_Instance pp_instance,
72 pp::proxy::InterfaceID id) OVERRIDE; 57 pp::proxy::InterfaceID id) OVERRIDE;
73 virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE;
74 virtual ::ppapi::VarTracker* GetVarTracker() OVERRIDE; 58 virtual ::ppapi::VarTracker* GetVarTracker() OVERRIDE;
59 virtual ::ppapi::ResourceTracker* GetResourceTracker() OVERRIDE;
75 60
76 // PP_Vars ------------------------------------------------------------------- 61 // PP_Vars -------------------------------------------------------------------
77 62
78 // Tracks all live NPObjectVar. This is so we can map between instance + 63 // Tracks all live NPObjectVar. This is so we can map between instance +
79 // NPObject and get the NPObjectVar corresponding to it. This Add/Remove 64 // NPObject and get the NPObjectVar corresponding to it. This Add/Remove
80 // function is called by the NPObjectVar when it is created and 65 // function is called by the NPObjectVar when it is created and
81 // destroyed. 66 // destroyed.
82 void AddNPObjectVar(::ppapi::NPObjectVar* object_var); 67 void AddNPObjectVar(::ppapi::NPObjectVar* object_var);
83 void RemoveNPObjectVar(::ppapi::NPObjectVar* object_var); 68 void RemoveNPObjectVar(::ppapi::NPObjectVar* object_var);
84 69
85 // Looks up a previously registered NPObjectVar for the given NPObject and 70 // Looks up a previously registered NPObjectVar for the given NPObject and
86 // instance. Returns NULL if there is no NPObjectVar corresponding to the 71 // instance. Returns NULL if there is no NPObjectVar corresponding to the
87 // given NPObject for the given instance. See AddNPObjectVar above. 72 // given NPObject for the given instance. See AddNPObjectVar above.
88 ::ppapi::NPObjectVar* NPObjectVarForNPObject(PP_Instance instance, 73 ::ppapi::NPObjectVar* NPObjectVarForNPObject(PP_Instance instance,
89 NPObject* np_object); 74 NPObject* np_object);
90 75
76 // Returns the number of NPObjectVar's associated with the given instance.
77 // Returns 0 if the instance isn't known.
78 int GetLiveNPObjectVarsForInstance(PP_Instance instance) const;
79
91 // PP_Modules ---------------------------------------------------------------- 80 // PP_Modules ----------------------------------------------------------------
92 81
93 // Adds a new plugin module to the list of tracked module, and returns a new 82 // Adds a new plugin module to the list of tracked module, and returns a new
94 // module handle to identify it. 83 // module handle to identify it.
95 PP_Module AddModule(PluginModule* module); 84 PP_Module AddModule(PluginModule* module);
96 85
97 // Called when a plugin modulde was deleted and should no longer be tracked. 86 // Called when a plugin modulde was deleted and should no longer be tracked.
98 // The given handle should be one generated by AddModule. 87 // The given handle should be one generated by AddModule.
99 void ModuleDeleted(PP_Module module); 88 void ModuleDeleted(PP_Module module);
100 89
(...skipping 22 matching lines...) Expand all
123 friend class Resource; 112 friend class Resource;
124 friend class ResourceTrackerTest; 113 friend class ResourceTrackerTest;
125 114
126 typedef std::set<PP_Resource> ResourceSet; 115 typedef std::set<PP_Resource> ResourceSet;
127 116
128 // Per-instance data we track. 117 // Per-instance data we track.
129 struct InstanceData; 118 struct InstanceData;
130 119
131 // Prohibit creation other then by the Singleton class. 120 // Prohibit creation other then by the Singleton class.
132 ResourceTracker(); 121 ResourceTracker();
133 ~ResourceTracker(); 122 virtual ~ResourceTracker();
134
135 // Called when a new resource is created and associates it with its
136 // PluginInstance.
137 void ResourceCreated(Resource* resource, PluginInstance* instance);
138
139 // Removes a resource from the resource map.
140 void ResourceDestroyed(Resource* resource);
141
142 // Adds the given resource to the tracker and assigns it a resource ID and
143 // refcount of 1. The assigned resource ID will be returned. Used only by the
144 // Resource class.
145 PP_Resource AddResource(Resource* resource);
146 123
147 // Force frees all vars and resources associated with the given instance. 124 // Force frees all vars and resources associated with the given instance.
148 // If delete_instance is true, the instance tracking information will also 125 // If delete_instance is true, the instance tracking information will also
149 // be deleted. 126 // be deleted.
150 void CleanupInstanceData(PP_Instance instance, bool delete_instance); 127 void CleanupInstanceData(PP_Instance instance, bool delete_instance);
151 128
152 // Overrides the singleton object. This is used for tests which want to 129 // Overrides the singleton object. This is used for tests which want to
153 // specify their own tracker (otherwise, you can get cross-talk between 130 // specify their own tracker (otherwise, you can get cross-talk between
154 // tests since the data will live into the subsequent tests). 131 // tests since the data will live into the subsequent tests).
155 static void SetSingletonOverride(ResourceTracker* tracker); 132 static void SetSingletonOverride(ResourceTracker* tracker);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 typedef std::map<PP_Module, PluginModule*> ModuleMap; 185 typedef std::map<PP_Module, PluginModule*> ModuleMap;
209 ModuleMap module_map_; 186 ModuleMap module_map_;
210 187
211 DISALLOW_COPY_AND_ASSIGN(ResourceTracker); 188 DISALLOW_COPY_AND_ASSIGN(ResourceTracker);
212 }; 189 };
213 190
214 } // namespace ppapi 191 } // namespace ppapi
215 } // namespace webkit 192 } // namespace webkit
216 193
217 #endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_ 194 #endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698