Update V8 to version 3.31.22 (based on 322bb23e82fc4e6f7493ce53a282ccdf82066195).
[chromium-blink-merge.git] / sync / protocol / proto_value_conversions.cc
blobcc022c4ce7c0cb704b16be4f5ccaab9dcadc3255
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/synced_notification_app_info_specifics.pb.h"
42 #include "sync/protocol/synced_notification_specifics.pb.h"
43 #include "sync/protocol/theme_specifics.pb.h"
44 #include "sync/protocol/typed_url_specifics.pb.h"
45 #include "sync/protocol/unique_position.pb.h"
46 #include "sync/util/time.h"
48 namespace syncer {
50 namespace {
52 // Basic Type -> Value functions.
54 base::StringValue* MakeInt64Value(int64 x) {
55 return new base::StringValue(base::Int64ToString(x));
58 // TODO(akalin): Perhaps make JSONWriter support BinaryValue and use
59 // that instead of a StringValue.
60 base::StringValue* MakeBytesValue(const std::string& bytes) {
61 std::string bytes_base64;
62 base::Base64Encode(bytes, &bytes_base64);
63 return new base::StringValue(bytes_base64);
66 base::StringValue* MakeStringValue(const std::string& str) {
67 return new base::StringValue(str);
70 // T is the enum type.
71 template <class T>
72 base::StringValue* MakeEnumValue(T t, const char* (*converter_fn)(T)) {
73 return new base::StringValue(converter_fn(t));
76 // T is the field type, F is either RepeatedField or RepeatedPtrField,
77 // and V is a subclass of Value.
78 template <class T, class F, class V>
79 base::ListValue* MakeRepeatedValue(const F& fields, V* (*converter_fn)(T)) {
80 base::ListValue* list = new base::ListValue();
81 for (typename F::const_iterator it = fields.begin(); it != fields.end();
82 ++it) {
83 list->Append(converter_fn(*it));
85 return list;
88 base::StringValue* MakeTimestampValue(int64 tm) {
89 return new base::StringValue(
90 base::TimeFormatShortDateAndTime(syncer::ProtoTimeToTime(tm)));
93 } // namespace
95 // Helper macros to reduce the amount of boilerplate.
97 #define SET(field, fn) \
98 if (proto.has_##field()) { \
99 value->Set(#field, fn(proto.field())); \
101 #define SET_REP(field, fn) \
102 value->Set(#field, MakeRepeatedValue(proto.field(), fn))
103 #define SET_ENUM(field, fn) \
104 value->Set(#field, MakeEnumValue(proto.field(), fn))
106 #define SET_BOOL(field) SET(field, new base::FundamentalValue)
107 #define SET_BYTES(field) SET(field, MakeBytesValue)
108 #define SET_INT32(field) SET(field, MakeInt64Value)
109 #define SET_INT32_REP(field) SET_REP(field, MakeInt64Value)
110 #define SET_INT64(field) SET(field, MakeInt64Value)
111 #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value)
112 #define SET_STR(field) SET(field, new base::StringValue)
113 #define SET_TIME_STR(field) SET(field, MakeTimestampValue)
114 #define SET_STR_REP(field) \
115 value->Set(#field, \
116 MakeRepeatedValue<const std::string&, \
117 google::protobuf::RepeatedPtrField< \
118 std::string >, \
119 base::StringValue>(proto.field(), \
120 MakeStringValue))
121 #define SET_EXPERIMENT_ENABLED_FIELD(field) \
122 do { \
123 if (proto.has_##field() && \
124 proto.field().has_enabled()) { \
125 value->Set(#field, \
126 new base::FundamentalValue( \
127 proto.field().enabled())); \
129 } while (0)
131 #define SET_FIELD(field, fn) \
132 do { \
133 if (specifics.has_##field()) { \
134 value->Set(#field, fn(specifics.field())); \
136 } while (0)
138 // If you add another macro, don't forget to add an #undef at the end
139 // of this file, too.
141 base::DictionaryValue* EncryptedDataToValue(
142 const sync_pb::EncryptedData& proto) {
143 base::DictionaryValue* value = new base::DictionaryValue();
144 SET_STR(key_name);
145 // TODO(akalin): Shouldn't blob be of type bytes instead of string?
146 SET_BYTES(blob);
147 return value;
150 base::DictionaryValue* AppSettingsToValue(
151 const sync_pb::AppNotificationSettings& proto) {
152 base::DictionaryValue* value = new base::DictionaryValue();
153 SET_BOOL(initial_setup_done);
154 SET_BOOL(disabled);
155 SET_STR(oauth_client_id);
156 return value;
159 base::DictionaryValue* SessionHeaderToValue(
160 const sync_pb::SessionHeader& proto) {
161 base::DictionaryValue* value = new base::DictionaryValue();
162 SET_REP(window, SessionWindowToValue);
163 SET_STR(client_name);
164 SET_ENUM(device_type, GetDeviceTypeString);
165 return value;
168 base::DictionaryValue* SessionTabToValue(const sync_pb::SessionTab& proto) {
169 base::DictionaryValue* value = new base::DictionaryValue();
170 SET_INT32(tab_id);
171 SET_INT32(window_id);
172 SET_INT32(tab_visual_index);
173 SET_INT32(current_navigation_index);
174 SET_BOOL(pinned);
175 SET_STR(extension_app_id);
176 SET_REP(navigation, TabNavigationToValue);
177 SET_BYTES(favicon);
178 SET_ENUM(favicon_type, GetFaviconTypeString);
179 SET_STR(favicon_source);
180 return value;
183 base::DictionaryValue* SessionWindowToValue(
184 const sync_pb::SessionWindow& proto) {
185 base::DictionaryValue* value = new base::DictionaryValue();
186 SET_INT32(window_id);
187 SET_INT32(selected_tab_index);
188 SET_INT32_REP(tab);
189 SET_ENUM(browser_type, GetBrowserTypeString);
190 return value;
193 base::DictionaryValue* TabNavigationToValue(
194 const sync_pb::TabNavigation& proto) {
195 base::DictionaryValue* value = new base::DictionaryValue();
196 SET_STR(virtual_url);
197 SET_STR(referrer);
198 SET_STR(title);
199 SET_STR(state);
200 SET_ENUM(page_transition, GetPageTransitionString);
201 SET_ENUM(redirect_type, GetPageTransitionRedirectTypeString);
202 SET_INT32(unique_id);
203 SET_INT64(timestamp_msec);
204 SET_BOOL(navigation_forward_back);
205 SET_BOOL(navigation_from_address_bar);
206 SET_BOOL(navigation_home_page);
207 SET_BOOL(navigation_chain_start);
208 SET_BOOL(navigation_chain_end);
209 SET_INT64(global_id);
210 SET_STR(search_terms);
211 SET_STR(favicon_url);
212 SET_ENUM(blocked_state, GetBlockedStateString);
213 SET_STR_REP(content_pack_categories);
214 SET_INT32(http_status_code);
215 SET_INT32(referrer_policy);
216 SET_BOOL(is_restored);
217 SET_REP(navigation_redirect, NavigationRedirectToValue);
218 SET_STR(last_navigation_redirect_url);
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* SyncedNotificationAppInfoToValue(
270 const sync_pb::SyncedNotificationAppInfo& proto) {
271 base::DictionaryValue* value = new base::DictionaryValue();
272 SET_STR_REP(app_id);
273 SET_STR(settings_display_name);
274 SET_STR(app_name);
275 SET_STR(settings_url);
276 SET_STR(info_url);
277 SET(icon, SyncedNotificationImageToValue);
278 // TODO(petewil): Add fields for the monochrome icon when it is available.
279 return value;
282 base::DictionaryValue* SyncedNotificationImageToValue(
283 const sync_pb::SyncedNotificationImage& proto) {
284 base::DictionaryValue* value = new base::DictionaryValue();
285 SET_STR(url);
286 SET_STR(alt_text);
287 SET_INT32(preferred_width);
288 SET_INT32(preferred_height);
289 return value;
292 base::DictionaryValue* SyncedNotificationProfileImageToValue(
293 const sync_pb::SyncedNotificationProfileImage& proto) {
294 base::DictionaryValue* value = new base::DictionaryValue();
295 SET_STR(image_url);
296 SET_STR(oid);
297 SET_STR(display_name);
298 return value;
301 base::DictionaryValue* MediaToValue(
302 const sync_pb::Media& proto) {
303 base::DictionaryValue* value = new base::DictionaryValue();
304 SET(image, SyncedNotificationImageToValue);
305 return value;
308 base::DictionaryValue* SyncedNotificationActionToValue(
309 const sync_pb::SyncedNotificationAction& proto) {
310 base::DictionaryValue* value = new base::DictionaryValue();
311 SET_STR(text);
312 SET(icon, SyncedNotificationImageToValue);
313 SET_STR(url);
314 SET_STR(request_data);
315 SET_STR(accessibility_label);
316 return value;
319 base::DictionaryValue* SyncedNotificationDestiationToValue(
320 const sync_pb::SyncedNotificationDestination& proto) {
321 base::DictionaryValue* value = new base::DictionaryValue();
322 SET_STR(text);
323 SET(icon, SyncedNotificationImageToValue);
324 SET_STR(url);
325 SET_STR(accessibility_label);
326 return value;
329 base::DictionaryValue* TargetToValue(
330 const sync_pb::Target& proto) {
331 base::DictionaryValue* value = new base::DictionaryValue();
332 SET(destination, SyncedNotificationDestiationToValue);
333 SET(action, SyncedNotificationActionToValue);
334 SET_STR(target_key);
335 return value;
338 base::DictionaryValue* SimpleCollapsedLayoutToValue(
339 const sync_pb::SimpleCollapsedLayout& proto) {
340 base::DictionaryValue* value = new base::DictionaryValue();
341 SET(app_icon, SyncedNotificationImageToValue);
342 SET_REP(profile_image, SyncedNotificationProfileImageToValue);
343 SET_STR(heading);
344 SET_STR(description);
345 SET_STR(annotation);
346 SET_REP(media, MediaToValue);
347 return value;
350 base::DictionaryValue* CollapsedInfoToValue(
351 const sync_pb::CollapsedInfo& proto) {
352 base::DictionaryValue* value = new base::DictionaryValue();
353 SET(simple_collapsed_layout, SimpleCollapsedLayoutToValue);
354 SET_INT64(creation_timestamp_usec);
355 SET(default_destination, SyncedNotificationDestiationToValue);
356 SET_REP(target, TargetToValue);
357 return value;
360 base::DictionaryValue* SyncedNotificationToValue(
361 const sync_pb::SyncedNotification& proto) {
362 base::DictionaryValue* value = new base::DictionaryValue();
363 SET_STR(type);
364 SET_STR(external_id);
365 // TODO(petewil) Add SyncedNotificationCreator here if we ever need it.
366 return value;
369 base::DictionaryValue* RenderInfoToValue(
370 const sync_pb::SyncedNotificationRenderInfo& proto) {
371 base::DictionaryValue* value = new base::DictionaryValue();
372 // TODO(petewil): Add the expanded info values once we start using them.
373 SET(collapsed_info, CollapsedInfoToValue);
374 return value;
377 base::DictionaryValue* CoalescedNotificationToValue(
378 const sync_pb::CoalescedSyncedNotification& proto) {
379 base::DictionaryValue* value = new base::DictionaryValue();
380 SET_STR(key);
381 SET_STR(app_id);
382 SET_REP(notification, SyncedNotificationToValue);
383 SET(render_info, RenderInfoToValue);
384 SET_INT32(read_state);
385 SET_INT64(creation_time_msec);
386 SET_INT32(priority);
387 return value;
390 base::DictionaryValue* AppListSpecificsToValue(
391 const sync_pb::AppListSpecifics& proto) {
392 base::DictionaryValue* value = new base::DictionaryValue();
393 SET_STR(item_id);
394 SET_ENUM(item_type, GetAppListItemTypeString);
395 SET_STR(item_name);
396 SET_STR(parent_id);
397 SET_STR(item_ordinal);
399 return value;
402 base::DictionaryValue* AppNotificationToValue(
403 const sync_pb::AppNotification& proto) {
404 base::DictionaryValue* value = new base::DictionaryValue();
405 SET_STR(guid);
406 SET_STR(app_id);
407 SET_INT64(creation_timestamp_ms);
408 SET_STR(title);
409 SET_STR(body_text);
410 SET_STR(link_url);
411 SET_STR(link_text);
412 return value;
415 base::DictionaryValue* AppSettingSpecificsToValue(
416 const sync_pb::AppSettingSpecifics& proto) {
417 base::DictionaryValue* value = new base::DictionaryValue();
418 SET(extension_setting, ExtensionSettingSpecificsToValue);
419 return value;
422 base::DictionaryValue* AppSpecificsToValue(
423 const sync_pb::AppSpecifics& proto) {
424 base::DictionaryValue* value = new base::DictionaryValue();
425 SET(extension, ExtensionSpecificsToValue);
426 SET(notification_settings, AppSettingsToValue);
427 SET_STR(app_launch_ordinal);
428 SET_STR(page_ordinal);
429 SET_ENUM(launch_type, GetLaunchTypeString);
430 SET_STR(bookmark_app_url);
431 SET_STR(bookmark_app_description);
433 return value;
436 base::DictionaryValue* AutofillSpecificsToValue(
437 const sync_pb::AutofillSpecifics& proto) {
438 base::DictionaryValue* value = new base::DictionaryValue();
439 SET_STR(name);
440 SET_STR(value);
441 SET_INT64_REP(usage_timestamp);
442 SET(profile, AutofillProfileSpecificsToValue);
443 return value;
446 base::DictionaryValue* AutofillProfileSpecificsToValue(
447 const sync_pb::AutofillProfileSpecifics& proto) {
448 base::DictionaryValue* value = new base::DictionaryValue();
449 SET_STR(guid);
450 SET_STR(origin);
452 SET_STR_REP(name_first);
453 SET_STR_REP(name_middle);
454 SET_STR_REP(name_last);
455 SET_STR_REP(name_full);
456 SET_STR_REP(email_address);
457 SET_STR(company_name);
459 SET_STR(address_home_line1);
460 SET_STR(address_home_line2);
461 SET_STR(address_home_city);
462 SET_STR(address_home_state);
463 SET_STR(address_home_zip);
464 SET_STR(address_home_country);
466 SET_STR(address_home_street_address);
467 SET_STR(address_home_sorting_code);
468 SET_STR(address_home_dependent_locality);
469 SET_STR(address_home_language_code);
471 SET_STR_REP(phone_home_whole_number);
472 return value;
475 base::DictionaryValue* MetaInfoToValue(
476 const sync_pb::MetaInfo& proto) {
477 base::DictionaryValue* value = new base::DictionaryValue();
478 SET_STR(key);
479 SET_STR(value);
480 return value;
483 base::DictionaryValue* BookmarkSpecificsToValue(
484 const sync_pb::BookmarkSpecifics& proto) {
485 base::DictionaryValue* value = new base::DictionaryValue();
486 SET_STR(url);
487 SET_BYTES(favicon);
488 SET_STR(title);
489 SET_INT64(creation_time_us);
490 SET_STR(icon_url);
491 SET_REP(meta_info, &MetaInfoToValue);
492 return value;
495 base::DictionaryValue* DeviceInfoSpecificsToValue(
496 const sync_pb::DeviceInfoSpecifics& proto) {
497 base::DictionaryValue* value = new base::DictionaryValue();
498 SET_STR(cache_guid);
499 SET_STR(client_name);
500 SET_ENUM(device_type, GetDeviceTypeString);
501 SET_STR(sync_user_agent);
502 SET_STR(chrome_version);
503 SET_TIME_STR(backup_timestamp);
504 SET_STR(signin_scoped_device_id);
505 return value;
508 base::DictionaryValue* DictionarySpecificsToValue(
509 const sync_pb::DictionarySpecifics& proto) {
510 base::DictionaryValue* value = new base::DictionaryValue();
511 SET_STR(word);
512 return value;
515 namespace {
517 base::DictionaryValue* FaviconSyncFlagsToValue(
518 const sync_pb::FaviconSyncFlags& proto) {
519 base::DictionaryValue* value = new base::DictionaryValue();
520 SET_BOOL(enabled);
521 SET_INT32(favicon_sync_limit);
522 return value;
525 base::DictionaryValue* EnhancedBookmarksFlagsToValue(
526 const sync_pb::EnhancedBookmarksFlags& proto) {
527 base::DictionaryValue* value = new base::DictionaryValue();
528 SET_BOOL(enabled);
529 SET_STR(extension_id);
530 return value;
533 } // namespace
535 base::DictionaryValue* ExperimentsSpecificsToValue(
536 const sync_pb::ExperimentsSpecifics& proto) {
537 base::DictionaryValue* value = new base::DictionaryValue();
538 SET_EXPERIMENT_ENABLED_FIELD(keystore_encryption);
539 SET_EXPERIMENT_ENABLED_FIELD(history_delete_directives);
540 SET_EXPERIMENT_ENABLED_FIELD(autofill_culling);
541 SET_EXPERIMENT_ENABLED_FIELD(pre_commit_update_avoidance);
542 SET(favicon_sync, FaviconSyncFlagsToValue);
543 SET_EXPERIMENT_ENABLED_FIELD(gcm_channel);
544 SET(enhanced_bookmarks, EnhancedBookmarksFlagsToValue);
545 SET_EXPERIMENT_ENABLED_FIELD(gcm_invalidations);
546 return value;
549 base::DictionaryValue* ExtensionSettingSpecificsToValue(
550 const sync_pb::ExtensionSettingSpecifics& proto) {
551 base::DictionaryValue* value = new base::DictionaryValue();
552 SET_STR(extension_id);
553 SET_STR(key);
554 SET_STR(value);
555 return value;
558 base::DictionaryValue* ExtensionSpecificsToValue(
559 const sync_pb::ExtensionSpecifics& proto) {
560 base::DictionaryValue* value = new base::DictionaryValue();
561 SET_STR(id);
562 SET_STR(version);
563 SET_STR(update_url);
564 SET_BOOL(enabled);
565 SET_BOOL(incognito_enabled);
566 SET_BOOL(remote_install);
567 SET_BOOL(installed_by_custodian);
568 SET_STR(name);
569 return value;
572 namespace {
573 base::DictionaryValue* FaviconDataToValue(
574 const sync_pb::FaviconData& proto) {
575 base::DictionaryValue* value = new base::DictionaryValue();
576 SET_BYTES(favicon);
577 SET_INT32(width);
578 SET_INT32(height);
579 return value;
581 } // namespace
583 base::DictionaryValue* FaviconImageSpecificsToValue(
584 const sync_pb::FaviconImageSpecifics& proto) {
585 base::DictionaryValue* value = new base::DictionaryValue();
586 SET_STR(favicon_url);
587 SET(favicon_web, FaviconDataToValue);
588 SET(favicon_web_32, FaviconDataToValue);
589 SET(favicon_touch_64, FaviconDataToValue);
590 SET(favicon_touch_precomposed_64, FaviconDataToValue);
591 return value;
594 base::DictionaryValue* FaviconTrackingSpecificsToValue(
595 const sync_pb::FaviconTrackingSpecifics& proto) {
596 base::DictionaryValue* value = new base::DictionaryValue();
597 SET_STR(favicon_url);
598 SET_INT64(last_visit_time_ms)
599 SET_BOOL(is_bookmarked);
600 return value;
603 base::DictionaryValue* HistoryDeleteDirectiveSpecificsToValue(
604 const sync_pb::HistoryDeleteDirectiveSpecifics& proto) {
605 base::DictionaryValue* value = new base::DictionaryValue();
606 SET(global_id_directive, GlobalIdDirectiveToValue);
607 SET(time_range_directive, TimeRangeDirectiveToValue);
608 return value;
611 base::DictionaryValue* ManagedUserSettingSpecificsToValue(
612 const sync_pb::ManagedUserSettingSpecifics& proto) {
613 base::DictionaryValue* value = new base::DictionaryValue();
614 SET_STR(name);
615 SET_STR(value);
616 return value;
619 base::DictionaryValue* ManagedUserSpecificsToValue(
620 const sync_pb::ManagedUserSpecifics& proto) {
621 base::DictionaryValue* value = new base::DictionaryValue();
622 SET_STR(id);
623 SET_STR(name);
624 SET_BOOL(acknowledged);
625 SET_STR(master_key);
626 SET_STR(chrome_avatar);
627 SET_STR(chromeos_avatar);
628 return value;
631 base::DictionaryValue* ManagedUserSharedSettingSpecificsToValue(
632 const sync_pb::ManagedUserSharedSettingSpecifics& proto) {
633 base::DictionaryValue* value = new base::DictionaryValue();
634 SET_STR(mu_id);
635 SET_STR(key);
636 SET_STR(value);
637 SET_BOOL(acknowledged);
638 return value;
641 base::DictionaryValue* NigoriSpecificsToValue(
642 const sync_pb::NigoriSpecifics& proto) {
643 base::DictionaryValue* value = new base::DictionaryValue();
644 SET(encryption_keybag, EncryptedDataToValue);
645 SET_BOOL(keybag_is_frozen);
646 SET_BOOL(encrypt_bookmarks);
647 SET_BOOL(encrypt_preferences);
648 SET_BOOL(encrypt_autofill_profile);
649 SET_BOOL(encrypt_autofill);
650 SET_BOOL(encrypt_themes);
651 SET_BOOL(encrypt_typed_urls);
652 SET_BOOL(encrypt_extension_settings);
653 SET_BOOL(encrypt_extensions);
654 SET_BOOL(encrypt_sessions);
655 SET_BOOL(encrypt_app_settings);
656 SET_BOOL(encrypt_apps);
657 SET_BOOL(encrypt_search_engines);
658 SET_BOOL(encrypt_dictionary);
659 SET_BOOL(encrypt_articles);
660 SET_BOOL(encrypt_app_list);
661 SET_BOOL(encrypt_everything);
662 SET_BOOL(sync_tab_favicons);
663 SET_ENUM(passphrase_type, PassphraseTypeString);
664 SET(keystore_decryptor_token, EncryptedDataToValue);
665 SET_INT64(keystore_migration_time);
666 SET_INT64(custom_passphrase_time);
667 return value;
670 base::DictionaryValue* ArticlePageToValue(
671 const sync_pb::ArticlePage& proto) {
672 base::DictionaryValue* value = new base::DictionaryValue();
673 SET_STR(url);
674 return value;
677 base::DictionaryValue* ArticleSpecificsToValue(
678 const sync_pb::ArticleSpecifics& proto) {
679 base::DictionaryValue* value = new base::DictionaryValue();
680 SET_STR(entry_id);
681 SET_STR(title);
682 SET_REP(pages, ArticlePageToValue);
683 return value;
686 base::DictionaryValue* PasswordSpecificsToValue(
687 const sync_pb::PasswordSpecifics& proto) {
688 base::DictionaryValue* value = new base::DictionaryValue();
689 SET(encrypted, EncryptedDataToValue);
690 return value;
693 base::DictionaryValue* PreferenceSpecificsToValue(
694 const sync_pb::PreferenceSpecifics& proto) {
695 base::DictionaryValue* value = new base::DictionaryValue();
696 SET_STR(name);
697 SET_STR(value);
698 return value;
701 base::DictionaryValue* PriorityPreferenceSpecificsToValue(
702 const sync_pb::PriorityPreferenceSpecifics& specifics) {
703 base::DictionaryValue* value = new base::DictionaryValue();
704 SET_FIELD(preference, PreferenceSpecificsToValue);
705 return value;
708 base::DictionaryValue* SyncedNotificationAppInfoSpecificsToValue(
709 const sync_pb::SyncedNotificationAppInfoSpecifics& proto) {
710 base::DictionaryValue* value = new base::DictionaryValue();
711 SET_REP(synced_notification_app_info, SyncedNotificationAppInfoToValue);
712 return value;
715 base::DictionaryValue* SyncedNotificationSpecificsToValue(
716 const sync_pb::SyncedNotificationSpecifics& proto) {
717 // There is a lot of data, for now just use heading, description, key, and
718 // the read state.
719 // TODO(petewil): Eventually add more data here.
720 base::DictionaryValue* value = new base::DictionaryValue();
721 SET(coalesced_notification, CoalescedNotificationToValue);
722 return value;
725 base::DictionaryValue* SearchEngineSpecificsToValue(
726 const sync_pb::SearchEngineSpecifics& proto) {
727 base::DictionaryValue* value = new base::DictionaryValue();
728 SET_STR(short_name);
729 SET_STR(keyword);
730 SET_STR(favicon_url);
731 SET_STR(url);
732 SET_BOOL(safe_for_autoreplace);
733 SET_STR(originating_url);
734 SET_INT64(date_created);
735 SET_STR(input_encodings);
736 SET_BOOL(show_in_default_list);
737 SET_STR(suggestions_url);
738 SET_INT32(prepopulate_id);
739 SET_BOOL(autogenerate_keyword);
740 SET_STR(instant_url);
741 SET_INT64(last_modified);
742 SET_STR(sync_guid);
743 SET_STR_REP(alternate_urls);
744 SET_STR(search_terms_replacement_key);
745 SET_STR(image_url);
746 SET_STR(search_url_post_params);
747 SET_STR(suggestions_url_post_params);
748 SET_STR(instant_url_post_params);
749 SET_STR(image_url_post_params);
750 SET_STR(new_tab_url);
751 return value;
754 base::DictionaryValue* SessionSpecificsToValue(
755 const sync_pb::SessionSpecifics& proto) {
756 base::DictionaryValue* value = new base::DictionaryValue();
757 SET_STR(session_tag);
758 SET(header, SessionHeaderToValue);
759 SET(tab, SessionTabToValue);
760 SET_INT32(tab_node_id);
761 return value;
764 base::DictionaryValue* ThemeSpecificsToValue(
765 const sync_pb::ThemeSpecifics& proto) {
766 base::DictionaryValue* value = new base::DictionaryValue();
767 SET_BOOL(use_custom_theme);
768 SET_BOOL(use_system_theme_by_default);
769 SET_STR(custom_theme_name);
770 SET_STR(custom_theme_id);
771 SET_STR(custom_theme_update_url);
772 return value;
775 base::DictionaryValue* TypedUrlSpecificsToValue(
776 const sync_pb::TypedUrlSpecifics& proto) {
777 base::DictionaryValue* value = new base::DictionaryValue();
778 SET_STR(url);
779 SET_STR(title);
780 SET_BOOL(hidden);
781 SET_INT64_REP(visits);
782 SET_INT32_REP(visit_transitions);
783 return value;
786 base::DictionaryValue* WifiCredentialSpecificsToValue(
787 const sync_pb::WifiCredentialSpecifics& proto) {
788 base::DictionaryValue* value = new base::DictionaryValue();
789 SET_BYTES(ssid);
790 SET_ENUM(security_class, GetWifiCredentialSecurityClassString);
791 SET_BYTES(passphrase);
792 return value;
795 base::DictionaryValue* EntitySpecificsToValue(
796 const sync_pb::EntitySpecifics& specifics) {
797 base::DictionaryValue* value = new base::DictionaryValue();
798 SET_FIELD(app, AppSpecificsToValue);
799 SET_FIELD(app_list, AppListSpecificsToValue);
800 SET_FIELD(app_notification, AppNotificationToValue);
801 SET_FIELD(app_setting, AppSettingSpecificsToValue);
802 SET_FIELD(article, ArticleSpecificsToValue);
803 SET_FIELD(autofill, AutofillSpecificsToValue);
804 SET_FIELD(autofill_profile, AutofillProfileSpecificsToValue);
805 SET_FIELD(bookmark, BookmarkSpecificsToValue);
806 SET_FIELD(device_info, DeviceInfoSpecificsToValue);
807 SET_FIELD(dictionary, DictionarySpecificsToValue);
808 SET_FIELD(experiments, ExperimentsSpecificsToValue);
809 SET_FIELD(extension, ExtensionSpecificsToValue);
810 SET_FIELD(extension_setting, ExtensionSettingSpecificsToValue);
811 SET_FIELD(favicon_image, FaviconImageSpecificsToValue);
812 SET_FIELD(favicon_tracking, FaviconTrackingSpecificsToValue);
813 SET_FIELD(history_delete_directive, HistoryDeleteDirectiveSpecificsToValue);
814 SET_FIELD(managed_user_setting, ManagedUserSettingSpecificsToValue);
815 SET_FIELD(managed_user_shared_setting,
816 ManagedUserSharedSettingSpecificsToValue);
817 SET_FIELD(managed_user, ManagedUserSpecificsToValue);
818 SET_FIELD(nigori, NigoriSpecificsToValue);
819 SET_FIELD(password, PasswordSpecificsToValue);
820 SET_FIELD(preference, PreferenceSpecificsToValue);
821 SET_FIELD(priority_preference, PriorityPreferenceSpecificsToValue);
822 SET_FIELD(search_engine, SearchEngineSpecificsToValue);
823 SET_FIELD(session, SessionSpecificsToValue);
824 SET_FIELD(synced_notification, SyncedNotificationSpecificsToValue);
825 SET_FIELD(synced_notification_app_info,
826 SyncedNotificationAppInfoSpecificsToValue);
827 SET_FIELD(theme, ThemeSpecificsToValue);
828 SET_FIELD(typed_url, TypedUrlSpecificsToValue);
829 SET_FIELD(wifi_credential, WifiCredentialSpecificsToValue);
830 return value;
833 namespace {
835 base::StringValue* UniquePositionToStringValue(
836 const sync_pb::UniquePosition& proto) {
837 UniquePosition pos = UniquePosition::FromProto(proto);
838 return new base::StringValue(pos.ToDebugString());
841 } // namespace
843 base::DictionaryValue* SyncEntityToValue(const sync_pb::SyncEntity& proto,
844 bool include_specifics) {
845 base::DictionaryValue* value = new base::DictionaryValue();
846 SET_STR(id_string);
847 SET_STR(parent_id_string);
848 SET_STR(old_parent_id);
849 SET_INT64(version);
850 SET_INT64(mtime);
851 SET_INT64(ctime);
852 SET_STR(name);
853 SET_STR(non_unique_name);
854 SET_INT64(sync_timestamp);
855 SET_STR(server_defined_unique_tag);
856 SET_INT64(position_in_parent);
857 SET(unique_position, UniquePositionToStringValue);
858 SET_STR(insert_after_item_id);
859 SET_BOOL(deleted);
860 SET_STR(originator_cache_guid);
861 SET_STR(originator_client_item_id);
862 if (include_specifics)
863 SET(specifics, EntitySpecificsToValue);
864 SET_BOOL(folder);
865 SET_STR(client_defined_unique_tag);
866 SET_REP(attachment_id, AttachmentIdProtoToValue);
867 return value;
870 namespace {
872 base::ListValue* SyncEntitiesToValue(
873 const ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities,
874 bool include_specifics) {
875 base::ListValue* list = new base::ListValue();
876 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it;
877 for (it = entities.begin(); it != entities.end(); ++it) {
878 list->Append(SyncEntityToValue(*it, include_specifics));
881 return list;
884 base::DictionaryValue* ChromiumExtensionActivityToValue(
885 const sync_pb::ChromiumExtensionsActivity& proto) {
886 base::DictionaryValue* value = new base::DictionaryValue();
887 SET_STR(extension_id);
888 SET_INT32(bookmark_writes_since_last_commit);
889 return value;
892 base::DictionaryValue* CommitMessageToValue(
893 const sync_pb::CommitMessage& proto,
894 bool include_specifics) {
895 base::DictionaryValue* value = new base::DictionaryValue();
896 value->Set("entries",
897 SyncEntitiesToValue(proto.entries(), include_specifics));
898 SET_STR(cache_guid);
899 SET_REP(extensions_activity, ChromiumExtensionActivityToValue);
900 SET(config_params, ClientConfigParamsToValue);
901 return value;
904 base::DictionaryValue* GetUpdateTriggersToValue(
905 const sync_pb::GetUpdateTriggers& proto) {
906 base::DictionaryValue* value = new base::DictionaryValue();
907 SET_STR_REP(notification_hint);
908 SET_BOOL(client_dropped_hints);
909 SET_BOOL(invalidations_out_of_sync);
910 SET_INT64(local_modification_nudges);
911 SET_INT64(datatype_refresh_nudges);
912 return value;
915 base::DictionaryValue* DataTypeProgressMarkerToValue(
916 const sync_pb::DataTypeProgressMarker& proto) {
917 base::DictionaryValue* value = new base::DictionaryValue();
918 SET_INT32(data_type_id);
919 SET_BYTES(token);
920 SET_INT64(timestamp_token_for_migration);
921 SET_STR(notification_hint);
922 SET(get_update_triggers, GetUpdateTriggersToValue);
923 return value;
926 base::DictionaryValue* DataTypeContextToValue(
927 const sync_pb::DataTypeContext& proto) {
928 base::DictionaryValue* value = new base::DictionaryValue();
929 SET_INT32(data_type_id);
930 SET_STR(context);
931 SET_INT64(version);
932 return value;
935 base::DictionaryValue* GetUpdatesCallerInfoToValue(
936 const sync_pb::GetUpdatesCallerInfo& proto) {
937 base::DictionaryValue* value = new base::DictionaryValue();
938 SET_ENUM(source, GetUpdatesSourceString);
939 SET_BOOL(notifications_enabled);
940 return value;
943 base::DictionaryValue* GetUpdatesMessageToValue(
944 const sync_pb::GetUpdatesMessage& proto) {
945 base::DictionaryValue* value = new base::DictionaryValue();
946 SET(caller_info, GetUpdatesCallerInfoToValue);
947 SET_BOOL(fetch_folders);
948 SET_INT32(batch_size);
949 SET_REP(from_progress_marker, DataTypeProgressMarkerToValue);
950 SET_BOOL(streaming);
951 SET_BOOL(need_encryption_key);
952 SET_BOOL(create_mobile_bookmarks_folder);
953 SET_ENUM(get_updates_origin, GetUpdatesOriginString);
954 SET_REP(client_contexts, DataTypeContextToValue);
955 return value;
958 base::DictionaryValue* ClientStatusToValue(const sync_pb::ClientStatus& proto) {
959 base::DictionaryValue* value = new base::DictionaryValue();
960 SET_BOOL(hierarchy_conflict_detected);
961 return value;
964 base::DictionaryValue* EntryResponseToValue(
965 const sync_pb::CommitResponse::EntryResponse& proto) {
966 base::DictionaryValue* value = new base::DictionaryValue();
967 SET_ENUM(response_type, GetResponseTypeString);
968 SET_STR(id_string);
969 SET_STR(parent_id_string);
970 SET_INT64(position_in_parent);
971 SET_INT64(version);
972 SET_STR(name);
973 SET_STR(error_message);
974 SET_INT64(mtime);
975 return value;
978 base::DictionaryValue* CommitResponseToValue(
979 const sync_pb::CommitResponse& proto) {
980 base::DictionaryValue* value = new base::DictionaryValue();
981 SET_REP(entryresponse, EntryResponseToValue);
982 return value;
985 base::DictionaryValue* GetUpdatesResponseToValue(
986 const sync_pb::GetUpdatesResponse& proto,
987 bool include_specifics) {
988 base::DictionaryValue* value = new base::DictionaryValue();
989 value->Set("entries",
990 SyncEntitiesToValue(proto.entries(), include_specifics));
991 SET_INT64(changes_remaining);
992 SET_REP(new_progress_marker, DataTypeProgressMarkerToValue);
993 SET_REP(context_mutations, DataTypeContextToValue);
994 return value;
997 base::DictionaryValue* ClientCommandToValue(
998 const sync_pb::ClientCommand& proto) {
999 base::DictionaryValue* value = new base::DictionaryValue();
1000 SET_INT32(set_sync_poll_interval);
1001 SET_INT32(set_sync_long_poll_interval);
1002 SET_INT32(max_commit_batch_size);
1003 SET_INT32(sessions_commit_delay_seconds);
1004 SET_INT32(throttle_delay_seconds);
1005 SET_INT32(client_invalidation_hint_buffer_size);
1006 return value;
1009 base::DictionaryValue* ErrorToValue(
1010 const sync_pb::ClientToServerResponse::Error& proto) {
1011 base::DictionaryValue* value = new base::DictionaryValue();
1012 SET_ENUM(error_type, GetErrorTypeString);
1013 SET_STR(error_description);
1014 SET_STR(url);
1015 SET_ENUM(action, GetActionString);
1016 return value;
1019 } // namespace
1021 base::DictionaryValue* ClientToServerResponseToValue(
1022 const sync_pb::ClientToServerResponse& proto,
1023 bool include_specifics) {
1024 base::DictionaryValue* value = new base::DictionaryValue();
1025 SET(commit, CommitResponseToValue);
1026 if (proto.has_get_updates()) {
1027 value->Set("get_updates", GetUpdatesResponseToValue(proto.get_updates(),
1028 include_specifics));
1031 SET(error, ErrorToValue);
1032 SET_ENUM(error_code, GetErrorTypeString);
1033 SET_STR(error_message);
1034 SET_STR(store_birthday);
1035 SET(client_command, ClientCommandToValue);
1036 SET_INT32_REP(migrated_data_type_id);
1037 return value;
1040 base::DictionaryValue* ClientToServerMessageToValue(
1041 const sync_pb::ClientToServerMessage& proto,
1042 bool include_specifics) {
1043 base::DictionaryValue* value = new base::DictionaryValue();
1044 SET_STR(share);
1045 SET_INT32(protocol_version);
1046 if (proto.has_commit()) {
1047 value->Set("commit",
1048 CommitMessageToValue(proto.commit(), include_specifics));
1051 SET(get_updates, GetUpdatesMessageToValue);
1052 SET_STR(store_birthday);
1053 SET_BOOL(sync_problem_detected);
1054 SET(debug_info, DebugInfoToValue);
1055 SET(client_status, ClientStatusToValue);
1056 return value;
1059 base::DictionaryValue* DatatypeAssociationStatsToValue(
1060 const sync_pb::DatatypeAssociationStats& proto) {
1061 base::DictionaryValue* value = new base::DictionaryValue();
1062 SET_INT32(data_type_id);
1063 SET_INT32(num_local_items_before_association);
1064 SET_INT32(num_sync_items_before_association);
1065 SET_INT32(num_local_items_after_association);
1066 SET_INT32(num_sync_items_after_association);
1067 SET_INT32(num_local_items_added);
1068 SET_INT32(num_local_items_deleted);
1069 SET_INT32(num_local_items_modified);
1070 SET_INT32(num_sync_items_added);
1071 SET_INT32(num_sync_items_deleted);
1072 SET_INT32(num_sync_items_modified);
1073 SET_INT64(local_version_pre_association);
1074 SET_INT64(sync_version_pre_association)
1075 SET_BOOL(had_error);
1076 SET_INT64(download_wait_time_us);
1077 SET_INT64(download_time_us);
1078 SET_INT64(association_wait_time_for_high_priority_us);
1079 SET_INT64(association_wait_time_for_same_priority_us);
1080 return value;
1083 base::DictionaryValue* DebugEventInfoToValue(
1084 const sync_pb::DebugEventInfo& proto) {
1085 base::DictionaryValue* value = new base::DictionaryValue();
1086 SET_ENUM(singleton_event, SingletonDebugEventTypeString);
1087 SET(sync_cycle_completed_event_info, SyncCycleCompletedEventInfoToValue);
1088 SET_INT32(nudging_datatype);
1089 SET_INT32_REP(datatypes_notified_from_server);
1090 SET(datatype_association_stats, DatatypeAssociationStatsToValue);
1091 return value;
1094 base::DictionaryValue* DebugInfoToValue(const sync_pb::DebugInfo& proto) {
1095 base::DictionaryValue* value = new base::DictionaryValue();
1096 SET_REP(events, DebugEventInfoToValue);
1097 SET_BOOL(cryptographer_ready);
1098 SET_BOOL(cryptographer_has_pending_keys);
1099 SET_BOOL(events_dropped);
1100 return value;
1103 base::DictionaryValue* SyncCycleCompletedEventInfoToValue(
1104 const sync_pb::SyncCycleCompletedEventInfo& proto) {
1105 base::DictionaryValue* value = new base::DictionaryValue();
1106 SET_INT32(num_encryption_conflicts);
1107 SET_INT32(num_hierarchy_conflicts);
1108 SET_INT32(num_server_conflicts);
1109 SET_INT32(num_updates_downloaded);
1110 SET_INT32(num_reflected_updates_downloaded);
1111 SET(caller_info, GetUpdatesCallerInfoToValue);
1112 return value;
1115 base::DictionaryValue* ClientConfigParamsToValue(
1116 const sync_pb::ClientConfigParams& proto) {
1117 base::DictionaryValue* value = new base::DictionaryValue();
1118 SET_INT32_REP(enabled_type_ids);
1119 SET_BOOL(tabs_datatype_enabled);
1120 return value;
1123 base::DictionaryValue* AttachmentIdProtoToValue(
1124 const sync_pb::AttachmentIdProto& proto) {
1125 base::DictionaryValue* value = new base::DictionaryValue();
1126 SET_STR(unique_id);
1127 return value;
1130 #undef SET
1131 #undef SET_REP
1133 #undef SET_BOOL
1134 #undef SET_BYTES
1135 #undef SET_INT32
1136 #undef SET_INT64
1137 #undef SET_INT64_REP
1138 #undef SET_STR
1139 #undef SET_STR_REP
1141 #undef SET_FIELD
1143 } // namespace syncer