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

Side by Side Diff: ppapi/proxy/raw_var_data.cc

Issue 1659003003: IPC::Message -> base::Pickle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one more mac fix Created 4 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
« no previous file with comments | « ppapi/proxy/raw_var_data.h ('k') | ppapi/proxy/raw_var_data_unittest.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/proxy/raw_var_data.h" 5 #include "ppapi/proxy/raw_var_data.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 graph.push_back(data_[i]->CreatePPVar(instance)); 166 graph.push_back(data_[i]->CreatePPVar(instance));
167 for (size_t i = 0; i < data_.size(); ++i) 167 for (size_t i = 0; i < data_.size(); ++i)
168 data_[i]->PopulatePPVar(graph[i], graph); 168 data_[i]->PopulatePPVar(graph[i], graph);
169 // Everything except the root will have one extra ref. Remove that ref. 169 // Everything except the root will have one extra ref. Remove that ref.
170 for (size_t i = 1; i < data_.size(); ++i) 170 for (size_t i = 1; i < data_.size(); ++i)
171 ScopedPPVar(ScopedPPVar::PassRef(), graph[i]); 171 ScopedPPVar(ScopedPPVar::PassRef(), graph[i]);
172 // The first element is the root. 172 // The first element is the root.
173 return graph[0]; 173 return graph[0];
174 } 174 }
175 175
176 void RawVarDataGraph::Write(IPC::Message* m, 176 void RawVarDataGraph::Write(base::Pickle* m,
177 const HandleWriter& handle_writer) { 177 const HandleWriter& handle_writer) {
178 // Write the size, followed by each node in the graph. 178 // Write the size, followed by each node in the graph.
179 m->WriteUInt32(static_cast<uint32_t>(data_.size())); 179 m->WriteUInt32(static_cast<uint32_t>(data_.size()));
180 for (size_t i = 0; i < data_.size(); ++i) { 180 for (size_t i = 0; i < data_.size(); ++i) {
181 m->WriteInt(data_[i]->Type()); 181 m->WriteInt(data_[i]->Type());
182 data_[i]->Write(m, handle_writer); 182 data_[i]->Write(m, handle_writer);
183 } 183 }
184 } 184 }
185 185
186 // static 186 // static
187 scoped_ptr<RawVarDataGraph> RawVarDataGraph::Read(const IPC::Message* m, 187 scoped_ptr<RawVarDataGraph> RawVarDataGraph::Read(const base::Pickle* m,
188 base::PickleIterator* iter) { 188 base::PickleIterator* iter) {
189 scoped_ptr<RawVarDataGraph> result(new RawVarDataGraph); 189 scoped_ptr<RawVarDataGraph> result(new RawVarDataGraph);
190 uint32_t size = 0; 190 uint32_t size = 0;
191 if (!iter->ReadUInt32(&size)) 191 if (!iter->ReadUInt32(&size))
192 return scoped_ptr<RawVarDataGraph>(); 192 return scoped_ptr<RawVarDataGraph>();
193 for (uint32_t i = 0; i < size; ++i) { 193 for (uint32_t i = 0; i < size; ++i) {
194 int32_t type; 194 int32_t type;
195 if (!iter->ReadInt(&type)) 195 if (!iter->ReadInt(&type))
196 return scoped_ptr<RawVarDataGraph>(); 196 return scoped_ptr<RawVarDataGraph>();
197 PP_VarType var_type = static_cast<PP_VarType>(type); 197 PP_VarType var_type = static_cast<PP_VarType>(type);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 276 }
277 277
278 PP_Var BasicRawVarData::CreatePPVar(PP_Instance instance) { 278 PP_Var BasicRawVarData::CreatePPVar(PP_Instance instance) {
279 return var_; 279 return var_;
280 } 280 }
281 281
282 void BasicRawVarData::PopulatePPVar(const PP_Var& var, 282 void BasicRawVarData::PopulatePPVar(const PP_Var& var,
283 const std::vector<PP_Var>& graph) { 283 const std::vector<PP_Var>& graph) {
284 } 284 }
285 285
286 void BasicRawVarData::Write( 286 void BasicRawVarData::Write(base::Pickle* m,
287 IPC::Message* m, 287 const HandleWriter& handle_writer) {
288 const HandleWriter& handle_writer) {
289 switch (var_.type) { 288 switch (var_.type) {
290 case PP_VARTYPE_UNDEFINED: 289 case PP_VARTYPE_UNDEFINED:
291 case PP_VARTYPE_NULL: 290 case PP_VARTYPE_NULL:
292 // These don't need any data associated with them other than the type we 291 // These don't need any data associated with them other than the type we
293 // just serialized. 292 // just serialized.
294 break; 293 break;
295 case PP_VARTYPE_BOOL: 294 case PP_VARTYPE_BOOL:
296 m->WriteBool(PP_ToBool(var_.value.as_bool)); 295 m->WriteBool(PP_ToBool(var_.value.as_bool));
297 break; 296 break;
298 case PP_VARTYPE_INT32: 297 case PP_VARTYPE_INT32:
299 m->WriteInt(var_.value.as_int); 298 m->WriteInt(var_.value.as_int);
300 break; 299 break;
301 case PP_VARTYPE_DOUBLE: 300 case PP_VARTYPE_DOUBLE:
302 IPC::WriteParam(m, var_.value.as_double); 301 IPC::WriteParam(m, var_.value.as_double);
303 break; 302 break;
304 case PP_VARTYPE_OBJECT: 303 case PP_VARTYPE_OBJECT:
305 m->WriteInt64(var_.value.as_id); 304 m->WriteInt64(var_.value.as_id);
306 break; 305 break;
307 default: 306 default:
308 NOTREACHED(); 307 NOTREACHED();
309 break; 308 break;
310 } 309 }
311 } 310 }
312 311
313 bool BasicRawVarData::Read(PP_VarType type, 312 bool BasicRawVarData::Read(PP_VarType type,
314 const IPC::Message* m, 313 const base::Pickle* m,
315 base::PickleIterator* iter) { 314 base::PickleIterator* iter) {
316 PP_Var result; 315 PP_Var result;
317 result.type = type; 316 result.type = type;
318 switch (type) { 317 switch (type) {
319 case PP_VARTYPE_UNDEFINED: 318 case PP_VARTYPE_UNDEFINED:
320 case PP_VARTYPE_NULL: 319 case PP_VARTYPE_NULL:
321 // These don't have any data associated with them other than the type we 320 // These don't have any data associated with them other than the type we
322 // just deserialized. 321 // just deserialized.
323 break; 322 break;
324 case PP_VARTYPE_BOOL: { 323 case PP_VARTYPE_BOOL: {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 369 }
371 370
372 PP_Var StringRawVarData::CreatePPVar(PP_Instance instance) { 371 PP_Var StringRawVarData::CreatePPVar(PP_Instance instance) {
373 return StringVar::SwapValidatedUTF8StringIntoPPVar(&data_); 372 return StringVar::SwapValidatedUTF8StringIntoPPVar(&data_);
374 } 373 }
375 374
376 void StringRawVarData::PopulatePPVar(const PP_Var& var, 375 void StringRawVarData::PopulatePPVar(const PP_Var& var,
377 const std::vector<PP_Var>& graph) { 376 const std::vector<PP_Var>& graph) {
378 } 377 }
379 378
380 void StringRawVarData::Write(IPC::Message* m, 379 void StringRawVarData::Write(base::Pickle* m,
381 const HandleWriter& handle_writer) { 380 const HandleWriter& handle_writer) {
382 m->WriteString(data_); 381 m->WriteString(data_);
383 } 382 }
384 383
385 bool StringRawVarData::Read(PP_VarType type, 384 bool StringRawVarData::Read(PP_VarType type,
386 const IPC::Message* m, 385 const base::Pickle* m,
387 base::PickleIterator* iter) { 386 base::PickleIterator* iter) {
388 if (!iter->ReadString(&data_)) 387 if (!iter->ReadString(&data_))
389 return false; 388 return false;
390 return true; 389 return true;
391 } 390 }
392 391
393 // ArrayBufferRawVarData ------------------------------------------------------- 392 // ArrayBufferRawVarData -------------------------------------------------------
394 ArrayBufferRawVarData::ArrayBufferRawVarData() { 393 ArrayBufferRawVarData::ArrayBufferRawVarData() {
395 } 394 }
396 395
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 return PP_MakeUndefined(); 474 return PP_MakeUndefined();
476 } 475 }
477 DCHECK(result.type == PP_VARTYPE_ARRAY_BUFFER); 476 DCHECK(result.type == PP_VARTYPE_ARRAY_BUFFER);
478 return result; 477 return result;
479 } 478 }
480 479
481 void ArrayBufferRawVarData::PopulatePPVar(const PP_Var& var, 480 void ArrayBufferRawVarData::PopulatePPVar(const PP_Var& var,
482 const std::vector<PP_Var>& graph) { 481 const std::vector<PP_Var>& graph) {
483 } 482 }
484 483
485 void ArrayBufferRawVarData::Write( 484 void ArrayBufferRawVarData::Write(base::Pickle* m,
486 IPC::Message* m, 485 const HandleWriter& handle_writer) {
487 const HandleWriter& handle_writer) {
488 m->WriteInt(type_); 486 m->WriteInt(type_);
489 switch (type_) { 487 switch (type_) {
490 case ARRAY_BUFFER_SHMEM_HOST: 488 case ARRAY_BUFFER_SHMEM_HOST:
491 m->WriteInt(host_shm_handle_id_); 489 m->WriteInt(host_shm_handle_id_);
492 break; 490 break;
493 case ARRAY_BUFFER_SHMEM_PLUGIN: 491 case ARRAY_BUFFER_SHMEM_PLUGIN:
494 handle_writer.Run(m, plugin_shm_handle_); 492 handle_writer.Run(m, plugin_shm_handle_);
495 break; 493 break;
496 case ARRAY_BUFFER_NO_SHMEM: 494 case ARRAY_BUFFER_NO_SHMEM:
497 m->WriteString(data_); 495 m->WriteString(data_);
498 break; 496 break;
499 } 497 }
500 } 498 }
501 499
502 bool ArrayBufferRawVarData::Read(PP_VarType type, 500 bool ArrayBufferRawVarData::Read(PP_VarType type,
503 const IPC::Message* m, 501 const base::Pickle* m,
504 base::PickleIterator* iter) { 502 base::PickleIterator* iter) {
505 int shmem_type; 503 int shmem_type;
506 if (!iter->ReadInt(&shmem_type)) 504 if (!iter->ReadInt(&shmem_type))
507 return false; 505 return false;
508 type_ = static_cast<ShmemType>(shmem_type); 506 type_ = static_cast<ShmemType>(shmem_type);
509 switch (type_) { 507 switch (type_) {
510 case ARRAY_BUFFER_SHMEM_HOST: 508 case ARRAY_BUFFER_SHMEM_HOST:
511 if (!iter->ReadInt(&host_shm_handle_id_)) 509 if (!iter->ReadInt(&host_shm_handle_id_))
512 return false; 510 return false;
513 break; 511 break;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 if (var.type != PP_VARTYPE_ARRAY) { 563 if (var.type != PP_VARTYPE_ARRAY) {
566 NOTREACHED(); 564 NOTREACHED();
567 return; 565 return;
568 } 566 }
569 ArrayVar* array_var = ArrayVar::FromPPVar(var); 567 ArrayVar* array_var = ArrayVar::FromPPVar(var);
570 DCHECK(array_var->elements().empty()); 568 DCHECK(array_var->elements().empty());
571 for (size_t i = 0; i < children_.size(); ++i) 569 for (size_t i = 0; i < children_.size(); ++i)
572 array_var->elements().push_back(ScopedPPVar(graph[children_[i]])); 570 array_var->elements().push_back(ScopedPPVar(graph[children_[i]]));
573 } 571 }
574 572
575 void ArrayRawVarData::Write(IPC::Message* m, 573 void ArrayRawVarData::Write(base::Pickle* m,
576 const HandleWriter& handle_writer) { 574 const HandleWriter& handle_writer) {
577 m->WriteUInt32(static_cast<uint32_t>(children_.size())); 575 m->WriteUInt32(static_cast<uint32_t>(children_.size()));
578 for (size_t i = 0; i < children_.size(); ++i) 576 for (size_t i = 0; i < children_.size(); ++i)
579 m->WriteUInt32(static_cast<uint32_t>(children_[i])); 577 m->WriteUInt32(static_cast<uint32_t>(children_[i]));
580 } 578 }
581 579
582 bool ArrayRawVarData::Read(PP_VarType type, 580 bool ArrayRawVarData::Read(PP_VarType type,
583 const IPC::Message* m, 581 const base::Pickle* m,
584 base::PickleIterator* iter) { 582 base::PickleIterator* iter) {
585 uint32_t size; 583 uint32_t size;
586 if (!iter->ReadUInt32(&size)) 584 if (!iter->ReadUInt32(&size))
587 return false; 585 return false;
588 for (uint32_t i = 0; i < size; ++i) { 586 for (uint32_t i = 0; i < size; ++i) {
589 uint32_t index; 587 uint32_t index;
590 if (!iter->ReadUInt32(&index)) 588 if (!iter->ReadUInt32(&index))
591 return false; 589 return false;
592 children_.push_back(index); 590 children_.push_back(index);
593 } 591 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 } 626 }
629 DictionaryVar* dictionary_var = DictionaryVar::FromPPVar(var); 627 DictionaryVar* dictionary_var = DictionaryVar::FromPPVar(var);
630 DCHECK(dictionary_var->key_value_map().empty()); 628 DCHECK(dictionary_var->key_value_map().empty());
631 for (size_t i = 0; i < children_.size(); ++i) { 629 for (size_t i = 0; i < children_.size(); ++i) {
632 bool success = dictionary_var->SetWithStringKey(children_[i].first, 630 bool success = dictionary_var->SetWithStringKey(children_[i].first,
633 graph[children_[i].second]); 631 graph[children_[i].second]);
634 DCHECK(success); 632 DCHECK(success);
635 } 633 }
636 } 634 }
637 635
638 void DictionaryRawVarData::Write( 636 void DictionaryRawVarData::Write(base::Pickle* m,
639 IPC::Message* m, 637 const HandleWriter& handle_writer) {
640 const HandleWriter& handle_writer) {
641 m->WriteUInt32(static_cast<uint32_t>(children_.size())); 638 m->WriteUInt32(static_cast<uint32_t>(children_.size()));
642 for (size_t i = 0; i < children_.size(); ++i) { 639 for (size_t i = 0; i < children_.size(); ++i) {
643 m->WriteString(children_[i].first); 640 m->WriteString(children_[i].first);
644 m->WriteUInt32(static_cast<uint32_t>(children_[i].second)); 641 m->WriteUInt32(static_cast<uint32_t>(children_[i].second));
645 } 642 }
646 } 643 }
647 644
648 bool DictionaryRawVarData::Read(PP_VarType type, 645 bool DictionaryRawVarData::Read(PP_VarType type,
649 const IPC::Message* m, 646 const base::Pickle* m,
650 base::PickleIterator* iter) { 647 base::PickleIterator* iter) {
651 uint32_t size; 648 uint32_t size;
652 if (!iter->ReadUInt32(&size)) 649 if (!iter->ReadUInt32(&size))
653 return false; 650 return false;
654 for (uint32_t i = 0; i < size; ++i) { 651 for (uint32_t i = 0; i < size; ++i) {
655 std::string key; 652 std::string key;
656 uint32_t value; 653 uint32_t value;
657 if (!iter->ReadString(&key)) 654 if (!iter->ReadString(&key))
658 return false; 655 return false;
659 if (!iter->ReadUInt32(&value)) 656 if (!iter->ReadUInt32(&value))
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 instance, 702 instance,
706 *creation_message_, 703 *creation_message_,
707 pending_renderer_host_id_, 704 pending_renderer_host_id_,
708 pending_browser_host_id_); 705 pending_browser_host_id_);
709 } 706 }
710 707
711 void ResourceRawVarData::PopulatePPVar(const PP_Var& var, 708 void ResourceRawVarData::PopulatePPVar(const PP_Var& var,
712 const std::vector<PP_Var>& graph) { 709 const std::vector<PP_Var>& graph) {
713 } 710 }
714 711
715 void ResourceRawVarData::Write(IPC::Message* m, 712 void ResourceRawVarData::Write(base::Pickle* m,
716 const HandleWriter& handle_writer) { 713 const HandleWriter& handle_writer) {
717 m->WriteInt(static_cast<int>(pp_resource_)); 714 m->WriteInt(static_cast<int>(pp_resource_));
718 m->WriteInt(pending_renderer_host_id_); 715 m->WriteInt(pending_renderer_host_id_);
719 m->WriteInt(pending_browser_host_id_); 716 m->WriteInt(pending_browser_host_id_);
720 m->WriteBool(creation_message_); 717 m->WriteBool(creation_message_);
721 if (creation_message_) 718 if (creation_message_)
722 IPC::WriteParam(m, *creation_message_); 719 IPC::WriteParam(m, *creation_message_);
723 } 720 }
724 721
725 bool ResourceRawVarData::Read(PP_VarType type, 722 bool ResourceRawVarData::Read(PP_VarType type,
726 const IPC::Message* m, 723 const base::Pickle* m,
727 base::PickleIterator* iter) { 724 base::PickleIterator* iter) {
728 int value; 725 int value;
729 if (!iter->ReadInt(&value)) 726 if (!iter->ReadInt(&value))
730 return false; 727 return false;
731 pp_resource_ = static_cast<PP_Resource>(value); 728 pp_resource_ = static_cast<PP_Resource>(value);
732 if (!iter->ReadInt(&pending_renderer_host_id_)) 729 if (!iter->ReadInt(&pending_renderer_host_id_))
733 return false; 730 return false;
734 if (!iter->ReadInt(&pending_browser_host_id_)) 731 if (!iter->ReadInt(&pending_browser_host_id_))
735 return false; 732 return false;
736 bool has_creation_message; 733 bool has_creation_message;
737 if (!iter->ReadBool(&has_creation_message)) 734 if (!iter->ReadBool(&has_creation_message))
738 return false; 735 return false;
739 if (has_creation_message) { 736 if (has_creation_message) {
740 creation_message_.reset(new IPC::Message()); 737 creation_message_.reset(new IPC::Message());
741 if (!IPC::ReadParam(m, iter, creation_message_.get())) 738 if (!IPC::ReadParam(m, iter, creation_message_.get()))
742 return false; 739 return false;
743 } else { 740 } else {
744 creation_message_.reset(); 741 creation_message_.reset();
745 } 742 }
746 return true; 743 return true;
747 } 744 }
748 745
749 } // namespace proxy 746 } // namespace proxy
750 } // namespace ppapi 747 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/raw_var_data.h ('k') | ppapi/proxy/raw_var_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698