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 // Keep this file in sync with the .proto files in this directory. | 5 // Keep this file in sync with the .proto files in this directory. |
6 | 6 |
7 #include "sync/protocol/proto_value_conversions.h" | 7 #include "sync/protocol/proto_value_conversions.h" |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 SET_FIELD(nigori, NigoriSpecificsToValue); | 390 SET_FIELD(nigori, NigoriSpecificsToValue); |
391 SET_FIELD(password, PasswordSpecificsToValue); | 391 SET_FIELD(password, PasswordSpecificsToValue); |
392 SET_FIELD(preference, PreferenceSpecificsToValue); | 392 SET_FIELD(preference, PreferenceSpecificsToValue); |
393 SET_FIELD(search_engine, SearchEngineSpecificsToValue); | 393 SET_FIELD(search_engine, SearchEngineSpecificsToValue); |
394 SET_FIELD(session, SessionSpecificsToValue); | 394 SET_FIELD(session, SessionSpecificsToValue); |
395 SET_FIELD(theme, ThemeSpecificsToValue); | 395 SET_FIELD(theme, ThemeSpecificsToValue); |
396 SET_FIELD(typed_url, TypedUrlSpecificsToValue); | 396 SET_FIELD(typed_url, TypedUrlSpecificsToValue); |
397 return value; | 397 return value; |
398 } | 398 } |
399 | 399 |
| 400 namespace { |
| 401 |
| 402 DictionaryValue* SyncEntityToValue(const sync_pb::SyncEntity& proto, |
| 403 bool include_specifics) { |
| 404 DictionaryValue* value = new DictionaryValue(); |
| 405 SET_STR(id_string); |
| 406 SET_STR(parent_id_string); |
| 407 SET_STR(old_parent_id); |
| 408 SET_INT64(version); |
| 409 SET_INT64(mtime); |
| 410 SET_INT64(ctime); |
| 411 SET_STR(name); |
| 412 SET_STR(non_unique_name); |
| 413 SET_INT64(sync_timestamp); |
| 414 SET_STR(server_defined_unique_tag); |
| 415 SET_INT64(position_in_parent); |
| 416 SET_STR(insert_after_item_id); |
| 417 SET_BOOL(deleted); |
| 418 SET_STR(originator_cache_guid); |
| 419 SET_STR(originator_client_item_id); |
| 420 if (include_specifics) |
| 421 SET(specifics, EntitySpecificsToValue); |
| 422 SET_BOOL(folder); |
| 423 SET_STR(client_defined_unique_tag); |
| 424 return value; |
| 425 } |
| 426 |
| 427 ListValue* SyncEntitiesToValue( |
| 428 const ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, |
| 429 bool include_specifics) { |
| 430 ListValue* list = new ListValue(); |
| 431 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it; |
| 432 for (it = entities.begin(); it != entities.end(); ++it) { |
| 433 list->Append(SyncEntityToValue(*it, include_specifics)); |
| 434 } |
| 435 |
| 436 return list; |
| 437 } |
| 438 |
| 439 DictionaryValue* ChromiumExtensionActivityToValue( |
| 440 const sync_pb::ChromiumExtensionsActivity& proto) { |
| 441 DictionaryValue* value = new DictionaryValue(); |
| 442 SET_STR(extension_id); |
| 443 SET_INT32(bookmark_writes_since_last_commit); |
| 444 return value; |
| 445 } |
| 446 |
| 447 DictionaryValue* CommitMessageToValue( |
| 448 const sync_pb::CommitMessage& proto, |
| 449 bool include_specifics) { |
| 450 DictionaryValue* value = new DictionaryValue(); |
| 451 value->Set("entries", |
| 452 SyncEntitiesToValue(proto.entries(), include_specifics)); |
| 453 SET_STR(cache_guid); |
| 454 SET_REP(extensions_activity, ChromiumExtensionActivityToValue); |
| 455 return value; |
| 456 } |
| 457 |
| 458 DictionaryValue* DataTypeProgressMarkerToValue( |
| 459 const sync_pb::DataTypeProgressMarker& proto) { |
| 460 DictionaryValue* value = new DictionaryValue(); |
| 461 SET_INT32(data_type_id); |
| 462 SET_BYTES(token); |
| 463 SET_INT64(timestamp_token_for_migration); |
| 464 SET_STR(notification_hint); |
| 465 return value; |
| 466 } |
| 467 |
| 468 DictionaryValue* GetUpdatesCallerInfoToValue( |
| 469 const sync_pb::GetUpdatesCallerInfo& proto) { |
| 470 DictionaryValue* value = new DictionaryValue(); |
| 471 SET_ENUM(source, GetUpdatesSourceString); |
| 472 SET_BOOL(notifications_enabled); |
| 473 return value; |
| 474 } |
| 475 |
| 476 DictionaryValue* GetUpdatesMessageToValue( |
| 477 const sync_pb::GetUpdatesMessage& proto) { |
| 478 DictionaryValue* value = new DictionaryValue(); |
| 479 SET(caller_info, GetUpdatesCallerInfoToValue); |
| 480 SET_BOOL(fetch_folders); |
| 481 SET_INT32(batch_size); |
| 482 SET_REP(from_progress_marker, DataTypeProgressMarkerToValue); |
| 483 SET_BOOL(streaming); |
| 484 SET_BOOL(create_mobile_bookmarks_folder); |
| 485 return value; |
| 486 } |
| 487 |
| 488 DictionaryValue* EntryResponseToValue( |
| 489 const sync_pb::CommitResponse::EntryResponse& proto) { |
| 490 DictionaryValue* value = new DictionaryValue(); |
| 491 SET_ENUM(response_type, GetResponseTypeString); |
| 492 SET_STR(id_string); |
| 493 SET_STR(parent_id_string); |
| 494 SET_INT64(position_in_parent); |
| 495 SET_INT64(version); |
| 496 SET_STR(name); |
| 497 SET_STR(error_message); |
| 498 SET_INT64(mtime); |
| 499 return value; |
| 500 } |
| 501 |
| 502 DictionaryValue* CommitResponseToValue(const sync_pb::CommitResponse& proto) { |
| 503 DictionaryValue* value = new DictionaryValue(); |
| 504 SET_REP(entryresponse, EntryResponseToValue); |
| 505 return value; |
| 506 } |
| 507 |
| 508 DictionaryValue* GetUpdatesResponseToValue( |
| 509 const sync_pb::GetUpdatesResponse& proto, |
| 510 bool include_specifics) { |
| 511 DictionaryValue* value = new DictionaryValue(); |
| 512 value->Set("entries", |
| 513 SyncEntitiesToValue(proto.entries(), include_specifics)); |
| 514 SET_INT64(changes_remaining); |
| 515 SET_REP(new_progress_marker, DataTypeProgressMarkerToValue); |
| 516 return value; |
| 517 } |
| 518 |
| 519 DictionaryValue* ClientCommandToValue(const sync_pb::ClientCommand& proto) { |
| 520 DictionaryValue* value = new DictionaryValue(); |
| 521 SET_INT32(set_sync_poll_interval); |
| 522 SET_INT32(set_sync_long_poll_interval); |
| 523 SET_INT32(max_commit_batch_size); |
| 524 SET_INT32(sessions_commit_delay_seconds); |
| 525 SET_INT32(throttle_delay_seconds); |
| 526 return value; |
| 527 } |
| 528 |
| 529 DictionaryValue* ErrorToValue( |
| 530 const sync_pb::ClientToServerResponse::Error& proto) { |
| 531 DictionaryValue* value = new DictionaryValue(); |
| 532 SET_ENUM(error_type, GetErrorTypeString); |
| 533 SET_STR(error_description); |
| 534 SET_STR(url); |
| 535 SET_ENUM(action, GetActionString); |
| 536 return value; |
| 537 } |
| 538 |
| 539 } // namespace |
| 540 |
| 541 DictionaryValue* ClientToServerResponseToValue( |
| 542 const sync_pb::ClientToServerResponse& proto, |
| 543 bool include_specifics) { |
| 544 DictionaryValue* value = new DictionaryValue(); |
| 545 SET(commit, CommitResponseToValue); |
| 546 if (proto.has_get_updates()) { |
| 547 value->Set("get_updates", GetUpdatesResponseToValue(proto.get_updates(), |
| 548 include_specifics)); |
| 549 } |
| 550 |
| 551 SET(error, ErrorToValue); |
| 552 SET_ENUM(error_code, GetErrorTypeString); |
| 553 SET_STR(error_message); |
| 554 SET_STR(store_birthday); |
| 555 SET(client_command, ClientCommandToValue); |
| 556 SET_INT32_REP(migrated_data_type_id); |
| 557 return value; |
| 558 } |
| 559 |
| 560 DictionaryValue* ClientToServerMessageToValue( |
| 561 const sync_pb::ClientToServerMessage& proto, |
| 562 bool include_specifics) { |
| 563 DictionaryValue* value = new DictionaryValue(); |
| 564 SET_STR(share); |
| 565 SET_INT32(protocol_version); |
| 566 if (proto.has_commit()) { |
| 567 value->Set("commit", |
| 568 CommitMessageToValue(proto.commit(), include_specifics)); |
| 569 } |
| 570 |
| 571 SET(get_updates, GetUpdatesMessageToValue); |
| 572 SET_STR(store_birthday); |
| 573 SET_BOOL(sync_problem_detected); |
| 574 return value; |
| 575 } |
| 576 |
| 577 |
400 #undef SET | 578 #undef SET |
401 #undef SET_REP | 579 #undef SET_REP |
402 | 580 |
403 #undef SET_BOOL | 581 #undef SET_BOOL |
404 #undef SET_BYTES | 582 #undef SET_BYTES |
405 #undef SET_INT32 | 583 #undef SET_INT32 |
406 #undef SET_INT64 | 584 #undef SET_INT64 |
407 #undef SET_INT64_REP | 585 #undef SET_INT64_REP |
408 #undef SET_STR | 586 #undef SET_STR |
409 #undef SET_STR_REP | 587 #undef SET_STR_REP |
410 | 588 |
411 #undef SET_FIELD | 589 #undef SET_FIELD |
412 | 590 |
413 } // namespace browser_sync | 591 } // namespace browser_sync |
OLD | NEW |