Remove link_chrome_on_windows GN flag.
[chromium-blink-merge.git] / sync / protocol / proto_value_conversions.cc
blobd3f22fa0613f1138b543b35cbc0df2f53945a76c
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"
9 #include <string>
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"
46 namespace syncer {
48 namespace {
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.
69 template <class T>
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();
80 ++it) {
81 list->Append(converter_fn(*it));
83 return list;
86 base::StringValue* MakeTimestampValue(int64 tm) {
87 return new base::StringValue(
88 base::TimeFormatShortDateAndTime(syncer::ProtoTimeToTime(tm)));
91 } // namespace
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) \
113 value->Set(#field, \
114 MakeRepeatedValue<const std::string&, \
115 google::protobuf::RepeatedPtrField< \
116 std::string >, \
117 base::StringValue>(proto.field(), \
118 MakeStringValue))
119 #define SET_EXPERIMENT_ENABLED_FIELD(field) \
120 do { \
121 if (proto.has_##field() && \
122 proto.field().has_enabled()) { \
123 value->Set(#field, \
124 new base::FundamentalValue( \
125 proto.field().enabled())); \
127 } while (0)
129 #define SET_FIELD(field, fn) \
130 do { \
131 if (specifics.has_##field()) { \
132 value->Set(#field, fn(specifics.field())); \
134 } while (0)
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();
142 SET_STR(key_name);
143 // TODO(akalin): Shouldn't blob be of type bytes instead of string?
144 SET_BYTES(blob);
145 return value;
148 base::DictionaryValue* AppSettingsToValue(
149 const sync_pb::AppNotificationSettings& proto) {
150 base::DictionaryValue* value = new base::DictionaryValue();
151 SET_BOOL(initial_setup_done);
152 SET_BOOL(disabled);
153 SET_STR(oauth_client_id);
154 return value;
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);
163 return value;
166 base::DictionaryValue* SessionTabToValue(const sync_pb::SessionTab& proto) {
167 base::DictionaryValue* value = new base::DictionaryValue();
168 SET_INT32(tab_id);
169 SET_INT32(window_id);
170 SET_INT32(tab_visual_index);
171 SET_INT32(current_navigation_index);
172 SET_BOOL(pinned);
173 SET_STR(extension_app_id);
174 SET_REP(navigation, TabNavigationToValue);
175 SET_BYTES(favicon);
176 SET_ENUM(favicon_type, GetFaviconTypeString);
177 SET_STR(favicon_source);
178 SET_REP(variation_id, MakeInt64Value);
179 return value;
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);
187 SET_INT32_REP(tab);
188 SET_ENUM(browser_type, GetBrowserTypeString);
189 return value;
192 base::DictionaryValue* TabNavigationToValue(
193 const sync_pb::TabNavigation& proto) {
194 base::DictionaryValue* value = new base::DictionaryValue();
195 SET_STR(virtual_url);
196 SET_STR(referrer);
197 SET_STR(title);
198 SET_STR(state);
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);
219 return value;
222 base::DictionaryValue* NavigationRedirectToValue(
223 const sync_pb::NavigationRedirect& proto) {
224 base::DictionaryValue* value = new base::DictionaryValue();
225 SET_STR(url);
226 return value;
229 base::DictionaryValue* PasswordSpecificsDataToValue(
230 const sync_pb::PasswordSpecificsData& proto) {
231 base::DictionaryValue* value = new base::DictionaryValue();
232 SET_INT32(scheme);
233 SET_STR(signon_realm);
234 SET_STR(origin);
235 SET_STR(action);
236 SET_STR(username_element);
237 SET_STR(username_value);
238 SET_STR(password_element);
239 value->SetString("password_value", "<redacted>");
240 SET_BOOL(ssl_valid);
241 SET_BOOL(preferred);
242 SET_INT64(date_created);
243 SET_BOOL(blacklisted);
244 SET_INT32(type);
245 SET_INT32(times_used);
246 SET_STR(display_name);
247 SET_STR(avatar_url);
248 SET_STR(federation_url);
249 return value;
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);
258 return value;
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);
266 return value;
269 base::DictionaryValue* AppListSpecificsToValue(
270 const sync_pb::AppListSpecifics& proto) {
271 base::DictionaryValue* value = new base::DictionaryValue();
272 SET_STR(item_id);
273 SET_ENUM(item_type, GetAppListItemTypeString);
274 SET_STR(item_name);
275 SET_STR(parent_id);
276 SET_STR(item_ordinal);
278 return value;
281 base::DictionaryValue* AppNotificationToValue(
282 const sync_pb::AppNotification& proto) {
283 base::DictionaryValue* value = new base::DictionaryValue();
284 SET_STR(guid);
285 SET_STR(app_id);
286 SET_INT64(creation_timestamp_ms);
287 SET_STR(title);
288 SET_STR(body_text);
289 SET_STR(link_url);
290 SET_STR(link_text);
291 return value;
294 base::DictionaryValue* AppSettingSpecificsToValue(
295 const sync_pb::AppSettingSpecifics& proto) {
296 base::DictionaryValue* value = new base::DictionaryValue();
297 SET(extension_setting, ExtensionSettingSpecificsToValue);
298 return value;
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);
312 return value;
315 base::DictionaryValue* AutofillSpecificsToValue(
316 const sync_pb::AutofillSpecifics& proto) {
317 base::DictionaryValue* value = new base::DictionaryValue();
318 SET_STR(name);
319 SET_STR(value);
320 SET_INT64_REP(usage_timestamp);
321 SET(profile, AutofillProfileSpecificsToValue);
322 return value;
325 base::DictionaryValue* AutofillProfileSpecificsToValue(
326 const sync_pb::AutofillProfileSpecifics& proto) {
327 base::DictionaryValue* value = new base::DictionaryValue();
328 SET_STR(guid);
329 SET_STR(origin);
330 SET_INT64(use_count);
331 SET_INT64(use_date);
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);
353 return value;
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()));
368 return value;
371 base::DictionaryValue* MetaInfoToValue(
372 const sync_pb::MetaInfo& proto) {
373 base::DictionaryValue* value = new base::DictionaryValue();
374 SET_STR(key);
375 SET_STR(value);
376 return value;
379 base::DictionaryValue* BookmarkSpecificsToValue(
380 const sync_pb::BookmarkSpecifics& proto) {
381 base::DictionaryValue* value = new base::DictionaryValue();
382 SET_STR(url);
383 SET_BYTES(favicon);
384 SET_STR(title);
385 SET_INT64(creation_time_us);
386 SET_STR(icon_url);
387 SET_REP(meta_info, &MetaInfoToValue);
388 return value;
391 base::DictionaryValue* DeviceInfoSpecificsToValue(
392 const sync_pb::DeviceInfoSpecifics& proto) {
393 base::DictionaryValue* value = new base::DictionaryValue();
394 SET_STR(cache_guid);
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);
401 return value;
404 base::DictionaryValue* DictionarySpecificsToValue(
405 const sync_pb::DictionarySpecifics& proto) {
406 base::DictionaryValue* value = new base::DictionaryValue();
407 SET_STR(word);
408 return value;
411 namespace {
413 base::DictionaryValue* FaviconSyncFlagsToValue(
414 const sync_pb::FaviconSyncFlags& proto) {
415 base::DictionaryValue* value = new base::DictionaryValue();
416 SET_BOOL(enabled);
417 SET_INT32(favicon_sync_limit);
418 return value;
421 base::DictionaryValue* EnhancedBookmarksFlagsToValue(
422 const sync_pb::EnhancedBookmarksFlags& proto) {
423 base::DictionaryValue* value = new base::DictionaryValue();
424 SET_BOOL(enabled);
425 SET_STR(extension_id);
426 return value;
429 } // namespace
431 base::DictionaryValue* ExperimentsSpecificsToValue(
432 const sync_pb::ExperimentsSpecifics& proto) {
433 base::DictionaryValue* value = new base::DictionaryValue();
434 SET_EXPERIMENT_ENABLED_FIELD(keystore_encryption);
435 SET_EXPERIMENT_ENABLED_FIELD(history_delete_directives);
436 SET_EXPERIMENT_ENABLED_FIELD(autofill_culling);
437 SET_EXPERIMENT_ENABLED_FIELD(pre_commit_update_avoidance);
438 SET(favicon_sync, FaviconSyncFlagsToValue);
439 SET_EXPERIMENT_ENABLED_FIELD(gcm_channel);
440 SET(enhanced_bookmarks, EnhancedBookmarksFlagsToValue);
441 SET_EXPERIMENT_ENABLED_FIELD(gcm_invalidations);
442 SET_EXPERIMENT_ENABLED_FIELD(wallet_sync);
443 return value;
446 base::DictionaryValue* ExtensionSettingSpecificsToValue(
447 const sync_pb::ExtensionSettingSpecifics& proto) {
448 base::DictionaryValue* value = new base::DictionaryValue();
449 SET_STR(extension_id);
450 SET_STR(key);
451 SET_STR(value);
452 return value;
455 base::DictionaryValue* ExtensionSpecificsToValue(
456 const sync_pb::ExtensionSpecifics& proto) {
457 base::DictionaryValue* value = new base::DictionaryValue();
458 SET_STR(id);
459 SET_STR(version);
460 SET_STR(update_url);
461 SET_BOOL(enabled);
462 SET_BOOL(incognito_enabled);
463 SET_BOOL(remote_install);
464 SET_BOOL(installed_by_custodian);
465 SET_BOOL(all_urls_enabled);
466 SET_STR(name);
467 return value;
470 namespace {
471 base::DictionaryValue* FaviconDataToValue(
472 const sync_pb::FaviconData& proto) {
473 base::DictionaryValue* value = new base::DictionaryValue();
474 SET_BYTES(favicon);
475 SET_INT32(width);
476 SET_INT32(height);
477 return value;
479 } // namespace
481 base::DictionaryValue* FaviconImageSpecificsToValue(
482 const sync_pb::FaviconImageSpecifics& proto) {
483 base::DictionaryValue* value = new base::DictionaryValue();
484 SET_STR(favicon_url);
485 SET(favicon_web, FaviconDataToValue);
486 SET(favicon_web_32, FaviconDataToValue);
487 SET(favicon_touch_64, FaviconDataToValue);
488 SET(favicon_touch_precomposed_64, FaviconDataToValue);
489 return value;
492 base::DictionaryValue* FaviconTrackingSpecificsToValue(
493 const sync_pb::FaviconTrackingSpecifics& proto) {
494 base::DictionaryValue* value = new base::DictionaryValue();
495 SET_STR(favicon_url);
496 SET_INT64(last_visit_time_ms)
497 SET_BOOL(is_bookmarked);
498 return value;
501 base::DictionaryValue* HistoryDeleteDirectiveSpecificsToValue(
502 const sync_pb::HistoryDeleteDirectiveSpecifics& proto) {
503 base::DictionaryValue* value = new base::DictionaryValue();
504 SET(global_id_directive, GlobalIdDirectiveToValue);
505 SET(time_range_directive, TimeRangeDirectiveToValue);
506 return value;
509 base::DictionaryValue* ManagedUserSettingSpecificsToValue(
510 const sync_pb::ManagedUserSettingSpecifics& proto) {
511 base::DictionaryValue* value = new base::DictionaryValue();
512 SET_STR(name);
513 SET_STR(value);
514 return value;
517 base::DictionaryValue* ManagedUserSpecificsToValue(
518 const sync_pb::ManagedUserSpecifics& proto) {
519 base::DictionaryValue* value = new base::DictionaryValue();
520 SET_STR(id);
521 SET_STR(name);
522 SET_BOOL(acknowledged);
523 SET_STR(master_key);
524 SET_STR(chrome_avatar);
525 SET_STR(chromeos_avatar);
526 return value;
529 base::DictionaryValue* ManagedUserSharedSettingSpecificsToValue(
530 const sync_pb::ManagedUserSharedSettingSpecifics& proto) {
531 base::DictionaryValue* value = new base::DictionaryValue();
532 SET_STR(mu_id);
533 SET_STR(key);
534 SET_STR(value);
535 SET_BOOL(acknowledged);
536 return value;
539 base::DictionaryValue* ManagedUserWhitelistSpecificsToValue(
540 const sync_pb::ManagedUserWhitelistSpecifics& proto) {
541 base::DictionaryValue* value = new base::DictionaryValue();
542 SET_STR(id);
543 SET_STR(name);
544 return value;
547 base::DictionaryValue* NigoriSpecificsToValue(
548 const sync_pb::NigoriSpecifics& proto) {
549 base::DictionaryValue* value = new base::DictionaryValue();
550 SET(encryption_keybag, EncryptedDataToValue);
551 SET_BOOL(keybag_is_frozen);
552 SET_BOOL(encrypt_bookmarks);
553 SET_BOOL(encrypt_preferences);
554 SET_BOOL(encrypt_autofill_profile);
555 SET_BOOL(encrypt_autofill);
556 SET_BOOL(encrypt_themes);
557 SET_BOOL(encrypt_typed_urls);
558 SET_BOOL(encrypt_extension_settings);
559 SET_BOOL(encrypt_extensions);
560 SET_BOOL(encrypt_sessions);
561 SET_BOOL(encrypt_app_settings);
562 SET_BOOL(encrypt_apps);
563 SET_BOOL(encrypt_search_engines);
564 SET_BOOL(encrypt_dictionary);
565 SET_BOOL(encrypt_articles);
566 SET_BOOL(encrypt_app_list);
567 SET_BOOL(encrypt_everything);
568 SET_BOOL(sync_tab_favicons);
569 SET_ENUM(passphrase_type, PassphraseTypeString);
570 SET(keystore_decryptor_token, EncryptedDataToValue);
571 SET_INT64(keystore_migration_time);
572 SET_INT64(custom_passphrase_time);
573 return value;
576 base::DictionaryValue* ArticlePageToValue(
577 const sync_pb::ArticlePage& proto) {
578 base::DictionaryValue* value = new base::DictionaryValue();
579 SET_STR(url);
580 return value;
583 base::DictionaryValue* ArticleSpecificsToValue(
584 const sync_pb::ArticleSpecifics& proto) {
585 base::DictionaryValue* value = new base::DictionaryValue();
586 SET_STR(entry_id);
587 SET_STR(title);
588 SET_REP(pages, ArticlePageToValue);
589 return value;
592 base::DictionaryValue* PasswordSpecificsToValue(
593 const sync_pb::PasswordSpecifics& proto) {
594 base::DictionaryValue* value = new base::DictionaryValue();
595 SET(encrypted, EncryptedDataToValue);
596 return value;
599 base::DictionaryValue* PreferenceSpecificsToValue(
600 const sync_pb::PreferenceSpecifics& proto) {
601 base::DictionaryValue* value = new base::DictionaryValue();
602 SET_STR(name);
603 SET_STR(value);
604 return value;
607 base::DictionaryValue* PriorityPreferenceSpecificsToValue(
608 const sync_pb::PriorityPreferenceSpecifics& specifics) {
609 base::DictionaryValue* value = new base::DictionaryValue();
610 SET_FIELD(preference, PreferenceSpecificsToValue);
611 return value;
614 base::DictionaryValue* SyncedNotificationAppInfoSpecificsToValue(
615 const sync_pb::SyncedNotificationAppInfoSpecifics& proto) {
616 base::DictionaryValue* value = new base::DictionaryValue();
617 return value;
620 base::DictionaryValue* SyncedNotificationSpecificsToValue(
621 const sync_pb::SyncedNotificationSpecifics& proto) {
622 base::DictionaryValue* value = new base::DictionaryValue();
623 return value;
626 base::DictionaryValue* SearchEngineSpecificsToValue(
627 const sync_pb::SearchEngineSpecifics& proto) {
628 base::DictionaryValue* value = new base::DictionaryValue();
629 SET_STR(short_name);
630 SET_STR(keyword);
631 SET_STR(favicon_url);
632 SET_STR(url);
633 SET_BOOL(safe_for_autoreplace);
634 SET_STR(originating_url);
635 SET_INT64(date_created);
636 SET_STR(input_encodings);
637 SET_BOOL(show_in_default_list);
638 SET_STR(suggestions_url);
639 SET_INT32(prepopulate_id);
640 SET_BOOL(autogenerate_keyword);
641 SET_STR(instant_url);
642 SET_INT64(last_modified);
643 SET_STR(sync_guid);
644 SET_STR_REP(alternate_urls);
645 SET_STR(search_terms_replacement_key);
646 SET_STR(image_url);
647 SET_STR(search_url_post_params);
648 SET_STR(suggestions_url_post_params);
649 SET_STR(instant_url_post_params);
650 SET_STR(image_url_post_params);
651 SET_STR(new_tab_url);
652 return value;
655 base::DictionaryValue* SessionSpecificsToValue(
656 const sync_pb::SessionSpecifics& proto) {
657 base::DictionaryValue* value = new base::DictionaryValue();
658 SET_STR(session_tag);
659 SET(header, SessionHeaderToValue);
660 SET(tab, SessionTabToValue);
661 SET_INT32(tab_node_id);
662 return value;
665 base::DictionaryValue* ThemeSpecificsToValue(
666 const sync_pb::ThemeSpecifics& proto) {
667 base::DictionaryValue* value = new base::DictionaryValue();
668 SET_BOOL(use_custom_theme);
669 SET_BOOL(use_system_theme_by_default);
670 SET_STR(custom_theme_name);
671 SET_STR(custom_theme_id);
672 SET_STR(custom_theme_update_url);
673 return value;
676 base::DictionaryValue* TypedUrlSpecificsToValue(
677 const sync_pb::TypedUrlSpecifics& proto) {
678 base::DictionaryValue* value = new base::DictionaryValue();
679 SET_STR(url);
680 SET_STR(title);
681 SET_BOOL(hidden);
682 SET_INT64_REP(visits);
683 SET_INT32_REP(visit_transitions);
684 return value;
687 base::DictionaryValue* WalletMaskedCreditCardToValue(
688 const sync_pb::WalletMaskedCreditCard& proto) {
689 base::DictionaryValue* value = new base::DictionaryValue();
690 SET_STR(id);
691 SET_ENUM(status, GetWalletCardStatusString);
692 SET_STR(name_on_card);
693 SET_ENUM(type, GetWalletCardTypeString);
694 SET_STR(last_four);
695 SET_INT32(exp_month);
696 SET_INT32(exp_year);
697 return value;
700 base::DictionaryValue* WalletPostalAddressToValue(
701 const sync_pb::WalletPostalAddress& proto) {
702 base::DictionaryValue* value = new base::DictionaryValue();
703 SET_STR(company_name);
704 SET_STR_REP(street_address);
705 SET_STR(address_1);
706 SET_STR(address_2);
707 SET_STR(address_3);
708 SET_STR(address_4);
709 SET_STR(postal_code);
710 SET_STR(sorting_code);
711 SET_STR(country_code);
712 SET_STR(language_code);
713 return value;
716 base::DictionaryValue* WifiCredentialSpecificsToValue(
717 const sync_pb::WifiCredentialSpecifics& proto) {
718 base::DictionaryValue* value = new base::DictionaryValue();
719 SET_BYTES(ssid);
720 SET_ENUM(security_class, GetWifiCredentialSecurityClassString);
721 SET_BYTES(passphrase);
722 return value;
725 base::DictionaryValue* EntitySpecificsToValue(
726 const sync_pb::EntitySpecifics& specifics) {
727 base::DictionaryValue* value = new base::DictionaryValue();
728 SET_FIELD(app, AppSpecificsToValue);
729 SET_FIELD(app_list, AppListSpecificsToValue);
730 SET_FIELD(app_notification, AppNotificationToValue);
731 SET_FIELD(app_setting, AppSettingSpecificsToValue);
732 SET_FIELD(article, ArticleSpecificsToValue);
733 SET_FIELD(autofill, AutofillSpecificsToValue);
734 SET_FIELD(autofill_profile, AutofillProfileSpecificsToValue);
735 SET_FIELD(autofill_wallet, AutofillWalletSpecificsToValue);
736 SET_FIELD(bookmark, BookmarkSpecificsToValue);
737 SET_FIELD(device_info, DeviceInfoSpecificsToValue);
738 SET_FIELD(dictionary, DictionarySpecificsToValue);
739 SET_FIELD(experiments, ExperimentsSpecificsToValue);
740 SET_FIELD(extension, ExtensionSpecificsToValue);
741 SET_FIELD(extension_setting, ExtensionSettingSpecificsToValue);
742 SET_FIELD(favicon_image, FaviconImageSpecificsToValue);
743 SET_FIELD(favicon_tracking, FaviconTrackingSpecificsToValue);
744 SET_FIELD(history_delete_directive, HistoryDeleteDirectiveSpecificsToValue);
745 SET_FIELD(managed_user_setting, ManagedUserSettingSpecificsToValue);
746 SET_FIELD(managed_user_shared_setting,
747 ManagedUserSharedSettingSpecificsToValue);
748 SET_FIELD(managed_user, ManagedUserSpecificsToValue);
749 SET_FIELD(managed_user_whitelist, ManagedUserWhitelistSpecificsToValue);
750 SET_FIELD(nigori, NigoriSpecificsToValue);
751 SET_FIELD(password, PasswordSpecificsToValue);
752 SET_FIELD(preference, PreferenceSpecificsToValue);
753 SET_FIELD(priority_preference, PriorityPreferenceSpecificsToValue);
754 SET_FIELD(search_engine, SearchEngineSpecificsToValue);
755 SET_FIELD(session, SessionSpecificsToValue);
756 SET_FIELD(synced_notification, SyncedNotificationSpecificsToValue);
757 SET_FIELD(synced_notification_app_info,
758 SyncedNotificationAppInfoSpecificsToValue);
759 SET_FIELD(theme, ThemeSpecificsToValue);
760 SET_FIELD(typed_url, TypedUrlSpecificsToValue);
761 SET_FIELD(wifi_credential, WifiCredentialSpecificsToValue);
762 return value;
765 namespace {
767 base::StringValue* UniquePositionToStringValue(
768 const sync_pb::UniquePosition& proto) {
769 UniquePosition pos = UniquePosition::FromProto(proto);
770 return new base::StringValue(pos.ToDebugString());
773 } // namespace
775 base::DictionaryValue* SyncEntityToValue(const sync_pb::SyncEntity& proto,
776 bool include_specifics) {
777 base::DictionaryValue* value = new base::DictionaryValue();
778 SET_STR(id_string);
779 SET_STR(parent_id_string);
780 SET_STR(old_parent_id);
781 SET_INT64(version);
782 SET_INT64(mtime);
783 SET_INT64(ctime);
784 SET_STR(name);
785 SET_STR(non_unique_name);
786 SET_INT64(sync_timestamp);
787 SET_STR(server_defined_unique_tag);
788 SET_INT64(position_in_parent);
789 SET(unique_position, UniquePositionToStringValue);
790 SET_STR(insert_after_item_id);
791 SET_BOOL(deleted);
792 SET_STR(originator_cache_guid);
793 SET_STR(originator_client_item_id);
794 if (include_specifics)
795 SET(specifics, EntitySpecificsToValue);
796 SET_BOOL(folder);
797 SET_STR(client_defined_unique_tag);
798 SET_REP(attachment_id, AttachmentIdProtoToValue);
799 return value;
802 namespace {
804 base::ListValue* SyncEntitiesToValue(
805 const ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities,
806 bool include_specifics) {
807 base::ListValue* list = new base::ListValue();
808 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it;
809 for (it = entities.begin(); it != entities.end(); ++it) {
810 list->Append(SyncEntityToValue(*it, include_specifics));
813 return list;
816 base::DictionaryValue* ChromiumExtensionActivityToValue(
817 const sync_pb::ChromiumExtensionsActivity& proto) {
818 base::DictionaryValue* value = new base::DictionaryValue();
819 SET_STR(extension_id);
820 SET_INT32(bookmark_writes_since_last_commit);
821 return value;
824 base::DictionaryValue* CommitMessageToValue(
825 const sync_pb::CommitMessage& proto,
826 bool include_specifics) {
827 base::DictionaryValue* value = new base::DictionaryValue();
828 value->Set("entries",
829 SyncEntitiesToValue(proto.entries(), include_specifics));
830 SET_STR(cache_guid);
831 SET_REP(extensions_activity, ChromiumExtensionActivityToValue);
832 SET(config_params, ClientConfigParamsToValue);
833 return value;
836 base::DictionaryValue* GetUpdateTriggersToValue(
837 const sync_pb::GetUpdateTriggers& proto) {
838 base::DictionaryValue* value = new base::DictionaryValue();
839 SET_STR_REP(notification_hint);
840 SET_BOOL(client_dropped_hints);
841 SET_BOOL(invalidations_out_of_sync);
842 SET_INT64(local_modification_nudges);
843 SET_INT64(datatype_refresh_nudges);
844 return value;
847 base::DictionaryValue* DataTypeProgressMarkerToValue(
848 const sync_pb::DataTypeProgressMarker& proto) {
849 base::DictionaryValue* value = new base::DictionaryValue();
850 SET_INT32(data_type_id);
851 SET_BYTES(token);
852 SET_INT64(timestamp_token_for_migration);
853 SET_STR(notification_hint);
854 SET(get_update_triggers, GetUpdateTriggersToValue);
855 return value;
858 base::DictionaryValue* DataTypeContextToValue(
859 const sync_pb::DataTypeContext& proto) {
860 base::DictionaryValue* value = new base::DictionaryValue();
861 SET_INT32(data_type_id);
862 SET_STR(context);
863 SET_INT64(version);
864 return value;
867 base::DictionaryValue* GetUpdatesCallerInfoToValue(
868 const sync_pb::GetUpdatesCallerInfo& proto) {
869 base::DictionaryValue* value = new base::DictionaryValue();
870 SET_ENUM(source, GetUpdatesSourceString);
871 SET_BOOL(notifications_enabled);
872 return value;
875 base::DictionaryValue* GetUpdatesMessageToValue(
876 const sync_pb::GetUpdatesMessage& proto) {
877 base::DictionaryValue* value = new base::DictionaryValue();
878 SET(caller_info, GetUpdatesCallerInfoToValue);
879 SET_BOOL(fetch_folders);
880 SET_INT32(batch_size);
881 SET_REP(from_progress_marker, DataTypeProgressMarkerToValue);
882 SET_BOOL(streaming);
883 SET_BOOL(need_encryption_key);
884 SET_BOOL(create_mobile_bookmarks_folder);
885 SET_ENUM(get_updates_origin, GetUpdatesOriginString);
886 SET_REP(client_contexts, DataTypeContextToValue);
887 return value;
890 base::DictionaryValue* ClientStatusToValue(const sync_pb::ClientStatus& proto) {
891 base::DictionaryValue* value = new base::DictionaryValue();
892 SET_BOOL(hierarchy_conflict_detected);
893 return value;
896 base::DictionaryValue* EntryResponseToValue(
897 const sync_pb::CommitResponse::EntryResponse& proto) {
898 base::DictionaryValue* value = new base::DictionaryValue();
899 SET_ENUM(response_type, GetResponseTypeString);
900 SET_STR(id_string);
901 SET_STR(parent_id_string);
902 SET_INT64(position_in_parent);
903 SET_INT64(version);
904 SET_STR(name);
905 SET_STR(error_message);
906 SET_INT64(mtime);
907 return value;
910 base::DictionaryValue* CommitResponseToValue(
911 const sync_pb::CommitResponse& proto) {
912 base::DictionaryValue* value = new base::DictionaryValue();
913 SET_REP(entryresponse, EntryResponseToValue);
914 return value;
917 base::DictionaryValue* GetUpdatesResponseToValue(
918 const sync_pb::GetUpdatesResponse& proto,
919 bool include_specifics) {
920 base::DictionaryValue* value = new base::DictionaryValue();
921 value->Set("entries",
922 SyncEntitiesToValue(proto.entries(), include_specifics));
923 SET_INT64(changes_remaining);
924 SET_REP(new_progress_marker, DataTypeProgressMarkerToValue);
925 SET_REP(context_mutations, DataTypeContextToValue);
926 return value;
929 base::DictionaryValue* ClientCommandToValue(
930 const sync_pb::ClientCommand& proto) {
931 base::DictionaryValue* value = new base::DictionaryValue();
932 SET_INT32(set_sync_poll_interval);
933 SET_INT32(set_sync_long_poll_interval);
934 SET_INT32(max_commit_batch_size);
935 SET_INT32(sessions_commit_delay_seconds);
936 SET_INT32(throttle_delay_seconds);
937 SET_INT32(client_invalidation_hint_buffer_size);
938 return value;
941 base::DictionaryValue* ErrorToValue(
942 const sync_pb::ClientToServerResponse::Error& proto) {
943 base::DictionaryValue* value = new base::DictionaryValue();
944 SET_ENUM(error_type, GetErrorTypeString);
945 SET_STR(error_description);
946 SET_STR(url);
947 SET_ENUM(action, GetActionString);
948 return value;
951 } // namespace
953 base::DictionaryValue* ClientToServerResponseToValue(
954 const sync_pb::ClientToServerResponse& proto,
955 bool include_specifics) {
956 base::DictionaryValue* value = new base::DictionaryValue();
957 SET(commit, CommitResponseToValue);
958 if (proto.has_get_updates()) {
959 value->Set("get_updates", GetUpdatesResponseToValue(proto.get_updates(),
960 include_specifics));
963 SET(error, ErrorToValue);
964 SET_ENUM(error_code, GetErrorTypeString);
965 SET_STR(error_message);
966 SET_STR(store_birthday);
967 SET(client_command, ClientCommandToValue);
968 SET_INT32_REP(migrated_data_type_id);
969 return value;
972 base::DictionaryValue* ClientToServerMessageToValue(
973 const sync_pb::ClientToServerMessage& proto,
974 bool include_specifics) {
975 base::DictionaryValue* value = new base::DictionaryValue();
976 SET_STR(share);
977 SET_INT32(protocol_version);
978 if (proto.has_commit()) {
979 value->Set("commit",
980 CommitMessageToValue(proto.commit(), include_specifics));
983 SET(get_updates, GetUpdatesMessageToValue);
984 SET_STR(store_birthday);
985 SET_BOOL(sync_problem_detected);
986 SET(debug_info, DebugInfoToValue);
987 SET(client_status, ClientStatusToValue);
988 return value;
991 base::DictionaryValue* DatatypeAssociationStatsToValue(
992 const sync_pb::DatatypeAssociationStats& proto) {
993 base::DictionaryValue* value = new base::DictionaryValue();
994 SET_INT32(data_type_id);
995 SET_INT32(num_local_items_before_association);
996 SET_INT32(num_sync_items_before_association);
997 SET_INT32(num_local_items_after_association);
998 SET_INT32(num_sync_items_after_association);
999 SET_INT32(num_local_items_added);
1000 SET_INT32(num_local_items_deleted);
1001 SET_INT32(num_local_items_modified);
1002 SET_INT32(num_sync_items_added);
1003 SET_INT32(num_sync_items_deleted);
1004 SET_INT32(num_sync_items_modified);
1005 SET_INT64(local_version_pre_association);
1006 SET_INT64(sync_version_pre_association)
1007 SET_BOOL(had_error);
1008 SET_INT64(download_wait_time_us);
1009 SET_INT64(download_time_us);
1010 SET_INT64(association_wait_time_for_high_priority_us);
1011 SET_INT64(association_wait_time_for_same_priority_us);
1012 return value;
1015 base::DictionaryValue* DebugEventInfoToValue(
1016 const sync_pb::DebugEventInfo& proto) {
1017 base::DictionaryValue* value = new base::DictionaryValue();
1018 SET_ENUM(singleton_event, SingletonDebugEventTypeString);
1019 SET(sync_cycle_completed_event_info, SyncCycleCompletedEventInfoToValue);
1020 SET_INT32(nudging_datatype);
1021 SET_INT32_REP(datatypes_notified_from_server);
1022 SET(datatype_association_stats, DatatypeAssociationStatsToValue);
1023 return value;
1026 base::DictionaryValue* DebugInfoToValue(const sync_pb::DebugInfo& proto) {
1027 base::DictionaryValue* value = new base::DictionaryValue();
1028 SET_REP(events, DebugEventInfoToValue);
1029 SET_BOOL(cryptographer_ready);
1030 SET_BOOL(cryptographer_has_pending_keys);
1031 SET_BOOL(events_dropped);
1032 return value;
1035 base::DictionaryValue* SyncCycleCompletedEventInfoToValue(
1036 const sync_pb::SyncCycleCompletedEventInfo& proto) {
1037 base::DictionaryValue* value = new base::DictionaryValue();
1038 SET_INT32(num_encryption_conflicts);
1039 SET_INT32(num_hierarchy_conflicts);
1040 SET_INT32(num_server_conflicts);
1041 SET_INT32(num_updates_downloaded);
1042 SET_INT32(num_reflected_updates_downloaded);
1043 SET(caller_info, GetUpdatesCallerInfoToValue);
1044 return value;
1047 base::DictionaryValue* ClientConfigParamsToValue(
1048 const sync_pb::ClientConfigParams& proto) {
1049 base::DictionaryValue* value = new base::DictionaryValue();
1050 SET_INT32_REP(enabled_type_ids);
1051 SET_BOOL(tabs_datatype_enabled);
1052 return value;
1055 base::DictionaryValue* AttachmentIdProtoToValue(
1056 const sync_pb::AttachmentIdProto& proto) {
1057 base::DictionaryValue* value = new base::DictionaryValue();
1058 SET_STR(unique_id);
1059 return value;
1062 #undef SET
1063 #undef SET_REP
1065 #undef SET_BOOL
1066 #undef SET_BYTES
1067 #undef SET_INT32
1068 #undef SET_INT64
1069 #undef SET_INT64_REP
1070 #undef SET_STR
1071 #undef SET_STR_REP
1073 #undef SET_FIELD
1075 } // namespace syncer