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

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

Issue 9316123: Remove special handling for strings in var serialization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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) 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_SHARED_IMPL_VAR_H_ 5 #ifndef PPAPI_SHARED_IMPL_VAR_H_
6 #define PPAPI_SHARED_IMPL_VAR_H_ 6 #define PPAPI_SHARED_IMPL_VAR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // 87 //
88 // Converting a PP_Var to a string: 88 // Converting a PP_Var to a string:
89 // StringVar* string = StringVar::FromPPVar(var); 89 // StringVar* string = StringVar::FromPPVar(var);
90 // if (!string) 90 // if (!string)
91 // return false; // Not a string or an invalid var. 91 // return false; // Not a string or an invalid var.
92 // DoSomethingWithTheString(string->value()); 92 // DoSomethingWithTheString(string->value());
93 class PPAPI_SHARED_EXPORT StringVar : public Var { 93 class PPAPI_SHARED_EXPORT StringVar : public Var {
94 public: 94 public:
95 StringVar(const std::string& str); 95 StringVar(const std::string& str);
96 StringVar(const char* str, uint32 len); 96 StringVar(const char* str, uint32 len);
97 StringVar(scoped_ptr<std::string> str);
98 virtual ~StringVar(); 97 virtual ~StringVar();
99 98
100 const std::string& value() const { return value_; } 99 const std::string& value() const { return value_; }
101 // Return a pointer to the internal string. This allows other objects to 100 // Return a pointer to the internal string. This allows other objects to
102 // temporarily store a weak pointer to our internal string. Use with care; the 101 // temporarily store a weak pointer to our internal string. Use with care; the
103 // pointer *will* become invalid if this StringVar is removed from the 102 // pointer *will* become invalid if this StringVar is removed from the
104 // tracker. (All of this applies to value(), but this one's even easier to use 103 // tracker. (All of this applies to value(), but this one's even easier to use
105 // dangerously). 104 // dangerously).
106 const std::string* ptr() const { return &value_; } 105 const std::string* ptr() const { return &value_; }
107 106
108 // Var override. 107 // Var override.
109 virtual StringVar* AsStringVar() OVERRIDE; 108 virtual StringVar* AsStringVar() OVERRIDE;
110 virtual PP_VarType GetType() const OVERRIDE; 109 virtual PP_VarType GetType() const OVERRIDE;
111 110
112 // Helper function to create a PP_Var of type string that contains a copy of 111 // Helper function to create a PP_Var of type string that contains a copy of
113 // the given string. The input data must be valid UTF-8 encoded text, if it 112 // the given string. The input data must be valid UTF-8 encoded text, if it
114 // is not valid UTF-8, a NULL var will be returned. 113 // is not valid UTF-8, a NULL var will be returned.
115 // 114 //
116 // The return value will have a reference count of 1. Internally, this will 115 // The return value will have a reference count of 1. Internally, this will
117 // create a StringVar and return the reference to it in the var. 116 // create a StringVar and return the reference to it in the var.
118 static PP_Var StringToPPVar(const std::string& str); 117 static PP_Var StringToPPVar(const std::string& str);
119 static PP_Var StringToPPVar(const char* str, uint32 len); 118 static PP_Var StringToPPVar(const char* str, uint32 len);
120 static PP_Var StringToPPVar(scoped_ptr<std::string> str); 119
120 // Same as StringToPPVar but avoids a copy by destructively swapping the
121 // given string into the newly created StringVar. The string must already be
122 // valid UTF-8. After the call, *src will be empty.
123 static PP_Var SwapValidatedUTF8StringIntoPPVar(std::string* src);
121 124
122 // Helper function that converts a PP_Var to a string. This will return NULL 125 // Helper function that converts a PP_Var to a string. This will return NULL
123 // if the PP_Var is not of string type or the string is invalid. 126 // if the PP_Var is not of string type or the string is invalid.
124 static StringVar* FromPPVar(PP_Var var); 127 static StringVar* FromPPVar(PP_Var var);
125 128
126 private: 129 private:
130 StringVar(); // Makes an empty string.
131
127 std::string value_; 132 std::string value_;
128 133
129 DISALLOW_COPY_AND_ASSIGN(StringVar); 134 DISALLOW_COPY_AND_ASSIGN(StringVar);
130 }; 135 };
131 136
132 // ArrayBufferVar -------------------------------------------------------------- 137 // ArrayBufferVar --------------------------------------------------------------
133 138
134 // Represents an array buffer Var. 139 // Represents an array buffer Var.
135 // 140 //
136 // Note this is an abstract class. To create an appropriate concrete one, you 141 // Note this is an abstract class. To create an appropriate concrete one, you
(...skipping 23 matching lines...) Expand all
160 // return NULL if the PP_Var is not of ArrayBuffer type. 165 // return NULL if the PP_Var is not of ArrayBuffer type.
161 static ArrayBufferVar* FromPPVar(PP_Var var); 166 static ArrayBufferVar* FromPPVar(PP_Var var);
162 167
163 private: 168 private:
164 DISALLOW_COPY_AND_ASSIGN(ArrayBufferVar); 169 DISALLOW_COPY_AND_ASSIGN(ArrayBufferVar);
165 }; 170 };
166 171
167 } // namespace ppapi 172 } // namespace ppapi
168 173
169 #endif // PPAPI_SHARED_IMPL_VAR_H_ 174 #endif // PPAPI_SHARED_IMPL_VAR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698