| OLD | NEW |
| 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" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/nullable_string16.h" | 13 #include "base/strings/nullable_string16.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "base/unguessable_token.h" | 17 #include "base/unguessable_token.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 #include "ipc/ipc_channel_handle.h" | 20 #include "ipc/ipc_channel_handle.h" |
| 20 #include "ipc/ipc_message_attachment.h" | 21 #include "ipc/ipc_message_attachment.h" |
| 21 #include "ipc/ipc_message_attachment_set.h" | 22 #include "ipc/ipc_message_attachment_set.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 if (data.size() > kMaxBytesToLog) { | 65 if (data.size() > kMaxBytesToLog) { |
| 65 out->append(base::StringPrintf( | 66 out->append(base::StringPrintf( |
| 66 " and %u more bytes", | 67 " and %u more bytes", |
| 67 static_cast<unsigned>(data.size() - kMaxBytesToLog))); | 68 static_cast<unsigned>(data.size() - kMaxBytesToLog))); |
| 68 } | 69 } |
| 69 #endif | 70 #endif |
| 70 } | 71 } |
| 71 | 72 |
| 72 bool ReadValue(const base::Pickle* m, | 73 bool ReadValue(const base::Pickle* m, |
| 73 base::PickleIterator* iter, | 74 base::PickleIterator* iter, |
| 74 base::Value** value, | 75 std::unique_ptr<base::Value>* value, |
| 75 int recursion); | 76 int recursion); |
| 76 | 77 |
| 77 void GetValueSize(base::PickleSizer* sizer, | 78 void GetValueSize(base::PickleSizer* sizer, |
| 78 const base::Value* value, | 79 const base::Value* value, |
| 79 int recursion) { | 80 int recursion) { |
| 80 if (recursion > kMaxRecursionDepth) { | 81 if (recursion > kMaxRecursionDepth) { |
| 81 LOG(ERROR) << "Max recursion depth hit in GetValueSize."; | 82 LOG(ERROR) << "Max recursion depth hit in GetValueSize."; |
| 82 return; | 83 return; |
| 83 } | 84 } |
| 84 | 85 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 bool ReadDictionaryValue(const base::Pickle* m, | 212 bool ReadDictionaryValue(const base::Pickle* m, |
| 212 base::PickleIterator* iter, | 213 base::PickleIterator* iter, |
| 213 base::DictionaryValue* value, | 214 base::DictionaryValue* value, |
| 214 int recursion) { | 215 int recursion) { |
| 215 int size; | 216 int size; |
| 216 if (!ReadParam(m, iter, &size)) | 217 if (!ReadParam(m, iter, &size)) |
| 217 return false; | 218 return false; |
| 218 | 219 |
| 219 for (int i = 0; i < size; ++i) { | 220 for (int i = 0; i < size; ++i) { |
| 220 std::string key; | 221 std::string key; |
| 221 base::Value* subval; | 222 std::unique_ptr<base::Value> subval; |
| 222 if (!ReadParam(m, iter, &key) || | 223 if (!ReadParam(m, iter, &key) || |
| 223 !ReadValue(m, iter, &subval, recursion + 1)) | 224 !ReadValue(m, iter, &subval, recursion + 1)) |
| 224 return false; | 225 return false; |
| 225 value->SetWithoutPathExpansion(key, subval); | 226 value->SetWithoutPathExpansion(key, std::move(subval)); |
| 226 } | 227 } |
| 227 | 228 |
| 228 return true; | 229 return true; |
| 229 } | 230 } |
| 230 | 231 |
| 231 // Helper for ReadValue that reads a ReadListValue into a pre-allocated | 232 // Helper for ReadValue that reads a ReadListValue into a pre-allocated |
| 232 // object. | 233 // object. |
| 233 bool ReadListValue(const base::Pickle* m, | 234 bool ReadListValue(const base::Pickle* m, |
| 234 base::PickleIterator* iter, | 235 base::PickleIterator* iter, |
| 235 base::ListValue* value, | 236 base::ListValue* value, |
| 236 int recursion) { | 237 int recursion) { |
| 237 int size; | 238 int size; |
| 238 if (!ReadParam(m, iter, &size)) | 239 if (!ReadParam(m, iter, &size)) |
| 239 return false; | 240 return false; |
| 240 | 241 |
| 241 for (int i = 0; i < size; ++i) { | 242 for (int i = 0; i < size; ++i) { |
| 242 base::Value* subval; | 243 std::unique_ptr<base::Value> subval; |
| 243 if (!ReadValue(m, iter, &subval, recursion + 1)) | 244 if (!ReadValue(m, iter, &subval, recursion + 1)) |
| 244 return false; | 245 return false; |
| 245 value->Set(i, subval); | 246 value->Set(i, std::move(subval)); |
| 246 } | 247 } |
| 247 | 248 |
| 248 return true; | 249 return true; |
| 249 } | 250 } |
| 250 | 251 |
| 251 bool ReadValue(const base::Pickle* m, | 252 bool ReadValue(const base::Pickle* m, |
| 252 base::PickleIterator* iter, | 253 base::PickleIterator* iter, |
| 253 base::Value** value, | 254 std::unique_ptr<base::Value>* value, |
| 254 int recursion) { | 255 int recursion) { |
| 255 if (recursion > kMaxRecursionDepth) { | 256 if (recursion > kMaxRecursionDepth) { |
| 256 LOG(ERROR) << "Max recursion depth hit in ReadValue."; | 257 LOG(ERROR) << "Max recursion depth hit in ReadValue."; |
| 257 return false; | 258 return false; |
| 258 } | 259 } |
| 259 | 260 |
| 260 int type; | 261 int type; |
| 261 if (!ReadParam(m, iter, &type)) | 262 if (!ReadParam(m, iter, &type)) |
| 262 return false; | 263 return false; |
| 263 | 264 |
| 264 switch (static_cast<base::Value::Type>(type)) { | 265 switch (static_cast<base::Value::Type>(type)) { |
| 265 case base::Value::Type::NONE: | 266 case base::Value::Type::NONE: |
| 266 *value = new base::Value(); | 267 *value = base::MakeUnique<base::Value>(); |
| 267 break; | 268 break; |
| 268 case base::Value::Type::BOOLEAN: { | 269 case base::Value::Type::BOOLEAN: { |
| 269 bool val; | 270 bool val; |
| 270 if (!ReadParam(m, iter, &val)) | 271 if (!ReadParam(m, iter, &val)) |
| 271 return false; | 272 return false; |
| 272 *value = new base::Value(val); | 273 *value = base::MakeUnique<base::Value>(val); |
| 273 break; | 274 break; |
| 274 } | 275 } |
| 275 case base::Value::Type::INTEGER: { | 276 case base::Value::Type::INTEGER: { |
| 276 int val; | 277 int val; |
| 277 if (!ReadParam(m, iter, &val)) | 278 if (!ReadParam(m, iter, &val)) |
| 278 return false; | 279 return false; |
| 279 *value = new base::Value(val); | 280 *value = base::MakeUnique<base::Value>(val); |
| 280 break; | 281 break; |
| 281 } | 282 } |
| 282 case base::Value::Type::DOUBLE: { | 283 case base::Value::Type::DOUBLE: { |
| 283 double val; | 284 double val; |
| 284 if (!ReadParam(m, iter, &val)) | 285 if (!ReadParam(m, iter, &val)) |
| 285 return false; | 286 return false; |
| 286 *value = new base::Value(val); | 287 *value = base::MakeUnique<base::Value>(val); |
| 287 break; | 288 break; |
| 288 } | 289 } |
| 289 case base::Value::Type::STRING: { | 290 case base::Value::Type::STRING: { |
| 290 std::string val; | 291 std::string val; |
| 291 if (!ReadParam(m, iter, &val)) | 292 if (!ReadParam(m, iter, &val)) |
| 292 return false; | 293 return false; |
| 293 *value = new base::Value(val); | 294 *value = base::MakeUnique<base::Value>(std::move(val)); |
| 294 break; | 295 break; |
| 295 } | 296 } |
| 296 case base::Value::Type::BINARY: { | 297 case base::Value::Type::BINARY: { |
| 297 const char* data; | 298 const char* data; |
| 298 int length; | 299 int length; |
| 299 if (!iter->ReadData(&data, &length)) | 300 if (!iter->ReadData(&data, &length)) |
| 300 return false; | 301 return false; |
| 301 std::unique_ptr<base::Value> val = | 302 *value = base::Value::CreateWithCopiedBuffer(data, length); |
| 302 base::Value::CreateWithCopiedBuffer(data, length); | |
| 303 *value = val.release(); | |
| 304 break; | 303 break; |
| 305 } | 304 } |
| 306 case base::Value::Type::DICTIONARY: { | 305 case base::Value::Type::DICTIONARY: { |
| 307 std::unique_ptr<base::DictionaryValue> val(new base::DictionaryValue()); | 306 base::DictionaryValue val; |
| 308 if (!ReadDictionaryValue(m, iter, val.get(), recursion)) | 307 if (!ReadDictionaryValue(m, iter, &val, recursion)) |
| 309 return false; | 308 return false; |
| 310 *value = val.release(); | 309 *value = base::MakeUnique<base::Value>(std::move(val)); |
| 311 break; | 310 break; |
| 312 } | 311 } |
| 313 case base::Value::Type::LIST: { | 312 case base::Value::Type::LIST: { |
| 314 std::unique_ptr<base::ListValue> val(new base::ListValue()); | 313 base::ListValue val; |
| 315 if (!ReadListValue(m, iter, val.get(), recursion)) | 314 if (!ReadListValue(m, iter, &val, recursion)) |
| 316 return false; | 315 return false; |
| 317 *value = val.release(); | 316 *value = base::MakeUnique<base::Value>(std::move(val)); |
| 318 break; | 317 break; |
| 319 } | 318 } |
| 320 default: | 319 default: |
| 321 return false; | 320 return false; |
| 322 } | 321 } |
| 323 | 322 |
| 324 return true; | 323 return true; |
| 325 } | 324 } |
| 326 | 325 |
| 327 } // namespace | 326 } // namespace |
| (...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 return result; | 1229 return result; |
| 1231 } | 1230 } |
| 1232 | 1231 |
| 1233 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 1232 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
| 1234 l->append("<MSG>"); | 1233 l->append("<MSG>"); |
| 1235 } | 1234 } |
| 1236 | 1235 |
| 1237 #endif // OS_WIN | 1236 #endif // OS_WIN |
| 1238 | 1237 |
| 1239 } // namespace IPC | 1238 } // namespace IPC |
| OLD | NEW |