| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/common/common_param_traits.h" | 5 #include "chrome/common/common_param_traits.h" |
| 6 | 6 |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "chrome/common/chrome_constants.h" | 8 #include "chrome/common/chrome_constants.h" |
| 9 #include "chrome/common/content_settings.h" | 9 #include "chrome/common/content_settings.h" |
| 10 #include "chrome/common/geoposition.h" | 10 #include "chrome/common/geoposition.h" |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 343 } |
| 344 | 344 |
| 345 // Only the net::UploadData ParamTraits<> definition needs this definition, so | 345 // Only the net::UploadData ParamTraits<> definition needs this definition, so |
| 346 // keep this in the implementation file so we can forward declare UploadData in | 346 // keep this in the implementation file so we can forward declare UploadData in |
| 347 // the header. | 347 // the header. |
| 348 template <> | 348 template <> |
| 349 struct ParamTraits<net::UploadData::Element> { | 349 struct ParamTraits<net::UploadData::Element> { |
| 350 typedef net::UploadData::Element param_type; | 350 typedef net::UploadData::Element param_type; |
| 351 static void Write(Message* m, const param_type& p) { | 351 static void Write(Message* m, const param_type& p) { |
| 352 WriteParam(m, static_cast<int>(p.type())); | 352 WriteParam(m, static_cast<int>(p.type())); |
| 353 if (p.type() == net::UploadData::TYPE_BYTES) { | 353 switch (p.type()) { |
| 354 m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size())); | 354 case net::UploadData::TYPE_BYTES: { |
| 355 } else if (p.type() == net::UploadData::TYPE_FILE) { | 355 m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size())); |
| 356 WriteParam(m, p.file_path()); | 356 break; |
| 357 WriteParam(m, p.file_range_offset()); | 357 } |
| 358 WriteParam(m, p.file_range_length()); | 358 case net::UploadData::TYPE_CHUNK: { |
| 359 WriteParam(m, p.expected_file_modification_time()); | 359 m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size())); |
| 360 } else { | 360 // If this element is part of a chunk upload then send over information |
| 361 WriteParam(m, p.blob_url()); | 361 // indicating if this is the last chunk. |
| 362 WriteParam(m, p.is_last_chunk()); |
| 363 break; |
| 364 } |
| 365 case net::UploadData::TYPE_FILE: { |
| 366 WriteParam(m, p.file_path()); |
| 367 WriteParam(m, p.file_range_offset()); |
| 368 WriteParam(m, p.file_range_length()); |
| 369 WriteParam(m, p.expected_file_modification_time()); |
| 370 break; |
| 371 } |
| 372 default: { |
| 373 WriteParam(m, p.blob_url()); |
| 374 break; |
| 375 } |
| 362 } | 376 } |
| 363 } | 377 } |
| 364 static bool Read(const Message* m, void** iter, param_type* r) { | 378 static bool Read(const Message* m, void** iter, param_type* r) { |
| 365 int type; | 379 int type; |
| 366 if (!ReadParam(m, iter, &type)) | 380 if (!ReadParam(m, iter, &type)) |
| 367 return false; | 381 return false; |
| 368 if (type == net::UploadData::TYPE_BYTES) { | 382 switch (type) { |
| 369 const char* data; | 383 case net::UploadData::TYPE_BYTES: { |
| 370 int len; | 384 const char* data; |
| 371 if (!m->ReadData(iter, &data, &len)) | 385 int len; |
| 372 return false; | 386 if (!m->ReadData(iter, &data, &len)) |
| 373 r->SetToBytes(data, len); | 387 return false; |
| 374 } else if (type == net::UploadData::TYPE_FILE) { | 388 r->SetToBytes(data, len); |
| 375 FilePath file_path; | 389 break; |
| 376 uint64 offset, length; | 390 } |
| 377 base::Time expected_modification_time; | 391 case net::UploadData::TYPE_CHUNK: { |
| 378 if (!ReadParam(m, iter, &file_path)) | 392 const char* data; |
| 379 return false; | 393 int len; |
| 380 if (!ReadParam(m, iter, &offset)) | 394 if (!m->ReadData(iter, &data, &len)) |
| 381 return false; | 395 return false; |
| 382 if (!ReadParam(m, iter, &length)) | 396 r->SetToBytes(data, len); |
| 383 return false; | 397 // If this element is part of a chunk upload then we need to explicitly |
| 384 if (!ReadParam(m, iter, &expected_modification_time)) | 398 // set the type of the element and whether it is the last chunk. |
| 385 return false; | 399 bool is_last_chunk = false; |
| 386 r->SetToFilePathRange(file_path, offset, length, | 400 if (!ReadParam(m, iter, &is_last_chunk)) |
| 387 expected_modification_time); | 401 return false; |
| 388 } else { | 402 r->set_type(net::UploadData::TYPE_CHUNK); |
| 389 DCHECK(type == net::UploadData::TYPE_BLOB); | 403 r->set_is_last_chunk(is_last_chunk); |
| 390 GURL blob_url; | 404 break; |
| 391 if (!ReadParam(m, iter, &blob_url)) | 405 } |
| 392 return false; | 406 case net::UploadData::TYPE_FILE: { |
| 393 r->SetToBlobUrl(blob_url); | 407 FilePath file_path; |
| 408 uint64 offset, length; |
| 409 base::Time expected_modification_time; |
| 410 if (!ReadParam(m, iter, &file_path)) |
| 411 return false; |
| 412 if (!ReadParam(m, iter, &offset)) |
| 413 return false; |
| 414 if (!ReadParam(m, iter, &length)) |
| 415 return false; |
| 416 if (!ReadParam(m, iter, &expected_modification_time)) |
| 417 return false; |
| 418 r->SetToFilePathRange(file_path, offset, length, |
| 419 expected_modification_time); |
| 420 break; |
| 421 } |
| 422 default: { |
| 423 DCHECK(type == net::UploadData::TYPE_BLOB); |
| 424 GURL blob_url; |
| 425 if (!ReadParam(m, iter, &blob_url)) |
| 426 return false; |
| 427 r->SetToBlobUrl(blob_url); |
| 428 break; |
| 429 } |
| 394 } | 430 } |
| 395 return true; | 431 return true; |
| 396 } | 432 } |
| 397 static void Log(const param_type& p, std::string* l) { | 433 static void Log(const param_type& p, std::string* l) { |
| 398 l->append("<net::UploadData::Element>"); | 434 l->append("<net::UploadData::Element>"); |
| 399 } | 435 } |
| 400 }; | 436 }; |
| 401 | 437 |
| 402 void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m, | 438 void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m, |
| 403 const param_type& p) { | 439 const param_type& p) { |
| 404 WriteParam(m, p.get() != NULL); | 440 WriteParam(m, p.get() != NULL); |
| 405 if (p) { | 441 if (p) { |
| 406 WriteParam(m, *p->elements()); | 442 WriteParam(m, *p->elements()); |
| 407 WriteParam(m, p->identifier()); | 443 WriteParam(m, p->identifier()); |
| 444 WriteParam(m, p->is_chunked()); |
| 408 } | 445 } |
| 409 } | 446 } |
| 410 | 447 |
| 411 bool ParamTraits<scoped_refptr<net::UploadData> >::Read(const Message* m, | 448 bool ParamTraits<scoped_refptr<net::UploadData> >::Read(const Message* m, |
| 412 void** iter, | 449 void** iter, |
| 413 param_type* r) { | 450 param_type* r) { |
| 414 bool has_object; | 451 bool has_object; |
| 415 if (!ReadParam(m, iter, &has_object)) | 452 if (!ReadParam(m, iter, &has_object)) |
| 416 return false; | 453 return false; |
| 417 if (!has_object) | 454 if (!has_object) |
| 418 return true; | 455 return true; |
| 419 std::vector<net::UploadData::Element> elements; | 456 std::vector<net::UploadData::Element> elements; |
| 420 if (!ReadParam(m, iter, &elements)) | 457 if (!ReadParam(m, iter, &elements)) |
| 421 return false; | 458 return false; |
| 422 int64 identifier; | 459 int64 identifier; |
| 423 if (!ReadParam(m, iter, &identifier)) | 460 if (!ReadParam(m, iter, &identifier)) |
| 424 return false; | 461 return false; |
| 462 bool is_chunked = false; |
| 463 if (!ReadParam(m, iter, &is_chunked)) |
| 464 return false; |
| 425 *r = new net::UploadData; | 465 *r = new net::UploadData; |
| 426 (*r)->swap_elements(&elements); | 466 (*r)->swap_elements(&elements); |
| 427 (*r)->set_identifier(identifier); | 467 (*r)->set_identifier(identifier); |
| 468 (*r)->set_is_chunked(is_chunked); |
| 428 return true; | 469 return true; |
| 429 } | 470 } |
| 430 | 471 |
| 431 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, | 472 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, |
| 432 std::string* l) { | 473 std::string* l) { |
| 433 l->append("<net::UploadData>"); | 474 l->append("<net::UploadData>"); |
| 434 } | 475 } |
| 435 | 476 |
| 436 void ParamTraits<ThumbnailScore>::Write(Message* m, const param_type& p) { | 477 void ParamTraits<ThumbnailScore>::Write(Message* m, const param_type& p) { |
| 437 IPC::ParamTraits<double>::Write(m, p.boring_score); | 478 IPC::ParamTraits<double>::Write(m, p.boring_score); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 l->append(","); | 714 l->append(","); |
| 674 LogParam(p.caps_mime_type, l); | 715 LogParam(p.caps_mime_type, l); |
| 675 l->append(","); | 716 l->append(","); |
| 676 LogParam(p.printer_defaults, l); | 717 LogParam(p.printer_defaults, l); |
| 677 l->append(","); | 718 l->append(","); |
| 678 LogParam(p.defaults_mime_type, l); | 719 LogParam(p.defaults_mime_type, l); |
| 679 l->append(")"); | 720 l->append(")"); |
| 680 } | 721 } |
| 681 | 722 |
| 682 } // namespace IPC | 723 } // namespace IPC |
| OLD | NEW |