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(sync_tab_favicons
);
576 SET_ENUM(passphrase_type
, PassphraseTypeString
);
577 SET(keystore_decryptor_token
, EncryptedDataToValue
);
578 SET_INT64(keystore_migration_time
);
579 SET_INT64(custom_passphrase_time
);
583 scoped_ptr
<base::DictionaryValue
> ArticlePageToValue(
584 const sync_pb::ArticlePage
& proto
) {
585 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
590 scoped_ptr
<base::DictionaryValue
> ArticleSpecificsToValue(
591 const sync_pb::ArticleSpecifics
& proto
) {
592 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
595 SET_REP(pages
, ArticlePageToValue
);
599 scoped_ptr
<base::DictionaryValue
> PasswordSpecificsToValue(
600 const sync_pb::PasswordSpecifics
& proto
) {
601 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
602 SET(encrypted
, EncryptedDataToValue
);
606 scoped_ptr
<base::DictionaryValue
> PreferenceSpecificsToValue(
607 const sync_pb::PreferenceSpecifics
& proto
) {
608 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
614 scoped_ptr
<base::DictionaryValue
> PriorityPreferenceSpecificsToValue(
615 const sync_pb::PriorityPreferenceSpecifics
& specifics
) {
616 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
617 SET_FIELD(preference
, PreferenceSpecificsToValue
);
621 scoped_ptr
<base::DictionaryValue
> SyncedNotificationAppInfoSpecificsToValue(
622 const sync_pb::SyncedNotificationAppInfoSpecifics
& proto
) {
623 return make_scoped_ptr(new base::DictionaryValue());
626 scoped_ptr
<base::DictionaryValue
> SyncedNotificationSpecificsToValue(
627 const sync_pb::SyncedNotificationSpecifics
& proto
) {
628 return make_scoped_ptr(new base::DictionaryValue());
631 scoped_ptr
<base::DictionaryValue
> SearchEngineSpecificsToValue(
632 const sync_pb::SearchEngineSpecifics
& proto
) {
633 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
636 SET_STR(favicon_url
);
638 SET_BOOL(safe_for_autoreplace
);
639 SET_STR(originating_url
);
640 SET_INT64(date_created
);
641 SET_STR(input_encodings
);
642 SET_BOOL(show_in_default_list
);
643 SET_STR(suggestions_url
);
644 SET_INT32(prepopulate_id
);
645 SET_BOOL(autogenerate_keyword
);
646 SET_STR(instant_url
);
647 SET_INT64(last_modified
);
649 SET_STR_REP(alternate_urls
);
650 SET_STR(search_terms_replacement_key
);
652 SET_STR(search_url_post_params
);
653 SET_STR(suggestions_url_post_params
);
654 SET_STR(instant_url_post_params
);
655 SET_STR(image_url_post_params
);
656 SET_STR(new_tab_url
);
660 scoped_ptr
<base::DictionaryValue
> SessionSpecificsToValue(
661 const sync_pb::SessionSpecifics
& proto
) {
662 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
663 SET_STR(session_tag
);
664 SET(header
, SessionHeaderToValue
);
665 SET(tab
, SessionTabToValue
);
666 SET_INT32(tab_node_id
);
670 scoped_ptr
<base::DictionaryValue
> ThemeSpecificsToValue(
671 const sync_pb::ThemeSpecifics
& proto
) {
672 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
673 SET_BOOL(use_custom_theme
);
674 SET_BOOL(use_system_theme_by_default
);
675 SET_STR(custom_theme_name
);
676 SET_STR(custom_theme_id
);
677 SET_STR(custom_theme_update_url
);
681 scoped_ptr
<base::DictionaryValue
> TypedUrlSpecificsToValue(
682 const sync_pb::TypedUrlSpecifics
& proto
) {
683 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
687 SET_INT64_REP(visits
);
688 SET_INT32_REP(visit_transitions
);
692 scoped_ptr
<base::DictionaryValue
> WalletMaskedCreditCardToValue(
693 const sync_pb::WalletMaskedCreditCard
& proto
) {
694 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
696 SET_ENUM(status
, GetWalletCardStatusString
);
697 SET_STR(name_on_card
);
698 SET_ENUM(type
, GetWalletCardTypeString
);
700 SET_INT32(exp_month
);
705 scoped_ptr
<base::DictionaryValue
> WalletPostalAddressToValue(
706 const sync_pb::WalletPostalAddress
& proto
) {
707 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
708 SET_STR(recipient_name
);
709 SET_STR(company_name
);
710 SET_STR_REP(street_address
);
715 SET_STR(postal_code
);
716 SET_STR(sorting_code
);
717 SET_STR(country_code
);
718 SET_STR(phone_number
);
719 SET_STR(language_code
);
723 scoped_ptr
<base::DictionaryValue
> WifiCredentialSpecificsToValue(
724 const sync_pb::WifiCredentialSpecifics
& proto
) {
725 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
727 SET_ENUM(security_class
, GetWifiCredentialSecurityClassString
);
728 SET_BYTES(passphrase
);
732 scoped_ptr
<base::DictionaryValue
> EntitySpecificsToValue(
733 const sync_pb::EntitySpecifics
& specifics
) {
734 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
735 SET_FIELD(app
, AppSpecificsToValue
);
736 SET_FIELD(app_list
, AppListSpecificsToValue
);
737 SET_FIELD(app_notification
, AppNotificationToValue
);
738 SET_FIELD(app_setting
, AppSettingSpecificsToValue
);
739 SET_FIELD(article
, ArticleSpecificsToValue
);
740 SET_FIELD(autofill
, AutofillSpecificsToValue
);
741 SET_FIELD(autofill_profile
, AutofillProfileSpecificsToValue
);
742 SET_FIELD(autofill_wallet
, AutofillWalletSpecificsToValue
);
743 SET_FIELD(wallet_metadata
, WalletMetadataSpecificsToValue
);
744 SET_FIELD(bookmark
, BookmarkSpecificsToValue
);
745 SET_FIELD(device_info
, DeviceInfoSpecificsToValue
);
746 SET_FIELD(dictionary
, DictionarySpecificsToValue
);
747 SET_FIELD(experiments
, ExperimentsSpecificsToValue
);
748 SET_FIELD(extension
, ExtensionSpecificsToValue
);
749 SET_FIELD(extension_setting
, ExtensionSettingSpecificsToValue
);
750 SET_FIELD(favicon_image
, FaviconImageSpecificsToValue
);
751 SET_FIELD(favicon_tracking
, FaviconTrackingSpecificsToValue
);
752 SET_FIELD(history_delete_directive
, HistoryDeleteDirectiveSpecificsToValue
);
753 SET_FIELD(managed_user_setting
, ManagedUserSettingSpecificsToValue
);
754 SET_FIELD(managed_user_shared_setting
,
755 ManagedUserSharedSettingSpecificsToValue
);
756 SET_FIELD(managed_user
, ManagedUserSpecificsToValue
);
757 SET_FIELD(managed_user_whitelist
, ManagedUserWhitelistSpecificsToValue
);
758 SET_FIELD(nigori
, NigoriSpecificsToValue
);
759 SET_FIELD(password
, PasswordSpecificsToValue
);
760 SET_FIELD(preference
, PreferenceSpecificsToValue
);
761 SET_FIELD(priority_preference
, PriorityPreferenceSpecificsToValue
);
762 SET_FIELD(search_engine
, SearchEngineSpecificsToValue
);
763 SET_FIELD(session
, SessionSpecificsToValue
);
764 SET_FIELD(synced_notification
, SyncedNotificationSpecificsToValue
);
765 SET_FIELD(synced_notification_app_info
,
766 SyncedNotificationAppInfoSpecificsToValue
);
767 SET_FIELD(theme
, ThemeSpecificsToValue
);
768 SET_FIELD(typed_url
, TypedUrlSpecificsToValue
);
769 SET_FIELD(wifi_credential
, WifiCredentialSpecificsToValue
);
775 base::StringValue
* UniquePositionToStringValue(
776 const sync_pb::UniquePosition
& proto
) {
777 UniquePosition pos
= UniquePosition::FromProto(proto
);
778 return new base::StringValue(pos
.ToDebugString());
783 scoped_ptr
<base::DictionaryValue
> SyncEntityToValue(
784 const sync_pb::SyncEntity
& proto
,
785 bool include_specifics
) {
786 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
788 SET_STR(parent_id_string
);
789 SET_STR(old_parent_id
);
794 SET_STR(non_unique_name
);
795 SET_INT64(sync_timestamp
);
796 SET_STR(server_defined_unique_tag
);
797 SET_INT64(position_in_parent
);
798 SET(unique_position
, UniquePositionToStringValue
);
799 SET_STR(insert_after_item_id
);
801 SET_STR(originator_cache_guid
);
802 SET_STR(originator_client_item_id
);
803 if (include_specifics
)
804 SET(specifics
, EntitySpecificsToValue
);
806 SET_STR(client_defined_unique_tag
);
807 SET_REP(attachment_id
, AttachmentIdProtoToValue
);
813 base::ListValue
* SyncEntitiesToValue(
814 const ::google::protobuf::RepeatedPtrField
<sync_pb::SyncEntity
>& entities
,
815 bool include_specifics
) {
816 base::ListValue
* list
= new base::ListValue();
817 ::google::protobuf::RepeatedPtrField
<sync_pb::SyncEntity
>::const_iterator it
;
818 for (it
= entities
.begin(); it
!= entities
.end(); ++it
) {
819 list
->Append(SyncEntityToValue(*it
, include_specifics
));
825 scoped_ptr
<base::DictionaryValue
> ChromiumExtensionActivityToValue(
826 const sync_pb::ChromiumExtensionsActivity
& proto
) {
827 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
828 SET_STR(extension_id
);
829 SET_INT32(bookmark_writes_since_last_commit
);
833 scoped_ptr
<base::DictionaryValue
> CommitMessageToValue(
834 const sync_pb::CommitMessage
& proto
,
835 bool include_specifics
) {
836 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
837 value
->Set("entries",
838 SyncEntitiesToValue(proto
.entries(), include_specifics
));
840 SET_REP(extensions_activity
, ChromiumExtensionActivityToValue
);
841 SET(config_params
, ClientConfigParamsToValue
);
845 scoped_ptr
<base::DictionaryValue
> GetUpdateTriggersToValue(
846 const sync_pb::GetUpdateTriggers
& proto
) {
847 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
848 SET_STR_REP(notification_hint
);
849 SET_BOOL(client_dropped_hints
);
850 SET_BOOL(invalidations_out_of_sync
);
851 SET_INT64(local_modification_nudges
);
852 SET_INT64(datatype_refresh_nudges
);
856 scoped_ptr
<base::DictionaryValue
> DataTypeProgressMarkerToValue(
857 const sync_pb::DataTypeProgressMarker
& proto
) {
858 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
859 SET_INT32(data_type_id
);
861 SET_INT64(timestamp_token_for_migration
);
862 SET_STR(notification_hint
);
863 SET(get_update_triggers
, GetUpdateTriggersToValue
);
867 scoped_ptr
<base::DictionaryValue
> DataTypeContextToValue(
868 const sync_pb::DataTypeContext
& proto
) {
869 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
870 SET_INT32(data_type_id
);
876 scoped_ptr
<base::DictionaryValue
> GetUpdatesCallerInfoToValue(
877 const sync_pb::GetUpdatesCallerInfo
& proto
) {
878 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
879 SET_ENUM(source
, GetUpdatesSourceString
);
880 SET_BOOL(notifications_enabled
);
884 scoped_ptr
<base::DictionaryValue
> GetUpdatesMessageToValue(
885 const sync_pb::GetUpdatesMessage
& proto
) {
886 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
887 SET(caller_info
, GetUpdatesCallerInfoToValue
);
888 SET_BOOL(fetch_folders
);
889 SET_INT32(batch_size
);
890 SET_REP(from_progress_marker
, DataTypeProgressMarkerToValue
);
892 SET_BOOL(need_encryption_key
);
893 SET_BOOL(create_mobile_bookmarks_folder
);
894 SET_ENUM(get_updates_origin
, GetUpdatesOriginString
);
895 SET_REP(client_contexts
, DataTypeContextToValue
);
899 scoped_ptr
<base::DictionaryValue
> ClientStatusToValue(
900 const sync_pb::ClientStatus
& proto
) {
901 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
902 SET_BOOL(hierarchy_conflict_detected
);
906 scoped_ptr
<base::DictionaryValue
> EntryResponseToValue(
907 const sync_pb::CommitResponse::EntryResponse
& proto
) {
908 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
909 SET_ENUM(response_type
, GetResponseTypeString
);
911 SET_STR(parent_id_string
);
912 SET_INT64(position_in_parent
);
915 SET_STR(error_message
);
920 scoped_ptr
<base::DictionaryValue
> CommitResponseToValue(
921 const sync_pb::CommitResponse
& proto
) {
922 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
923 SET_REP(entryresponse
, EntryResponseToValue
);
927 scoped_ptr
<base::DictionaryValue
> GetUpdatesResponseToValue(
928 const sync_pb::GetUpdatesResponse
& proto
,
929 bool include_specifics
) {
930 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
931 value
->Set("entries",
932 SyncEntitiesToValue(proto
.entries(), include_specifics
));
933 SET_INT64(changes_remaining
);
934 SET_REP(new_progress_marker
, DataTypeProgressMarkerToValue
);
935 SET_REP(context_mutations
, DataTypeContextToValue
);
939 scoped_ptr
<base::DictionaryValue
> ClientCommandToValue(
940 const sync_pb::ClientCommand
& proto
) {
941 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
942 SET_INT32(set_sync_poll_interval
);
943 SET_INT32(set_sync_long_poll_interval
);
944 SET_INT32(max_commit_batch_size
);
945 SET_INT32(sessions_commit_delay_seconds
);
946 SET_INT32(throttle_delay_seconds
);
947 SET_INT32(client_invalidation_hint_buffer_size
);
951 scoped_ptr
<base::DictionaryValue
> ErrorToValue(
952 const sync_pb::ClientToServerResponse::Error
& proto
) {
953 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
954 SET_ENUM(error_type
, GetErrorTypeString
);
955 SET_STR(error_description
);
957 SET_ENUM(action
, GetActionString
);
963 scoped_ptr
<base::DictionaryValue
> ClientToServerResponseToValue(
964 const sync_pb::ClientToServerResponse
& proto
,
965 bool include_specifics
) {
966 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
967 SET(commit
, CommitResponseToValue
);
968 if (proto
.has_get_updates()) {
969 value
->Set("get_updates", GetUpdatesResponseToValue(proto
.get_updates(),
973 SET(error
, ErrorToValue
);
974 SET_ENUM(error_code
, GetErrorTypeString
);
975 SET_STR(error_message
);
976 SET_STR(store_birthday
);
977 SET(client_command
, ClientCommandToValue
);
978 SET_INT32_REP(migrated_data_type_id
);
982 scoped_ptr
<base::DictionaryValue
> ClientToServerMessageToValue(
983 const sync_pb::ClientToServerMessage
& proto
,
984 bool include_specifics
) {
985 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
987 SET_INT32(protocol_version
);
988 if (proto
.has_commit()) {
990 CommitMessageToValue(proto
.commit(), include_specifics
));
993 SET(get_updates
, GetUpdatesMessageToValue
);
994 SET_STR(store_birthday
);
995 SET_BOOL(sync_problem_detected
);
996 SET(debug_info
, DebugInfoToValue
);
997 SET(client_status
, ClientStatusToValue
);
1001 scoped_ptr
<base::DictionaryValue
> DatatypeAssociationStatsToValue(
1002 const sync_pb::DatatypeAssociationStats
& proto
) {
1003 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1004 SET_INT32(data_type_id
);
1005 SET_INT32(num_local_items_before_association
);
1006 SET_INT32(num_sync_items_before_association
);
1007 SET_INT32(num_local_items_after_association
);
1008 SET_INT32(num_sync_items_after_association
);
1009 SET_INT32(num_local_items_added
);
1010 SET_INT32(num_local_items_deleted
);
1011 SET_INT32(num_local_items_modified
);
1012 SET_INT32(num_sync_items_added
);
1013 SET_INT32(num_sync_items_deleted
);
1014 SET_INT32(num_sync_items_modified
);
1015 SET_INT64(local_version_pre_association
);
1016 SET_INT64(sync_version_pre_association
)
1017 SET_BOOL(had_error
);
1018 SET_INT64(download_wait_time_us
);
1019 SET_INT64(download_time_us
);
1020 SET_INT64(association_wait_time_for_high_priority_us
);
1021 SET_INT64(association_wait_time_for_same_priority_us
);
1025 scoped_ptr
<base::DictionaryValue
> DebugEventInfoToValue(
1026 const sync_pb::DebugEventInfo
& proto
) {
1027 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1028 SET_ENUM(singleton_event
, SingletonDebugEventTypeString
);
1029 SET(sync_cycle_completed_event_info
, SyncCycleCompletedEventInfoToValue
);
1030 SET_INT32(nudging_datatype
);
1031 SET_INT32_REP(datatypes_notified_from_server
);
1032 SET(datatype_association_stats
, DatatypeAssociationStatsToValue
);
1036 scoped_ptr
<base::DictionaryValue
> DebugInfoToValue(
1037 const sync_pb::DebugInfo
& proto
) {
1038 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1039 SET_REP(events
, DebugEventInfoToValue
);
1040 SET_BOOL(cryptographer_ready
);
1041 SET_BOOL(cryptographer_has_pending_keys
);
1042 SET_BOOL(events_dropped
);
1046 scoped_ptr
<base::DictionaryValue
> SyncCycleCompletedEventInfoToValue(
1047 const sync_pb::SyncCycleCompletedEventInfo
& proto
) {
1048 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1049 SET_INT32(num_encryption_conflicts
);
1050 SET_INT32(num_hierarchy_conflicts
);
1051 SET_INT32(num_server_conflicts
);
1052 SET_INT32(num_updates_downloaded
);
1053 SET_INT32(num_reflected_updates_downloaded
);
1054 SET(caller_info
, GetUpdatesCallerInfoToValue
);
1058 scoped_ptr
<base::DictionaryValue
> ClientConfigParamsToValue(
1059 const sync_pb::ClientConfigParams
& proto
) {
1060 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1061 SET_INT32_REP(enabled_type_ids
);
1062 SET_BOOL(tabs_datatype_enabled
);
1066 scoped_ptr
<base::DictionaryValue
> AttachmentIdProtoToValue(
1067 const sync_pb::AttachmentIdProto
& proto
) {
1068 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
1081 #undef SET_INT64_REP
1087 } // namespace syncer