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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 2539363004: Make base::Value::TYPE a scoped enum. (Closed)
Patch Set: Rebase Created 4 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 | « ios/web/webui/mojo_facade.mm ('k') | jingle/glue/utils.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 #include "ipc/ipc_message_utils.h" 5 #include "ipc/ipc_message_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 void GetValueSize(base::PickleSizer* sizer, 77 void GetValueSize(base::PickleSizer* sizer,
78 const base::Value* value, 78 const base::Value* value,
79 int recursion) { 79 int recursion) {
80 if (recursion > kMaxRecursionDepth) { 80 if (recursion > kMaxRecursionDepth) {
81 LOG(WARNING) << "Max recursion depth hit in GetValueSize."; 81 LOG(WARNING) << "Max recursion depth hit in GetValueSize.";
82 return; 82 return;
83 } 83 }
84 84
85 sizer->AddInt(); 85 sizer->AddInt();
86 switch (value->GetType()) { 86 switch (value->GetType()) {
87 case base::Value::TYPE_NULL: 87 case base::Value::Type::NONE:
88 break; 88 break;
89 case base::Value::TYPE_BOOLEAN: 89 case base::Value::Type::BOOLEAN:
90 sizer->AddBool(); 90 sizer->AddBool();
91 break; 91 break;
92 case base::Value::TYPE_INTEGER: 92 case base::Value::Type::INTEGER:
93 sizer->AddInt(); 93 sizer->AddInt();
94 break; 94 break;
95 case base::Value::TYPE_DOUBLE: 95 case base::Value::Type::DOUBLE:
96 sizer->AddDouble(); 96 sizer->AddDouble();
97 break; 97 break;
98 case base::Value::TYPE_STRING: { 98 case base::Value::Type::STRING: {
99 const base::StringValue* result; 99 const base::StringValue* result;
100 value->GetAsString(&result); 100 value->GetAsString(&result);
101 if (value->GetAsString(&result)) { 101 if (value->GetAsString(&result)) {
102 DCHECK(result); 102 DCHECK(result);
103 GetParamSize(sizer, result->GetString()); 103 GetParamSize(sizer, result->GetString());
104 } else { 104 } else {
105 std::string str; 105 std::string str;
106 bool as_string_result = value->GetAsString(&str); 106 bool as_string_result = value->GetAsString(&str);
107 DCHECK(as_string_result); 107 DCHECK(as_string_result);
108 GetParamSize(sizer, str); 108 GetParamSize(sizer, str);
109 } 109 }
110 break; 110 break;
111 } 111 }
112 case base::Value::TYPE_BINARY: { 112 case base::Value::Type::BINARY: {
113 const base::BinaryValue* binary = 113 const base::BinaryValue* binary =
114 static_cast<const base::BinaryValue*>(value); 114 static_cast<const base::BinaryValue*>(value);
115 sizer->AddData(static_cast<int>(binary->GetSize())); 115 sizer->AddData(static_cast<int>(binary->GetSize()));
116 break; 116 break;
117 } 117 }
118 case base::Value::TYPE_DICTIONARY: { 118 case base::Value::Type::DICTIONARY: {
119 sizer->AddInt(); 119 sizer->AddInt();
120 const base::DictionaryValue* dict = 120 const base::DictionaryValue* dict =
121 static_cast<const base::DictionaryValue*>(value); 121 static_cast<const base::DictionaryValue*>(value);
122 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); 122 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd();
123 it.Advance()) { 123 it.Advance()) {
124 GetParamSize(sizer, it.key()); 124 GetParamSize(sizer, it.key());
125 GetValueSize(sizer, &it.value(), recursion + 1); 125 GetValueSize(sizer, &it.value(), recursion + 1);
126 } 126 }
127 break; 127 break;
128 } 128 }
129 case base::Value::TYPE_LIST: { 129 case base::Value::Type::LIST: {
130 sizer->AddInt(); 130 sizer->AddInt();
131 const base::ListValue* list = static_cast<const base::ListValue*>(value); 131 const base::ListValue* list = static_cast<const base::ListValue*>(value);
132 for (const auto& entry : *list) { 132 for (const auto& entry : *list) {
133 GetValueSize(sizer, entry.get(), recursion + 1); 133 GetValueSize(sizer, entry.get(), recursion + 1);
134 } 134 }
135 break; 135 break;
136 } 136 }
137 default: 137 default:
138 NOTREACHED() << "Invalid base::Value type."; 138 NOTREACHED() << "Invalid base::Value type.";
139 } 139 }
140 } 140 }
141 141
142 void WriteValue(base::Pickle* m, const base::Value* value, int recursion) { 142 void WriteValue(base::Pickle* m, const base::Value* value, int recursion) {
143 bool result; 143 bool result;
144 if (recursion > kMaxRecursionDepth) { 144 if (recursion > kMaxRecursionDepth) {
145 LOG(WARNING) << "Max recursion depth hit in WriteValue."; 145 LOG(WARNING) << "Max recursion depth hit in WriteValue.";
146 return; 146 return;
147 } 147 }
148 148
149 m->WriteInt(value->GetType()); 149 m->WriteInt(static_cast<int>(value->GetType()));
150 150
151 switch (value->GetType()) { 151 switch (value->GetType()) {
152 case base::Value::TYPE_NULL: 152 case base::Value::Type::NONE:
153 break; 153 break;
154 case base::Value::TYPE_BOOLEAN: { 154 case base::Value::Type::BOOLEAN: {
155 bool val; 155 bool val;
156 result = value->GetAsBoolean(&val); 156 result = value->GetAsBoolean(&val);
157 DCHECK(result); 157 DCHECK(result);
158 WriteParam(m, val); 158 WriteParam(m, val);
159 break; 159 break;
160 } 160 }
161 case base::Value::TYPE_INTEGER: { 161 case base::Value::Type::INTEGER: {
162 int val; 162 int val;
163 result = value->GetAsInteger(&val); 163 result = value->GetAsInteger(&val);
164 DCHECK(result); 164 DCHECK(result);
165 WriteParam(m, val); 165 WriteParam(m, val);
166 break; 166 break;
167 } 167 }
168 case base::Value::TYPE_DOUBLE: { 168 case base::Value::Type::DOUBLE: {
169 double val; 169 double val;
170 result = value->GetAsDouble(&val); 170 result = value->GetAsDouble(&val);
171 DCHECK(result); 171 DCHECK(result);
172 WriteParam(m, val); 172 WriteParam(m, val);
173 break; 173 break;
174 } 174 }
175 case base::Value::TYPE_STRING: { 175 case base::Value::Type::STRING: {
176 std::string val; 176 std::string val;
177 result = value->GetAsString(&val); 177 result = value->GetAsString(&val);
178 DCHECK(result); 178 DCHECK(result);
179 WriteParam(m, val); 179 WriteParam(m, val);
180 break; 180 break;
181 } 181 }
182 case base::Value::TYPE_BINARY: { 182 case base::Value::Type::BINARY: {
183 const base::BinaryValue* binary = 183 const base::BinaryValue* binary =
184 static_cast<const base::BinaryValue*>(value); 184 static_cast<const base::BinaryValue*>(value);
185 m->WriteData(binary->GetBuffer(), static_cast<int>(binary->GetSize())); 185 m->WriteData(binary->GetBuffer(), static_cast<int>(binary->GetSize()));
186 break; 186 break;
187 } 187 }
188 case base::Value::TYPE_DICTIONARY: { 188 case base::Value::Type::DICTIONARY: {
189 const base::DictionaryValue* dict = 189 const base::DictionaryValue* dict =
190 static_cast<const base::DictionaryValue*>(value); 190 static_cast<const base::DictionaryValue*>(value);
191 191
192 WriteParam(m, static_cast<int>(dict->size())); 192 WriteParam(m, static_cast<int>(dict->size()));
193 193
194 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); 194 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd();
195 it.Advance()) { 195 it.Advance()) {
196 WriteParam(m, it.key()); 196 WriteParam(m, it.key());
197 WriteValue(m, &it.value(), recursion + 1); 197 WriteValue(m, &it.value(), recursion + 1);
198 } 198 }
199 break; 199 break;
200 } 200 }
201 case base::Value::TYPE_LIST: { 201 case base::Value::Type::LIST: {
202 const base::ListValue* list = static_cast<const base::ListValue*>(value); 202 const base::ListValue* list = static_cast<const base::ListValue*>(value);
203 WriteParam(m, static_cast<int>(list->GetSize())); 203 WriteParam(m, static_cast<int>(list->GetSize()));
204 for (const auto& entry : *list) { 204 for (const auto& entry : *list) {
205 WriteValue(m, entry.get(), recursion + 1); 205 WriteValue(m, entry.get(), recursion + 1);
206 } 206 }
207 break; 207 break;
208 } 208 }
209 } 209 }
210 } 210 }
211 211
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 int recursion) { 257 int recursion) {
258 if (recursion > kMaxRecursionDepth) { 258 if (recursion > kMaxRecursionDepth) {
259 LOG(WARNING) << "Max recursion depth hit in ReadValue."; 259 LOG(WARNING) << "Max recursion depth hit in ReadValue.";
260 return false; 260 return false;
261 } 261 }
262 262
263 int type; 263 int type;
264 if (!ReadParam(m, iter, &type)) 264 if (!ReadParam(m, iter, &type))
265 return false; 265 return false;
266 266
267 switch (type) { 267 switch (static_cast<base::Value::Type>(type)) {
268 case base::Value::TYPE_NULL: 268 case base::Value::Type::NONE:
269 *value = base::Value::CreateNullValue().release(); 269 *value = base::Value::CreateNullValue().release();
270 break; 270 break;
271 case base::Value::TYPE_BOOLEAN: { 271 case base::Value::Type::BOOLEAN: {
272 bool val; 272 bool val;
273 if (!ReadParam(m, iter, &val)) 273 if (!ReadParam(m, iter, &val))
274 return false; 274 return false;
275 *value = new base::FundamentalValue(val); 275 *value = new base::FundamentalValue(val);
276 break; 276 break;
277 } 277 }
278 case base::Value::TYPE_INTEGER: { 278 case base::Value::Type::INTEGER: {
279 int val; 279 int val;
280 if (!ReadParam(m, iter, &val)) 280 if (!ReadParam(m, iter, &val))
281 return false; 281 return false;
282 *value = new base::FundamentalValue(val); 282 *value = new base::FundamentalValue(val);
283 break; 283 break;
284 } 284 }
285 case base::Value::TYPE_DOUBLE: { 285 case base::Value::Type::DOUBLE: {
286 double val; 286 double val;
287 if (!ReadParam(m, iter, &val)) 287 if (!ReadParam(m, iter, &val))
288 return false; 288 return false;
289 *value = new base::FundamentalValue(val); 289 *value = new base::FundamentalValue(val);
290 break; 290 break;
291 } 291 }
292 case base::Value::TYPE_STRING: { 292 case base::Value::Type::STRING: {
293 std::string val; 293 std::string val;
294 if (!ReadParam(m, iter, &val)) 294 if (!ReadParam(m, iter, &val))
295 return false; 295 return false;
296 *value = new base::StringValue(val); 296 *value = new base::StringValue(val);
297 break; 297 break;
298 } 298 }
299 case base::Value::TYPE_BINARY: { 299 case base::Value::Type::BINARY: {
300 const char* data; 300 const char* data;
301 int length; 301 int length;
302 if (!iter->ReadData(&data, &length)) 302 if (!iter->ReadData(&data, &length))
303 return false; 303 return false;
304 std::unique_ptr<base::BinaryValue> val = 304 std::unique_ptr<base::BinaryValue> val =
305 base::BinaryValue::CreateWithCopiedBuffer(data, length); 305 base::BinaryValue::CreateWithCopiedBuffer(data, length);
306 *value = val.release(); 306 *value = val.release();
307 break; 307 break;
308 } 308 }
309 case base::Value::TYPE_DICTIONARY: { 309 case base::Value::Type::DICTIONARY: {
310 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); 310 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue());
311 if (!ReadDictionaryValue(m, iter, val.get(), recursion)) 311 if (!ReadDictionaryValue(m, iter, val.get(), recursion))
312 return false; 312 return false;
313 *value = val.release(); 313 *value = val.release();
314 break; 314 break;
315 } 315 }
316 case base::Value::TYPE_LIST: { 316 case base::Value::Type::LIST: {
317 std::unique_ptr<base::ListValue> val(new base::ListValue()); 317 std::unique_ptr<base::ListValue> val(new base::ListValue());
318 if (!ReadListValue(m, iter, val.get(), recursion)) 318 if (!ReadListValue(m, iter, val.get(), recursion))
319 return false; 319 return false;
320 *value = val.release(); 320 *value = val.release();
321 break; 321 break;
322 } 322 }
323 default: 323 default:
324 return false; 324 return false;
325 } 325 }
326 326
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 595
596 void ParamTraits<base::DictionaryValue>::Write(base::Pickle* m, 596 void ParamTraits<base::DictionaryValue>::Write(base::Pickle* m,
597 const param_type& p) { 597 const param_type& p) {
598 WriteValue(m, &p, 0); 598 WriteValue(m, &p, 0);
599 } 599 }
600 600
601 bool ParamTraits<base::DictionaryValue>::Read(const base::Pickle* m, 601 bool ParamTraits<base::DictionaryValue>::Read(const base::Pickle* m,
602 base::PickleIterator* iter, 602 base::PickleIterator* iter,
603 param_type* r) { 603 param_type* r) {
604 int type; 604 int type;
605 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_DICTIONARY) 605 if (!ReadParam(m, iter, &type) ||
606 type != static_cast<int>(base::Value::Type::DICTIONARY))
606 return false; 607 return false;
607 608
608 return ReadDictionaryValue(m, iter, r, 0); 609 return ReadDictionaryValue(m, iter, r, 0);
609 } 610 }
610 611
611 void ParamTraits<base::DictionaryValue>::Log(const param_type& p, 612 void ParamTraits<base::DictionaryValue>::Log(const param_type& p,
612 std::string* l) { 613 std::string* l) {
613 std::string json; 614 std::string json;
614 base::JSONWriter::Write(p, &json); 615 base::JSONWriter::Write(p, &json);
615 l->append(json); 616 l->append(json);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 } 812 }
812 813
813 void ParamTraits<base::ListValue>::Write(base::Pickle* m, const param_type& p) { 814 void ParamTraits<base::ListValue>::Write(base::Pickle* m, const param_type& p) {
814 WriteValue(m, &p, 0); 815 WriteValue(m, &p, 0);
815 } 816 }
816 817
817 bool ParamTraits<base::ListValue>::Read(const base::Pickle* m, 818 bool ParamTraits<base::ListValue>::Read(const base::Pickle* m,
818 base::PickleIterator* iter, 819 base::PickleIterator* iter,
819 param_type* r) { 820 param_type* r) {
820 int type; 821 int type;
821 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_LIST) 822 if (!ReadParam(m, iter, &type) ||
823 type != static_cast<int>(base::Value::Type::LIST))
822 return false; 824 return false;
823 825
824 return ReadListValue(m, iter, r, 0); 826 return ReadListValue(m, iter, r, 0);
825 } 827 }
826 828
827 void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) { 829 void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) {
828 std::string json; 830 std::string json;
829 base::JSONWriter::Write(p, &json); 831 base::JSONWriter::Write(p, &json);
830 l->append(json); 832 l->append(json);
831 } 833 }
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 return result; 1233 return result;
1232 } 1234 }
1233 1235
1234 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 1236 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
1235 l->append("<MSG>"); 1237 l->append("<MSG>");
1236 } 1238 }
1237 1239
1238 #endif // OS_WIN 1240 #endif // OS_WIN
1239 1241
1240 } // namespace IPC 1242 } // namespace IPC
OLDNEW
« no previous file with comments | « ios/web/webui/mojo_facade.mm ('k') | jingle/glue/utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698