proto_value_conversions.cc revision effb81e5f8246d0db0270817048dc992db66e9fb
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 3// found in the LICENSE file. 4 5// Keep this file in sync with the .proto files in this directory. 6 7#include "sync/protocol/proto_value_conversions.h" 8 9#include <string> 10 11#include "base/base64.h" 12#include "base/basictypes.h" 13#include "base/logging.h" 14#include "base/strings/string_number_conversions.h" 15#include "base/values.h" 16#include "sync/internal_api/public/base/unique_position.h" 17#include "sync/protocol/app_list_specifics.pb.h" 18#include "sync/protocol/app_notification_specifics.pb.h" 19#include "sync/protocol/app_setting_specifics.pb.h" 20#include "sync/protocol/app_specifics.pb.h" 21#include "sync/protocol/autofill_specifics.pb.h" 22#include "sync/protocol/bookmark_specifics.pb.h" 23#include "sync/protocol/dictionary_specifics.pb.h" 24#include "sync/protocol/encryption.pb.h" 25#include "sync/protocol/experiments_specifics.pb.h" 26#include "sync/protocol/extension_setting_specifics.pb.h" 27#include "sync/protocol/extension_specifics.pb.h" 28#include "sync/protocol/favicon_image_specifics.pb.h" 29#include "sync/protocol/favicon_tracking_specifics.pb.h" 30#include "sync/protocol/history_delete_directive_specifics.pb.h" 31#include "sync/protocol/nigori_specifics.pb.h" 32#include "sync/protocol/password_specifics.pb.h" 33#include "sync/protocol/preference_specifics.pb.h" 34#include "sync/protocol/priority_preference_specifics.pb.h" 35#include "sync/protocol/proto_enum_conversions.h" 36#include "sync/protocol/search_engine_specifics.pb.h" 37#include "sync/protocol/session_specifics.pb.h" 38#include "sync/protocol/sync.pb.h" 39#include "sync/protocol/synced_notification_app_info_specifics.pb.h" 40#include "sync/protocol/synced_notification_specifics.pb.h" 41#include "sync/protocol/theme_specifics.pb.h" 42#include "sync/protocol/typed_url_specifics.pb.h" 43#include "sync/protocol/unique_position.pb.h" 44 45namespace syncer { 46 47namespace { 48 49// Basic Type -> Value functions. 50 51base::StringValue* MakeInt64Value(int64 x) { 52 return new base::StringValue(base::Int64ToString(x)); 53} 54 55// TODO(akalin): Perhaps make JSONWriter support BinaryValue and use 56// that instead of a StringValue. 57base::StringValue* MakeBytesValue(const std::string& bytes) { 58 std::string bytes_base64; 59 base::Base64Encode(bytes, &bytes_base64); 60 return new base::StringValue(bytes_base64); 61} 62 63base::StringValue* MakeStringValue(const std::string& str) { 64 return new base::StringValue(str); 65} 66 67// T is the enum type. 68template <class T> 69base::StringValue* MakeEnumValue(T t, const char* (*converter_fn)(T)) { 70 return new base::StringValue(converter_fn(t)); 71} 72 73// T is the field type, F is either RepeatedField or RepeatedPtrField, 74// and V is a subclass of Value. 75template <class T, class F, class V> 76base::ListValue* MakeRepeatedValue(const F& fields, V* (*converter_fn)(T)) { 77 base::ListValue* list = new base::ListValue(); 78 for (typename F::const_iterator it = fields.begin(); it != fields.end(); 79 ++it) { 80 list->Append(converter_fn(*it)); 81 } 82 return list; 83} 84 85} // namespace 86 87// Helper macros to reduce the amount of boilerplate. 88 89#define SET(field, fn) \ 90 if (proto.has_##field()) { \ 91 value->Set(#field, fn(proto.field())); \ 92 } 93#define SET_REP(field, fn) \ 94 value->Set(#field, MakeRepeatedValue(proto.field(), fn)) 95#define SET_ENUM(field, fn) \ 96 value->Set(#field, MakeEnumValue(proto.field(), fn)) 97 98#define SET_BOOL(field) SET(field, new base::FundamentalValue) 99#define SET_BYTES(field) SET(field, MakeBytesValue) 100#define SET_INT32(field) SET(field, MakeInt64Value) 101#define SET_INT32_REP(field) SET_REP(field, MakeInt64Value) 102#define SET_INT64(field) SET(field, MakeInt64Value) 103#define SET_INT64_REP(field) SET_REP(field, MakeInt64Value) 104#define SET_STR(field) SET(field, new base::StringValue) 105#define SET_STR_REP(field) \ 106 value->Set(#field, \ 107 MakeRepeatedValue<const std::string&, \ 108 google::protobuf::RepeatedPtrField< \ 109 std::string >, \ 110 base::StringValue>(proto.field(), \ 111 MakeStringValue)) 112#define SET_EXPERIMENT_ENABLED_FIELD(field) \ 113 do { \ 114 if (proto.has_##field() && \ 115 proto.field().has_enabled()) { \ 116 value->Set(#field, \ 117 new base::FundamentalValue( \ 118 proto.field().enabled())); \ 119 } \ 120 } while (0) 121 122#define SET_FIELD(field, fn) \ 123 do { \ 124 if (specifics.has_##field()) { \ 125 value->Set(#field, fn(specifics.field())); \ 126 } \ 127 } while (0) 128 129// If you add another macro, don't forget to add an #undef at the end 130// of this file, too. 131 132base::DictionaryValue* EncryptedDataToValue( 133 const sync_pb::EncryptedData& proto) { 134 base::DictionaryValue* value = new base::DictionaryValue(); 135 SET_STR(key_name); 136 // TODO(akalin): Shouldn't blob be of type bytes instead of string? 137 SET_BYTES(blob); 138 return value; 139} 140 141base::DictionaryValue* AppSettingsToValue( 142 const sync_pb::AppNotificationSettings& proto) { 143 base::DictionaryValue* value = new base::DictionaryValue(); 144 SET_BOOL(initial_setup_done); 145 SET_BOOL(disabled); 146 SET_STR(oauth_client_id); 147 return value; 148} 149 150base::DictionaryValue* SessionHeaderToValue( 151 const sync_pb::SessionHeader& proto) { 152 base::DictionaryValue* value = new base::DictionaryValue(); 153 SET_REP(window, SessionWindowToValue); 154 SET_STR(client_name); 155 SET_ENUM(device_type, GetDeviceTypeString); 156 return value; 157} 158 159base::DictionaryValue* SessionTabToValue(const sync_pb::SessionTab& proto) { 160 base::DictionaryValue* value = new base::DictionaryValue(); 161 SET_INT32(tab_id); 162 SET_INT32(window_id); 163 SET_INT32(tab_visual_index); 164 SET_INT32(current_navigation_index); 165 SET_BOOL(pinned); 166 SET_STR(extension_app_id); 167 SET_REP(navigation, TabNavigationToValue); 168 SET_BYTES(favicon); 169 SET_ENUM(favicon_type, GetFaviconTypeString); 170 SET_STR(favicon_source); 171 return value; 172} 173 174base::DictionaryValue* SessionWindowToValue( 175 const sync_pb::SessionWindow& proto) { 176 base::DictionaryValue* value = new base::DictionaryValue(); 177 SET_INT32(window_id); 178 SET_INT32(selected_tab_index); 179 SET_INT32_REP(tab); 180 SET_ENUM(browser_type, GetBrowserTypeString); 181 return value; 182} 183 184base::DictionaryValue* TabNavigationToValue( 185 const sync_pb::TabNavigation& proto) { 186 base::DictionaryValue* value = new base::DictionaryValue(); 187 SET_STR(virtual_url); 188 SET_STR(referrer); 189 SET_STR(title); 190 SET_STR(state); 191 SET_ENUM(page_transition, GetPageTransitionString); 192 SET_ENUM(redirect_type, GetPageTransitionRedirectTypeString); 193 SET_INT32(unique_id); 194 SET_INT64(timestamp_msec); 195 SET_BOOL(navigation_forward_back); 196 SET_BOOL(navigation_from_address_bar); 197 SET_BOOL(navigation_home_page); 198 SET_BOOL(navigation_chain_start); 199 SET_BOOL(navigation_chain_end); 200 SET_INT64(global_id); 201 SET_STR(search_terms); 202 SET_STR(favicon_url); 203 SET_ENUM(blocked_state, GetBlockedStateString); 204 SET_STR_REP(content_pack_categories); 205 SET_INT32(http_status_code); 206 SET_INT32(referrer_policy); 207 SET_BOOL(is_restored); 208 return value; 209} 210 211base::DictionaryValue* PasswordSpecificsDataToValue( 212 const sync_pb::PasswordSpecificsData& proto) { 213 base::DictionaryValue* value = new base::DictionaryValue(); 214 SET_INT32(scheme); 215 SET_STR(signon_realm); 216 SET_STR(origin); 217 SET_STR(action); 218 SET_STR(username_element); 219 SET_STR(username_value); 220 SET_STR(password_element); 221 value->SetString("password_value", "<redacted>"); 222 SET_BOOL(ssl_valid); 223 SET_BOOL(preferred); 224 SET_INT64(date_created); 225 SET_BOOL(blacklisted); 226 return value; 227} 228 229base::DictionaryValue* GlobalIdDirectiveToValue( 230 const sync_pb::GlobalIdDirective& proto) { 231 base::DictionaryValue* value = new base::DictionaryValue(); 232 SET_INT64_REP(global_id); 233 SET_INT64(start_time_usec); 234 SET_INT64(end_time_usec); 235 return value; 236} 237 238base::DictionaryValue* TimeRangeDirectiveToValue( 239 const sync_pb::TimeRangeDirective& proto) { 240 base::DictionaryValue* value = new base::DictionaryValue(); 241 SET_INT64(start_time_usec); 242 SET_INT64(end_time_usec); 243 return value; 244} 245 246base::DictionaryValue* SyncedNotificationAppInfoToValue( 247 const sync_pb::SyncedNotificationAppInfo& proto) { 248 base::DictionaryValue* value = new base::DictionaryValue(); 249 SET_STR_REP(app_id); 250 SET_STR(settings_display_name); 251 SET(icon, SyncedNotificationImageToValue); 252 // TODO(petewil): Add fields for the monochrome icon when it is available. 253 return value; 254} 255 256base::DictionaryValue* SyncedNotificationImageToValue( 257 const sync_pb::SyncedNotificationImage& proto) { 258 base::DictionaryValue* value = new base::DictionaryValue(); 259 SET_STR(url); 260 SET_STR(alt_text); 261 SET_INT32(preferred_width); 262 SET_INT32(preferred_height); 263 return value; 264} 265 266base::DictionaryValue* SyncedNotificationProfileImageToValue( 267 const sync_pb::SyncedNotificationProfileImage& proto) { 268 base::DictionaryValue* value = new base::DictionaryValue(); 269 SET_STR(image_url); 270 SET_STR(oid); 271 SET_STR(display_name); 272 return value; 273} 274 275base::DictionaryValue* MediaToValue( 276 const sync_pb::Media& proto) { 277 base::DictionaryValue* value = new base::DictionaryValue(); 278 SET(image, SyncedNotificationImageToValue); 279 return value; 280} 281 282base::DictionaryValue* SyncedNotificationActionToValue( 283 const sync_pb::SyncedNotificationAction& proto) { 284 base::DictionaryValue* value = new base::DictionaryValue(); 285 SET_STR(text); 286 SET(icon, SyncedNotificationImageToValue); 287 SET_STR(url); 288 SET_STR(request_data); 289 SET_STR(accessibility_label); 290 return value; 291} 292 293base::DictionaryValue* SyncedNotificationDestiationToValue( 294 const sync_pb::SyncedNotificationDestination& proto) { 295 base::DictionaryValue* value = new base::DictionaryValue(); 296 SET_STR(text); 297 SET(icon, SyncedNotificationImageToValue); 298 SET_STR(url); 299 SET_STR(accessibility_label); 300 return value; 301} 302 303base::DictionaryValue* TargetToValue( 304 const sync_pb::Target& proto) { 305 base::DictionaryValue* value = new base::DictionaryValue(); 306 SET(destination, SyncedNotificationDestiationToValue); 307 SET(action, SyncedNotificationActionToValue); 308 SET_STR(target_key); 309 return value; 310} 311 312base::DictionaryValue* SimpleCollapsedLayoutToValue( 313 const sync_pb::SimpleCollapsedLayout& proto) { 314 base::DictionaryValue* value = new base::DictionaryValue(); 315 SET(app_icon, SyncedNotificationImageToValue); 316 SET_REP(profile_image, SyncedNotificationProfileImageToValue); 317 SET_STR(heading); 318 SET_STR(description); 319 SET_STR(annotation); 320 SET_REP(media, MediaToValue); 321 return value; 322} 323 324base::DictionaryValue* CollapsedInfoToValue( 325 const sync_pb::CollapsedInfo& proto) { 326 base::DictionaryValue* value = new base::DictionaryValue(); 327 SET(simple_collapsed_layout, SimpleCollapsedLayoutToValue); 328 SET_INT64(creation_timestamp_usec); 329 SET(default_destination, SyncedNotificationDestiationToValue); 330 SET_REP(target, TargetToValue); 331 return value; 332} 333 334base::DictionaryValue* SyncedNotificationToValue( 335 const sync_pb::SyncedNotification& proto) { 336 base::DictionaryValue* value = new base::DictionaryValue(); 337 SET_STR(type); 338 SET_STR(external_id); 339 // TODO(petewil) Add SyncedNotificationCreator here if we ever need it. 340 return value; 341} 342 343base::DictionaryValue* RenderInfoToValue( 344 const sync_pb::SyncedNotificationRenderInfo& proto) { 345 base::DictionaryValue* value = new base::DictionaryValue(); 346 // TODO(petewil): Add the expanded info values once we start using them. 347 SET(collapsed_info, CollapsedInfoToValue); 348 return value; 349} 350 351base::DictionaryValue* CoalescedNotificationToValue( 352 const sync_pb::CoalescedSyncedNotification& proto) { 353 base::DictionaryValue* value = new base::DictionaryValue(); 354 SET_STR(key); 355 SET_STR(app_id); 356 SET_REP(notification, SyncedNotificationToValue); 357 SET(render_info, RenderInfoToValue); 358 SET_INT32(read_state); 359 SET_INT64(creation_time_msec); 360 SET_INT32(priority); 361 return value; 362} 363 364base::DictionaryValue* AppListSpecificsToValue( 365 const sync_pb::AppListSpecifics& proto) { 366 base::DictionaryValue* value = new base::DictionaryValue(); 367 SET_STR(item_id); 368 SET_ENUM(item_type, GetAppListItemTypeString); 369 SET_STR(item_name); 370 SET_STR(parent_id); 371 SET_STR(page_ordinal); 372 SET_STR(item_ordinal); 373 374 return value; 375} 376 377base::DictionaryValue* AppNotificationToValue( 378 const sync_pb::AppNotification& proto) { 379 base::DictionaryValue* value = new base::DictionaryValue(); 380 SET_STR(guid); 381 SET_STR(app_id); 382 SET_INT64(creation_timestamp_ms); 383 SET_STR(title); 384 SET_STR(body_text); 385 SET_STR(link_url); 386 SET_STR(link_text); 387 return value; 388} 389 390base::DictionaryValue* AppSettingSpecificsToValue( 391 const sync_pb::AppSettingSpecifics& proto) { 392 base::DictionaryValue* value = new base::DictionaryValue(); 393 SET(extension_setting, ExtensionSettingSpecificsToValue); 394 return value; 395} 396 397base::DictionaryValue* AppSpecificsToValue( 398 const sync_pb::AppSpecifics& proto) { 399 base::DictionaryValue* value = new base::DictionaryValue(); 400 SET(extension, ExtensionSpecificsToValue); 401 SET(notification_settings, AppSettingsToValue); 402 SET_STR(app_launch_ordinal); 403 SET_STR(page_ordinal); 404 SET_ENUM(launch_type, GetLaunchTypeString); 405 406 return value; 407} 408 409base::DictionaryValue* AutofillSpecificsToValue( 410 const sync_pb::AutofillSpecifics& proto) { 411 base::DictionaryValue* value = new base::DictionaryValue(); 412 SET_STR(name); 413 SET_STR(value); 414 SET_INT64_REP(usage_timestamp); 415 SET(profile, AutofillProfileSpecificsToValue); 416 return value; 417} 418 419base::DictionaryValue* AutofillProfileSpecificsToValue( 420 const sync_pb::AutofillProfileSpecifics& proto) { 421 base::DictionaryValue* value = new base::DictionaryValue(); 422 SET_STR(guid); 423 SET_STR(origin); 424 425 SET_STR_REP(name_first); 426 SET_STR_REP(name_middle); 427 SET_STR_REP(name_last); 428 SET_STR_REP(email_address); 429 SET_STR(company_name); 430 431 SET_STR(address_home_line1); 432 SET_STR(address_home_line2); 433 SET_STR(address_home_city); 434 SET_STR(address_home_state); 435 SET_STR(address_home_zip); 436 SET_STR(address_home_country); 437 438 SET_STR(address_home_street_address); 439 SET_STR(address_home_sorting_code); 440 SET_STR(address_home_dependent_locality); 441 442 SET_STR_REP(phone_home_whole_number); 443 return value; 444} 445 446base::DictionaryValue* MetaInfoToValue( 447 const sync_pb::MetaInfo& proto) { 448 base::DictionaryValue* value = new base::DictionaryValue(); 449 SET_STR(key); 450 SET_STR(value); 451 return value; 452} 453 454base::DictionaryValue* BookmarkSpecificsToValue( 455 const sync_pb::BookmarkSpecifics& proto) { 456 base::DictionaryValue* value = new base::DictionaryValue(); 457 SET_STR(url); 458 SET_BYTES(favicon); 459 SET_STR(title); 460 SET_INT64(creation_time_us); 461 SET_STR(icon_url); 462 SET_REP(meta_info, &MetaInfoToValue); 463 return value; 464} 465 466base::DictionaryValue* DeviceInfoSpecificsToValue( 467 const sync_pb::DeviceInfoSpecifics& proto) { 468 base::DictionaryValue* value = new base::DictionaryValue(); 469 SET_STR(cache_guid); 470 SET_STR(client_name); 471 SET_ENUM(device_type, GetDeviceTypeString); 472 SET_STR(sync_user_agent); 473 SET_STR(chrome_version); 474 return value; 475} 476 477base::DictionaryValue* DictionarySpecificsToValue( 478 const sync_pb::DictionarySpecifics& proto) { 479 base::DictionaryValue* value = new base::DictionaryValue(); 480 SET_STR(word); 481 return value; 482} 483 484namespace { 485 486base::DictionaryValue* FaviconSyncFlagsToValue( 487 const sync_pb::FaviconSyncFlags& proto) { 488 base::DictionaryValue* value = new base::DictionaryValue(); 489 SET_BOOL(enabled); 490 SET_INT32(favicon_sync_limit); 491 return value; 492} 493 494} // namespace 495 496base::DictionaryValue* ExperimentsSpecificsToValue( 497 const sync_pb::ExperimentsSpecifics& proto) { 498 base::DictionaryValue* value = new base::DictionaryValue(); 499 SET_EXPERIMENT_ENABLED_FIELD(keystore_encryption); 500 SET_EXPERIMENT_ENABLED_FIELD(history_delete_directives); 501 SET_EXPERIMENT_ENABLED_FIELD(autofill_culling); 502 SET_EXPERIMENT_ENABLED_FIELD(pre_commit_update_avoidance); 503 SET(favicon_sync, FaviconSyncFlagsToValue); 504 SET_EXPERIMENT_ENABLED_FIELD(gcm_channel); 505 SET_EXPERIMENT_ENABLED_FIELD(enhanced_bookmarks); 506 SET_EXPERIMENT_ENABLED_FIELD(gcm_invalidations); 507 return value; 508} 509 510base::DictionaryValue* ExtensionSettingSpecificsToValue( 511 const sync_pb::ExtensionSettingSpecifics& proto) { 512 base::DictionaryValue* value = new base::DictionaryValue(); 513 SET_STR(extension_id); 514 SET_STR(key); 515 SET_STR(value); 516 return value; 517} 518 519base::DictionaryValue* ExtensionSpecificsToValue( 520 const sync_pb::ExtensionSpecifics& proto) { 521 base::DictionaryValue* value = new base::DictionaryValue(); 522 SET_STR(id); 523 SET_STR(version); 524 SET_STR(update_url); 525 SET_BOOL(enabled); 526 SET_BOOL(incognito_enabled); 527 SET_STR(name); 528 return value; 529} 530 531namespace { 532base::DictionaryValue* FaviconDataToValue( 533 const sync_pb::FaviconData& proto) { 534 base::DictionaryValue* value = new base::DictionaryValue(); 535 SET_BYTES(favicon); 536 SET_INT32(width); 537 SET_INT32(height); 538 return value; 539} 540} // namespace 541 542base::DictionaryValue* FaviconImageSpecificsToValue( 543 const sync_pb::FaviconImageSpecifics& proto) { 544 base::DictionaryValue* value = new base::DictionaryValue(); 545 SET_STR(favicon_url); 546 SET(favicon_web, FaviconDataToValue); 547 SET(favicon_web_32, FaviconDataToValue); 548 SET(favicon_touch_64, FaviconDataToValue); 549 SET(favicon_touch_precomposed_64, FaviconDataToValue); 550 return value; 551} 552 553base::DictionaryValue* FaviconTrackingSpecificsToValue( 554 const sync_pb::FaviconTrackingSpecifics& proto) { 555 base::DictionaryValue* value = new base::DictionaryValue(); 556 SET_STR(favicon_url); 557 SET_INT64(last_visit_time_ms) 558 SET_BOOL(is_bookmarked); 559 return value; 560} 561 562base::DictionaryValue* HistoryDeleteDirectiveSpecificsToValue( 563 const sync_pb::HistoryDeleteDirectiveSpecifics& proto) { 564 base::DictionaryValue* value = new base::DictionaryValue(); 565 SET(global_id_directive, GlobalIdDirectiveToValue); 566 SET(time_range_directive, TimeRangeDirectiveToValue); 567 return value; 568} 569 570base::DictionaryValue* ManagedUserSettingSpecificsToValue( 571 const sync_pb::ManagedUserSettingSpecifics& proto) { 572 base::DictionaryValue* value = new base::DictionaryValue(); 573 SET_STR(name); 574 SET_STR(value); 575 return value; 576} 577 578base::DictionaryValue* ManagedUserSpecificsToValue( 579 const sync_pb::ManagedUserSpecifics& proto) { 580 base::DictionaryValue* value = new base::DictionaryValue(); 581 SET_STR(id); 582 SET_STR(name); 583 SET_BOOL(acknowledged); 584 SET_STR(master_key); 585 SET_STR(chrome_avatar); 586 SET_STR(chromeos_avatar); 587 return value; 588} 589 590base::DictionaryValue* ManagedUserSharedSettingSpecificsToValue( 591 const sync_pb::ManagedUserSharedSettingSpecifics& proto) { 592 base::DictionaryValue* value = new base::DictionaryValue(); 593 SET_STR(mu_id); 594 SET_STR(key); 595 SET_STR(value); 596 SET_BOOL(acknowledged); 597 return value; 598} 599 600base::DictionaryValue* NigoriSpecificsToValue( 601 const sync_pb::NigoriSpecifics& proto) { 602 base::DictionaryValue* value = new base::DictionaryValue(); 603 SET(encryption_keybag, EncryptedDataToValue); 604 SET_BOOL(keybag_is_frozen); 605 SET_BOOL(encrypt_bookmarks); 606 SET_BOOL(encrypt_preferences); 607 SET_BOOL(encrypt_autofill_profile); 608 SET_BOOL(encrypt_autofill); 609 SET_BOOL(encrypt_themes); 610 SET_BOOL(encrypt_typed_urls); 611 SET_BOOL(encrypt_extension_settings); 612 SET_BOOL(encrypt_extensions); 613 SET_BOOL(encrypt_sessions); 614 SET_BOOL(encrypt_app_settings); 615 SET_BOOL(encrypt_apps); 616 SET_BOOL(encrypt_search_engines); 617 SET_BOOL(encrypt_dictionary); 618 SET_BOOL(encrypt_articles); 619 SET_BOOL(encrypt_app_list); 620 SET_BOOL(encrypt_everything); 621 SET_BOOL(sync_tab_favicons); 622 SET_ENUM(passphrase_type, PassphraseTypeString); 623 SET(keystore_decryptor_token, EncryptedDataToValue); 624 SET_INT64(keystore_migration_time); 625 SET_INT64(custom_passphrase_time); 626 return value; 627} 628 629base::DictionaryValue* ArticlePageToValue( 630 const sync_pb::ArticlePage& proto) { 631 base::DictionaryValue* value = new base::DictionaryValue(); 632 SET_STR(url); 633 return value; 634} 635 636base::DictionaryValue* ArticleSpecificsToValue( 637 const sync_pb::ArticleSpecifics& proto) { 638 base::DictionaryValue* value = new base::DictionaryValue(); 639 SET_STR(entry_id); 640 SET_STR(title); 641 SET_REP(pages, ArticlePageToValue); 642 return value; 643} 644 645base::DictionaryValue* PasswordSpecificsToValue( 646 const sync_pb::PasswordSpecifics& proto) { 647 base::DictionaryValue* value = new base::DictionaryValue(); 648 SET(encrypted, EncryptedDataToValue); 649 return value; 650} 651 652base::DictionaryValue* PreferenceSpecificsToValue( 653 const sync_pb::PreferenceSpecifics& proto) { 654 base::DictionaryValue* value = new base::DictionaryValue(); 655 SET_STR(name); 656 SET_STR(value); 657 return value; 658} 659 660base::DictionaryValue* PriorityPreferenceSpecificsToValue( 661 const sync_pb::PriorityPreferenceSpecifics& specifics) { 662 base::DictionaryValue* value = new base::DictionaryValue(); 663 SET_FIELD(preference, PreferenceSpecificsToValue); 664 return value; 665} 666 667base::DictionaryValue* SyncedNotificationAppInfoSpecificsToValue( 668 const sync_pb::SyncedNotificationAppInfoSpecifics& proto) { 669 base::DictionaryValue* value = new base::DictionaryValue(); 670 SET_REP(synced_notification_app_info, SyncedNotificationAppInfoToValue); 671 return value; 672} 673 674base::DictionaryValue* SyncedNotificationSpecificsToValue( 675 const sync_pb::SyncedNotificationSpecifics& proto) { 676 // There is a lot of data, for now just use heading, description, key, and 677 // the read state. 678 // TODO(petewil): Eventually add more data here. 679 base::DictionaryValue* value = new base::DictionaryValue(); 680 SET(coalesced_notification, CoalescedNotificationToValue); 681 return value; 682} 683 684base::DictionaryValue* SearchEngineSpecificsToValue( 685 const sync_pb::SearchEngineSpecifics& proto) { 686 base::DictionaryValue* value = new base::DictionaryValue(); 687 SET_STR(short_name); 688 SET_STR(keyword); 689 SET_STR(favicon_url); 690 SET_STR(url); 691 SET_BOOL(safe_for_autoreplace); 692 SET_STR(originating_url); 693 SET_INT64(date_created); 694 SET_STR(input_encodings); 695 SET_BOOL(show_in_default_list); 696 SET_STR(suggestions_url); 697 SET_INT32(prepopulate_id); 698 SET_BOOL(autogenerate_keyword); 699 SET_STR(instant_url); 700 SET_INT64(last_modified); 701 SET_STR(sync_guid); 702 SET_STR_REP(alternate_urls); 703 SET_STR(search_terms_replacement_key); 704 SET_STR(image_url); 705 SET_STR(search_url_post_params); 706 SET_STR(suggestions_url_post_params); 707 SET_STR(instant_url_post_params); 708 SET_STR(image_url_post_params); 709 SET_STR(new_tab_url); 710 return value; 711} 712 713base::DictionaryValue* SessionSpecificsToValue( 714 const sync_pb::SessionSpecifics& proto) { 715 base::DictionaryValue* value = new base::DictionaryValue(); 716 SET_STR(session_tag); 717 SET(header, SessionHeaderToValue); 718 SET(tab, SessionTabToValue); 719 SET_INT32(tab_node_id); 720 return value; 721} 722 723base::DictionaryValue* ThemeSpecificsToValue( 724 const sync_pb::ThemeSpecifics& proto) { 725 base::DictionaryValue* value = new base::DictionaryValue(); 726 SET_BOOL(use_custom_theme); 727 SET_BOOL(use_system_theme_by_default); 728 SET_STR(custom_theme_name); 729 SET_STR(custom_theme_id); 730 SET_STR(custom_theme_update_url); 731 return value; 732} 733 734base::DictionaryValue* TypedUrlSpecificsToValue( 735 const sync_pb::TypedUrlSpecifics& proto) { 736 base::DictionaryValue* value = new base::DictionaryValue(); 737 SET_STR(url); 738 SET_STR(title); 739 SET_BOOL(hidden); 740 SET_INT64_REP(visits); 741 SET_INT32_REP(visit_transitions); 742 return value; 743} 744 745base::DictionaryValue* EntitySpecificsToValue( 746 const sync_pb::EntitySpecifics& specifics) { 747 base::DictionaryValue* value = new base::DictionaryValue(); 748 SET_FIELD(app, AppSpecificsToValue); 749 SET_FIELD(app_list, AppListSpecificsToValue); 750 SET_FIELD(app_notification, AppNotificationToValue); 751 SET_FIELD(app_setting, AppSettingSpecificsToValue); 752 SET_FIELD(article, ArticleSpecificsToValue); 753 SET_FIELD(autofill, AutofillSpecificsToValue); 754 SET_FIELD(autofill_profile, AutofillProfileSpecificsToValue); 755 SET_FIELD(bookmark, BookmarkSpecificsToValue); 756 SET_FIELD(device_info, DeviceInfoSpecificsToValue); 757 SET_FIELD(dictionary, DictionarySpecificsToValue); 758 SET_FIELD(experiments, ExperimentsSpecificsToValue); 759 SET_FIELD(extension, ExtensionSpecificsToValue); 760 SET_FIELD(extension_setting, ExtensionSettingSpecificsToValue); 761 SET_FIELD(favicon_image, FaviconImageSpecificsToValue); 762 SET_FIELD(favicon_tracking, FaviconTrackingSpecificsToValue); 763 SET_FIELD(history_delete_directive, HistoryDeleteDirectiveSpecificsToValue); 764 SET_FIELD(managed_user_setting, ManagedUserSettingSpecificsToValue); 765 SET_FIELD(managed_user_shared_setting, 766 ManagedUserSharedSettingSpecificsToValue); 767 SET_FIELD(managed_user, ManagedUserSpecificsToValue); 768 SET_FIELD(nigori, NigoriSpecificsToValue); 769 SET_FIELD(password, PasswordSpecificsToValue); 770 SET_FIELD(preference, PreferenceSpecificsToValue); 771 SET_FIELD(priority_preference, PriorityPreferenceSpecificsToValue); 772 SET_FIELD(search_engine, SearchEngineSpecificsToValue); 773 SET_FIELD(session, SessionSpecificsToValue); 774 SET_FIELD(synced_notification, SyncedNotificationSpecificsToValue); 775 SET_FIELD(synced_notification_app_info, 776 SyncedNotificationAppInfoSpecificsToValue); 777 SET_FIELD(theme, ThemeSpecificsToValue); 778 SET_FIELD(typed_url, TypedUrlSpecificsToValue); 779 return value; 780} 781 782namespace { 783 784base::StringValue* UniquePositionToStringValue( 785 const sync_pb::UniquePosition& proto) { 786 UniquePosition pos = UniquePosition::FromProto(proto); 787 return new base::StringValue(pos.ToDebugString()); 788} 789 790base::DictionaryValue* SyncEntityToValue(const sync_pb::SyncEntity& proto, 791 bool include_specifics) { 792 base::DictionaryValue* value = new base::DictionaryValue(); 793 SET_STR(id_string); 794 SET_STR(parent_id_string); 795 SET_STR(old_parent_id); 796 SET_INT64(version); 797 SET_INT64(mtime); 798 SET_INT64(ctime); 799 SET_STR(name); 800 SET_STR(non_unique_name); 801 SET_INT64(sync_timestamp); 802 SET_STR(server_defined_unique_tag); 803 SET_INT64(position_in_parent); 804 SET(unique_position, UniquePositionToStringValue); 805 SET_STR(insert_after_item_id); 806 SET_BOOL(deleted); 807 SET_STR(originator_cache_guid); 808 SET_STR(originator_client_item_id); 809 if (include_specifics) 810 SET(specifics, EntitySpecificsToValue); 811 SET_BOOL(folder); 812 SET_STR(client_defined_unique_tag); 813 return value; 814} 815 816base::ListValue* SyncEntitiesToValue( 817 const ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, 818 bool include_specifics) { 819 base::ListValue* list = new base::ListValue(); 820 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it; 821 for (it = entities.begin(); it != entities.end(); ++it) { 822 list->Append(SyncEntityToValue(*it, include_specifics)); 823 } 824 825 return list; 826} 827 828base::DictionaryValue* ChromiumExtensionActivityToValue( 829 const sync_pb::ChromiumExtensionsActivity& proto) { 830 base::DictionaryValue* value = new base::DictionaryValue(); 831 SET_STR(extension_id); 832 SET_INT32(bookmark_writes_since_last_commit); 833 return value; 834} 835 836base::DictionaryValue* CommitMessageToValue( 837 const sync_pb::CommitMessage& proto, 838 bool include_specifics) { 839 base::DictionaryValue* value = new base::DictionaryValue(); 840 value->Set("entries", 841 SyncEntitiesToValue(proto.entries(), include_specifics)); 842 SET_STR(cache_guid); 843 SET_REP(extensions_activity, ChromiumExtensionActivityToValue); 844 SET(config_params, ClientConfigParamsToValue); 845 return value; 846} 847 848base::DictionaryValue* GetUpdateTriggersToValue( 849 const sync_pb::GetUpdateTriggers& proto) { 850 base::DictionaryValue* value = new base::DictionaryValue(); 851 SET_STR_REP(notification_hint); 852 SET_BOOL(client_dropped_hints); 853 SET_BOOL(invalidations_out_of_sync); 854 SET_INT64(local_modification_nudges); 855 SET_INT64(datatype_refresh_nudges); 856 return value; 857} 858 859base::DictionaryValue* DataTypeProgressMarkerToValue( 860 const sync_pb::DataTypeProgressMarker& proto) { 861 base::DictionaryValue* value = new base::DictionaryValue(); 862 SET_INT32(data_type_id); 863 SET_BYTES(token); 864 SET_INT64(timestamp_token_for_migration); 865 SET_STR(notification_hint); 866 SET(get_update_triggers, GetUpdateTriggersToValue); 867 return value; 868} 869 870base::DictionaryValue* GetUpdatesCallerInfoToValue( 871 const sync_pb::GetUpdatesCallerInfo& proto) { 872 base::DictionaryValue* value = new base::DictionaryValue(); 873 SET_ENUM(source, GetUpdatesSourceString); 874 SET_BOOL(notifications_enabled); 875 return value; 876} 877 878base::DictionaryValue* GetUpdatesMessageToValue( 879 const sync_pb::GetUpdatesMessage& proto) { 880 base::DictionaryValue* value = new base::DictionaryValue(); 881 SET(caller_info, GetUpdatesCallerInfoToValue); 882 SET_BOOL(fetch_folders); 883 SET_INT32(batch_size); 884 SET_REP(from_progress_marker, DataTypeProgressMarkerToValue); 885 SET_BOOL(streaming); 886 SET_BOOL(need_encryption_key); 887 SET_BOOL(create_mobile_bookmarks_folder); 888 SET_ENUM(get_updates_origin, GetUpdatesOriginString); 889 return value; 890} 891 892base::DictionaryValue* ClientStatusToValue(const sync_pb::ClientStatus& proto) { 893 base::DictionaryValue* value = new base::DictionaryValue(); 894 SET_BOOL(hierarchy_conflict_detected); 895 return value; 896} 897 898base::DictionaryValue* EntryResponseToValue( 899 const sync_pb::CommitResponse::EntryResponse& proto) { 900 base::DictionaryValue* value = new base::DictionaryValue(); 901 SET_ENUM(response_type, GetResponseTypeString); 902 SET_STR(id_string); 903 SET_STR(parent_id_string); 904 SET_INT64(position_in_parent); 905 SET_INT64(version); 906 SET_STR(name); 907 SET_STR(error_message); 908 SET_INT64(mtime); 909 return value; 910} 911 912base::DictionaryValue* CommitResponseToValue( 913 const sync_pb::CommitResponse& proto) { 914 base::DictionaryValue* value = new base::DictionaryValue(); 915 SET_REP(entryresponse, EntryResponseToValue); 916 return value; 917} 918 919base::DictionaryValue* GetUpdatesResponseToValue( 920 const sync_pb::GetUpdatesResponse& proto, 921 bool include_specifics) { 922 base::DictionaryValue* value = new base::DictionaryValue(); 923 value->Set("entries", 924 SyncEntitiesToValue(proto.entries(), include_specifics)); 925 SET_INT64(changes_remaining); 926 SET_REP(new_progress_marker, DataTypeProgressMarkerToValue); 927 return value; 928} 929 930base::DictionaryValue* ClientCommandToValue( 931 const sync_pb::ClientCommand& proto) { 932 base::DictionaryValue* value = new base::DictionaryValue(); 933 SET_INT32(set_sync_poll_interval); 934 SET_INT32(set_sync_long_poll_interval); 935 SET_INT32(max_commit_batch_size); 936 SET_INT32(sessions_commit_delay_seconds); 937 SET_INT32(throttle_delay_seconds); 938 SET_INT32(client_invalidation_hint_buffer_size); 939 return value; 940} 941 942base::DictionaryValue* ErrorToValue( 943 const sync_pb::ClientToServerResponse::Error& proto) { 944 base::DictionaryValue* value = new base::DictionaryValue(); 945 SET_ENUM(error_type, GetErrorTypeString); 946 SET_STR(error_description); 947 SET_STR(url); 948 SET_ENUM(action, GetActionString); 949 return value; 950} 951 952} // namespace 953 954base::DictionaryValue* ClientToServerResponseToValue( 955 const sync_pb::ClientToServerResponse& proto, 956 bool include_specifics) { 957 base::DictionaryValue* value = new base::DictionaryValue(); 958 SET(commit, CommitResponseToValue); 959 if (proto.has_get_updates()) { 960 value->Set("get_updates", GetUpdatesResponseToValue(proto.get_updates(), 961 include_specifics)); 962 } 963 964 SET(error, ErrorToValue); 965 SET_ENUM(error_code, GetErrorTypeString); 966 SET_STR(error_message); 967 SET_STR(store_birthday); 968 SET(client_command, ClientCommandToValue); 969 SET_INT32_REP(migrated_data_type_id); 970 return value; 971} 972 973base::DictionaryValue* ClientToServerMessageToValue( 974 const sync_pb::ClientToServerMessage& proto, 975 bool include_specifics) { 976 base::DictionaryValue* value = new base::DictionaryValue(); 977 SET_STR(share); 978 SET_INT32(protocol_version); 979 if (proto.has_commit()) { 980 value->Set("commit", 981 CommitMessageToValue(proto.commit(), include_specifics)); 982 } 983 984 SET(get_updates, GetUpdatesMessageToValue); 985 SET_STR(store_birthday); 986 SET_BOOL(sync_problem_detected); 987 SET(debug_info, DebugInfoToValue); 988 SET(client_status, ClientStatusToValue); 989 return value; 990} 991 992base::DictionaryValue* DatatypeAssociationStatsToValue( 993 const sync_pb::DatatypeAssociationStats& proto) { 994 base::DictionaryValue* value = new base::DictionaryValue(); 995 SET_INT32(data_type_id); 996 SET_INT32(num_local_items_before_association); 997 SET_INT32(num_sync_items_before_association); 998 SET_INT32(num_local_items_after_association); 999 SET_INT32(num_sync_items_after_association); 1000 SET_INT32(num_local_items_added); 1001 SET_INT32(num_local_items_deleted); 1002 SET_INT32(num_local_items_modified); 1003 SET_INT32(num_sync_items_added); 1004 SET_INT32(num_sync_items_deleted); 1005 SET_INT32(num_sync_items_modified); 1006 SET_INT64(local_version_pre_association); 1007 SET_INT64(sync_version_pre_association) 1008 SET_BOOL(had_error); 1009 SET_INT64(download_wait_time_us); 1010 SET_INT64(download_time_us); 1011 SET_INT64(association_wait_time_for_high_priority_us); 1012 SET_INT64(association_wait_time_for_same_priority_us); 1013 return value; 1014} 1015 1016base::DictionaryValue* DebugEventInfoToValue( 1017 const sync_pb::DebugEventInfo& proto) { 1018 base::DictionaryValue* value = new base::DictionaryValue(); 1019 SET_ENUM(singleton_event, SingletonDebugEventTypeString); 1020 SET(sync_cycle_completed_event_info, SyncCycleCompletedEventInfoToValue); 1021 SET_INT32(nudging_datatype); 1022 SET_INT32_REP(datatypes_notified_from_server); 1023 SET(datatype_association_stats, DatatypeAssociationStatsToValue); 1024 return value; 1025} 1026 1027base::DictionaryValue* DebugInfoToValue(const sync_pb::DebugInfo& proto) { 1028 base::DictionaryValue* value = new base::DictionaryValue(); 1029 SET_REP(events, DebugEventInfoToValue); 1030 SET_BOOL(cryptographer_ready); 1031 SET_BOOL(cryptographer_has_pending_keys); 1032 SET_BOOL(events_dropped); 1033 return value; 1034} 1035 1036base::DictionaryValue* SyncCycleCompletedEventInfoToValue( 1037 const sync_pb::SyncCycleCompletedEventInfo& proto) { 1038 base::DictionaryValue* value = new base::DictionaryValue(); 1039 SET_INT32(num_encryption_conflicts); 1040 SET_INT32(num_hierarchy_conflicts); 1041 SET_INT32(num_server_conflicts); 1042 SET_INT32(num_updates_downloaded); 1043 SET_INT32(num_reflected_updates_downloaded); 1044 SET(caller_info, GetUpdatesCallerInfoToValue); 1045 return value; 1046} 1047 1048base::DictionaryValue* ClientConfigParamsToValue( 1049 const sync_pb::ClientConfigParams& proto) { 1050 base::DictionaryValue* value = new base::DictionaryValue(); 1051 SET_INT32_REP(enabled_type_ids); 1052 SET_BOOL(tabs_datatype_enabled); 1053 return value; 1054} 1055 1056#undef SET 1057#undef SET_REP 1058 1059#undef SET_BOOL 1060#undef SET_BYTES 1061#undef SET_INT32 1062#undef SET_INT64 1063#undef SET_INT64_REP 1064#undef SET_STR 1065#undef SET_STR_REP 1066 1067#undef SET_FIELD 1068 1069} // namespace syncer 1070