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

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

Issue 6995083: Proxy PPB_Var, fix o-o-p string var id tracking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated copyright header Created 9 years, 6 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 | « ppapi/proxy/plugin_var_serialization_rules.cc ('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) 2010 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_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/memory/ref_counted.h"
11 #include "ppapi/c/pp_stdint.h" 12 #include "ppapi/c/pp_stdint.h"
12 #include "ppapi/c/pp_var.h" 13 #include "ppapi/c/pp_var.h"
13 14
14 struct PPB_Var; 15 struct PPB_Var;
15 16
16 template<typename T> struct DefaultSingletonTraits; 17 template<typename T> struct DefaultSingletonTraits;
17 18
18 namespace pp { 19 namespace pp {
19 namespace proxy { 20 namespace proxy {
20 21
(...skipping 23 matching lines...) Expand all
44 // across tests. 45 // across tests.
45 static void SetInstanceForTest(PluginVarTracker* tracker); 46 static void SetInstanceForTest(PluginVarTracker* tracker);
46 47
47 // Returns the global var tracker for the plugin object. 48 // Returns the global var tracker for the plugin object.
48 static PluginVarTracker* GetInstance(); 49 static PluginVarTracker* GetInstance();
49 50
50 // Allocates a string and returns the ID of it. The refcount will be 1. 51 // Allocates a string and returns the ID of it. The refcount will be 1.
51 VarID MakeString(const std::string& str); 52 VarID MakeString(const std::string& str);
52 VarID MakeString(const char* str, uint32_t len); 53 VarID MakeString(const char* str, uint32_t len);
53 54
54 // Returns the string associated with the given string var. The var must be
55 // of type string and must be valid or this function will crash.
56 std::string GetString(const PP_Var& plugin_var) const;
57
58 // Returns a pointer to the given string if it exists, or NULL if the var 55 // Returns a pointer to the given string if it exists, or NULL if the var
59 // isn't a string var. 56 // isn't a string var.
60 const std::string* GetExistingString(const PP_Var& plugin_var) const; 57 const std::string* GetExistingString(const PP_Var& plugin_var) const;
61 58
62 void AddRef(const PP_Var& plugin_var); 59 void AddRef(const PP_Var& plugin_var);
63 void Release(const PP_Var& plugin_var); 60 void Release(const PP_Var& plugin_var);
64 61
65 // Manages tracking for receiving a VARTYPE_OBJECT from the remote side 62 // Manages tracking for receiving a VARTYPE_OBJECT from the remote side
66 // (either the plugin or the renderer) that has already had its reference 63 // (either the plugin or the renderer) that has already had its reference
67 // count incremented on behalf of the caller. 64 // count incremented on behalf of the caller.
(...skipping 18 matching lines...) Expand all
86 // Retrieves the internal reference counts for testing. Returns 0 if we 83 // Retrieves the internal reference counts for testing. Returns 0 if we
87 // know about the object but the corresponding value is 0, or -1 if the 84 // know about the object but the corresponding value is 0, or -1 if the
88 // given object ID isn't in our map. 85 // given object ID isn't in our map.
89 int GetRefCountForObject(const PP_Var& plugin_object); 86 int GetRefCountForObject(const PP_Var& plugin_object);
90 int GetTrackedWithNoReferenceCountForObject(const PP_Var& plugin_object); 87 int GetTrackedWithNoReferenceCountForObject(const PP_Var& plugin_object);
91 88
92 private: 89 private:
93 friend struct DefaultSingletonTraits<PluginVarTracker>; 90 friend struct DefaultSingletonTraits<PluginVarTracker>;
94 friend class PluginProxyTest; 91 friend class PluginProxyTest;
95 92
93 class RefCountedString : public base::RefCounted<RefCountedString> {
94 public:
95 RefCountedString() {
96 }
97 RefCountedString(const std::string& str) : value_(str) {
98 }
99 RefCountedString(const char* data, size_t len)
100 : value_(data, len) {
101 }
102
103 const std::string& value() const { return value_; }
104
105 private:
106 std::string value_;
107
108 // Ensure only base::RefCounted can delete a RefCountedString.
109 friend void base::RefCounted<RefCountedString>::Release() const;
110 virtual ~RefCountedString() {}
111 };
112 typedef scoped_refptr<RefCountedString> RefCountedStringPtr;
113
96 // Represents a var as received from the host. 114 // Represents a var as received from the host.
97 struct HostVar { 115 struct HostVar {
98 HostVar(PluginDispatcher* d, int64_t i); 116 HostVar(PluginDispatcher* d, int64_t i);
99 117
100 bool operator<(const HostVar& other) const; 118 bool operator<(const HostVar& other) const;
101 119
102 // The dispatcher that sent us this object. This is used so we know how to 120 // The dispatcher that sent us this object. This is used so we know how to
103 // send back requests on this object. 121 // send back requests on this object.
104 PluginDispatcher* dispatcher; 122 PluginDispatcher* dispatcher;
105 123
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 void DeletePluginVarInfoIfNecessary(PluginVarInfoMap::iterator iter); 171 void DeletePluginVarInfoIfNecessary(PluginVarInfoMap::iterator iter);
154 172
155 // Tracks all information about plugin vars. 173 // Tracks all information about plugin vars.
156 PluginVarInfoMap plugin_var_info_; 174 PluginVarInfoMap plugin_var_info_;
157 175
158 // Maps host vars to plugin vars. This allows us to know if we've previously 176 // Maps host vars to plugin vars. This allows us to know if we've previously
159 // seen a host var and re-use the information. 177 // seen a host var and re-use the information.
160 typedef std::map<HostVar, VarID> HostVarToPluginVarMap; 178 typedef std::map<HostVar, VarID> HostVarToPluginVarMap;
161 HostVarToPluginVarMap host_var_to_plugin_var_; 179 HostVarToPluginVarMap host_var_to_plugin_var_;
162 180
163 // The last plugin object ID we've handed out. This must be unique for the 181 // Maps plugin var IDs to ref counted strings.
182 typedef std::map<VarID, RefCountedStringPtr> VarIDStringMap;
183 VarIDStringMap var_id_to_string_;
184
185 // The last plugin PP_Var ID we've handed out. This must be unique for the
164 // process. 186 // process.
165 VarID last_plugin_object_id_; 187 VarID last_plugin_var_id_;
188
189 // Get a new Var ID and increment last_plugin_var_id_.
190 VarID GetNewVarID();
166 }; 191 };
167 192
168 } // namespace proxy 193 } // namespace proxy
169 } // namespace pp 194 } // namespace pp
170 195
171 #endif // PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ 196 #endif // PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/plugin_var_serialization_rules.cc ('k') | ppapi/proxy/plugin_var_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698