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

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

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
« ppapi/proxy/serialized_var.cc ('K') | « ppapi/shared_impl/var.h ('k') | no next file » | 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 #include "ppapi/shared_impl/var.h" 5 #include "ppapi/shared_impl/var.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 return var_id_; 106 return var_id_;
107 } 107 }
108 108
109 void Var::AssignVarID(int32 id) { 109 void Var::AssignVarID(int32 id) {
110 DCHECK(!var_id_); // Must not have already been generated. 110 DCHECK(!var_id_); // Must not have already been generated.
111 var_id_ = id; 111 var_id_ = id;
112 } 112 }
113 113
114 // StringVar ------------------------------------------------------------------- 114 // StringVar -------------------------------------------------------------------
115 115
116 StringVar::StringVar() {
117 }
118
116 StringVar::StringVar(const std::string& str) 119 StringVar::StringVar(const std::string& str)
117 : value_(str) { 120 : value_(str) {
118 } 121 }
119 122
120 StringVar::StringVar(const char* str, uint32 len) 123 StringVar::StringVar(const char* str, uint32 len)
121 : value_(str, len) { 124 : value_(str, len) {
122 } 125 }
123 126
124 StringVar::~StringVar() { 127 StringVar::~StringVar() {
125 } 128 }
126 129
127 StringVar::StringVar(scoped_ptr<std::string> str) {
128 // Swap the given string's contents in to value to avoid copying.
129 str->swap(value_);
130 }
131
132 StringVar* StringVar::AsStringVar() { 130 StringVar* StringVar::AsStringVar() {
133 return this; 131 return this;
134 } 132 }
135 133
136 PP_VarType StringVar::GetType() const { 134 PP_VarType StringVar::GetType() const {
137 return PP_VARTYPE_STRING; 135 return PP_VARTYPE_STRING;
138 } 136 }
139 137
140 // static 138 // static
141 PP_Var StringVar::StringToPPVar(const std::string& var) { 139 PP_Var StringVar::StringToPPVar(const std::string& var) {
142 return StringToPPVar(var.c_str(), var.size()); 140 return StringToPPVar(var.c_str(), var.size());
143 } 141 }
144 142
145 // static 143 // static
146 PP_Var StringVar::StringToPPVar(const char* data, uint32 len) { 144 PP_Var StringVar::StringToPPVar(const char* data, uint32 len) {
147 scoped_refptr<StringVar> str(new StringVar(data, len)); 145 scoped_refptr<StringVar> str(new StringVar(data, len));
148 if (!str || !IsStringUTF8(str->value())) 146 if (!str || !IsStringUTF8(str->value()))
149 return PP_MakeNull(); 147 return PP_MakeNull();
150 return str->GetPPVar(); 148 return str->GetPPVar();
151 } 149 }
152 150
153 // static 151 // static
154 PP_Var StringVar::StringToPPVar(scoped_ptr<std::string> str) {
155 DCHECK(str.get());
156 if (!str.get())
157 return PP_MakeNull();
158 scoped_refptr<StringVar> str_var(new StringVar(str.Pass()));
159 if (!str_var || !IsStringUTF8(str_var->value()))
160 return PP_MakeNull();
161 return str_var->GetPPVar();
162 }
163
164 // static
165 StringVar* StringVar::FromPPVar(PP_Var var) { 152 StringVar* StringVar::FromPPVar(PP_Var var) {
166 if (var.type != PP_VARTYPE_STRING) 153 if (var.type != PP_VARTYPE_STRING)
167 return NULL; 154 return NULL;
168 scoped_refptr<Var> var_object( 155 scoped_refptr<Var> var_object(
169 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); 156 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
170 if (!var_object) 157 if (!var_object)
171 return NULL; 158 return NULL;
172 return var_object->AsStringVar(); 159 return var_object->AsStringVar();
173 } 160 }
174 161
162 // static
163 PP_Var StringVar::SwapValidatedUTF8StringIntoPPVar(std::string* src) {
164 scoped_refptr<StringVar> str(new StringVar);
165 str->value_.swap(*src);
166 return str->GetPPVar();
167 }
168
175 // ArrayBufferVar -------------------------------------------------------------- 169 // ArrayBufferVar --------------------------------------------------------------
176 170
177 ArrayBufferVar::ArrayBufferVar() { 171 ArrayBufferVar::ArrayBufferVar() {
178 } 172 }
179 173
180 ArrayBufferVar::~ArrayBufferVar() { 174 ArrayBufferVar::~ArrayBufferVar() {
181 } 175 }
182 176
183 ArrayBufferVar* ArrayBufferVar::AsArrayBufferVar() { 177 ArrayBufferVar* ArrayBufferVar::AsArrayBufferVar() {
184 return this; 178 return this;
185 } 179 }
186 180
187 PP_VarType ArrayBufferVar::GetType() const { 181 PP_VarType ArrayBufferVar::GetType() const {
188 return PP_VARTYPE_ARRAY_BUFFER; 182 return PP_VARTYPE_ARRAY_BUFFER;
189 } 183 }
190 184
191 // static 185 // static
192 ArrayBufferVar* ArrayBufferVar::FromPPVar(PP_Var var) { 186 ArrayBufferVar* ArrayBufferVar::FromPPVar(PP_Var var) {
193 if (var.type != PP_VARTYPE_ARRAY_BUFFER) 187 if (var.type != PP_VARTYPE_ARRAY_BUFFER)
194 return NULL; 188 return NULL;
195 scoped_refptr<Var> var_object( 189 scoped_refptr<Var> var_object(
196 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); 190 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
197 if (!var_object) 191 if (!var_object)
198 return NULL; 192 return NULL;
199 return var_object->AsArrayBufferVar(); 193 return var_object->AsArrayBufferVar();
200 } 194 }
201 195
202 } // namespace ppapi 196 } // namespace ppapi
203 197
OLDNEW
« ppapi/proxy/serialized_var.cc ('K') | « ppapi/shared_impl/var.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698