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.
5 // Keep this file in sync with the .proto files in this directory.
7 #include "sync/protocol/proto_value_conversions.h"
11 #include "base/base64.h"
12 #include "base/basictypes.h"
13 #include "base/i18n/time_formatting.h"
14 #include "base/logging.h"
15 #include "base/strings/string_number_conversions.h"
16 #include "base/time/time.h"
17 #include "base/values.h"
18 #include "sync/internal_api/public/base/unique_position.h"
19 #include "sync/protocol/app_list_specifics.pb.h"
20 #include "sync/protocol/app_notification_specifics.pb.h"
21 #include "sync/protocol/app_setting_specifics.pb.h"
22 #include "sync/protocol/app_specifics.pb.h"
23 #include "sync/protocol/autofill_specifics.pb.h"
24 #include "sync/protocol/bookmark_specifics.pb.h"
25 #include "sync/protocol/dictionary_specifics.pb.h"
26 #include "sync/protocol/encryption.pb.h"
27 #include "sync/protocol/experiments_specifics.pb.h"
28 #include "sync/protocol/extension_setting_specifics.pb.h"
29 #include "sync/protocol/extension_specifics.pb.h"
30 #include "sync/protocol/favicon_image_specifics.pb.h"
31 #include "sync/protocol/favicon_tracking_specifics.pb.h"
32 #include "sync/protocol/history_delete_directive_specifics.pb.h"
33 #include "sync/protocol/nigori_specifics.pb.h"
34 #include "sync/protocol/password_specifics.pb.h"
35 #include "sync/protocol/preference_specifics.pb.h"
36 #include "sync/protocol/priority_preference_specifics.pb.h"
37 #include "sync/protocol/proto_enum_conversions.h"
38 #include "sync/protocol/search_engine_specifics.pb.h"
39 #include "sync/protocol/session_specifics.pb.h"
40 #include "sync/protocol/sync.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 #include "sync/util/time.h"
50 // Basic Type -> Value functions.
52 base::StringValue
* MakeInt64Value(int64 x
) {
53 return new base::StringValue(base::Int64ToString(x
));
56 // TODO(akalin): Perhaps make JSONWriter support BinaryValue and use
57 // that instead of a StringValue.
58 base::StringValue
* MakeBytesValue(const std::string
& bytes
) {
59 std::string bytes_base64
;
60 base::Base64Encode(bytes
, &bytes_base64
);
61 return new base::StringValue(bytes_base64
);
64 base::StringValue
* MakeStringValue(const std::string
& str
) {
65 return new base::StringValue(str
);
68 // T is the enum type.
70 base::StringValue
* MakeEnumValue(T t
, const char* (*converter_fn
)(T
)) {
71 return new base::StringValue(converter_fn(t
));
74 // T is the field type, F is either RepeatedField or RepeatedPtrField,
75 // and V is a subclass of Value.
76 template <class T
, class F
, class V
>
77 base::ListValue
* MakeRepeatedValue(const F
& fields
, V
* (*converter_fn
)(T
)) {
78 base::ListValue
* list
= new base::ListValue();
79 for (typename
F::const_iterator it
= fields
.begin(); it
!= fields
.end();
81 list
->Append(converter_fn(*it
));
86 base::StringValue
* MakeTimestampValue(int64 tm
) {
87 return new base::StringValue(
88 base::TimeFormatShortDateAndTime(syncer::ProtoTimeToTime(tm
)));
93 // Helper macros to reduce the amount of boilerplate.
95 #define SET(field, fn) \
96 if (proto.has_##field()) { \
97 value->Set(#field, fn(proto.field())); \
99 #define SET_REP(field, fn) \
100 value->Set(#field, MakeRepeatedValue(proto.field(), fn))
101 #define SET_ENUM(field, fn) \
102 value->Set(#field, MakeEnumValue(proto.field(), fn))
104 #define SET_BOOL(field) SET(field, new base::FundamentalValue)
105 #define SET_BYTES(field) SET(field, MakeBytesValue)
106 #define SET_INT32(field) SET(field, MakeInt64Value)
107 #define SET_INT32_REP(field) SET_REP(field, MakeInt64Value)
108 #define SET_INT64(field) SET(field, MakeInt64Value)
109 #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value)
110 #define SET_STR(field) SET(field, new base::StringValue)
111 #define SET_TIME_STR(field) SET(field, MakeTimestampValue)
112 #define SET_STR_REP(field) \
114 MakeRepeatedValue<const std::string&, \
115 google::protobuf::RepeatedPtrField< \
117 base::StringValue>(proto.field(), \
119 #define SET_EXPERIMENT_ENABLED_FIELD(field) \
121 if (proto.has_##field() && \
122 proto.field().has_enabled()) { \
124 new base::FundamentalValue( \
125 proto.field().enabled())); \
129 #define SET_FIELD(field, fn) \
131 if (specifics.has_##field()) { \
132 value->Set(#field, fn(specifics.field())); \
136 // If you add another macro, don't forget to add an #undef at the end
137 // of this file, too.
139 base::DictionaryValue
* EncryptedDataToValue(
140 const sync_pb::EncryptedData
& proto
) {
141 base::DictionaryValue
* value
= new base::DictionaryValue();
143 // TODO(akalin): Shouldn't blob be of type bytes instead of string?
148 base::DictionaryValue
* AppSettingsToValue(
149 const sync_pb::AppNotificationSettings
& proto
) {
150 base::DictionaryValue
* value
= new base::DictionaryValue();
151 SET_BOOL(initial_setup_done
);
153 SET_STR(oauth_client_id
);
157 base::DictionaryValue
* SessionHeaderToValue(
158 const sync_pb::SessionHeader
& proto
) {
159 base::DictionaryValue
* value
= new base::DictionaryValue();
160 SET_REP(window
, SessionWindowToValue
);
161 SET_STR(client_name
);
162 SET_ENUM(device_type
, GetDeviceTypeString
);
166 base::DictionaryValue
* SessionTabToValue(const sync_pb::SessionTab
& proto
) {
167 base::DictionaryValue
* value
= new base::DictionaryValue();
169 SET_INT32(window_id
);
170 SET_INT32(tab_visual_index
);
171 SET_INT32(current_navigation_index
);
173 SET_STR(extension_app_id
);
174 SET_REP(navigation
, TabNavigationToValue
);
176 SET_ENUM(favicon_type
, GetFaviconTypeString
);
177 SET_STR(favicon_source
);
178 SET_REP(variation_id
, MakeInt64Value
);
182 base::DictionaryValue
* SessionWindowToValue(
183 const sync_pb::SessionWindow
& proto
) {
184 base::DictionaryValue
* value
= new base::DictionaryValue();
185 SET_INT32(window_id
);
186 SET_INT32(selected_tab_index
);
188 SET_ENUM(browser_type
, GetBrowserTypeString
);
192 base::DictionaryValue
* TabNavigationToValue(
193 const sync_pb::TabNavigation
& proto
) {
194 base::DictionaryValue
* value
= new base::DictionaryValue();
195 SET_STR(virtual_url
);
199 SET_ENUM(page_transition
, GetPageTransitionString
);
200 SET_ENUM(redirect_type
, GetPageTransitionRedirectTypeString
);
201 SET_INT32(unique_id
);
202 SET_INT64(timestamp_msec
);
203 SET_BOOL(navigation_forward_back
);
204 SET_BOOL(navigation_from_address_bar
);
205 SET_BOOL(navigation_home_page
);
206 SET_BOOL(navigation_chain_start
);
207 SET_BOOL(navigation_chain_end
);
208 SET_INT64(global_id
);
209 SET_STR(search_terms
);
210 SET_STR(favicon_url
);
211 SET_ENUM(blocked_state
, GetBlockedStateString
);
212 SET_STR_REP(content_pack_categories
);
213 SET_INT32(http_status_code
);
214 SET_INT32(obsolete_referrer_policy
);
215 SET_BOOL(is_restored
);
216 SET_REP(navigation_redirect
, NavigationRedirectToValue
);
217 SET_STR(last_navigation_redirect_url
);
218 SET_INT32(correct_referrer_policy
);
222 base::DictionaryValue
* NavigationRedirectToValue(
223 const sync_pb::NavigationRedirect
& proto
) {
224 base::DictionaryValue
* value
= new base::DictionaryValue();
229 base::DictionaryValue
* PasswordSpecificsDataToValue(
230 const sync_pb::PasswordSpecificsData
& proto
) {
231 base::DictionaryValue
* value
= new base::DictionaryValue();
233 SET_STR(signon_realm
);
236 SET_STR(username_element
);
237 SET_STR(username_value
);
238 SET_STR(password_element
);
239 value
->SetString("password_value", "<redacted>");
242 SET_INT64(date_created
);
243 SET_BOOL(blacklisted
);
245 SET_INT32(times_used
);
246 SET_STR(display_name
);
248 SET_STR(federation_url
);
252 base::DictionaryValue
* GlobalIdDirectiveToValue(
253 const sync_pb::GlobalIdDirective
& proto
) {
254 base::DictionaryValue
* value
= new base::DictionaryValue();
255 SET_INT64_REP(global_id
);
256 SET_INT64(start_time_usec
);
257 SET_INT64(end_time_usec
);
261 base::DictionaryValue
* TimeRangeDirectiveToValue(
262 const sync_pb::TimeRangeDirective
& proto
) {
263 base::DictionaryValue
* value
= new base::DictionaryValue();
264 SET_INT64(start_time_usec
);
265 SET_INT64(end_time_usec
);
269 base::DictionaryValue
* AppListSpecificsToValue(
270 const sync_pb::AppListSpecifics
& proto
) {
271 base::DictionaryValue
* value
= new base::DictionaryValue();
273 SET_ENUM(item_type
, GetAppListItemTypeString
);
276 SET_STR(item_ordinal
);
281 base::DictionaryValue
* AppNotificationToValue(
282 const sync_pb::AppNotification
& proto
) {
283 base::DictionaryValue
* value
= new base::DictionaryValue();
286 SET_INT64(creation_timestamp_ms
);
294 base::DictionaryValue
* AppSettingSpecificsToValue(
295 const sync_pb::AppSettingSpecifics
& proto
) {
296 base::DictionaryValue
* value
= new base::DictionaryValue();
297 SET(extension_setting
, ExtensionSettingSpecificsToValue
);
301 base::DictionaryValue
* AppSpecificsToValue(
302 const sync_pb::AppSpecifics
& proto
) {
303 base::DictionaryValue
* value
= new base::DictionaryValue();
304 SET(extension
, ExtensionSpecificsToValue
);
305 SET(notification_settings
, AppSettingsToValue
);
306 SET_STR(app_launch_ordinal
);
307 SET_STR(page_ordinal
);
308 SET_ENUM(launch_type
, GetLaunchTypeString
);
309 SET_STR(bookmark_app_url
);
310 SET_STR(bookmark_app_description
);
315 base::DictionaryValue
* AutofillSpecificsToValue(
316 const sync_pb::AutofillSpecifics
& proto
) {
317 base::DictionaryValue
* value
= new base::DictionaryValue();
320 SET_INT64_REP(usage_timestamp
);
321 SET(profile
, AutofillProfileSpecificsToValue
);
325 base::DictionaryValue
* AutofillProfileSpecificsToValue(
326 const sync_pb::AutofillProfileSpecifics
& proto
) {
327 base::DictionaryValue
* value
= new base::DictionaryValue();
330 SET_INT64(use_count
);
333 SET_STR_REP(name_first
);
334 SET_STR_REP(name_middle
);
335 SET_STR_REP(name_last
);
336 SET_STR_REP(name_full
);
337 SET_STR_REP(email_address
);
338 SET_STR(company_name
);
340 SET_STR(address_home_line1
);
341 SET_STR(address_home_line2
);
342 SET_STR(address_home_city
);
343 SET_STR(address_home_state
);
344 SET_STR(address_home_zip
);
345 SET_STR(address_home_country
);
347 SET_STR(address_home_street_address
);
348 SET_STR(address_home_sorting_code
);
349 SET_STR(address_home_dependent_locality
);
350 SET_STR(address_home_language_code
);
352 SET_STR_REP(phone_home_whole_number
);
356 base::DictionaryValue
* AutofillWalletSpecificsToValue(
357 const sync_pb::AutofillWalletSpecifics
& proto
) {
358 base::DictionaryValue
* value
= new base::DictionaryValue();
360 SET_ENUM(type
, GetWalletInfoTypeString
);
361 if (proto
.type() == sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD
) {
362 value
->Set("masked_card",
363 WalletMaskedCreditCardToValue(proto
.masked_card()));
364 } else if (proto
.type() == sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS
) {
365 value
->Set("masked_card",
366 WalletPostalAddressToValue(proto
.address()));
371 base::DictionaryValue
* MetaInfoToValue(
372 const sync_pb::MetaInfo
& proto
) {
373 base::DictionaryValue
* value
= new base::DictionaryValue();
379 base::DictionaryValue
* BookmarkSpecificsToValue(
380 const sync_pb::BookmarkSpecifics
& proto
) {
381 base::DictionaryValue
* value
= new base::DictionaryValue();
385 SET_INT64(creation_time_us
);
387 SET_REP(meta_info
, &MetaInfoToValue
);
391 base::DictionaryValue
* DeviceInfoSpecificsToValue(
392 const sync_pb::DeviceInfoSpecifics
& proto
) {
393 base::DictionaryValue
* value
= new base::DictionaryValue();
395 SET_STR(client_name
);
396 SET_ENUM(device_type
, GetDeviceTypeString
);
397 SET_STR(sync_user_agent
);
398 SET_STR(chrome_version
);
399 SET_TIME_STR(backup_timestamp
);
400 SET_STR(signin_scoped_device_id
);
404 base::DictionaryValue
* DictionarySpecificsToValue(
405 const sync_pb::DictionarySpecifics
& proto
) {
406 base::DictionaryValue
* value
= new base::DictionaryValue();
413 base::DictionaryValue
* FaviconSyncFlagsToValue(
414 const sync_pb::FaviconSyncFlags
& proto
) {
415 base::DictionaryValue
* value
= new base::DictionaryValue();
417 SET_INT32(favicon_sync_limit
);
423 base::DictionaryValue
* ExperimentsSpecificsToValue(
424 const sync_pb::ExperimentsSpecifics
& proto
) {
425 base::DictionaryValue
* value
= new base::DictionaryValue();
426 SET_EXPERIMENT_ENABLED_FIELD(keystore_encryption
);
427 SET_EXPERIMENT_ENABLED_FIELD(history_delete_directives
);
428 SET_EXPERIMENT_ENABLED_FIELD(autofill_culling
);
429 SET_EXPERIMENT_ENABLED_FIELD(pre_commit_update_avoidance
);
430 SET(favicon_sync
, FaviconSyncFlagsToValue
);
431 SET_EXPERIMENT_ENABLED_FIELD(gcm_channel
);
432 SET_EXPERIMENT_ENABLED_FIELD(gcm_invalidations
);
433 SET_EXPERIMENT_ENABLED_FIELD(wallet_sync
);
437 base::DictionaryValue
* ExtensionSettingSpecificsToValue(
438 const sync_pb::ExtensionSettingSpecifics
& proto
) {
439 base::DictionaryValue
* value
= new base::DictionaryValue();
440 SET_STR(extension_id
);
446 base::DictionaryValue
* ExtensionSpecificsToValue(
447 const sync_pb::ExtensionSpecifics
& proto
) {
448 base::DictionaryValue
* value
= new base::DictionaryValue();
453 SET_BOOL(incognito_enabled
);
454 SET_BOOL(remote_install
);
455 SET_BOOL(installed_by_custodian
);
456 SET_BOOL(all_urls_enabled
);
462 base::DictionaryValue
* FaviconDataToValue(
463 const sync_pb::FaviconData
& proto
) {
464 base::DictionaryValue
* value
= new base::DictionaryValue();
472 base::DictionaryValue
* FaviconImageSpecificsToValue(
473 const sync_pb::FaviconImageSpecifics
& proto
) {
474 base::DictionaryValue
* value
= new base::DictionaryValue();
475 SET_STR(favicon_url
);
476 SET(favicon_web
, FaviconDataToValue
);
477 SET(favicon_web_32
, FaviconDataToValue
);
478 SET(favicon_touch_64
, FaviconDataToValue
);
479 SET(favicon_touch_precomposed_64
, FaviconDataToValue
);
483 base::DictionaryValue
* FaviconTrackingSpecificsToValue(
484 const sync_pb::FaviconTrackingSpecifics
& proto
) {
485 base::DictionaryValue
* value
= new base::DictionaryValue();
486 SET_STR(favicon_url
);
487 SET_INT64(last_visit_time_ms
)
488 SET_BOOL(is_bookmarked
);
492 base::DictionaryValue
* HistoryDeleteDirectiveSpecificsToValue(
493 const sync_pb::HistoryDeleteDirectiveSpecifics
& proto
) {
494 base::DictionaryValue
* value
= new base::DictionaryValue();
495 SET(global_id_directive
, GlobalIdDirectiveToValue
);
496 SET(time_range_directive
, TimeRangeDirectiveToValue
);
500 base::DictionaryValue
* ManagedUserSettingSpecificsToValue(
501 const sync_pb::ManagedUserSettingSpecifics
& proto
) {
502 base::DictionaryValue
* value
= new base::DictionaryValue();
508 base::DictionaryValue
* ManagedUserSpecificsToValue(
509 const sync_pb::ManagedUserSpecifics
& proto
) {
510 base::DictionaryValue
* value
= new base::DictionaryValue();
513 SET_BOOL(acknowledged
);
515 SET_STR(chrome_avatar
);
516 SET_STR(chromeos_avatar
);
520 base::DictionaryValue
* ManagedUserSharedSettingSpecificsToValue(
521 const sync_pb::ManagedUserSharedSettingSpecifics
& proto
) {
522 base::DictionaryValue
* value
= new base::DictionaryValue();
526 SET_BOOL(acknowledged
);
530 base::DictionaryValue
* ManagedUserWhitelistSpecificsToValue(
531 const sync_pb::ManagedUserWhitelistSpecifics
& proto
) {
532 base::DictionaryValue
* value
= new base::DictionaryValue();
538 base::DictionaryValue
* NigoriSpecificsToValue(
539 const sync_pb::NigoriSpecifics
& proto
) {
540 base::DictionaryValue
* value
= new base::DictionaryValue();
541 SET(encryption_keybag
, EncryptedDataToValue
);
542 SET_BOOL(keybag_is_frozen
);
543 SET_BOOL(encrypt_bookmarks
);
544 SET_BOOL(encrypt_preferences
);
545 SET_BOOL(encrypt_autofill_profile
);
546 SET_BOOL(encrypt_autofill
);
547 SET_BOOL(encrypt_themes
);
548 SET_BOOL(encrypt_typed_urls
);
549 SET_BOOL(encrypt_extension_settings
);
550 SET_BOOL(encrypt_extensions
);
551 SET_BOOL(encrypt_sessions
);
552 SET_BOOL(encrypt_app_settings
);
553 SET_BOOL(encrypt_apps
);
554 SET_BOOL(encrypt_search_engines
);
555 SET_BOOL(encrypt_dictionary
);
556 SET_BOOL(encrypt_articles
);
557 SET_BOOL(encrypt_app_list
);
558 SET_BOOL(encrypt_everything
);
559 SET_BOOL(sync_tab_favicons
);
560 SET_ENUM(passphrase_type
, PassphraseTypeString
);
561 SET(keystore_decryptor_token
, EncryptedDataToValue
);
562 SET_INT64(keystore_migration_time
);
563 SET_INT64(custom_passphrase_time
);
567 base::DictionaryValue
* ArticlePageToValue(
568 const sync_pb::ArticlePage
& proto
) {
569 base::DictionaryValue
* value
= new base::DictionaryValue();
574 base::DictionaryValue
* ArticleSpecificsToValue(
575 const sync_pb::ArticleSpecifics
& proto
) {
576 base::DictionaryValue
* value
= new base::DictionaryValue();
579 SET_REP(pages
, ArticlePageToValue
);
583 base::DictionaryValue
* PasswordSpecificsToValue(
584 const sync_pb::PasswordSpecifics
& proto
) {
585 base::DictionaryValue
* value
= new base::DictionaryValue();
586 SET(encrypted
, EncryptedDataToValue
);
590 base::DictionaryValue
* PreferenceSpecificsToValue(
591 const sync_pb::PreferenceSpecifics
& proto
) {
592 base::DictionaryValue
* value
= new base::DictionaryValue();
598 base::DictionaryValue
* PriorityPreferenceSpecificsToValue(
599 const sync_pb::PriorityPreferenceSpecifics
& specifics
) {
600 base::DictionaryValue
* value
= new base::DictionaryValue();
601 SET_FIELD(preference
, PreferenceSpecificsToValue
);
605 base::DictionaryValue
* SyncedNotificationAppInfoSpecificsToValue(
606 const sync_pb::SyncedNotificationAppInfoSpecifics
& proto
) {
607 base::DictionaryValue
* value
= new base::DictionaryValue();
611 base::DictionaryValue
* SyncedNotificationSpecificsToValue(
612 const sync_pb::SyncedNotificationSpecifics
& proto
) {
613 base::DictionaryValue
* value
= new base::DictionaryValue();
617 base::DictionaryValue
* SearchEngineSpecificsToValue(
618 const sync_pb::SearchEngineSpecifics
& proto
) {
619 base::DictionaryValue
* value
= new base::DictionaryValue();
622 SET_STR(favicon_url
);
624 SET_BOOL(safe_for_autoreplace
);
625 SET_STR(originating_url
);
626 SET_INT64(date_created
);
627 SET_STR(input_encodings
);
628 SET_BOOL(show_in_default_list
);
629 SET_STR(suggestions_url
);
630 SET_INT32(prepopulate_id
);
631 SET_BOOL(autogenerate_keyword
);
632 SET_STR(instant_url
);
633 SET_INT64(last_modified
);
635 SET_STR_REP(alternate_urls
);
636 SET_STR(search_terms_replacement_key
);
638 SET_STR(search_url_post_params
);
639 SET_STR(suggestions_url_post_params
);
640 SET_STR(instant_url_post_params
);
641 SET_STR(image_url_post_params
);
642 SET_STR(new_tab_url
);
646 base::DictionaryValue
* SessionSpecificsToValue(
647 const sync_pb::SessionSpecifics
& proto
) {
648 base::DictionaryValue
* value
= new base::DictionaryValue();
649 SET_STR(session_tag
);
650 SET(header
, SessionHeaderToValue
);
651 SET(tab
, SessionTabToValue
);
652 SET_INT32(tab_node_id
);
656 base::DictionaryValue
* ThemeSpecificsToValue(
657 const sync_pb::ThemeSpecifics
& proto
) {
658 base::DictionaryValue
* value
= new base::DictionaryValue();
659 SET_BOOL(use_custom_theme
);
660 SET_BOOL(use_system_theme_by_default
);
661 SET_STR(custom_theme_name
);
662 SET_STR(custom_theme_id
);
663 SET_STR(custom_theme_update_url
);
667 base::DictionaryValue
* TypedUrlSpecificsToValue(
668 const sync_pb::TypedUrlSpecifics
& proto
) {
669 base::DictionaryValue
* value
= new base::DictionaryValue();
673 SET_INT64_REP(visits
);
674 SET_INT32_REP(visit_transitions
);
678 base::DictionaryValue
* WalletMaskedCreditCardToValue(
679 const sync_pb::WalletMaskedCreditCard
& proto
) {
680 base::DictionaryValue
* value
= new base::DictionaryValue();
682 SET_ENUM(status
, GetWalletCardStatusString
);
683 SET_STR(name_on_card
);
684 SET_ENUM(type
, GetWalletCardTypeString
);
686 SET_INT32(exp_month
);
691 base::DictionaryValue
* WalletPostalAddressToValue(
692 const sync_pb::WalletPostalAddress
& proto
) {
693 base::DictionaryValue
* value
= new base::DictionaryValue();
694 SET_STR(recipient_name
);
695 SET_STR(company_name
);
696 SET_STR_REP(street_address
);
701 SET_STR(postal_code
);
702 SET_STR(sorting_code
);
703 SET_STR(country_code
);
704 SET_STR(phone_number
);
705 SET_STR(language_code
);
709 base::DictionaryValue
* WifiCredentialSpecificsToValue(
710 const sync_pb::WifiCredentialSpecifics
& proto
) {
711 base::DictionaryValue
* value
= new base::DictionaryValue();
713 SET_ENUM(security_class
, GetWifiCredentialSecurityClassString
);
714 SET_BYTES(passphrase
);
718 base::DictionaryValue
* EntitySpecificsToValue(
719 const sync_pb::EntitySpecifics
& specifics
) {
720 base::DictionaryValue
* value
= new base::DictionaryValue();
721 SET_FIELD(app
, AppSpecificsToValue
);
722 SET_FIELD(app_list
, AppListSpecificsToValue
);
723 SET_FIELD(app_notification
, AppNotificationToValue
);
724 SET_FIELD(app_setting
, AppSettingSpecificsToValue
);
725 SET_FIELD(article
, ArticleSpecificsToValue
);
726 SET_FIELD(autofill
, AutofillSpecificsToValue
);
727 SET_FIELD(autofill_profile
, AutofillProfileSpecificsToValue
);
728 SET_FIELD(autofill_wallet
, AutofillWalletSpecificsToValue
);
729 SET_FIELD(bookmark
, BookmarkSpecificsToValue
);
730 SET_FIELD(device_info
, DeviceInfoSpecificsToValue
);
731 SET_FIELD(dictionary
, DictionarySpecificsToValue
);
732 SET_FIELD(experiments
, ExperimentsSpecificsToValue
);
733 SET_FIELD(extension
, ExtensionSpecificsToValue
);
734 SET_FIELD(extension_setting
, ExtensionSettingSpecificsToValue
);
735 SET_FIELD(favicon_image
, FaviconImageSpecificsToValue
);
736 SET_FIELD(favicon_tracking
, FaviconTrackingSpecificsToValue
);
737 SET_FIELD(history_delete_directive
, HistoryDeleteDirectiveSpecificsToValue
);
738 SET_FIELD(managed_user_setting
, ManagedUserSettingSpecificsToValue
);
739 SET_FIELD(managed_user_shared_setting
,
740 ManagedUserSharedSettingSpecificsToValue
);
741 SET_FIELD(managed_user
, ManagedUserSpecificsToValue
);
742 SET_FIELD(managed_user_whitelist
, ManagedUserWhitelistSpecificsToValue
);
743 SET_FIELD(nigori
, NigoriSpecificsToValue
);
744 SET_FIELD(password
, PasswordSpecificsToValue
);
745 SET_FIELD(preference
, PreferenceSpecificsToValue
);
746 SET_FIELD(priority_preference
, PriorityPreferenceSpecificsToValue
);
747 SET_FIELD(search_engine
, SearchEngineSpecificsToValue
);
748 SET_FIELD(session
, SessionSpecificsToValue
);
749 SET_FIELD(synced_notification
, SyncedNotificationSpecificsToValue
);
750 SET_FIELD(synced_notification_app_info
,
751 SyncedNotificationAppInfoSpecificsToValue
);
752 SET_FIELD(theme
, ThemeSpecificsToValue
);
753 SET_FIELD(typed_url
, TypedUrlSpecificsToValue
);
754 SET_FIELD(wifi_credential
, WifiCredentialSpecificsToValue
);
760 base::StringValue
* UniquePositionToStringValue(
761 const sync_pb::UniquePosition
& proto
) {
762 UniquePosition pos
= UniquePosition::FromProto(proto
);
763 return new base::StringValue(pos
.ToDebugString());
768 base::DictionaryValue
* SyncEntityToValue(const sync_pb::SyncEntity
& proto
,
769 bool include_specifics
) {
770 base::DictionaryValue
* value
= new base::DictionaryValue();
772 SET_STR(parent_id_string
);
773 SET_STR(old_parent_id
);
778 SET_STR(non_unique_name
);
779 SET_INT64(sync_timestamp
);
780 SET_STR(server_defined_unique_tag
);
781 SET_INT64(position_in_parent
);
782 SET(unique_position
, UniquePositionToStringValue
);
783 SET_STR(insert_after_item_id
);
785 SET_STR(originator_cache_guid
);
786 SET_STR(originator_client_item_id
);
787 if (include_specifics
)
788 SET(specifics
, EntitySpecificsToValue
);
790 SET_STR(client_defined_unique_tag
);
791 SET_REP(attachment_id
, AttachmentIdProtoToValue
);
797 base::ListValue
* SyncEntitiesToValue(
798 const ::google::protobuf::RepeatedPtrField
<sync_pb::SyncEntity
>& entities
,
799 bool include_specifics
) {
800 base::ListValue
* list
= new base::ListValue();
801 ::google::protobuf::RepeatedPtrField
<sync_pb::SyncEntity
>::const_iterator it
;
802 for (it
= entities
.begin(); it
!= entities
.end(); ++it
) {
803 list
->Append(SyncEntityToValue(*it
, include_specifics
));
809 base::DictionaryValue
* ChromiumExtensionActivityToValue(
810 const sync_pb::ChromiumExtensionsActivity
& proto
) {
811 base::DictionaryValue
* value
= new base::DictionaryValue();
812 SET_STR(extension_id
);
813 SET_INT32(bookmark_writes_since_last_commit
);
817 base::DictionaryValue
* CommitMessageToValue(
818 const sync_pb::CommitMessage
& proto
,
819 bool include_specifics
) {
820 base::DictionaryValue
* value
= new base::DictionaryValue();
821 value
->Set("entries",
822 SyncEntitiesToValue(proto
.entries(), include_specifics
));
824 SET_REP(extensions_activity
, ChromiumExtensionActivityToValue
);
825 SET(config_params
, ClientConfigParamsToValue
);
829 base::DictionaryValue
* GetUpdateTriggersToValue(
830 const sync_pb::GetUpdateTriggers
& proto
) {
831 base::DictionaryValue
* value
= new base::DictionaryValue();
832 SET_STR_REP(notification_hint
);
833 SET_BOOL(client_dropped_hints
);
834 SET_BOOL(invalidations_out_of_sync
);
835 SET_INT64(local_modification_nudges
);
836 SET_INT64(datatype_refresh_nudges
);
840 base::DictionaryValue
* DataTypeProgressMarkerToValue(
841 const sync_pb::DataTypeProgressMarker
& proto
) {
842 base::DictionaryValue
* value
= new base::DictionaryValue();
843 SET_INT32(data_type_id
);
845 SET_INT64(timestamp_token_for_migration
);
846 SET_STR(notification_hint
);
847 SET(get_update_triggers
, GetUpdateTriggersToValue
);
851 base::DictionaryValue
* DataTypeContextToValue(
852 const sync_pb::DataTypeContext
& proto
) {
853 base::DictionaryValue
* value
= new base::DictionaryValue();
854 SET_INT32(data_type_id
);
860 base::DictionaryValue
* GetUpdatesCallerInfoToValue(
861 const sync_pb::GetUpdatesCallerInfo
& proto
) {
862 base::DictionaryValue
* value
= new base::DictionaryValue();
863 SET_ENUM(source
, GetUpdatesSourceString
);
864 SET_BOOL(notifications_enabled
);
868 base::DictionaryValue
* GetUpdatesMessageToValue(
869 const sync_pb::GetUpdatesMessage
& proto
) {
870 base::DictionaryValue
* value
= new base::DictionaryValue();
871 SET(caller_info
, GetUpdatesCallerInfoToValue
);
872 SET_BOOL(fetch_folders
);
873 SET_INT32(batch_size
);
874 SET_REP(from_progress_marker
, DataTypeProgressMarkerToValue
);
876 SET_BOOL(need_encryption_key
);
877 SET_BOOL(create_mobile_bookmarks_folder
);
878 SET_ENUM(get_updates_origin
, GetUpdatesOriginString
);
879 SET_REP(client_contexts
, DataTypeContextToValue
);
883 base::DictionaryValue
* ClientStatusToValue(const sync_pb::ClientStatus
& proto
) {
884 base::DictionaryValue
* value
= new base::DictionaryValue();
885 SET_BOOL(hierarchy_conflict_detected
);
889 base::DictionaryValue
* EntryResponseToValue(
890 const sync_pb::CommitResponse::EntryResponse
& proto
) {
891 base::DictionaryValue
* value
= new base::DictionaryValue();
892 SET_ENUM(response_type
, GetResponseTypeString
);
894 SET_STR(parent_id_string
);
895 SET_INT64(position_in_parent
);
898 SET_STR(error_message
);
903 base::DictionaryValue
* CommitResponseToValue(
904 const sync_pb::CommitResponse
& proto
) {
905 base::DictionaryValue
* value
= new base::DictionaryValue();
906 SET_REP(entryresponse
, EntryResponseToValue
);
910 base::DictionaryValue
* GetUpdatesResponseToValue(
911 const sync_pb::GetUpdatesResponse
& proto
,
912 bool include_specifics
) {
913 base::DictionaryValue
* value
= new base::DictionaryValue();
914 value
->Set("entries",
915 SyncEntitiesToValue(proto
.entries(), include_specifics
));
916 SET_INT64(changes_remaining
);
917 SET_REP(new_progress_marker
, DataTypeProgressMarkerToValue
);
918 SET_REP(context_mutations
, DataTypeContextToValue
);
922 base::DictionaryValue
* ClientCommandToValue(
923 const sync_pb::ClientCommand
& proto
) {
924 base::DictionaryValue
* value
= new base::DictionaryValue();
925 SET_INT32(set_sync_poll_interval
);
926 SET_INT32(set_sync_long_poll_interval
);
927 SET_INT32(max_commit_batch_size
);
928 SET_INT32(sessions_commit_delay_seconds
);
929 SET_INT32(throttle_delay_seconds
);
930 SET_INT32(client_invalidation_hint_buffer_size
);
934 base::DictionaryValue
* ErrorToValue(
935 const sync_pb::ClientToServerResponse::Error
& proto
) {
936 base::DictionaryValue
* value
= new base::DictionaryValue();
937 SET_ENUM(error_type
, GetErrorTypeString
);
938 SET_STR(error_description
);
940 SET_ENUM(action
, GetActionString
);
946 base::DictionaryValue
* ClientToServerResponseToValue(
947 const sync_pb::ClientToServerResponse
& proto
,
948 bool include_specifics
) {
949 base::DictionaryValue
* value
= new base::DictionaryValue();
950 SET(commit
, CommitResponseToValue
);
951 if (proto
.has_get_updates()) {
952 value
->Set("get_updates", GetUpdatesResponseToValue(proto
.get_updates(),
956 SET(error
, ErrorToValue
);
957 SET_ENUM(error_code
, GetErrorTypeString
);
958 SET_STR(error_message
);
959 SET_STR(store_birthday
);
960 SET(client_command
, ClientCommandToValue
);
961 SET_INT32_REP(migrated_data_type_id
);
965 base::DictionaryValue
* ClientToServerMessageToValue(
966 const sync_pb::ClientToServerMessage
& proto
,
967 bool include_specifics
) {
968 base::DictionaryValue
* value
= new base::DictionaryValue();
970 SET_INT32(protocol_version
);
971 if (proto
.has_commit()) {
973 CommitMessageToValue(proto
.commit(), include_specifics
));
976 SET(get_updates
, GetUpdatesMessageToValue
);
977 SET_STR(store_birthday
);
978 SET_BOOL(sync_problem_detected
);
979 SET(debug_info
, DebugInfoToValue
);
980 SET(client_status
, ClientStatusToValue
);
984 base::DictionaryValue
* DatatypeAssociationStatsToValue(
985 const sync_pb::DatatypeAssociationStats
& proto
) {
986 base::DictionaryValue
* value
= new base::DictionaryValue();
987 SET_INT32(data_type_id
);
988 SET_INT32(num_local_items_before_association
);
989 SET_INT32(num_sync_items_before_association
);
990 SET_INT32(num_local_items_after_association
);
991 SET_INT32(num_sync_items_after_association
);
992 SET_INT32(num_local_items_added
);
993 SET_INT32(num_local_items_deleted
);
994 SET_INT32(num_local_items_modified
);
995 SET_INT32(num_sync_items_added
);
996 SET_INT32(num_sync_items_deleted
);
997 SET_INT32(num_sync_items_modified
);
998 SET_INT64(local_version_pre_association
);
999 SET_INT64(sync_version_pre_association
)
1000 SET_BOOL(had_error
);
1001 SET_INT64(download_wait_time_us
);
1002 SET_INT64(download_time_us
);
1003 SET_INT64(association_wait_time_for_high_priority_us
);
1004 SET_INT64(association_wait_time_for_same_priority_us
);
1008 base::DictionaryValue
* DebugEventInfoToValue(
1009 const sync_pb::DebugEventInfo
& proto
) {
1010 base::DictionaryValue
* value
= new base::DictionaryValue();
1011 SET_ENUM(singleton_event
, SingletonDebugEventTypeString
);
1012 SET(sync_cycle_completed_event_info
, SyncCycleCompletedEventInfoToValue
);
1013 SET_INT32(nudging_datatype
);
1014 SET_INT32_REP(datatypes_notified_from_server
);
1015 SET(datatype_association_stats
, DatatypeAssociationStatsToValue
);
1019 base::DictionaryValue
* DebugInfoToValue(const sync_pb::DebugInfo
& proto
) {
1020 base::DictionaryValue
* value
= new base::DictionaryValue();
1021 SET_REP(events
, DebugEventInfoToValue
);
1022 SET_BOOL(cryptographer_ready
);
1023 SET_BOOL(cryptographer_has_pending_keys
);
1024 SET_BOOL(events_dropped
);
1028 base::DictionaryValue
* SyncCycleCompletedEventInfoToValue(
1029 const sync_pb::SyncCycleCompletedEventInfo
& proto
) {
1030 base::DictionaryValue
* value
= new base::DictionaryValue();
1031 SET_INT32(num_encryption_conflicts
);
1032 SET_INT32(num_hierarchy_conflicts
);
1033 SET_INT32(num_server_conflicts
);
1034 SET_INT32(num_updates_downloaded
);
1035 SET_INT32(num_reflected_updates_downloaded
);
1036 SET(caller_info
, GetUpdatesCallerInfoToValue
);
1040 base::DictionaryValue
* ClientConfigParamsToValue(
1041 const sync_pb::ClientConfigParams
& proto
) {
1042 base::DictionaryValue
* value
= new base::DictionaryValue();
1043 SET_INT32_REP(enabled_type_ids
);
1044 SET_BOOL(tabs_datatype_enabled
);
1048 base::DictionaryValue
* AttachmentIdProtoToValue(
1049 const sync_pb::AttachmentIdProto
& proto
) {
1050 base::DictionaryValue
* value
= new base::DictionaryValue();
1062 #undef SET_INT64_REP
1068 } // namespace syncer