Chromium Code Reviews| 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 "chrome/browser/sync/protocol/proto_value_conversions.h" | 7 #include "chrome/browser/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" |
| 11 #include "base/bind.h" | |
| 12 #include "base/callback.h" | |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 13 #include "base/values.h" | 15 #include "base/values.h" |
| 14 #include "chrome/browser/sync/protocol/app_notification_specifics.pb.h" | 16 #include "chrome/browser/sync/protocol/app_notification_specifics.pb.h" |
| 15 #include "chrome/browser/sync/protocol/app_setting_specifics.pb.h" | 17 #include "chrome/browser/sync/protocol/app_setting_specifics.pb.h" |
| 16 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 18 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
| 17 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 19 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
| 18 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 20 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 19 #include "chrome/browser/sync/protocol/encryption.pb.h" | 21 #include "chrome/browser/sync/protocol/encryption.pb.h" |
| 20 #include "chrome/browser/sync/protocol/extension_setting_specifics.pb.h" | 22 #include "chrome/browser/sync/protocol/extension_setting_specifics.pb.h" |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 SET_FIELD(nigori, NigoriSpecificsToValue); | 392 SET_FIELD(nigori, NigoriSpecificsToValue); |
| 391 SET_FIELD(password, PasswordSpecificsToValue); | 393 SET_FIELD(password, PasswordSpecificsToValue); |
| 392 SET_FIELD(preference, PreferenceSpecificsToValue); | 394 SET_FIELD(preference, PreferenceSpecificsToValue); |
| 393 SET_FIELD(search_engine, SearchEngineSpecificsToValue); | 395 SET_FIELD(search_engine, SearchEngineSpecificsToValue); |
| 394 SET_FIELD(session, SessionSpecificsToValue); | 396 SET_FIELD(session, SessionSpecificsToValue); |
| 395 SET_FIELD(theme, ThemeSpecificsToValue); | 397 SET_FIELD(theme, ThemeSpecificsToValue); |
| 396 SET_FIELD(typed_url, TypedUrlSpecificsToValue); | 398 SET_FIELD(typed_url, TypedUrlSpecificsToValue); |
| 397 return value; | 399 return value; |
| 398 } | 400 } |
| 399 | 401 |
| 402 DictionaryValue* SyncEntityToValue(const sync_pb::SyncEntity& proto, | |
|
akalin
2012/03/13 00:20:43
declarations for these functions in the header fil
lipalani1
2012/03/13 21:32:40
Put them on a namespace. They are not used elsewhe
| |
| 403 bool decode_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 // Let us not go through the specifics if we dont have to. | |
|
akalin
2012/03/13 00:20:43
Seems like premature optimization, since this code
lipalani1
2012/03/13 21:32:40
removed the comment. The optimization is needed fo
| |
| 421 // So we save some CPU cycles in retail builds. | |
| 422 // This would be particularly useful in first sync scenarios. | |
| 423 // In that case it saves both memory and CPU. | |
| 424 if (decode_specifics) | |
| 425 SET(specifics, EntitySpecificsToValue); | |
| 426 SET_BOOL(folder); | |
| 427 SET_STR(client_defined_unique_tag); | |
| 428 return value; | |
| 429 } | |
| 430 | |
| 431 void ConvertSyncEntitiesToValue(DictionaryValue* value, | |
| 432 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities, | |
| 433 bool decode_specifics) { | |
| 434 CHECK(value); | |
| 435 | |
| 436 ListValue* list = new ListValue(); | |
| 437 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it; | |
| 438 for (it = entities.begin(); it != entities.end(); ++it) { | |
| 439 list->Append(SyncEntityToValue(*it, decode_specifics)); | |
| 440 } | |
| 441 | |
| 442 value->Set("entries", list); | |
| 443 } | |
| 444 | |
| 445 DictionaryValue* ChromiumExtensionActivityToValue( | |
| 446 const sync_pb::ChromiumExtensionsActivity& proto) { | |
| 447 DictionaryValue* value = new DictionaryValue(); | |
| 448 SET_STR(extension_id); | |
| 449 SET_INT32(bookmark_writes_since_last_commit); | |
| 450 return value; | |
| 451 } | |
| 452 | |
| 453 DictionaryValue* CommitMessageToValue(const sync_pb::CommitMessage& proto, | |
| 454 bool decode_specifics) { | |
| 455 DictionaryValue* value = new DictionaryValue(); | |
| 456 ConvertSyncEntitiesToValue(value, proto.entries(), decode_specifics); | |
| 457 SET_STR(cache_guid); | |
| 458 SET_REP(extensions_activity, ChromiumExtensionActivityToValue); | |
| 459 return value; | |
| 460 } | |
| 461 | |
| 462 DictionaryValue* DataTypeProgressMarkerToValue( | |
| 463 const sync_pb::DataTypeProgressMarker& proto) { | |
| 464 DictionaryValue* value = new DictionaryValue(); | |
| 465 SET_INT32(data_type_id); | |
| 466 SET_BYTES(token); | |
| 467 SET_INT64(timestamp_token_for_migration); | |
| 468 SET_STR(notification_hint); | |
| 469 return value; | |
| 470 } | |
| 471 | |
| 472 DictionaryValue* GetUpdatesCallerInfoToValue( | |
| 473 const sync_pb::GetUpdatesCallerInfo& proto) { | |
| 474 DictionaryValue* value = new DictionaryValue(); | |
| 475 SET_ENUM(source, GetUpdatesSourceString); | |
| 476 SET_BOOL(notifications_enabled); | |
| 477 return value; | |
| 478 } | |
| 479 | |
| 480 DictionaryValue* GetUpdatesMessageToValue( | |
| 481 const sync_pb::GetUpdatesMessage& proto) { | |
| 482 DictionaryValue* value = new DictionaryValue(); | |
| 483 SET(caller_info, GetUpdatesCallerInfoToValue); | |
| 484 SET_BOOL(fetch_folders); | |
| 485 SET_INT32(batch_size); | |
| 486 SET_REP(from_progress_marker, DataTypeProgressMarkerToValue); | |
| 487 SET_BOOL(streaming); | |
| 488 SET_BOOL(create_mobile_bookmarks_folder); | |
| 489 return value; | |
| 490 } | |
| 491 | |
| 492 DictionaryValue* EntryResponseToValue( | |
| 493 const sync_pb::CommitResponse::EntryResponse& proto) { | |
| 494 DictionaryValue* value = new DictionaryValue(); | |
| 495 SET_ENUM(response_type, ResponseTypeString); | |
| 496 SET_STR(id_string); | |
| 497 SET_STR(parent_id_string); | |
| 498 SET_INT64(position_in_parent); | |
| 499 SET_INT64(version); | |
| 500 SET_STR(name); | |
| 501 SET_STR(error_message); | |
| 502 SET_INT64(mtime); | |
| 503 return value; | |
| 504 } | |
| 505 | |
| 506 DictionaryValue* CommitResponseToValue(const sync_pb::CommitResponse& proto) { | |
| 507 DictionaryValue* value = new DictionaryValue(); | |
| 508 SET_REP(entryresponse, EntryResponseToValue); | |
| 509 return value; | |
| 510 } | |
| 511 | |
| 512 DictionaryValue* GetUpdatesResponseToValue( | |
| 513 const sync_pb::GetUpdatesResponse& proto, | |
| 514 bool decode_specifics) { | |
| 515 DictionaryValue* value = new DictionaryValue(); | |
| 516 ConvertSyncEntitiesToValue(value, proto.entries(), decode_specifics); | |
| 517 SET_INT64(changes_remaining); | |
| 518 SET_REP(new_progress_marker, DataTypeProgressMarkerToValue); | |
| 519 return value; | |
| 520 } | |
| 521 | |
| 522 DictionaryValue* ClientCommandToValue(const sync_pb::ClientCommand& proto) { | |
| 523 DictionaryValue* value = new DictionaryValue(); | |
| 524 SET_INT32(set_sync_poll_interval); | |
| 525 SET_INT32(set_sync_long_poll_interval); | |
| 526 SET_INT32(max_commit_batch_size); | |
| 527 SET_INT32(sessions_commit_delay_seconds); | |
| 528 SET_INT32(throttle_delay_seconds); | |
| 529 return value; | |
| 530 } | |
| 531 | |
| 532 DictionaryValue* ErrorToValue( | |
| 533 const sync_pb::ClientToServerResponse::Error& proto) { | |
| 534 DictionaryValue* value = new DictionaryValue(); | |
| 535 SET_ENUM(error_type, ErrorTypeString); | |
| 536 SET_STR(error_description); | |
| 537 SET_STR(url); | |
| 538 SET_ENUM(action, ActionString); | |
| 539 return value; | |
| 540 } | |
| 541 | |
| 542 DictionaryValue* ClientToServerResponseToValue( | |
| 543 const sync_pb::ClientToServerResponse& proto, | |
| 544 bool decode_specifics) { | |
| 545 DictionaryValue* value = new DictionaryValue(); | |
| 546 SET(commit, CommitResponseToValue); | |
| 547 if (proto.has_get_updates()) { | |
| 548 value->Set("get_updates", GetUpdatesResponseToValue(proto.get_updates(), | |
| 549 decode_specifics)); | |
| 550 } | |
| 551 | |
| 552 SET(error, ErrorToValue); | |
| 553 SET_ENUM(error_code, ErrorTypeString); | |
| 554 SET_STR(error_message); | |
| 555 SET_STR(store_birthday); | |
| 556 SET(client_command, ClientCommandToValue); | |
| 557 SET_INT32_REP(migrated_data_type_id); | |
| 558 return value; | |
| 559 } | |
| 560 | |
| 561 DictionaryValue* ClientToServerMessageToValue( | |
| 562 const sync_pb::ClientToServerMessage& proto, | |
| 563 bool decode_specifics) { | |
| 564 DictionaryValue* value = new DictionaryValue(); | |
| 565 SET_STR(share); | |
| 566 SET_INT32(protocol_version); | |
| 567 if (proto.has_commit()) { | |
| 568 value->Set("commit", CommitMessageToValue(proto.commit(), | |
| 569 decode_specifics)); | |
| 570 } | |
| 571 | |
| 572 SET(get_updates, GetUpdatesMessageToValue); | |
| 573 SET_STR(store_birthday); | |
| 574 SET_BOOL(sync_problem_detected); | |
| 575 return value; | |
| 576 } | |
| 577 | |
| 578 | |
| 400 #undef SET | 579 #undef SET |
| 401 #undef SET_REP | 580 #undef SET_REP |
| 402 | 581 |
| 403 #undef SET_BOOL | 582 #undef SET_BOOL |
| 404 #undef SET_BYTES | 583 #undef SET_BYTES |
| 405 #undef SET_INT32 | 584 #undef SET_INT32 |
| 406 #undef SET_INT64 | 585 #undef SET_INT64 |
| 407 #undef SET_INT64_REP | 586 #undef SET_INT64_REP |
| 408 #undef SET_STR | 587 #undef SET_STR |
| 409 #undef SET_STR_REP | 588 #undef SET_STR_REP |
| 410 | 589 |
| 411 #undef SET_FIELD | 590 #undef SET_FIELD |
| 412 | 591 |
| 413 } // namespace browser_sync | 592 } // namespace browser_sync |
| OLD | NEW |