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

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

Issue 1548813002: Switch to standard integer types in ppapi/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 5 years 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
« no previous file with comments | « ppapi/proxy/plugin_var_serialization_rules.h ('k') | ppapi/proxy/plugin_var_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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_VAR_TRACKER_H_ 5 #ifndef PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_
6 #define PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ 6 #define PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/shared_memory.h" 14 #include "base/memory/shared_memory.h"
15 #include "ppapi/c/pp_stdint.h" 15 #include "ppapi/c/pp_stdint.h"
16 #include "ppapi/c/pp_var.h" 16 #include "ppapi/c/pp_var.h"
17 #include "ppapi/proxy/ppapi_proxy_export.h" 17 #include "ppapi/proxy/ppapi_proxy_export.h"
18 #include "ppapi/shared_impl/var_tracker.h" 18 #include "ppapi/shared_impl/var_tracker.h"
19 19
20 namespace base { 20 namespace base {
21 template<typename T> struct DefaultSingletonTraits; 21 template<typename T> struct DefaultSingletonTraits;
22 } 22 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 // VarTracker public overrides. 64 // VarTracker public overrides.
65 PP_Var MakeResourcePPVarFromMessage(PP_Instance instance, 65 PP_Var MakeResourcePPVarFromMessage(PP_Instance instance,
66 const IPC::Message& creation_message, 66 const IPC::Message& creation_message,
67 int pending_renderer_id, 67 int pending_renderer_id,
68 int pending_browser_id) override; 68 int pending_browser_id) override;
69 ResourceVar* MakeResourceVar(PP_Resource pp_resource) override; 69 ResourceVar* MakeResourceVar(PP_Resource pp_resource) override;
70 void DidDeleteInstance(PP_Instance instance) override; 70 void DidDeleteInstance(PP_Instance instance) override;
71 int TrackSharedMemoryHandle(PP_Instance instance, 71 int TrackSharedMemoryHandle(PP_Instance instance,
72 base::SharedMemoryHandle file, 72 base::SharedMemoryHandle file,
73 uint32 size_in_bytes) override; 73 uint32_t size_in_bytes) override;
74 bool StopTrackingSharedMemoryHandle(int id, 74 bool StopTrackingSharedMemoryHandle(int id,
75 PP_Instance instance, 75 PP_Instance instance,
76 base::SharedMemoryHandle* handle, 76 base::SharedMemoryHandle* handle,
77 uint32* size_in_bytes) override; 77 uint32_t* size_in_bytes) override;
78 78
79 // Notification that a plugin-implemented object (PPP_Class) was created by 79 // Notification that a plugin-implemented object (PPP_Class) was created by
80 // the plugin or deallocated by WebKit over IPC. 80 // the plugin or deallocated by WebKit over IPC.
81 void PluginImplementedObjectCreated(PP_Instance instance, 81 void PluginImplementedObjectCreated(PP_Instance instance,
82 const PP_Var& created_var, 82 const PP_Var& created_var,
83 const PPP_Class_Deprecated* ppp_class, 83 const PPP_Class_Deprecated* ppp_class,
84 void* ppp_class_data); 84 void* ppp_class_data);
85 void PluginImplementedObjectDestroyed(void* ppp_class_data); 85 void PluginImplementedObjectDestroyed(void* ppp_class_data);
86 86
87 // Returns true if there is an object implemented by the plugin with the 87 // Returns true if there is an object implemented by the plugin with the
88 // given user_data that has not been deallocated yet. Call this when 88 // given user_data that has not been deallocated yet. Call this when
89 // receiving a scripting call to the plugin to validate that the object 89 // receiving a scripting call to the plugin to validate that the object
90 // receiving the call is still alive (see user_data_to_plugin_ below). 90 // receiving the call is still alive (see user_data_to_plugin_ below).
91 bool IsPluginImplementedObjectAlive(void* user_data); 91 bool IsPluginImplementedObjectAlive(void* user_data);
92 92
93 // Validates that the given class/user_data pair corresponds to a currently 93 // Validates that the given class/user_data pair corresponds to a currently
94 // living plugin object. 94 // living plugin object.
95 bool ValidatePluginObjectCall(const PPP_Class_Deprecated* ppp_class, 95 bool ValidatePluginObjectCall(const PPP_Class_Deprecated* ppp_class,
96 void* user_data); 96 void* user_data);
97 97
98 void DidDeleteDispatcher(PluginDispatcher* dispatcher); 98 void DidDeleteDispatcher(PluginDispatcher* dispatcher);
99 99
100 private: 100 private:
101 // VarTracker protected overrides. 101 // VarTracker protected overrides.
102 int32 AddVarInternal(Var* var, AddVarRefMode mode) override; 102 int32_t AddVarInternal(Var* var, AddVarRefMode mode) override;
103 void TrackedObjectGettingOneRef(VarMap::const_iterator iter) override; 103 void TrackedObjectGettingOneRef(VarMap::const_iterator iter) override;
104 void ObjectGettingZeroRef(VarMap::iterator iter) override; 104 void ObjectGettingZeroRef(VarMap::iterator iter) override;
105 bool DeleteObjectInfoIfNecessary(VarMap::iterator iter) override; 105 bool DeleteObjectInfoIfNecessary(VarMap::iterator iter) override;
106 ArrayBufferVar* CreateArrayBuffer(uint32 size_in_bytes) override; 106 ArrayBufferVar* CreateArrayBuffer(uint32_t size_in_bytes) override;
107 ArrayBufferVar* CreateShmArrayBuffer( 107 ArrayBufferVar* CreateShmArrayBuffer(
108 uint32 size_in_bytes, 108 uint32_t size_in_bytes,
109 base::SharedMemoryHandle handle) override; 109 base::SharedMemoryHandle handle) override;
110 110
111 private: 111 private:
112 friend struct base::DefaultSingletonTraits<PluginVarTracker>; 112 friend struct base::DefaultSingletonTraits<PluginVarTracker>;
113 friend class PluginProxyTestHarness; 113 friend class PluginProxyTestHarness;
114 114
115 // Represents a var as received from the host. 115 // Represents a var as received from the host.
116 struct HostVar { 116 struct HostVar {
117 HostVar(PluginDispatcher* d, int32 i); 117 HostVar(PluginDispatcher* d, int32_t i);
118 118
119 bool operator<(const HostVar& other) const; 119 bool operator<(const HostVar& other) const;
120 120
121 // The dispatcher that sent us this object. This is used so we know how to 121 // The dispatcher that sent us this object. This is used so we know how to
122 // send back requests on this object. 122 // send back requests on this object.
123 PluginDispatcher* dispatcher; 123 PluginDispatcher* dispatcher;
124 124
125 // The object ID that the host generated to identify the object. This is 125 // The object ID that the host generated to identify the object. This is
126 // unique only within that host: different hosts could give us different 126 // unique only within that host: different hosts could give us different
127 // objects with the same ID. 127 // objects with the same ID.
128 int32 host_object_id; 128 int32_t host_object_id;
129 }; 129 };
130 130
131 struct PluginImplementedVar { 131 struct PluginImplementedVar {
132 const PPP_Class_Deprecated* ppp_class; 132 const PPP_Class_Deprecated* ppp_class;
133 133
134 // The instance that created this Var. This will be 0 if the instance has 134 // The instance that created this Var. This will be 0 if the instance has
135 // been destroyed but the object is still alive. 135 // been destroyed but the object is still alive.
136 PP_Instance instance; 136 PP_Instance instance;
137 137
138 // Represents the plugin var ID for the var corresponding to this object. 138 // Represents the plugin var ID for the var corresponding to this object.
139 // If the plugin does not have a ref to the object but it's still alive 139 // If the plugin does not have a ref to the object but it's still alive
140 // (the DOM could be holding a ref keeping it alive) this will be 0. 140 // (the DOM could be holding a ref keeping it alive) this will be 0.
141 // 141 //
142 // There is an obscure corner case. If the plugin returns an object to the 142 // There is an obscure corner case. If the plugin returns an object to the
143 // renderer and releases all of its refs, the object will still be alive 143 // renderer and releases all of its refs, the object will still be alive
144 // but there will be no plugin refs. It's possible for the plugin to get 144 // but there will be no plugin refs. It's possible for the plugin to get
145 // this same object again through the DOM, and we'll lose the correlation 145 // this same object again through the DOM, and we'll lose the correlation
146 // between plugin implemented object and car. This means we won't know when 146 // between plugin implemented object and car. This means we won't know when
147 // the plugin releases its last refs and may call Deallocate when the 147 // the plugin releases its last refs and may call Deallocate when the
148 // plugin is still holding a ref. 148 // plugin is still holding a ref.
149 // 149 //
150 // However, for the plugin to be depending on holding a ref to an object 150 // However, for the plugin to be depending on holding a ref to an object
151 // that it implements that it previously released but got again through 151 // that it implements that it previously released but got again through
152 // indirect means would be extremely rare, and we only allow var scripting 152 // indirect means would be extremely rare, and we only allow var scripting
153 // in limited cases anyway. 153 // in limited cases anyway.
154 int32 plugin_object_id; 154 int32_t plugin_object_id;
155 }; 155 };
156 156
157 // Returns the existing var ID for the given object var, creating and 157 // Returns the existing var ID for the given object var, creating and
158 // assigning an ID to it if necessary. This does not affect the reference 158 // assigning an ID to it if necessary. This does not affect the reference
159 // count, so in the creation case the refcount will be 0. It's assumed in 159 // count, so in the creation case the refcount will be 0. It's assumed in
160 // this case the caller will either adjust the refcount or the 160 // this case the caller will either adjust the refcount or the
161 // track_with_no_reference_count. 161 // track_with_no_reference_count.
162 PP_Var GetOrCreateObjectVarID(ProxyObjectVar* object); 162 PP_Var GetOrCreateObjectVarID(ProxyObjectVar* object);
163 163
164 // Sends an addref or release message to the browser for the given object ID. 164 // Sends an addref or release message to the browser for the given object ID.
165 void SendAddRefObjectMsg(const ProxyObjectVar& proxy_object); 165 void SendAddRefObjectMsg(const ProxyObjectVar& proxy_object);
166 void SendReleaseObjectMsg(const ProxyObjectVar& proxy_object); 166 void SendReleaseObjectMsg(const ProxyObjectVar& proxy_object);
167 167
168 // Looks up the given host var. If we already know about it, returns a 168 // Looks up the given host var. If we already know about it, returns a
169 // reference to the already-tracked object. If it doesn't creates a new one 169 // reference to the already-tracked object. If it doesn't creates a new one
170 // and returns it. If it's created, it's not added to the map. 170 // and returns it. If it's created, it's not added to the map.
171 scoped_refptr<ProxyObjectVar> FindOrMakePluginVarFromHostVar( 171 scoped_refptr<ProxyObjectVar> FindOrMakePluginVarFromHostVar(
172 const PP_Var& var, 172 const PP_Var& var,
173 PluginDispatcher* dispatcher); 173 PluginDispatcher* dispatcher);
174 174
175 // Maps host vars in the host to IDs in the plugin process. 175 // Maps host vars in the host to IDs in the plugin process.
176 typedef std::map<HostVar, int32> HostVarToPluginVarMap; 176 typedef std::map<HostVar, int32_t> HostVarToPluginVarMap;
177 HostVarToPluginVarMap host_var_to_plugin_var_; 177 HostVarToPluginVarMap host_var_to_plugin_var_;
178 178
179 // Maps "user data" for plugin implemented objects (PPP_Class) that are 179 // Maps "user data" for plugin implemented objects (PPP_Class) that are
180 // alive to various tracking info. 180 // alive to various tracking info.
181 // 181 //
182 // This is tricky because there may not actually be any vars in the plugin 182 // This is tricky because there may not actually be any vars in the plugin
183 // associated with a plugin-implemented object, so they won't all have 183 // associated with a plugin-implemented object, so they won't all have
184 // entries in our HostVarToPluginVarMap or the base class VarTracker's map. 184 // entries in our HostVarToPluginVarMap or the base class VarTracker's map.
185 // 185 //
186 // All objects that the plugin has created using CreateObject that have not 186 // All objects that the plugin has created using CreateObject that have not
(...skipping 17 matching lines...) Expand all
204 UserDataToPluginImplementedVarMap; 204 UserDataToPluginImplementedVarMap;
205 UserDataToPluginImplementedVarMap user_data_to_plugin_; 205 UserDataToPluginImplementedVarMap user_data_to_plugin_;
206 206
207 DISALLOW_COPY_AND_ASSIGN(PluginVarTracker); 207 DISALLOW_COPY_AND_ASSIGN(PluginVarTracker);
208 }; 208 };
209 209
210 } // namespace proxy 210 } // namespace proxy
211 } // namespace ppapi 211 } // namespace ppapi
212 212
213 #endif // PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ 213 #endif // PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/plugin_var_serialization_rules.h ('k') | ppapi/proxy/plugin_var_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698