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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 818833004: Remove deprecated methods from Pickle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 12 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
« no previous file with comments | « ipc/ipc_message_utils.h ('k') | ipc/ipc_sync_message.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 "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/nullable_string16.h" 10 #include "base/strings/nullable_string16.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 case base::Value::TYPE_STRING: { 201 case base::Value::TYPE_STRING: {
202 std::string val; 202 std::string val;
203 if (!ReadParam(m, iter, &val)) 203 if (!ReadParam(m, iter, &val))
204 return false; 204 return false;
205 *value = new base::StringValue(val); 205 *value = new base::StringValue(val);
206 break; 206 break;
207 } 207 }
208 case base::Value::TYPE_BINARY: { 208 case base::Value::TYPE_BINARY: {
209 const char* data; 209 const char* data;
210 int length; 210 int length;
211 if (!m->ReadData(iter, &data, &length)) 211 if (!iter->ReadData(&data, &length))
212 return false; 212 return false;
213 *value = base::BinaryValue::CreateWithCopiedBuffer(data, length); 213 *value = base::BinaryValue::CreateWithCopiedBuffer(data, length);
214 break; 214 break;
215 } 215 }
216 case base::Value::TYPE_DICTIONARY: { 216 case base::Value::TYPE_DICTIONARY: {
217 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); 217 scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue());
218 if (!ReadDictionaryValue(m, iter, val.get(), recursion)) 218 if (!ReadDictionaryValue(m, iter, val.get(), recursion))
219 return false; 219 return false;
220 *value = val.release(); 220 *value = val.release();
221 break; 221 break;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 l->append(p ? "true" : "false"); 253 l->append(p ? "true" : "false");
254 } 254 }
255 255
256 void ParamTraits<unsigned char>::Write(Message* m, const param_type& p) { 256 void ParamTraits<unsigned char>::Write(Message* m, const param_type& p) {
257 m->WriteBytes(&p, sizeof(param_type)); 257 m->WriteBytes(&p, sizeof(param_type));
258 } 258 }
259 259
260 bool ParamTraits<unsigned char>::Read(const Message* m, PickleIterator* iter, 260 bool ParamTraits<unsigned char>::Read(const Message* m, PickleIterator* iter,
261 param_type* r) { 261 param_type* r) {
262 const char* data; 262 const char* data;
263 if (!m->ReadBytes(iter, &data, sizeof(param_type))) 263 if (!iter->ReadBytes(&data, sizeof(param_type)))
264 return false; 264 return false;
265 memcpy(r, data, sizeof(param_type)); 265 memcpy(r, data, sizeof(param_type));
266 return true; 266 return true;
267 } 267 }
268 268
269 void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) { 269 void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) {
270 l->append(base::UintToString(p)); 270 l->append(base::UintToString(p));
271 } 271 }
272 272
273 void ParamTraits<unsigned short>::Write(Message* m, const param_type& p) { 273 void ParamTraits<unsigned short>::Write(Message* m, const param_type& p) {
274 m->WriteBytes(&p, sizeof(param_type)); 274 m->WriteBytes(&p, sizeof(param_type));
275 } 275 }
276 276
277 bool ParamTraits<unsigned short>::Read(const Message* m, PickleIterator* iter, 277 bool ParamTraits<unsigned short>::Read(const Message* m, PickleIterator* iter,
278 param_type* r) { 278 param_type* r) {
279 const char* data; 279 const char* data;
280 if (!m->ReadBytes(iter, &data, sizeof(param_type))) 280 if (!iter->ReadBytes(&data, sizeof(param_type)))
281 return false; 281 return false;
282 memcpy(r, data, sizeof(param_type)); 282 memcpy(r, data, sizeof(param_type));
283 return true; 283 return true;
284 } 284 }
285 285
286 void ParamTraits<unsigned short>::Log(const param_type& p, std::string* l) { 286 void ParamTraits<unsigned short>::Log(const param_type& p, std::string* l) {
287 l->append(base::UintToString(p)); 287 l->append(base::UintToString(p));
288 } 288 }
289 289
290 void ParamTraits<int>::Log(const param_type& p, std::string* l) { 290 void ParamTraits<int>::Log(const param_type& p, std::string* l) {
(...skipping 24 matching lines...) Expand all
315 l->append(base::StringPrintf("%e", p)); 315 l->append(base::StringPrintf("%e", p));
316 } 316 }
317 317
318 void ParamTraits<double>::Write(Message* m, const param_type& p) { 318 void ParamTraits<double>::Write(Message* m, const param_type& p) {
319 m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type)); 319 m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type));
320 } 320 }
321 321
322 bool ParamTraits<double>::Read(const Message* m, PickleIterator* iter, 322 bool ParamTraits<double>::Read(const Message* m, PickleIterator* iter,
323 param_type* r) { 323 param_type* r) {
324 const char *data; 324 const char *data;
325 if (!m->ReadBytes(iter, &data, sizeof(*r))) { 325 if (!iter->ReadBytes(&data, sizeof(*r))) {
326 NOTREACHED(); 326 NOTREACHED();
327 return false; 327 return false;
328 } 328 }
329 memcpy(r, data, sizeof(param_type)); 329 memcpy(r, data, sizeof(param_type));
330 return true; 330 return true;
331 } 331 }
332 332
333 void ParamTraits<double>::Log(const param_type& p, std::string* l) { 333 void ParamTraits<double>::Log(const param_type& p, std::string* l) {
334 l->append(base::StringPrintf("%e", p)); 334 l->append(base::StringPrintf("%e", p));
335 } 335 }
(...skipping 19 matching lines...) Expand all
355 } else { 355 } else {
356 m->WriteData(&p.front(), static_cast<int>(p.size())); 356 m->WriteData(&p.front(), static_cast<int>(p.size()));
357 } 357 }
358 } 358 }
359 359
360 bool ParamTraits<std::vector<char> >::Read(const Message* m, 360 bool ParamTraits<std::vector<char> >::Read(const Message* m,
361 PickleIterator* iter, 361 PickleIterator* iter,
362 param_type* r) { 362 param_type* r) {
363 const char *data; 363 const char *data;
364 int data_size = 0; 364 int data_size = 0;
365 if (!m->ReadData(iter, &data, &data_size) || data_size < 0) 365 if (!iter->ReadData(&data, &data_size) || data_size < 0)
366 return false; 366 return false;
367 r->resize(data_size); 367 r->resize(data_size);
368 if (data_size) 368 if (data_size)
369 memcpy(&r->front(), data, data_size); 369 memcpy(&r->front(), data, data_size);
370 return true; 370 return true;
371 } 371 }
372 372
373 void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) { 373 void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) {
374 LogBytes(p, l); 374 LogBytes(p, l);
375 } 375 }
376 376
377 void ParamTraits<std::vector<unsigned char> >::Write(Message* m, 377 void ParamTraits<std::vector<unsigned char> >::Write(Message* m,
378 const param_type& p) { 378 const param_type& p) {
379 if (p.empty()) { 379 if (p.empty()) {
380 m->WriteData(NULL, 0); 380 m->WriteData(NULL, 0);
381 } else { 381 } else {
382 m->WriteData(reinterpret_cast<const char*>(&p.front()), 382 m->WriteData(reinterpret_cast<const char*>(&p.front()),
383 static_cast<int>(p.size())); 383 static_cast<int>(p.size()));
384 } 384 }
385 } 385 }
386 386
387 bool ParamTraits<std::vector<unsigned char> >::Read(const Message* m, 387 bool ParamTraits<std::vector<unsigned char> >::Read(const Message* m,
388 PickleIterator* iter, 388 PickleIterator* iter,
389 param_type* r) { 389 param_type* r) {
390 const char *data; 390 const char *data;
391 int data_size = 0; 391 int data_size = 0;
392 if (!m->ReadData(iter, &data, &data_size) || data_size < 0) 392 if (!iter->ReadData(&data, &data_size) || data_size < 0)
393 return false; 393 return false;
394 r->resize(data_size); 394 r->resize(data_size);
395 if (data_size) 395 if (data_size)
396 memcpy(&r->front(), data, data_size); 396 memcpy(&r->front(), data, data_size);
397 return true; 397 return true;
398 } 398 }
399 399
400 void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p, 400 void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p,
401 std::string* l) { 401 std::string* l) {
402 LogBytes(p, l); 402 LogBytes(p, l);
403 } 403 }
404 404
405 void ParamTraits<std::vector<bool> >::Write(Message* m, const param_type& p) { 405 void ParamTraits<std::vector<bool> >::Write(Message* m, const param_type& p) {
406 WriteParam(m, static_cast<int>(p.size())); 406 WriteParam(m, static_cast<int>(p.size()));
407 // Cast to bool below is required because libc++'s 407 // Cast to bool below is required because libc++'s
408 // vector<bool>::const_reference is different from bool, and we want to avoid 408 // vector<bool>::const_reference is different from bool, and we want to avoid
409 // writing an extra specialization of ParamTraits for it. 409 // writing an extra specialization of ParamTraits for it.
410 for (size_t i = 0; i < p.size(); i++) 410 for (size_t i = 0; i < p.size(); i++)
411 WriteParam(m, static_cast<bool>(p[i])); 411 WriteParam(m, static_cast<bool>(p[i]));
412 } 412 }
413 413
414 bool ParamTraits<std::vector<bool> >::Read(const Message* m, 414 bool ParamTraits<std::vector<bool> >::Read(const Message* m,
415 PickleIterator* iter, 415 PickleIterator* iter,
416 param_type* r) { 416 param_type* r) {
417 int size; 417 int size;
418 // ReadLength() checks for < 0 itself. 418 // ReadLength() checks for < 0 itself.
419 if (!m->ReadLength(iter, &size)) 419 if (!iter->ReadLength(&size))
420 return false; 420 return false;
421 r->resize(size); 421 r->resize(size);
422 for (int i = 0; i < size; i++) { 422 for (int i = 0; i < size; i++) {
423 bool value; 423 bool value;
424 if (!ReadParam(m, iter, &value)) 424 if (!ReadParam(m, iter, &value))
425 return false; 425 return false;
426 (*r)[i] = value; 426 (*r)[i] = value;
427 } 427 }
428 return true; 428 return true;
429 } 429 }
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 // leave that up to the code sending the message to ensure. 742 // leave that up to the code sending the message to ensure.
743 m->WriteUInt32(static_cast<uint32>(p.routing_id())); 743 m->WriteUInt32(static_cast<uint32>(p.routing_id()));
744 m->WriteUInt32(p.type()); 744 m->WriteUInt32(p.type());
745 m->WriteUInt32(p.flags()); 745 m->WriteUInt32(p.flags());
746 m->WriteData(p.payload(), static_cast<uint32>(p.payload_size())); 746 m->WriteData(p.payload(), static_cast<uint32>(p.payload_size()));
747 } 747 }
748 748
749 bool ParamTraits<Message>::Read(const Message* m, PickleIterator* iter, 749 bool ParamTraits<Message>::Read(const Message* m, PickleIterator* iter,
750 Message* r) { 750 Message* r) {
751 uint32 routing_id, type, flags; 751 uint32 routing_id, type, flags;
752 if (!m->ReadUInt32(iter, &routing_id) || 752 if (!iter->ReadUInt32(&routing_id) ||
753 !m->ReadUInt32(iter, &type) || 753 !iter->ReadUInt32(&type) ||
754 !m->ReadUInt32(iter, &flags)) 754 !iter->ReadUInt32(&flags))
755 return false; 755 return false;
756 756
757 int payload_size; 757 int payload_size;
758 const char* payload; 758 const char* payload;
759 if (!m->ReadData(iter, &payload, &payload_size)) 759 if (!iter->ReadData(&payload, &payload_size))
760 return false; 760 return false;
761 761
762 r->SetHeaderValues(static_cast<int32>(routing_id), type, flags); 762 r->SetHeaderValues(static_cast<int32>(routing_id), type, flags);
763 return r->WriteBytes(payload, payload_size); 763 return r->WriteBytes(payload, payload_size);
764 } 764 }
765 765
766 void ParamTraits<Message>::Log(const Message& p, std::string* l) { 766 void ParamTraits<Message>::Log(const Message& p, std::string* l) {
767 l->append("<IPC::Message>"); 767 l->append("<IPC::Message>");
768 } 768 }
769 769
770 #if defined(OS_WIN) 770 #if defined(OS_WIN)
771 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 771 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64
772 // bit systems. That's why we use the Windows macros to convert to 32 bits. 772 // bit systems. That's why we use the Windows macros to convert to 32 bits.
773 void ParamTraits<HANDLE>::Write(Message* m, const param_type& p) { 773 void ParamTraits<HANDLE>::Write(Message* m, const param_type& p) {
774 m->WriteInt(HandleToLong(p)); 774 m->WriteInt(HandleToLong(p));
775 } 775 }
776 776
777 bool ParamTraits<HANDLE>::Read(const Message* m, PickleIterator* iter, 777 bool ParamTraits<HANDLE>::Read(const Message* m, PickleIterator* iter,
778 param_type* r) { 778 param_type* r) {
779 int32 temp; 779 int32 temp;
780 if (!m->ReadInt(iter, &temp)) 780 if (!iter->ReadInt(&temp))
781 return false; 781 return false;
782 *r = LongToHandle(temp); 782 *r = LongToHandle(temp);
783 return true; 783 return true;
784 } 784 }
785 785
786 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) { 786 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) {
787 l->append(base::StringPrintf("0x%X", p)); 787 l->append(base::StringPrintf("0x%X", p));
788 } 788 }
789 789
790 void ParamTraits<LOGFONT>::Write(Message* m, const param_type& p) { 790 void ParamTraits<LOGFONT>::Write(Message* m, const param_type& p) {
791 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT)); 791 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT));
792 } 792 }
793 793
794 bool ParamTraits<LOGFONT>::Read(const Message* m, PickleIterator* iter, 794 bool ParamTraits<LOGFONT>::Read(const Message* m, PickleIterator* iter,
795 param_type* r) { 795 param_type* r) {
796 const char *data; 796 const char *data;
797 int data_size = 0; 797 int data_size = 0;
798 if (m->ReadData(iter, &data, &data_size) && data_size == sizeof(LOGFONT)) { 798 if (iter->ReadData(&data, &data_size) && data_size == sizeof(LOGFONT)) {
799 const LOGFONT *font = reinterpret_cast<LOGFONT*>(const_cast<char*>(data)); 799 const LOGFONT *font = reinterpret_cast<LOGFONT*>(const_cast<char*>(data));
800 if (_tcsnlen(font->lfFaceName, LF_FACESIZE) < LF_FACESIZE) { 800 if (_tcsnlen(font->lfFaceName, LF_FACESIZE) < LF_FACESIZE) {
801 memcpy(r, data, sizeof(LOGFONT)); 801 memcpy(r, data, sizeof(LOGFONT));
802 return true; 802 return true;
803 } 803 }
804 } 804 }
805 805
806 NOTREACHED(); 806 NOTREACHED();
807 return false; 807 return false;
808 } 808 }
809 809
810 void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) { 810 void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) {
811 l->append(base::StringPrintf("<LOGFONT>")); 811 l->append(base::StringPrintf("<LOGFONT>"));
812 } 812 }
813 813
814 void ParamTraits<MSG>::Write(Message* m, const param_type& p) { 814 void ParamTraits<MSG>::Write(Message* m, const param_type& p) {
815 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG)); 815 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG));
816 } 816 }
817 817
818 bool ParamTraits<MSG>::Read(const Message* m, PickleIterator* iter, 818 bool ParamTraits<MSG>::Read(const Message* m, PickleIterator* iter,
819 param_type* r) { 819 param_type* r) {
820 const char *data; 820 const char *data;
821 int data_size = 0; 821 int data_size = 0;
822 bool result = m->ReadData(iter, &data, &data_size); 822 bool result = iter->ReadData(&data, &data_size);
823 if (result && data_size == sizeof(MSG)) { 823 if (result && data_size == sizeof(MSG)) {
824 memcpy(r, data, sizeof(MSG)); 824 memcpy(r, data, sizeof(MSG));
825 } else { 825 } else {
826 result = false; 826 result = false;
827 NOTREACHED(); 827 NOTREACHED();
828 } 828 }
829 829
830 return result; 830 return result;
831 } 831 }
832 832
833 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 833 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
834 l->append("<MSG>"); 834 l->append("<MSG>");
835 } 835 }
836 836
837 #endif // OS_WIN 837 #endif // OS_WIN
838 838
839 } // namespace IPC 839 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_message_utils.h ('k') | ipc/ipc_sync_message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698