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 scoped_ptr
<base::StringValue
> MakeInt64Value(int64 x
) {
53 return make_scoped_ptr(new base::StringValue(base::Int64ToString(x
)));
56 // TODO(akalin): Perhaps make JSONWriter support BinaryValue and use
57 // that instead of a StringValue.
58 std::string
Base64EncodeString(const std::string
& bytes
) {
59 std::string bytes_base64
;
60 base::Base64Encode(bytes
, &bytes_base64
);
64 scoped_ptr
<base::StringValue
> MakeStringValue(const std::string
& str
) {
65 return make_scoped_ptr(new base::StringValue(str
));
68 // T is the field type, F is either RepeatedField or RepeatedPtrField,
69 // and V is a subclass of Value.
70 template <class T
, class F
, class V
>
71 scoped_ptr
<base::ListValue
> MakeRepeatedValue(const F
& fields
,
72 V (*converter_fn
)(T
)) {
73 scoped_ptr
<base::ListValue
> list(new base::ListValue());
74 for (typename
F::const_iterator it
= fields
.begin(); it
!= fields
.end();
76 list
->Append(converter_fn(*it
));
81 base::string16
TimestampToString(int64 tm
) {
82 return base::TimeFormatShortDateAndTime(syncer::ProtoTimeToTime(tm
));
87 // Helper macros to reduce the amount of boilerplate.
89 #define SET_TYPE(field, set_fn, transform) \
90 if (proto.has_##field()) { \
91 value->set_fn(#field, transform(proto.field())); \
93 #define SET(field, fn) SET_TYPE(field, Set, fn)
94 #define SET_REP(field, fn) \
95 value->Set(#field, MakeRepeatedValue(proto.field(), fn))
96 #define SET_ENUM(field, fn) SET_TYPE(field, SetString, fn)
98 #define SET_BOOL(field) SET_TYPE(field, SetBoolean, )
99 #define SET_BYTES(field) SET_TYPE(field, SetString, Base64EncodeString)
100 #define SET_INT32(field) SET_TYPE(field, SetString, base::Int64ToString)
101 #define SET_INT32_REP(field) SET_REP(field, MakeInt64Value)
102 #define SET_INT64(field) SET_TYPE(field, SetString, base::Int64ToString)
103 #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value)
104 #define SET_STR(field) SET_TYPE(field, SetString, )
105 #define SET_TIME_STR(field) SET_TYPE(field, SetString, TimestampToString)
106 #define SET_STR_REP(field) \
109 MakeRepeatedValue<const std::string&, \
110 google::protobuf::RepeatedPtrField<std::string>, \
111 scoped_ptr<base::StringValue>>(proto.field(), \
113 #define SET_EXPERIMENT_ENABLED_FIELD(field) \
115 if (proto.has_##field() && \
116 proto.field().has_enabled()) { \
118 new base::FundamentalValue( \
119 proto.field().enabled())); \
123 #define SET_FIELD(field, fn) \
125 if (specifics.has_##field()) { \
126 value->Set(#field, fn(specifics.field())); \
130 // If you add another macro, don't forget to add an #undef at the end
131 // of this file, too.
133 scoped_ptr
<base::DictionaryValue
> EncryptedDataToValue(
134 const sync_pb::EncryptedData
& proto
) {
135 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
137 // TODO(akalin): Shouldn't blob be of type bytes instead of string?
142 scoped_ptr
<base::DictionaryValue
> AppSettingsToValue(
143 const sync_pb::AppNotificationSettings
& proto
) {
144 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
145 SET_BOOL(initial_setup_done
);
147 SET_STR(oauth_client_id
);
151 scoped_ptr
<base::DictionaryValue
> SessionHeaderToValue(
152 const sync_pb::SessionHeader
& proto
) {
153 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
154 SET_REP(window
, SessionWindowToValue
);
155 SET_STR(client_name
);
156 SET_ENUM(device_type
, GetDeviceTypeString
);
160 scoped_ptr
<base::DictionaryValue
> SessionTabToValue(
161 const sync_pb::SessionTab
& proto
) {
162 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
164 SET_INT32(window_id
);
165 SET_INT32(tab_visual_index
);
166 SET_INT32(current_navigation_index
);
168 SET_STR(extension_app_id
);
169 SET_REP(navigation
, TabNavigationToValue
);
171 SET_ENUM(favicon_type
, GetFaviconTypeString
);
172 SET_STR(favicon_source
);
173 SET_REP(variation_id
, MakeInt64Value
);
177 scoped_ptr
<base::DictionaryValue
> SessionWindowToValue(
178 const sync_pb::SessionWindow
& proto
) {
179 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
180 SET_INT32(window_id
);
181 SET_INT32(selected_tab_index
);
183 SET_ENUM(browser_type
, GetBrowserTypeString
);
187 scoped_ptr
<base::DictionaryValue
> TabNavigationToValue(
188 const sync_pb::TabNavigation
& proto
) {
189 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
190 SET_STR(virtual_url
);
194 SET_ENUM(page_transition
, GetPageTransitionString
);
195 SET_ENUM(redirect_type
, GetPageTransitionRedirectTypeString
);
196 SET_INT32(unique_id
);
197 SET_INT64(timestamp_msec
);
198 SET_BOOL(navigation_forward_back
);
199 SET_BOOL(navigation_from_address_bar
);
200 SET_BOOL(navigation_home_page
);
201 SET_BOOL(navigation_chain_start
);
202 SET_BOOL(navigation_chain_end
);
203 SET_INT64(global_id
);
204 SET_STR(search_terms
);
205 SET_STR(favicon_url
);
206 SET_ENUM(blocked_state
, GetBlockedStateString
);
207 SET_STR_REP(content_pack_categories
);
208 SET_INT32(http_status_code
);
209 SET_INT32(obsolete_referrer_policy
);
210 SET_BOOL(is_restored
);
211 SET_REP(navigation_redirect
, NavigationRedirectToValue
);
212 SET_STR(last_navigation_redirect_url
);
213 SET_INT32(correct_referrer_policy
);
217 scoped_ptr
<base::DictionaryValue
> NavigationRedirectToValue(
218 const sync_pb::NavigationRedirect
& proto
) {
219 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
224 scoped_ptr
<base::DictionaryValue
> PasswordSpecificsDataToValue(
225 const sync_pb::PasswordSpecificsData
& proto
) {
226 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
228 SET_STR(signon_realm
);
231 SET_STR(username_element
);
232 SET_STR(username_value
);
233 SET_STR(password_element
);
234 value
->SetString("password_value", "<redacted>");
237 SET_INT64(date_created
);
238 SET_BOOL(blacklisted
);
240 SET_INT32(times_used
);
241 SET_STR(display_name
);
243 SET_STR(federation_url
);
247 scoped_ptr
<base::DictionaryValue
> GlobalIdDirectiveToValue(
248 const sync_pb::GlobalIdDirective
& proto
) {
249 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
250 SET_INT64_REP(global_id
);
251 SET_INT64(start_time_usec
);
252 SET_INT64(end_time_usec
);
256 scoped_ptr
<base::DictionaryValue
> TimeRangeDirectiveToValue(
257 const sync_pb::TimeRangeDirective
& proto
) {
258 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
259 SET_INT64(start_time_usec
);
260 SET_INT64(end_time_usec
);
264 scoped_ptr
<base::DictionaryValue
> AppListSpecificsToValue(
265 const sync_pb::AppListSpecifics
& proto
) {
266 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
268 SET_ENUM(item_type
, GetAppListItemTypeString
);
271 SET_STR(item_ordinal
);
276 scoped_ptr
<base::DictionaryValue
> AppNotificationToValue(
277 const sync_pb::AppNotification
& proto
) {
278 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
281 SET_INT64(creation_timestamp_ms
);
289 scoped_ptr
<base::DictionaryValue
> AppSettingSpecificsToValue(
290 const sync_pb::AppSettingSpecifics
& proto
) {
291 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
292 SET(extension_setting
, ExtensionSettingSpecificsToValue
);
296 scoped_ptr
<base::DictionaryValue
> LinkedAppIconInfoToValue(
297 const sync_pb::LinkedAppIconInfo
& proto
) {
298 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
304 scoped_ptr
<base::DictionaryValue
> AppSpecificsToValue(
305 const sync_pb::AppSpecifics
& proto
) {
306 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
307 SET(extension
, ExtensionSpecificsToValue
);
308 SET(notification_settings
, AppSettingsToValue
);
309 SET_STR(app_launch_ordinal
);
310 SET_STR(page_ordinal
);
311 SET_ENUM(launch_type
, GetLaunchTypeString
);
312 SET_STR(bookmark_app_url
);
313 SET_STR(bookmark_app_description
);
314 SET_STR(bookmark_app_icon_color
);
315 SET_REP(linked_app_icons
, LinkedAppIconInfoToValue
);
320 scoped_ptr
<base::DictionaryValue
> AutofillSpecificsToValue(
321 const sync_pb::AutofillSpecifics
& proto
) {
322 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
325 SET_INT64_REP(usage_timestamp
);
326 SET(profile
, AutofillProfileSpecificsToValue
);
330 scoped_ptr
<base::DictionaryValue
> AutofillProfileSpecificsToValue(
331 const sync_pb::AutofillProfileSpecifics
& proto
) {
332 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
335 SET_INT64(use_count
);
338 SET_STR_REP(name_first
);
339 SET_STR_REP(name_middle
);
340 SET_STR_REP(name_last
);
341 SET_STR_REP(name_full
);
342 SET_STR_REP(email_address
);
343 SET_STR(company_name
);
345 SET_STR(address_home_line1
);
346 SET_STR(address_home_line2
);
347 SET_STR(address_home_city
);
348 SET_STR(address_home_state
);
349 SET_STR(address_home_zip
);
350 SET_STR(address_home_country
);
352 SET_STR(address_home_street_address
);
353 SET_STR(address_home_sorting_code
);
354 SET_STR(address_home_dependent_locality
);
355 SET_STR(address_home_language_code
);
357 SET_STR_REP(phone_home_whole_number
);
361 scoped_ptr
<base::DictionaryValue
> WalletMetadataSpecificsToValue(
362 const sync_pb::WalletMetadataSpecifics
& proto
) {
363 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
364 SET_ENUM(type
, GetWalletMetadataTypeString
);
366 SET_INT64(use_count
);
371 scoped_ptr
<base::DictionaryValue
> AutofillWalletSpecificsToValue(
372 const sync_pb::AutofillWalletSpecifics
& proto
) {
373 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
375 SET_ENUM(type
, GetWalletInfoTypeString
);
376 if (proto
.type() == sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD
) {
377 value
->Set("masked_card",
378 WalletMaskedCreditCardToValue(proto
.masked_card()));
379 } else if (proto
.type() == sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS
) {
380 value
->Set("address",
381 WalletPostalAddressToValue(proto
.address()));
386 scoped_ptr
<base::DictionaryValue
> MetaInfoToValue(
387 const sync_pb::MetaInfo
& proto
) {
388 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
394 scoped_ptr
<base::DictionaryValue
> BookmarkSpecificsToValue(
395 const sync_pb::BookmarkSpecifics
& proto
) {
396 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
400 SET_INT64(creation_time_us
);
402 SET_REP(meta_info
, &MetaInfoToValue
);
406 scoped_ptr
<base::DictionaryValue
> DeviceInfoSpecificsToValue(
407 const sync_pb::DeviceInfoSpecifics
& proto
) {
408 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
410 SET_STR(client_name
);
411 SET_ENUM(device_type
, GetDeviceTypeString
);
412 SET_STR(sync_user_agent
);
413 SET_STR(chrome_version
);
414 SET_TIME_STR(backup_timestamp
);
415 SET_STR(signin_scoped_device_id
);
419 scoped_ptr
<base::DictionaryValue
> DictionarySpecificsToValue(
420 const sync_pb::DictionarySpecifics
& proto
) {
421 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
428 scoped_ptr
<base::DictionaryValue
> FaviconSyncFlagsToValue(
429 const sync_pb::FaviconSyncFlags
& proto
) {
430 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
432 SET_INT32(favicon_sync_limit
);
438 scoped_ptr
<base::DictionaryValue
> ExperimentsSpecificsToValue(
439 const sync_pb::ExperimentsSpecifics
& proto
) {
440 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
441 SET_EXPERIMENT_ENABLED_FIELD(keystore_encryption
);
442 SET_EXPERIMENT_ENABLED_FIELD(history_delete_directives
);
443 SET_EXPERIMENT_ENABLED_FIELD(autofill_culling
);
444 SET_EXPERIMENT_ENABLED_FIELD(pre_commit_update_avoidance
);
445 SET(favicon_sync
, FaviconSyncFlagsToValue
);
446 SET_EXPERIMENT_ENABLED_FIELD(gcm_channel
);
447 SET_EXPERIMENT_ENABLED_FIELD(gcm_invalidations
);
448 SET_EXPERIMENT_ENABLED_FIELD(wallet_sync
);
452 scoped_ptr
<base::DictionaryValue
> ExtensionSettingSpecificsToValue(
453 const sync_pb::ExtensionSettingSpecifics
& proto
) {
454 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
455 SET_STR(extension_id
);
461 scoped_ptr
<base::DictionaryValue
> ExtensionSpecificsToValue(
462 const sync_pb::ExtensionSpecifics
& proto
) {
463 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
468 SET_BOOL(incognito_enabled
);
470 SET_BOOL(remote_install
);
471 SET_BOOL(installed_by_custodian
);
472 SET_BOOL(all_urls_enabled
);
473 SET_INT32(disable_reasons
);
478 scoped_ptr
<base::DictionaryValue
> FaviconDataToValue(
479 const sync_pb::FaviconData
& proto
) {
480 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
488 scoped_ptr
<base::DictionaryValue
> FaviconImageSpecificsToValue(
489 const sync_pb::FaviconImageSpecifics
& proto
) {
490 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
491 SET_STR(favicon_url
);
492 SET(favicon_web
, FaviconDataToValue
);
493 SET(favicon_web_32
, FaviconDataToValue
);
494 SET(favicon_touch_64
, FaviconDataToValue
);
495 SET(favicon_touch_precomposed_64
, FaviconDataToValue
);
499 scoped_ptr
<base::DictionaryValue
> FaviconTrackingSpecificsToValue(
500 const sync_pb::FaviconTrackingSpecifics
& proto
) {
501 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
502 SET_STR(favicon_url
);
503 SET_INT64(last_visit_time_ms
)
504 SET_BOOL(is_bookmarked
);
508 scoped_ptr
<base::DictionaryValue
> HistoryDeleteDirectiveSpecificsToValue(
509 const sync_pb::HistoryDeleteDirectiveSpecifics
& proto
) {
510 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
511 SET(global_id_directive
, GlobalIdDirectiveToValue
);
512 SET(time_range_directive
, TimeRangeDirectiveToValue
);
516 scoped_ptr
<base::DictionaryValue
> ManagedUserSettingSpecificsToValue(
517 const sync_pb::ManagedUserSettingSpecifics
& proto
) {
518 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
524 scoped_ptr
<base::DictionaryValue
> ManagedUserSpecificsToValue(
525 const sync_pb::ManagedUserSpecifics
& proto
) {
526 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
529 SET_BOOL(acknowledged
);
531 SET_STR(chrome_avatar
);
532 SET_STR(chromeos_avatar
);
536 scoped_ptr
<base::DictionaryValue
> ManagedUserSharedSettingSpecificsToValue(
537 const sync_pb::ManagedUserSharedSettingSpecifics
& proto
) {
538 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
542 SET_BOOL(acknowledged
);
546 scoped_ptr
<base::DictionaryValue
> ManagedUserWhitelistSpecificsToValue(
547 const sync_pb::ManagedUserWhitelistSpecifics
& proto
) {
548 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
554 scoped_ptr
<base::DictionaryValue
> NigoriSpecificsToValue(
555 const sync_pb::NigoriSpecifics
& proto
) {
556 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
557 SET(encryption_keybag
, EncryptedDataToValue
);
558 SET_BOOL(keybag_is_frozen
);
559 SET_BOOL(encrypt_bookmarks
);
560 SET_BOOL(encrypt_preferences
);
561 SET_BOOL(encrypt_autofill_profile
);
562 SET_BOOL(encrypt_autofill
);
563 SET_BOOL(encrypt_themes
);
564 SET_BOOL(encrypt_typed_urls
);
565 SET_BOOL(encrypt_extension_settings
);
566 SET_BOOL(encrypt_extensions
);
567 SET_BOOL(encrypt_sessions
);
568 SET_BOOL(encrypt_app_settings
);
569 SET_BOOL(encrypt_apps
);
570 SET_BOOL(encrypt_search_engines
);
571 SET_BOOL(encrypt_dictionary
);
572 SET_BOOL(encrypt_articles
);
573 SET_BOOL(encrypt_app_list
);
574 SET_BOOL(encrypt_everything
);
575 SET_BOOL(server_only_was_missing_keystore_migration_time
);
576 SET_BOOL(sync_tab_favicons
);
577 SET_ENUM(passphrase_type
, PassphraseTypeString
);
578 SET(keystore_decryptor_token
, EncryptedDataToValue
);
579 SET_INT64(keystore_migration_time
);
580 SET_INT64(custom_passphrase_time
);
584 scoped_ptr
<base::DictionaryValue
> ArticlePageToValue(
585 const sync_pb::ArticlePage
& proto
) {
586 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
591 scoped_ptr
<base::DictionaryValue
> ArticleSpecificsToValue(
592 const sync_pb::ArticleSpecifics
& proto
) {
593 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
596 SET_REP(pages
, ArticlePageToValue
);
600 scoped_ptr
<base::DictionaryValue
> PasswordSpecificsToValue(
601 const sync_pb::PasswordSpecifics
& proto
) {
602 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
603 SET(encrypted
, EncryptedDataToValue
);
607 scoped_ptr
<base::DictionaryValue
> PreferenceSpecificsToValue(
608 const sync_pb::PreferenceSpecifics
& proto
) {
609 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
615 scoped_ptr
<base::DictionaryValue
> PriorityPreferenceSpecificsToValue(
616 const sync_pb::PriorityPreferenceSpecifics
& specifics
) {
617 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
618 SET_FIELD(preference
, PreferenceSpecificsToValue
);
622 scoped_ptr
<base::DictionaryValue
> SyncedNotificationAppInfoSpecificsToValue(
623 const sync_pb::SyncedNotificationAppInfoSpecifics
& proto
) {
624 return make_scoped_ptr(new base::DictionaryValue());
627 scoped_ptr
<base::DictionaryValue
> SyncedNotificationSpecificsToValue(
628 const sync_pb::SyncedNotificationSpecifics
& proto
) {
629 return make_scoped_ptr(new base::DictionaryValue());
632 scoped_ptr
<base::DictionaryValue
> SearchEngineSpecificsToValue(
633 const sync_pb::SearchEngineSpecifics
& proto
) {
634 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
637 SET_STR(favicon_url
);
639 SET_BOOL(safe_for_autoreplace
);
640 SET_STR(originating_url
);
641 SET_INT64(date_created
);
642 SET_STR(input_encodings
);
643 SET_BOOL(show_in_default_list
);
644 SET_STR(suggestions_url
);
645 SET_INT32(prepopulate_id
);
646 SET_BOOL(autogenerate_keyword
);
647 SET_STR(instant_url
);
648 SET_INT64(last_modified
);
650 SET_STR_REP(alternate_urls
);
651 SET_STR(search_terms_replacement_key
);
653 SET_STR(search_url_post_params
);
654 SET_STR(suggestions_url_post_params
);
655 SET_STR(instant_url_post_params
);
656 SET_STR(image_url_post_params
);
657 SET_STR(new_tab_url
);
661 scoped_ptr
<base::DictionaryValue
> SessionSpecificsToValue(
662 const sync_pb::SessionSpecifics
& proto
) {
663 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
664 SET_STR(session_tag
);
665 SET(header
, SessionHeaderToValue
);
666 SET(tab
, SessionTabToValue
);
667 SET_INT32(tab_node_id
);
671 scoped_ptr
<base::DictionaryValue
> ThemeSpecificsToValue(
672 const sync_pb::ThemeSpecifics
& proto
) {
673 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
674 SET_BOOL(use_custom_theme
);
675 SET_BOOL(use_system_theme_by_default
);
676 SET_STR(custom_theme_name
);
677 SET_STR(custom_theme_id
);
678 SET_STR(custom_theme_update_url
);
682 scoped_ptr
<base::DictionaryValue
> TypedUrlSpecificsToValue(
683 const sync_pb::TypedUrlSpecifics
& proto
) {
684 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
688 SET_INT64_REP(visits
);
689 SET_INT32_REP(visit_transitions
);
693 scoped_ptr
<base::DictionaryValue
> WalletMaskedCreditCardToValue(
694 const sync_pb::WalletMaskedCreditCard
& proto
) {
695 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
697 SET_ENUM(status
, GetWalletCardStatusString
);
698 SET_STR(name_on_card
);
699 SET_ENUM(type
, GetWalletCardTypeString
);
701 SET_INT32(exp_month
);
706 scoped_ptr
<base::DictionaryValue
> WalletPostalAddressToValue(
707 const sync_pb::WalletPostalAddress
& proto
) {
708 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
709 SET_STR(recipient_name
);
710 SET_STR(company_name
);
711 SET_STR_REP(street_address
);
716 SET_STR(postal_code
);
717 SET_STR(sorting_code
);
718 SET_STR(country_code
);
719 SET_STR(phone_number
);
720 SET_STR(language_code
);
724 scoped_ptr
<base::DictionaryValue
> WifiCredentialSpecificsToValue(
725 const sync_pb::WifiCredentialSpecifics
& proto
) {
726 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
728 SET_ENUM(security_class
, GetWifiCredentialSecurityClassString
);
729 SET_BYTES(passphrase
);
733 scoped_ptr
<base::DictionaryValue
> EntitySpecificsToValue(
734 const sync_pb::EntitySpecifics
& specifics
) {
735 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
736 SET_FIELD(app
, AppSpecificsToValue
);
737 SET_FIELD(app_list
, AppListSpecificsToValue
);
738 SET_FIELD(app_notification
, AppNotificationToValue
);
739 SET_FIELD(app_setting
, AppSettingSpecificsToValue
);
740 SET_FIELD(article
, ArticleSpecificsToValue
);
741 SET_FIELD(autofill
, AutofillSpecificsToValue
);
742 SET_FIELD(autofill_profile
, AutofillProfileSpecificsToValue
);
743 SET_FIELD(autofill_wallet
, AutofillWalletSpecificsToValue
);
744 SET_FIELD(wallet_metadata
, WalletMetadataSpecificsToValue
);
745 SET_FIELD(bookmark
, BookmarkSpecificsToValue
);
746 SET_FIELD(device_info
, DeviceInfoSpecificsToValue
);
747 SET_FIELD(dictionary
, DictionarySpecificsToValue
);
748 SET_FIELD(experiments
, ExperimentsSpecificsToValue
);
749 SET_FIELD(extension
, ExtensionSpecificsToValue
);
750 SET_FIELD(extension_setting
, ExtensionSettingSpecificsToValue
);
751 SET_FIELD(favicon_image
, FaviconImageSpecificsToValue
);
752 SET_FIELD(favicon_tracking
, FaviconTrackingSpecificsToValue
);
753 SET_FIELD(history_delete_directive
, HistoryDeleteDirectiveSpecificsToValue
);
754 SET_FIELD(managed_user_setting
, ManagedUserSettingSpecificsToValue
);
755 SET_FIELD(managed_user_shared_setting
,
756 ManagedUserSharedSettingSpecificsToValue
);
757 SET_FIELD(managed_user
, ManagedUserSpecificsToValue
);
758 SET_FIELD(managed_user_whitelist
, ManagedUserWhitelistSpecificsToValue
);
759 SET_FIELD(nigori
, NigoriSpecificsToValue
);
760 SET_FIELD(password
, PasswordSpecificsToValue
);
761 SET_FIELD(preference
, PreferenceSpecificsToValue
);
762 SET_FIELD(priority_preference
, PriorityPreferenceSpecificsToValue
);
763 SET_FIELD(search_engine
, SearchEngineSpecificsToValue
);
764 SET_FIELD(session
, SessionSpecificsToValue
);
765 SET_FIELD(synced_notification
, SyncedNotificationSpecificsToValue
);
766 SET_FIELD(synced_notification_app_info
,
767 SyncedNotificationAppInfoSpecificsToValue
);
768 SET_FIELD(theme
, ThemeSpecificsToValue
);
769 SET_FIELD(typed_url
, TypedUrlSpecificsToValue
);
770 SET_FIELD(wifi_credential
, WifiCredentialSpecificsToValue
);
776 base::StringValue
* UniquePositionToStringValue(
777 const sync_pb::UniquePosition
& proto
) {
778 UniquePosition pos
= UniquePosition::FromProto(proto
);
779 return new base::StringValue(pos
.ToDebugString());
784 scoped_ptr
<base::DictionaryValue
> SyncEntityToValue(
785 const sync_pb::SyncEntity
& proto
,
786 bool include_specifics
) {
787 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
789 SET_STR(parent_id_string
);
790 SET_STR(old_parent_id
);
795 SET_STR(non_unique_name
);
796 SET_INT64(sync_timestamp
);
797 SET_STR(server_defined_unique_tag
);
798 SET_INT64(position_in_parent
);
799 SET(unique_position
, UniquePositionToStringValue
);
800 SET_STR(insert_after_item_id
);
802 SET_STR(originator_cache_guid
);
803 SET_STR(originator_client_item_id
);
804 if (include_specifics
)
805 SET(specifics
, EntitySpecificsToValue
);
807 SET_STR(client_defined_unique_tag
);
808 SET_REP(attachment_id
, AttachmentIdProtoToValue
);
814 base::ListValue
* SyncEntitiesToValue(
815 const ::google::protobuf::RepeatedPtrField
<sync_pb::SyncEntity
>& entities
,
816 bool include_specifics
) {
817 base::ListValue
* list
= new base::ListValue();
818 ::google::protobuf::RepeatedPtrField
<sync_pb::SyncEntity
>::const_iterator it
;
819 for (it
= entities
.begin(); it
!= entities
.end(); ++it
) {
820 list
->Append(SyncEntityToValue(*it
, include_specifics
));
826 scoped_ptr
<base::DictionaryValue
> ChromiumExtensionActivityToValue(
827 const sync_pb::ChromiumExtensionsActivity
& proto
) {
828 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
829 SET_STR(extension_id
);
830 SET_INT32(bookmark_writes_since_last_commit
);
834 scoped_ptr
<base::DictionaryValue
> CommitMessageToValue(
835 const sync_pb::CommitMessage
& proto
,
836 bool include_specifics
) {
837 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
838 value
->Set("entries",
839 SyncEntitiesToValue(proto
.entries(), include_specifics
));
841 SET_REP(extensions_activity
, ChromiumExtensionActivityToValue
);
842 SET(config_params
, ClientConfigParamsToValue
);
846 scoped_ptr
<base::DictionaryValue
> GetUpdateTriggersToValue(
847 const sync_pb::GetUpdateTriggers
& proto
) {
848 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
849 SET_STR_REP(notification_hint
);
850 SET_BOOL(client_dropped_hints
);
851 SET_BOOL(invalidations_out_of_sync
);
852 SET_INT64(local_modification_nudges
);
853 SET_INT64(datatype_refresh_nudges
);
857 scoped_ptr
<base::DictionaryValue
> DataTypeProgressMarkerToValue(
858 const sync_pb::DataTypeProgressMarker
& proto
) {
859 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
860 SET_INT32(data_type_id
);
862 SET_INT64(timestamp_token_for_migration
);
863 SET_STR(notification_hint
);
864 SET(get_update_triggers
, GetUpdateTriggersToValue
);
868 scoped_ptr
<base::DictionaryValue
> DataTypeContextToValue(
869 const sync_pb::DataTypeContext
& proto
) {
870 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
871 SET_INT32(data_type_id
);
877 scoped_ptr
<base::DictionaryValue
> GetUpdatesCallerInfoToValue(
878 const sync_pb::GetUpdatesCallerInfo
& proto
) {
879 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
880 SET_ENUM(source
, GetUpdatesSourceString
);
881 SET_BOOL(notifications_enabled
);
885 scoped_ptr
<base::DictionaryValue
> GetUpdatesMessageToValue(
886 const sync_pb::GetUpdatesMessage
& proto
) {
887 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
888 SET(caller_info
, GetUpdatesCallerInfoToValue
);
889 SET_BOOL(fetch_folders
);
890 SET_INT32(batch_size
);
891 SET_REP(from_progress_marker
, DataTypeProgressMarkerToValue
);
893 SET_BOOL(need_encryption_key
);
894 SET_BOOL(create_mobile_bookmarks_folder
);
895 SET_ENUM(get_updates_origin
, GetUpdatesOriginString
);
896 SET_REP(client_contexts
, DataTypeContextToValue
);
900 scoped_ptr
<base::DictionaryValue
> ClientStatusToValue(
901 const sync_pb::ClientStatus
& proto
) {
902 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
903 SET_BOOL(hierarchy_conflict_detected
);
907 scoped_ptr
<base::DictionaryValue
> EntryResponseToValue(
908 const sync_pb::CommitResponse::EntryResponse
& proto
) {
909 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
910 SET_ENUM(response_type
, GetResponseTypeString
);
912 SET_STR(parent_id_string
);
913 SET_INT64(position_in_parent
);
916 SET_STR(error_message
);
921 scoped_ptr
<base::DictionaryValue
> CommitResponseToValue(
922 const sync_pb::CommitResponse
& proto
) {
923 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
924 SET_REP(entryresponse
, EntryResponseToValue
);
928 scoped_ptr
<base::DictionaryValue
> GetUpdatesResponseToValue(
929 const sync_pb::GetUpdatesResponse
& proto
,
930 bool include_specifics
) {
931 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
932 value
->Set("entries",
933 SyncEntitiesToValue(proto
.entries(), include_specifics
));
934 SET_INT64(changes_remaining
);
935 SET_REP(new_progress_marker
, DataTypeProgressMarkerToValue
);
936 SET_REP(context_mutations
, DataTypeContextToValue
);
940 scoped_ptr
<base::DictionaryValue
> ClientCommandToValue(
941 const sync_pb::ClientCommand
& proto
) {
942 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
943 SET_INT32(set_sync_poll_interval
);
944 SET_INT32(set_sync_long_poll_interval
);
945 SET_INT32(max_commit_batch_size
);
946 SET_INT32(sessions_commit_delay_seconds
);
947 SET_INT32(throttle_delay_seconds
);
948 SET_INT32(client_invalidation_hint_buffer_size
);
952 scoped_ptr
<base::DictionaryValue
> ErrorToValue(
953 const sync_pb::ClientToServerResponse::Error
& proto
) {
954 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
955 SET_ENUM(error_type
, GetErrorTypeString
);
956 SET_STR(error_description
);
958 SET_ENUM(action
, GetActionString
);
964 scoped_ptr
<base::DictionaryValue
> ClientToServerResponseToValue(
965 const sync_pb::ClientToServerResponse
& proto
,
966 bool include_specifics
) {
967 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
968 SET(commit
, CommitResponseToValue
);
969 if (proto
.has_get_updates()) {
970 value
->Set("get_updates", GetUpdatesResponseToValue(proto
.get_updates(),
974 SET(error
, ErrorToValue
);
975 SET_ENUM(error_code
, GetErrorTypeString
);
976 SET_STR(error_message
);
977 SET_STR(store_birthday
);
978 SET(client_command
, ClientCommandToValue
);
979 SET_INT32_REP(migrated_data_type_id
);
983 scoped_ptr
<base::DictionaryValue
> ClientToServerMessageToValue(
984 const sync_pb::ClientToServerMessage
& proto
,
985 bool include_specifics
) {
986 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
988 SET_INT32(protocol_version
);
989 if (proto
.has_commit()) {
991 CommitMessageToValue(proto
.commit(), include_specifics
));
994 SET(get_updates
, GetUpdatesMessageToValue
);
995 SET_STR(store_birthday
);
996 SET_BOOL(sync_problem_detected
);
997 SET(debug_info
, DebugInfoToValue
);
998 SET(client_status
, ClientStatusToValue
);
1002 scoped_ptr
<base::DictionaryValue
> DatatypeAssociationStatsToValue(
1003 const sync_pb::DatatypeAssociationStats
& proto
) {
1004 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1005 SET_INT32(data_type_id
);
1006 SET_INT32(num_local_items_before_association
);
1007 SET_INT32(num_sync_items_before_association
);
1008 SET_INT32(num_local_items_after_association
);
1009 SET_INT32(num_sync_items_after_association
);
1010 SET_INT32(num_local_items_added
);
1011 SET_INT32(num_local_items_deleted
);
1012 SET_INT32(num_local_items_modified
);
1013 SET_INT32(num_sync_items_added
);
1014 SET_INT32(num_sync_items_deleted
);
1015 SET_INT32(num_sync_items_modified
);
1016 SET_INT64(local_version_pre_association
);
1017 SET_INT64(sync_version_pre_association
)
1018 SET_BOOL(had_error
);
1019 SET_INT64(download_wait_time_us
);
1020 SET_INT64(download_time_us
);
1021 SET_INT64(association_wait_time_for_high_priority_us
);
1022 SET_INT64(association_wait_time_for_same_priority_us
);
1026 scoped_ptr
<base::DictionaryValue
> DebugEventInfoToValue(
1027 const sync_pb::DebugEventInfo
& proto
) {
1028 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1029 SET_ENUM(singleton_event
, SingletonDebugEventTypeString
);
1030 SET(sync_cycle_completed_event_info
, SyncCycleCompletedEventInfoToValue
);
1031 SET_INT32(nudging_datatype
);
1032 SET_INT32_REP(datatypes_notified_from_server
);
1033 SET(datatype_association_stats
, DatatypeAssociationStatsToValue
);
1037 scoped_ptr
<base::DictionaryValue
> DebugInfoToValue(
1038 const sync_pb::DebugInfo
& proto
) {
1039 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1040 SET_REP(events
, DebugEventInfoToValue
);
1041 SET_BOOL(cryptographer_ready
);
1042 SET_BOOL(cryptographer_has_pending_keys
);
1043 SET_BOOL(events_dropped
);
1047 scoped_ptr
<base::DictionaryValue
> SyncCycleCompletedEventInfoToValue(
1048 const sync_pb::SyncCycleCompletedEventInfo
& proto
) {
1049 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1050 SET_INT32(num_encryption_conflicts
);
1051 SET_INT32(num_hierarchy_conflicts
);
1052 SET_INT32(num_server_conflicts
);
1053 SET_INT32(num_updates_downloaded
);
1054 SET_INT32(num_reflected_updates_downloaded
);
1055 SET(caller_info
, GetUpdatesCallerInfoToValue
);
1059 scoped_ptr
<base::DictionaryValue
> ClientConfigParamsToValue(
1060 const sync_pb::ClientConfigParams
& proto
) {
1061 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1062 SET_INT32_REP(enabled_type_ids
);
1063 SET_BOOL(tabs_datatype_enabled
);
1067 scoped_ptr
<base::DictionaryValue
> AttachmentIdProtoToValue(
1068 const sync_pb::AttachmentIdProto
& proto
) {
1069 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1082 #undef SET_INT64_REP
1088 } // namespace syncer