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/proto_enum_conversions.h" | 16 #include "chrome/browser/sync/protocol/proto_enum_conversions.h" |
15 #include "sync/protocol/app_notification_specifics.pb.h" | 17 #include "sync/protocol/app_notification_specifics.pb.h" |
16 #include "sync/protocol/app_setting_specifics.pb.h" | 18 #include "sync/protocol/app_setting_specifics.pb.h" |
17 #include "sync/protocol/app_specifics.pb.h" | 19 #include "sync/protocol/app_specifics.pb.h" |
18 #include "sync/protocol/autofill_specifics.pb.h" | 20 #include "sync/protocol/autofill_specifics.pb.h" |
19 #include "sync/protocol/bookmark_specifics.pb.h" | 21 #include "sync/protocol/bookmark_specifics.pb.h" |
20 #include "sync/protocol/encryption.pb.h" | 22 #include "sync/protocol/encryption.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 namespace { | |
403 | |
404 DictionaryValue* SyncEntityToValue(const sync_pb::SyncEntity& proto, | |
405 bool decode_specifics) { | |
akalin
2012/03/14 00:17:30
replace decode_specifics with include_specifics ev
lipalani1
2012/03/15 00:02:13
Done.
| |
406 DictionaryValue* value = new DictionaryValue(); | |
407 SET_STR(id_string); | |
408 SET_STR(parent_id_string); | |
409 SET_STR(old_parent_id); | |
410 SET_INT64(version); | |
411 SET_INT64(mtime); | |
412 SET_INT64(ctime); | |
413 SET_STR(name); | |
414 SET_STR(non_unique_name); | |
415 SET_INT64(sync_timestamp); | |
416 SET_STR(server_defined_unique_tag); | |
417 SET_INT64(position_in_parent); | |
418 SET_STR(insert_after_item_id); | |
419 SET_BOOL(deleted); | |
420 SET_STR(originator_cache_guid); | |
421 SET_STR(originator_client_item_id); | |
422 if (decode_specifics) | |
423 SET(specifics, EntitySpecificsToValue); | |
424 SET_BOOL(folder); | |
425 SET_STR(client_defined_unique_tag); | |
426 return value; | |
427 } | |
428 | |
429 void ConvertSyncEntitiesToValue(DictionaryValue* value, | |
akalin
2012/03/14 00:17:30
make this return a ListValue*, and have the caller
akalin
2012/03/14 00:17:30
newline after ( and indent
lipalani1
2012/03/15 00:02:13
Done.
lipalani1
2012/03/15 00:02:13
Done.
| |
430 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities, | |
akalin
2012/03/14 00:17:30
const ref?
lipalani1
2012/03/15 00:02:13
Done.
| |
431 bool decode_specifics) { | |
432 CHECK(value); | |
433 | |
434 ListValue* list = new ListValue(); | |
435 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it; | |
436 for (it = entities.begin(); it != entities.end(); ++it) { | |
437 list->Append(SyncEntityToValue(*it, decode_specifics)); | |
438 } | |
439 | |
440 value->Set("entries", list); | |
441 } | |
442 | |
443 DictionaryValue* ChromiumExtensionActivityToValue( | |
444 const sync_pb::ChromiumExtensionsActivity& proto) { | |
445 DictionaryValue* value = new DictionaryValue(); | |
446 SET_STR(extension_id); | |
447 SET_INT32(bookmark_writes_since_last_commit); | |
448 return value; | |
449 } | |
450 | |
451 DictionaryValue* CommitMessageToValue(const sync_pb::CommitMessage& proto, | |
akalin
2012/03/14 00:17:30
newline and indent after (
lipalani1
2012/03/15 00:02:13
Done.
| |
452 bool decode_specifics) { | |
453 DictionaryValue* value = new DictionaryValue(); | |
454 ConvertSyncEntitiesToValue(value, proto.entries(), decode_specifics); | |
455 SET_STR(cache_guid); | |
456 SET_REP(extensions_activity, ChromiumExtensionActivityToValue); | |
457 return value; | |
458 } | |
459 | |
460 DictionaryValue* DataTypeProgressMarkerToValue( | |
461 const sync_pb::DataTypeProgressMarker& proto) { | |
462 DictionaryValue* value = new DictionaryValue(); | |
463 SET_INT32(data_type_id); | |
464 SET_BYTES(token); | |
465 SET_INT64(timestamp_token_for_migration); | |
466 SET_STR(notification_hint); | |
467 return value; | |
468 } | |
469 | |
470 DictionaryValue* GetUpdatesCallerInfoToValue( | |
471 const sync_pb::GetUpdatesCallerInfo& proto) { | |
472 DictionaryValue* value = new DictionaryValue(); | |
473 SET_ENUM(source, GetUpdatesSourceString); | |
474 SET_BOOL(notifications_enabled); | |
475 return value; | |
476 } | |
477 | |
478 DictionaryValue* GetUpdatesMessageToValue( | |
479 const sync_pb::GetUpdatesMessage& proto) { | |
480 DictionaryValue* value = new DictionaryValue(); | |
481 SET(caller_info, GetUpdatesCallerInfoToValue); | |
482 SET_BOOL(fetch_folders); | |
483 SET_INT32(batch_size); | |
484 SET_REP(from_progress_marker, DataTypeProgressMarkerToValue); | |
485 SET_BOOL(streaming); | |
486 SET_BOOL(create_mobile_bookmarks_folder); | |
487 return value; | |
488 } | |
489 | |
490 DictionaryValue* EntryResponseToValue( | |
491 const sync_pb::CommitResponse::EntryResponse& proto) { | |
492 DictionaryValue* value = new DictionaryValue(); | |
493 SET_ENUM(response_type, GetResponseTypeString); | |
494 SET_STR(id_string); | |
495 SET_STR(parent_id_string); | |
496 SET_INT64(position_in_parent); | |
497 SET_INT64(version); | |
498 SET_STR(name); | |
499 SET_STR(error_message); | |
500 SET_INT64(mtime); | |
501 return value; | |
502 } | |
503 | |
504 DictionaryValue* CommitResponseToValue(const sync_pb::CommitResponse& proto) { | |
505 DictionaryValue* value = new DictionaryValue(); | |
506 SET_REP(entryresponse, EntryResponseToValue); | |
507 return value; | |
508 } | |
509 | |
510 DictionaryValue* GetUpdatesResponseToValue( | |
511 const sync_pb::GetUpdatesResponse& proto, | |
512 bool decode_specifics) { | |
513 DictionaryValue* value = new DictionaryValue(); | |
514 ConvertSyncEntitiesToValue(value, proto.entries(), decode_specifics); | |
515 SET_INT64(changes_remaining); | |
516 SET_REP(new_progress_marker, DataTypeProgressMarkerToValue); | |
517 return value; | |
518 } | |
519 | |
520 DictionaryValue* ClientCommandToValue(const sync_pb::ClientCommand& proto) { | |
521 DictionaryValue* value = new DictionaryValue(); | |
522 SET_INT32(set_sync_poll_interval); | |
523 SET_INT32(set_sync_long_poll_interval); | |
524 SET_INT32(max_commit_batch_size); | |
525 SET_INT32(sessions_commit_delay_seconds); | |
526 SET_INT32(throttle_delay_seconds); | |
527 return value; | |
528 } | |
529 | |
530 DictionaryValue* ErrorToValue( | |
531 const sync_pb::ClientToServerResponse::Error& proto) { | |
532 DictionaryValue* value = new DictionaryValue(); | |
533 SET_ENUM(error_type, GetErrorTypeString); | |
534 SET_STR(error_description); | |
535 SET_STR(url); | |
536 SET_ENUM(action, GetActionString); | |
537 return value; | |
538 } | |
539 | |
540 } // namespace | |
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, GetErrorTypeString); | |
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(), | |
akalin
2012/03/14 00:17:30
newline after , and indent
lipalani1
2012/03/15 00:02:13
Done.
| |
569 decode_specifics)); | |
akalin
2012/03/14 00:17:30
line up after CommitMessageToValue
lipalani1
2012/03/15 00:02:13
Done.
| |
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 |