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

Side by Side Diff: ppapi/cpp/var.h

Issue 10905128: Pepper WebSocket API: Fix memory leak issue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: no leak! Created 8 years, 3 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/cpp/private/var_private.cc ('k') | ppapi/cpp/var.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_CPP_VAR_H_ 5 #ifndef PPAPI_CPP_VAR_H_
6 #define PPAPI_CPP_VAR_H_ 6 #define PPAPI_CPP_VAR_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 /// A constructor used to create a UTF-8 character <code>Var</code>. 50 /// A constructor used to create a UTF-8 character <code>Var</code>.
51 Var(const std::string& utf8_str); // Must be encoded in UTF-8. 51 Var(const std::string& utf8_str); // Must be encoded in UTF-8.
52 52
53 /// A constructor used when you have received a <code>Var</code> as a return 53 /// A constructor used when you have received a <code>Var</code> as a return
54 /// value that has had its reference count incremented for you. 54 /// value that has had its reference count incremented for you.
55 /// 55 ///
56 /// You will not normally need to use this constructor because 56 /// You will not normally need to use this constructor because
57 /// the reference count will not normally be incremented for you. 57 /// the reference count will not normally be incremented for you.
58 Var(PassRef, PP_Var var) { 58 Var(PassRef, PP_Var var) {
59 var_ = var; 59 var_ = var;
60 needs_release_ = true; 60 is_managed_ = true;
61 } 61 }
62 62
63 struct DontManage {}; 63 struct DontManage {};
64 64
65 // TODO(brettw): remove DontManage when this bug is fixed 65 // TODO(brettw): remove DontManage when this bug is fixed
66 // http://code.google.com/p/chromium/issues/detail?id=52105 66 // http://code.google.com/p/chromium/issues/detail?id=52105
67 /// This constructor is used when we've given a <code>PP_Var</code> as an 67 /// This constructor is used when we've given a <code>PP_Var</code> as an
68 /// input argument from somewhere and that reference is managing the 68 /// input argument from somewhere and that reference is managing the
69 /// reference count for us. The object will not have its reference count 69 /// reference count for us. The object will not have its reference count
70 /// increased or decreased by this class instance. 70 /// increased or decreased by this class instance.
71 /// 71 ///
72 /// @param[in] var A <code>Var</code>. 72 /// @param[in] var A <code>Var</code>.
73 Var(DontManage, PP_Var var) { 73 Var(DontManage, PP_Var var) {
74 var_ = var; 74 var_ = var;
75 needs_release_ = false; 75 is_managed_ = false;
76 } 76 }
77 77
78 /// A constructor for copying a <code>Var</code>. 78 /// A constructor for copying a <code>Var</code>.
79 Var(const Var& other); 79 Var(const Var& other);
80 80
81 /// Destructor. 81 /// Destructor.
82 virtual ~Var(); 82 virtual ~Var();
83 83
84 /// This function assigns one <code>Var</code> to another <code>Var</code>. 84 /// This function assigns one <code>Var</code> to another <code>Var</code>.
85 /// 85 ///
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 /// Detach() detaches from the internal <code>PP_Var</code> of this 204 /// Detach() detaches from the internal <code>PP_Var</code> of this
205 /// object, keeping the reference count the same. This is used when returning 205 /// object, keeping the reference count the same. This is used when returning
206 /// a <code>PP_Var</code> from an API function where the caller expects the 206 /// a <code>PP_Var</code> from an API function where the caller expects the
207 /// return value to have the reference count incremented for it. 207 /// return value to have the reference count incremented for it.
208 /// 208 ///
209 /// @return A detached version of this object without affecting the reference 209 /// @return A detached version of this object without affecting the reference
210 /// count. 210 /// count.
211 PP_Var Detach() { 211 PP_Var Detach() {
212 PP_Var ret = var_; 212 PP_Var ret = var_;
213 var_ = PP_MakeUndefined(); 213 var_ = PP_MakeUndefined();
214 needs_release_ = false; 214 is_managed_ = true;
215 return ret; 215 return ret;
216 } 216 }
217 217
218 /// DebugString() returns a short description "Var<X>" that can be used for 218 /// DebugString() returns a short description "Var<X>" that can be used for
219 /// logging, where "X" is the underlying scalar or "UNDEFINED" or "OBJ" as 219 /// logging, where "X" is the underlying scalar or "UNDEFINED" or "OBJ" as
220 /// it does not call into the browser to get the object description. 220 /// it does not call into the browser to get the object description.
221 /// 221 ///
222 /// @return A string displaying the value of this <code>Var</code>. This 222 /// @return A string displaying the value of this <code>Var</code>. This
223 /// function is used for debugging. 223 /// function is used for debugging.
224 std::string DebugString() const; 224 std::string DebugString() const;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 273 }
274 274
275 private: 275 private:
276 Var* output_; 276 Var* output_;
277 bool originally_had_exception_; 277 bool originally_had_exception_;
278 PP_Var temp_; 278 PP_Var temp_;
279 }; 279 };
280 280
281 protected: 281 protected:
282 PP_Var var_; 282 PP_Var var_;
283 bool needs_release_; 283
284 // |is_managed_| indicates if the instance manages |var_|.
285 // You need to check if |var_| is refcounted to call Release().
286 bool is_managed_;
284 287
285 private: 288 private:
286 // Prevent an arbitrary pointer argument from being implicitly converted to 289 // Prevent an arbitrary pointer argument from being implicitly converted to
287 // a bool at Var construction. If somebody makes such a mistake, (s)he will 290 // a bool at Var construction. If somebody makes such a mistake, (s)he will
288 // get a compilation error. 291 // get a compilation error.
289 Var(void* non_scriptable_object_pointer); 292 Var(void* non_scriptable_object_pointer);
290 }; 293 };
291 294
292 } // namespace pp 295 } // namespace pp
293 296
294 #endif // PPAPI_CPP_VAR_H_ 297 #endif // PPAPI_CPP_VAR_H_
OLDNEW
« no previous file with comments | « ppapi/cpp/private/var_private.cc ('k') | ppapi/cpp/var.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698