Update .DEPS.git
[chromium-blink-merge.git] / sync / protocol / proto_value_conversions.cc
blobbe6394257c259167b7b037e035bb77d5af891277
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/logging.h"
14 #include "base/strings/string_number_conversions.h"
15 #include "base/values.h"
16 #include "sync/internal_api/public/base/unique_position.h"
17 #include "sync/protocol/app_list_specifics.pb.h"
18 #include "sync/protocol/app_notification_specifics.pb.h"
19 #include "sync/protocol/app_setting_specifics.pb.h"
20 #include "sync/protocol/app_specifics.pb.h"
21 #include "sync/protocol/autofill_specifics.pb.h"
22 #include "sync/protocol/bookmark_specifics.pb.h"
23 #include "sync/protocol/dictionary_specifics.pb.h"
24 #include "sync/protocol/encryption.pb.h"
25 #include "sync/protocol/experiments_specifics.pb.h"
26 #include "sync/protocol/extension_setting_specifics.pb.h"
27 #include "sync/protocol/extension_specifics.pb.h"
28 #include "sync/protocol/favicon_image_specifics.pb.h"
29 #include "sync/protocol/favicon_tracking_specifics.pb.h"
30 #include "sync/protocol/history_delete_directive_specifics.pb.h"
31 #include "sync/protocol/nigori_specifics.pb.h"
32 #include "sync/protocol/password_specifics.pb.h"
33 #include "sync/protocol/preference_specifics.pb.h"
34 #include "sync/protocol/priority_preference_specifics.pb.h"
35 #include "sync/protocol/proto_enum_conversions.h"
36 #include "sync/protocol/search_engine_specifics.pb.h"
37 #include "sync/protocol/session_specifics.pb.h"
38 #include "sync/protocol/sync.pb.h"
39 #include "sync/protocol/synced_notification_specifics.pb.h"
40 #include "sync/protocol/theme_specifics.pb.h"
41 #include "sync/protocol/typed_url_specifics.pb.h"
42 #include "sync/protocol/unique_position.pb.h"
44 namespace syncer {
46 namespace {
48 // Basic Type -> Value functions.
50 base::StringValue* MakeInt64Value(int64 x) {
51 return new base::StringValue(base::Int64ToString(x));
54 // TODO(akalin): Perhaps make JSONWriter support BinaryValue and use
55 // that instead of a StringValue.
56 base::StringValue* MakeBytesValue(const std::string& bytes) {
57 std::string bytes_base64;
58 base::Base64Encode(bytes, &bytes_base64);
59 return new base::StringValue(bytes_base64);
62 base::StringValue* MakeStringValue(const std::string& str) {
63 return new base::StringValue(str);
66 // T is the enum type.
67 template <class T>
68 base::StringValue* MakeEnumValue(T t, const char* (*converter_fn)(T)) {
69 return new base::StringValue(converter_fn(t));
72 // T is the field type, F is either RepeatedField or RepeatedPtrField,
73 // and V is a subclass of Value.
74 template <class T, class F, class V>
75 base::ListValue* MakeRepeatedValue(const F& fields, V* (*converter_fn)(T)) {
76 base::ListValue* list = new base::ListValue();
77 for (typename F::const_iterator it = fields.begin(); it != fields.end();
78 ++it) {
79 list->Append(converter_fn(*it));
81 return list;
84 } // namespace
86 // Helper macros to reduce the amount of boilerplate.
88 #define SET(field, fn) \
89 if (proto.has_##field()) { \
90 value->Set(#field, fn(proto.field())); \
92 #define SET_REP(field, fn) \
93 value->Set(#field, MakeRepeatedValue(proto.field(), fn))
94 #define SET_ENUM(field, fn) \
95 value->Set(#field, MakeEnumValue(proto.field(), fn))
97 #define SET_BOOL(field) SET(field, new base::FundamentalValue)
98 #define SET_BYTES(field) SET(field, MakeBytesValue)
99 #define SET_INT32(field) SET(field, MakeInt64Value)
100 #define SET_INT32_REP(field) SET_REP(field, MakeInt64Value)
101 #define SET_INT64(field) SET(field, MakeInt64Value)
102 #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value)
103 #define SET_STR(field) SET(field, new base::StringValue)
104 #define SET_STR_REP(field) \
105 value->Set(#field, \
106 MakeRepeatedValue<const std::string&, \
107 google::protobuf::RepeatedPtrField< \
108 std::string >, \
109 base::StringValue>(proto.field(), \
110 MakeStringValue))
111 #define SET_EXPERIMENT_ENABLED_FIELD(field) \
112 do { \
113 if (proto.has_##field() && \
114 proto.field().has_enabled()) { \
115 value->Set(#field, \
116 new base::FundamentalValue( \
117 proto.field().enabled())); \
119 } while (0)
121 #define SET_FIELD(field, fn) \
122 do { \
123 if (specifics.has_##field()) { \
124 value->Set(#field, fn(specifics.field())); \
126 } while (0)
128 // If you add another macro, don't forget to add an #undef at the end
129 // of this file, too.
131 base::DictionaryValue* EncryptedDataToValue(
132 const sync_pb::EncryptedData& proto) {
133 base::DictionaryValue* value = new base::DictionaryValue();
134 SET_STR(key_name);
135 // TODO(akalin): Shouldn't blob be of type bytes instead of string?
136 SET_BYTES(blob);
137 return value;
140 base::DictionaryValue* AppSettingsToValue(
141 const sync_pb::AppNotificationSettings& proto) {
142 base::DictionaryValue* value = new base::DictionaryValue();
143 SET_BOOL(initial_setup_done);
144 SET_BOOL(disabled);
145 SET_STR(oauth_client_id);
146 return value;
149 base::DictionaryValue* SessionHeaderToValue(
150 const sync_pb::SessionHeader& proto) {
151 base::DictionaryValue* value = new base::DictionaryValue();
152 SET_REP(window, SessionWindowToValue);
153 SET_STR(client_name);
154 SET_ENUM(device_type, GetDeviceTypeString);
155 return value;
158 base::DictionaryValue* SessionTabToValue(const sync_pb::SessionTab& proto) {
159 base::DictionaryValue* value = new base::DictionaryValue();
160 SET_INT32(tab_id);
161 SET_INT32(window_id);
162 SET_INT32(tab_visual_index);
163 SET_INT32(current_navigation_index);
164 SET_BOOL(pinned);
165 SET_STR(extension_app_id);
166 SET_REP(navigation, TabNavigationToValue);
167 SET_BYTES(favicon);
168 SET_ENUM(favicon_type, GetFaviconTypeString);
169 SET_STR(favicon_source);
170 return value;
173 base::DictionaryValue* SessionWindowToValue(
174 const sync_pb::SessionWindow& proto) {
175 base::DictionaryValue* value = new base::DictionaryValue();
176 SET_INT32(window_id);
177 SET_INT32(selected_tab_index);
178 SET_INT32_REP(tab);
179 SET_ENUM(browser_type, GetBrowserTypeString);
180 return value;
183 base::DictionaryValue* TabNavigationToValue(
184 const sync_pb::TabNavigation& proto) {
185 base::DictionaryValue* value = new base::DictionaryValue();
186 SET_STR(virtual_url);
187 SET_STR(referrer);
188 SET_STR(title);
189 SET_STR(state);
190 SET_ENUM(page_transition, GetPageTransitionString);
191 SET_ENUM(redirect_type, GetPageTransitionRedirectTypeString);
192 SET_INT32(unique_id);
193 SET_INT64(timestamp_msec);
194 SET_BOOL(navigation_forward_back);
195 SET_BOOL(navigation_from_address_bar);
196 SET_BOOL(navigation_home_page);
197 SET_BOOL(navigation_chain_start);
198 SET_BOOL(navigation_chain_end);
199 SET_INT64(global_id);
200 SET_STR(search_terms);
201 SET_STR(favicon_url);
202 SET_ENUM(blocked_state, GetBlockedStateString);
203 SET_STR_REP(content_pack_categories);
204 SET_INT32(http_status_code);
205 SET_INT32(referrer_policy);
206 return value;
209 base::DictionaryValue* PasswordSpecificsDataToValue(
210 const sync_pb::PasswordSpecificsData& proto) {
211 base::DictionaryValue* value = new base::DictionaryValue();
212 SET_INT32(scheme);
213 SET_STR(signon_realm);
214 SET_STR(origin);
215 SET_STR(action);
216 SET_STR(username_element);
217 SET_STR(username_value);
218 SET_STR(password_element);
219 value->SetString("password_value", "<redacted>");
220 SET_BOOL(ssl_valid);
221 SET_BOOL(preferred);
222 SET_INT64(date_created);
223 SET_BOOL(blacklisted);
224 return value;
227 base::DictionaryValue* GlobalIdDirectiveToValue(
228 const sync_pb::GlobalIdDirective& proto) {
229 base::DictionaryValue* value = new base::DictionaryValue();
230 SET_INT64_REP(global_id);
231 SET_INT64(start_time_usec);
232 SET_INT64(end_time_usec);
233 return value;
236 base::DictionaryValue* TimeRangeDirectiveToValue(
237 const sync_pb::TimeRangeDirective& proto) {
238 base::DictionaryValue* value = new base::DictionaryValue();
239 SET_INT64(start_time_usec);
240 SET_INT64(end_time_usec);
241 return value;
244 base::DictionaryValue* SyncedNotificationImageToValue(
245 const sync_pb::SyncedNotificationImage& proto) {
246 base::DictionaryValue* value = new base::DictionaryValue();
247 SET_STR(url);
248 SET_STR(alt_text);
249 SET_INT32(preferred_width);
250 SET_INT32(preferred_height);
251 return value;
254 base::DictionaryValue* SyncedNotificationProfileImageToValue(
255 const sync_pb::SyncedNotificationProfileImage& proto) {
256 base::DictionaryValue* value = new base::DictionaryValue();
257 SET_STR(image_url);
258 SET_STR(oid);
259 SET_STR(display_name);
260 return value;
263 base::DictionaryValue* MediaToValue(
264 const sync_pb::Media& proto) {
265 base::DictionaryValue* value = new base::DictionaryValue();
266 SET(image, SyncedNotificationImageToValue);
267 return value;
270 base::DictionaryValue* SyncedNotificationActionToValue(
271 const sync_pb::SyncedNotificationAction& proto) {
272 base::DictionaryValue* value = new base::DictionaryValue();
273 SET_STR(text);
274 SET(icon, SyncedNotificationImageToValue);
275 SET_STR(url);
276 SET_STR(request_data);
277 SET_STR(accessibility_label);
278 return value;
281 base::DictionaryValue* SyncedNotificationDestiationToValue(
282 const sync_pb::SyncedNotificationDestination& proto) {
283 base::DictionaryValue* value = new base::DictionaryValue();
284 SET_STR(text);
285 SET(icon, SyncedNotificationImageToValue);
286 SET_STR(url);
287 SET_STR(accessibility_label);
288 return value;
291 base::DictionaryValue* TargetToValue(
292 const sync_pb::Target& proto) {
293 base::DictionaryValue* value = new base::DictionaryValue();
294 SET(destination, SyncedNotificationDestiationToValue);
295 SET(action, SyncedNotificationActionToValue);
296 SET_STR(target_key);
297 return value;
300 base::DictionaryValue* SimpleCollapsedLayoutToValue(
301 const sync_pb::SimpleCollapsedLayout& proto) {
302 base::DictionaryValue* value = new base::DictionaryValue();
303 SET(app_icon, SyncedNotificationImageToValue);
304 SET_REP(profile_image, SyncedNotificationProfileImageToValue);
305 SET_STR(heading);
306 SET_STR(description);
307 SET_STR(annotation);
308 SET_REP(media, MediaToValue);
309 return value;
312 base::DictionaryValue* CollapsedInfoToValue(
313 const sync_pb::CollapsedInfo& proto) {
314 base::DictionaryValue* value = new base::DictionaryValue();
315 SET(simple_collapsed_layout, SimpleCollapsedLayoutToValue);
316 SET_INT64(creation_timestamp_usec);
317 SET(default_destination, SyncedNotificationDestiationToValue);
318 SET_REP(target, TargetToValue);
319 return value;
322 base::DictionaryValue* SyncedNotificationToValue(
323 const sync_pb::SyncedNotification& proto) {
324 base::DictionaryValue* value = new base::DictionaryValue();
325 SET_STR(type);
326 SET_STR(external_id);
327 // TODO(petewil) Add SyncedNotificationCreator here if we ever need it.
328 return value;
331 base::DictionaryValue* RenderInfoToValue(
332 const sync_pb::SyncedNotificationRenderInfo& proto) {
333 base::DictionaryValue* value = new base::DictionaryValue();
334 // TODO(petewil): Add the expanded info values once we start using them.
335 SET(collapsed_info, CollapsedInfoToValue);
336 return value;
339 base::DictionaryValue* CoalescedNotificationToValue(
340 const sync_pb::CoalescedSyncedNotification& proto) {
341 base::DictionaryValue* value = new base::DictionaryValue();
342 SET_STR(key);
343 SET_STR(app_id);
344 SET_REP(notification, SyncedNotificationToValue);
345 SET(render_info, RenderInfoToValue);
346 SET_INT32(read_state);
347 SET_INT64(creation_time_msec);
348 SET_INT32(priority);
349 return value;
352 base::DictionaryValue* AppListSpecificsToValue(
353 const sync_pb::AppListSpecifics& proto) {
354 base::DictionaryValue* value = new base::DictionaryValue();
355 SET_STR(item_id);
356 SET_ENUM(item_type, GetAppListItemTypeString);
357 SET_STR(item_name);
358 SET_STR(parent_id);
359 SET_STR(page_ordinal);
360 SET_STR(item_ordinal);
362 return value;
365 base::DictionaryValue* AppNotificationToValue(
366 const sync_pb::AppNotification& proto) {
367 base::DictionaryValue* value = new base::DictionaryValue();
368 SET_STR(guid);
369 SET_STR(app_id);
370 SET_INT64(creation_timestamp_ms);
371 SET_STR(title);
372 SET_STR(body_text);
373 SET_STR(link_url);
374 SET_STR(link_text);
375 return value;
378 base::DictionaryValue* AppSettingSpecificsToValue(
379 const sync_pb::AppSettingSpecifics& proto) {
380 base::DictionaryValue* value = new base::DictionaryValue();
381 SET(extension_setting, ExtensionSettingSpecificsToValue);
382 return value;
385 base::DictionaryValue* AppSpecificsToValue(
386 const sync_pb::AppSpecifics& proto) {
387 base::DictionaryValue* value = new base::DictionaryValue();
388 SET(extension, ExtensionSpecificsToValue);
389 SET(notification_settings, AppSettingsToValue);
390 SET_STR(app_launch_ordinal);
391 SET_STR(page_ordinal);
392 SET_ENUM(launch_type, GetLaunchTypeString);
394 return value;
397 base::DictionaryValue* AutofillSpecificsToValue(
398 const sync_pb::AutofillSpecifics& proto) {
399 base::DictionaryValue* value = new base::DictionaryValue();
400 SET_STR(name);
401 SET_STR(value);
402 SET_INT64_REP(usage_timestamp);
403 SET(profile, AutofillProfileSpecificsToValue);
404 return value;
407 base::DictionaryValue* AutofillProfileSpecificsToValue(
408 const sync_pb::AutofillProfileSpecifics& proto) {
409 base::DictionaryValue* value = new base::DictionaryValue();
410 SET_STR(guid);
411 SET_STR(origin);
413 SET_STR_REP(name_first);
414 SET_STR_REP(name_middle);
415 SET_STR_REP(name_last);
416 SET_STR_REP(email_address);
417 SET_STR(company_name);
419 SET_STR(address_home_line1);
420 SET_STR(address_home_line2);
421 SET_STR(address_home_city);
422 SET_STR(address_home_state);
423 SET_STR(address_home_zip);
424 SET_STR(address_home_country);
426 SET_STR(address_home_street_address);
427 SET_STR(address_home_sorting_code);
428 SET_STR(address_home_dependent_locality);
430 SET_STR_REP(phone_home_whole_number);
431 return value;
434 base::DictionaryValue* MetaInfoToValue(
435 const sync_pb::MetaInfo& proto) {
436 base::DictionaryValue* value = new base::DictionaryValue();
437 SET_STR(key);
438 SET_STR(value);
439 return value;
442 base::DictionaryValue* BookmarkSpecificsToValue(
443 const sync_pb::BookmarkSpecifics& proto) {
444 base::DictionaryValue* value = new base::DictionaryValue();
445 SET_STR(url);
446 SET_BYTES(favicon);
447 SET_STR(title);
448 SET_INT64(creation_time_us);
449 SET_STR(icon_url);
450 SET_REP(meta_info, &MetaInfoToValue);
451 return value;
454 base::DictionaryValue* DeviceInfoSpecificsToValue(
455 const sync_pb::DeviceInfoSpecifics& proto) {
456 base::DictionaryValue* value = new base::DictionaryValue();
457 SET_STR(cache_guid);
458 SET_STR(client_name);
459 SET_ENUM(device_type, GetDeviceTypeString);
460 SET_STR(sync_user_agent);
461 SET_STR(chrome_version);
462 return value;
465 base::DictionaryValue* DictionarySpecificsToValue(
466 const sync_pb::DictionarySpecifics& proto) {
467 base::DictionaryValue* value = new base::DictionaryValue();
468 SET_STR(word);
469 return value;
472 namespace {
474 base::DictionaryValue* FaviconSyncFlagsToValue(
475 const sync_pb::FaviconSyncFlags& proto) {
476 base::DictionaryValue* value = new base::DictionaryValue();
477 SET_BOOL(enabled);
478 SET_INT32(favicon_sync_limit);
479 return value;
482 } // namespace
484 base::DictionaryValue* ExperimentsSpecificsToValue(
485 const sync_pb::ExperimentsSpecifics& proto) {
486 base::DictionaryValue* value = new base::DictionaryValue();
487 SET_EXPERIMENT_ENABLED_FIELD(keystore_encryption);
488 SET_EXPERIMENT_ENABLED_FIELD(history_delete_directives);
489 SET_EXPERIMENT_ENABLED_FIELD(autofill_culling);
490 SET_EXPERIMENT_ENABLED_FIELD(pre_commit_update_avoidance);
491 if (proto.has_favicon_sync())
492 SET(favicon_sync, FaviconSyncFlagsToValue);
493 return value;
496 base::DictionaryValue* ExtensionSettingSpecificsToValue(
497 const sync_pb::ExtensionSettingSpecifics& proto) {
498 base::DictionaryValue* value = new base::DictionaryValue();
499 SET_STR(extension_id);
500 SET_STR(key);
501 SET_STR(value);
502 return value;
505 base::DictionaryValue* ExtensionSpecificsToValue(
506 const sync_pb::ExtensionSpecifics& proto) {
507 base::DictionaryValue* value = new base::DictionaryValue();
508 SET_STR(id);
509 SET_STR(version);
510 SET_STR(update_url);
511 SET_BOOL(enabled);
512 SET_BOOL(incognito_enabled);
513 SET_STR(name);
514 return value;
517 namespace {
518 base::DictionaryValue* FaviconDataToValue(
519 const sync_pb::FaviconData& proto) {
520 base::DictionaryValue* value = new base::DictionaryValue();
521 SET_BYTES(favicon);
522 SET_INT32(width);
523 SET_INT32(height);
524 return value;
526 } // namespace
528 base::DictionaryValue* FaviconImageSpecificsToValue(
529 const sync_pb::FaviconImageSpecifics& proto) {
530 base::DictionaryValue* value = new base::DictionaryValue();
531 SET_STR(favicon_url);
532 SET(favicon_web, FaviconDataToValue);
533 SET(favicon_web_32, FaviconDataToValue);
534 SET(favicon_touch_64, FaviconDataToValue);
535 SET(favicon_touch_precomposed_64, FaviconDataToValue);
536 return value;
539 base::DictionaryValue* FaviconTrackingSpecificsToValue(
540 const sync_pb::FaviconTrackingSpecifics& proto) {
541 base::DictionaryValue* value = new base::DictionaryValue();
542 SET_STR(favicon_url);
543 SET_INT64(last_visit_time_ms)
544 SET_BOOL(is_bookmarked);
545 return value;
548 base::DictionaryValue* HistoryDeleteDirectiveSpecificsToValue(
549 const sync_pb::HistoryDeleteDirectiveSpecifics& proto) {
550 base::DictionaryValue* value = new base::DictionaryValue();
551 SET(global_id_directive, GlobalIdDirectiveToValue);
552 SET(time_range_directive, TimeRangeDirectiveToValue);
553 return value;
556 base::DictionaryValue* ManagedUserSettingSpecificsToValue(
557 const sync_pb::ManagedUserSettingSpecifics& proto) {
558 base::DictionaryValue* value = new base::DictionaryValue();
559 SET_STR(name);
560 SET_STR(value);
561 return value;
564 base::DictionaryValue* ManagedUserSpecificsToValue(
565 const sync_pb::ManagedUserSpecifics& proto) {
566 base::DictionaryValue* value = new base::DictionaryValue();
567 SET_STR(id);
568 SET_STR(name);
569 SET_BOOL(acknowledged);
570 SET_STR(master_key);
571 SET_STR(chrome_avatar);
572 SET_STR(chromeos_avatar);
573 return value;
576 base::DictionaryValue* ManagedUserSharedSettingSpecificsToValue(
577 const sync_pb::ManagedUserSharedSettingSpecifics& proto) {
578 base::DictionaryValue* value = new base::DictionaryValue();
579 SET_STR(mu_id);
580 SET_STR(key);
581 SET_STR(value);
582 SET_BOOL(acknowledged);
583 return value;
586 base::DictionaryValue* NigoriSpecificsToValue(
587 const sync_pb::NigoriSpecifics& proto) {
588 base::DictionaryValue* value = new base::DictionaryValue();
589 SET(encryption_keybag, EncryptedDataToValue);
590 SET_BOOL(keybag_is_frozen);
591 SET_BOOL(encrypt_bookmarks);
592 SET_BOOL(encrypt_preferences);
593 SET_BOOL(encrypt_autofill_profile);
594 SET_BOOL(encrypt_autofill);
595 SET_BOOL(encrypt_themes);
596 SET_BOOL(encrypt_typed_urls);
597 SET_BOOL(encrypt_extension_settings);
598 SET_BOOL(encrypt_extensions);
599 SET_BOOL(encrypt_sessions);
600 SET_BOOL(encrypt_app_settings);
601 SET_BOOL(encrypt_apps);
602 SET_BOOL(encrypt_search_engines);
603 SET_BOOL(encrypt_dictionary);
604 SET_BOOL(encrypt_articles);
605 SET_BOOL(encrypt_app_list);
606 SET_BOOL(encrypt_everything);
607 SET_BOOL(sync_tab_favicons);
608 SET_ENUM(passphrase_type, PassphraseTypeString);
609 SET(keystore_decryptor_token, EncryptedDataToValue);
610 SET_INT64(keystore_migration_time);
611 SET_INT64(custom_passphrase_time);
612 return value;
615 base::DictionaryValue* ArticlePageToValue(
616 const sync_pb::ArticlePage& proto) {
617 base::DictionaryValue* value = new base::DictionaryValue();
618 SET_STR(url);
619 return value;
622 base::DictionaryValue* ArticleSpecificsToValue(
623 const sync_pb::ArticleSpecifics& proto) {
624 base::DictionaryValue* value = new base::DictionaryValue();
625 SET_STR(entry_id);
626 SET_STR(title);
627 SET_REP(pages, ArticlePageToValue);
628 return value;
631 base::DictionaryValue* PasswordSpecificsToValue(
632 const sync_pb::PasswordSpecifics& proto) {
633 base::DictionaryValue* value = new base::DictionaryValue();
634 SET(encrypted, EncryptedDataToValue);
635 return value;
638 base::DictionaryValue* PreferenceSpecificsToValue(
639 const sync_pb::PreferenceSpecifics& proto) {
640 base::DictionaryValue* value = new base::DictionaryValue();
641 SET_STR(name);
642 SET_STR(value);
643 return value;
646 base::DictionaryValue* PriorityPreferenceSpecificsToValue(
647 const sync_pb::PriorityPreferenceSpecifics& specifics) {
648 base::DictionaryValue* value = new base::DictionaryValue();
649 SET_FIELD(preference, PreferenceSpecificsToValue);
650 return value;
653 base::DictionaryValue* SyncedNotificationSpecificsToValue(
654 const sync_pb::SyncedNotificationSpecifics& proto) {
655 // There is a lot of data, for now just use heading, description, key, and
656 // the read state.
657 // TODO(petewil): Eventually add more data here.
658 base::DictionaryValue* value = new base::DictionaryValue();
659 SET(coalesced_notification, CoalescedNotificationToValue);
660 return value;
663 base::DictionaryValue* SearchEngineSpecificsToValue(
664 const sync_pb::SearchEngineSpecifics& proto) {
665 base::DictionaryValue* value = new base::DictionaryValue();
666 SET_STR(short_name);
667 SET_STR(keyword);
668 SET_STR(favicon_url);
669 SET_STR(url);
670 SET_BOOL(safe_for_autoreplace);
671 SET_STR(originating_url);
672 SET_INT64(date_created);
673 SET_STR(input_encodings);
674 SET_BOOL(show_in_default_list);
675 SET_STR(suggestions_url);
676 SET_INT32(prepopulate_id);
677 SET_BOOL(autogenerate_keyword);
678 SET_STR(instant_url);
679 SET_INT64(last_modified);
680 SET_STR(sync_guid);
681 SET_STR_REP(alternate_urls);
682 SET_STR(search_terms_replacement_key);
683 SET_STR(image_url);
684 SET_STR(search_url_post_params);
685 SET_STR(suggestions_url_post_params);
686 SET_STR(instant_url_post_params);
687 SET_STR(image_url_post_params);
688 SET_STR(new_tab_url);
689 return value;
692 base::DictionaryValue* SessionSpecificsToValue(
693 const sync_pb::SessionSpecifics& proto) {
694 base::DictionaryValue* value = new base::DictionaryValue();
695 SET_STR(session_tag);
696 SET(header, SessionHeaderToValue);
697 SET(tab, SessionTabToValue);
698 SET_INT32(tab_node_id);
699 return value;
702 base::DictionaryValue* ThemeSpecificsToValue(
703 const sync_pb::ThemeSpecifics& proto) {
704 base::DictionaryValue* value = new base::DictionaryValue();
705 SET_BOOL(use_custom_theme);
706 SET_BOOL(use_system_theme_by_default);
707 SET_STR(custom_theme_name);
708 SET_STR(custom_theme_id);
709 SET_STR(custom_theme_update_url);
710 return value;
713 base::DictionaryValue* TypedUrlSpecificsToValue(
714 const sync_pb::TypedUrlSpecifics& proto) {
715 base::DictionaryValue* value = new base::DictionaryValue();
716 SET_STR(url);
717 SET_STR(title);
718 SET_BOOL(hidden);
719 SET_INT64_REP(visits);
720 SET_INT32_REP(visit_transitions);
721 return value;
724 base::DictionaryValue* EntitySpecificsToValue(
725 const sync_pb::EntitySpecifics& specifics) {
726 base::DictionaryValue* value = new base::DictionaryValue();
727 SET_FIELD(app, AppSpecificsToValue);
728 SET_FIELD(app_list, AppListSpecificsToValue);
729 SET_FIELD(app_notification, AppNotificationToValue);
730 SET_FIELD(app_setting, AppSettingSpecificsToValue);
731 SET_FIELD(article, ArticleSpecificsToValue);
732 SET_FIELD(autofill, AutofillSpecificsToValue);
733 SET_FIELD(autofill_profile, AutofillProfileSpecificsToValue);
734 SET_FIELD(bookmark, BookmarkSpecificsToValue);
735 SET_FIELD(device_info, DeviceInfoSpecificsToValue);
736 SET_FIELD(dictionary, DictionarySpecificsToValue);
737 SET_FIELD(experiments, ExperimentsSpecificsToValue);
738 SET_FIELD(extension, ExtensionSpecificsToValue);
739 SET_FIELD(extension_setting, ExtensionSettingSpecificsToValue);
740 SET_FIELD(favicon_image, FaviconImageSpecificsToValue);
741 SET_FIELD(favicon_tracking, FaviconTrackingSpecificsToValue);
742 SET_FIELD(history_delete_directive, HistoryDeleteDirectiveSpecificsToValue);
743 SET_FIELD(managed_user_setting, ManagedUserSettingSpecificsToValue);
744 SET_FIELD(managed_user_shared_setting,
745 ManagedUserSharedSettingSpecificsToValue);
746 SET_FIELD(managed_user, ManagedUserSpecificsToValue);
747 SET_FIELD(nigori, NigoriSpecificsToValue);
748 SET_FIELD(password, PasswordSpecificsToValue);
749 SET_FIELD(preference, PreferenceSpecificsToValue);
750 SET_FIELD(priority_preference, PriorityPreferenceSpecificsToValue);
751 SET_FIELD(search_engine, SearchEngineSpecificsToValue);
752 SET_FIELD(session, SessionSpecificsToValue);
753 SET_FIELD(synced_notification, SyncedNotificationSpecificsToValue);
754 SET_FIELD(theme, ThemeSpecificsToValue);
755 SET_FIELD(typed_url, TypedUrlSpecificsToValue);
756 return value;
759 namespace {
761 base::StringValue* UniquePositionToStringValue(
762 const sync_pb::UniquePosition& proto) {
763 UniquePosition pos = UniquePosition::FromProto(proto);
764 return new base::StringValue(pos.ToDebugString());
767 base::DictionaryValue* SyncEntityToValue(const sync_pb::SyncEntity& proto,
768 bool include_specifics) {
769 base::DictionaryValue* value = new base::DictionaryValue();
770 SET_STR(id_string);
771 SET_STR(parent_id_string);
772 SET_STR(old_parent_id);
773 SET_INT64(version);
774 SET_INT64(mtime);
775 SET_INT64(ctime);
776 SET_STR(name);
777 SET_STR(non_unique_name);
778 SET_INT64(sync_timestamp);
779 SET_STR(server_defined_unique_tag);
780 SET_INT64(position_in_parent);
781 SET(unique_position, UniquePositionToStringValue);
782 SET_STR(insert_after_item_id);
783 SET_BOOL(deleted);
784 SET_STR(originator_cache_guid);
785 SET_STR(originator_client_item_id);
786 if (include_specifics)
787 SET(specifics, EntitySpecificsToValue);
788 SET_BOOL(folder);
789 SET_STR(client_defined_unique_tag);
790 return value;
793 base::ListValue* SyncEntitiesToValue(
794 const ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities,
795 bool include_specifics) {
796 base::ListValue* list = new base::ListValue();
797 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it;
798 for (it = entities.begin(); it != entities.end(); ++it) {
799 list->Append(SyncEntityToValue(*it, include_specifics));
802 return list;
805 base::DictionaryValue* ChromiumExtensionActivityToValue(
806 const sync_pb::ChromiumExtensionsActivity& proto) {
807 base::DictionaryValue* value = new base::DictionaryValue();
808 SET_STR(extension_id);
809 SET_INT32(bookmark_writes_since_last_commit);
810 return value;
813 base::DictionaryValue* CommitMessageToValue(
814 const sync_pb::CommitMessage& proto,
815 bool include_specifics) {
816 base::DictionaryValue* value = new base::DictionaryValue();
817 value->Set("entries",
818 SyncEntitiesToValue(proto.entries(), include_specifics));
819 SET_STR(cache_guid);
820 SET_REP(extensions_activity, ChromiumExtensionActivityToValue);
821 SET(config_params, ClientConfigParamsToValue);
822 return value;
825 base::DictionaryValue* GetUpdateTriggersToValue(
826 const sync_pb::GetUpdateTriggers& proto) {
827 base::DictionaryValue* value = new base::DictionaryValue();
828 SET_STR_REP(notification_hint);
829 SET_BOOL(client_dropped_hints);
830 SET_BOOL(invalidations_out_of_sync);
831 SET_INT64(local_modification_nudges);
832 SET_INT64(datatype_refresh_nudges);
833 return value;
836 base::DictionaryValue* DataTypeProgressMarkerToValue(
837 const sync_pb::DataTypeProgressMarker& proto) {
838 base::DictionaryValue* value = new base::DictionaryValue();
839 SET_INT32(data_type_id);
840 SET_BYTES(token);
841 SET_INT64(timestamp_token_for_migration);
842 SET_STR(notification_hint);
843 SET(get_update_triggers, GetUpdateTriggersToValue);
844 return value;
847 base::DictionaryValue* GetUpdatesCallerInfoToValue(
848 const sync_pb::GetUpdatesCallerInfo& proto) {
849 base::DictionaryValue* value = new base::DictionaryValue();
850 SET_ENUM(source, GetUpdatesSourceString);
851 SET_BOOL(notifications_enabled);
852 return value;
855 base::DictionaryValue* GetUpdatesMessageToValue(
856 const sync_pb::GetUpdatesMessage& proto) {
857 base::DictionaryValue* value = new base::DictionaryValue();
858 SET(caller_info, GetUpdatesCallerInfoToValue);
859 SET_BOOL(fetch_folders);
860 SET_INT32(batch_size);
861 SET_REP(from_progress_marker, DataTypeProgressMarkerToValue);
862 SET_BOOL(streaming);
863 SET_BOOL(need_encryption_key);
864 SET_BOOL(create_mobile_bookmarks_folder);
865 SET_ENUM(get_updates_origin, GetUpdatesOriginString);
866 return value;
869 base::DictionaryValue* ClientStatusToValue(const sync_pb::ClientStatus& proto) {
870 base::DictionaryValue* value = new base::DictionaryValue();
871 SET_BOOL(hierarchy_conflict_detected);
872 return value;
875 base::DictionaryValue* EntryResponseToValue(
876 const sync_pb::CommitResponse::EntryResponse& proto) {
877 base::DictionaryValue* value = new base::DictionaryValue();
878 SET_ENUM(response_type, GetResponseTypeString);
879 SET_STR(id_string);
880 SET_STR(parent_id_string);
881 SET_INT64(position_in_parent);
882 SET_INT64(version);
883 SET_STR(name);
884 SET_STR(error_message);
885 SET_INT64(mtime);
886 return value;
889 base::DictionaryValue* CommitResponseToValue(
890 const sync_pb::CommitResponse& proto) {
891 base::DictionaryValue* value = new base::DictionaryValue();
892 SET_REP(entryresponse, EntryResponseToValue);
893 return value;
896 base::DictionaryValue* GetUpdatesResponseToValue(
897 const sync_pb::GetUpdatesResponse& proto,
898 bool include_specifics) {
899 base::DictionaryValue* value = new base::DictionaryValue();
900 value->Set("entries",
901 SyncEntitiesToValue(proto.entries(), include_specifics));
902 SET_INT64(changes_remaining);
903 SET_REP(new_progress_marker, DataTypeProgressMarkerToValue);
904 return value;
907 base::DictionaryValue* ClientCommandToValue(
908 const sync_pb::ClientCommand& proto) {
909 base::DictionaryValue* value = new base::DictionaryValue();
910 SET_INT32(set_sync_poll_interval);
911 SET_INT32(set_sync_long_poll_interval);
912 SET_INT32(max_commit_batch_size);
913 SET_INT32(sessions_commit_delay_seconds);
914 SET_INT32(throttle_delay_seconds);
915 SET_INT32(client_invalidation_hint_buffer_size);
916 return value;
919 base::DictionaryValue* ErrorToValue(
920 const sync_pb::ClientToServerResponse::Error& proto) {
921 base::DictionaryValue* value = new base::DictionaryValue();
922 SET_ENUM(error_type, GetErrorTypeString);
923 SET_STR(error_description);
924 SET_STR(url);
925 SET_ENUM(action, GetActionString);
926 return value;
929 } // namespace
931 base::DictionaryValue* ClientToServerResponseToValue(
932 const sync_pb::ClientToServerResponse& proto,
933 bool include_specifics) {
934 base::DictionaryValue* value = new base::DictionaryValue();
935 SET(commit, CommitResponseToValue);
936 if (proto.has_get_updates()) {
937 value->Set("get_updates", GetUpdatesResponseToValue(proto.get_updates(),
938 include_specifics));
941 SET(error, ErrorToValue);
942 SET_ENUM(error_code, GetErrorTypeString);
943 SET_STR(error_message);
944 SET_STR(store_birthday);
945 SET(client_command, ClientCommandToValue);
946 SET_INT32_REP(migrated_data_type_id);
947 return value;
950 base::DictionaryValue* ClientToServerMessageToValue(
951 const sync_pb::ClientToServerMessage& proto,
952 bool include_specifics) {
953 base::DictionaryValue* value = new base::DictionaryValue();
954 SET_STR(share);
955 SET_INT32(protocol_version);
956 if (proto.has_commit()) {
957 value->Set("commit",
958 CommitMessageToValue(proto.commit(), include_specifics));
961 SET(get_updates, GetUpdatesMessageToValue);
962 SET_STR(store_birthday);
963 SET_BOOL(sync_problem_detected);
964 SET(debug_info, DebugInfoToValue);
965 SET(client_status, ClientStatusToValue);
966 return value;
969 base::DictionaryValue* DatatypeAssociationStatsToValue(
970 const sync_pb::DatatypeAssociationStats& proto) {
971 base::DictionaryValue* value = new base::DictionaryValue();
972 SET_INT32(data_type_id);
973 SET_INT32(num_local_items_before_association);
974 SET_INT32(num_sync_items_before_association);
975 SET_INT32(num_local_items_after_association);
976 SET_INT32(num_sync_items_after_association);
977 SET_INT32(num_local_items_added);
978 SET_INT32(num_local_items_deleted);
979 SET_INT32(num_local_items_modified);
980 SET_INT32(num_sync_items_added);
981 SET_INT32(num_sync_items_deleted);
982 SET_INT32(num_sync_items_modified);
983 SET_INT64(local_version_pre_association);
984 SET_INT64(sync_version_pre_association)
985 SET_BOOL(had_error);
986 SET_INT64(download_wait_time_us);
987 SET_INT64(download_time_us);
988 SET_INT64(association_wait_time_for_high_priority_us);
989 SET_INT64(association_wait_time_for_same_priority_us);
990 return value;
993 base::DictionaryValue* DebugEventInfoToValue(
994 const sync_pb::DebugEventInfo& proto) {
995 base::DictionaryValue* value = new base::DictionaryValue();
996 SET_ENUM(singleton_event, SingletonEventTypeString);
997 SET(sync_cycle_completed_event_info, SyncCycleCompletedEventInfoToValue);
998 SET_INT32(nudging_datatype);
999 SET_INT32_REP(datatypes_notified_from_server);
1000 SET(datatype_association_stats, DatatypeAssociationStatsToValue);
1001 return value;
1004 base::DictionaryValue* DebugInfoToValue(const sync_pb::DebugInfo& proto) {
1005 base::DictionaryValue* value = new base::DictionaryValue();
1006 SET_REP(events, DebugEventInfoToValue);
1007 SET_BOOL(cryptographer_ready);
1008 SET_BOOL(cryptographer_has_pending_keys);
1009 SET_BOOL(events_dropped);
1010 return value;
1013 base::DictionaryValue* SyncCycleCompletedEventInfoToValue(
1014 const sync_pb::SyncCycleCompletedEventInfo& proto) {
1015 base::DictionaryValue* value = new base::DictionaryValue();
1016 SET_INT32(num_encryption_conflicts);
1017 SET_INT32(num_hierarchy_conflicts);
1018 SET_INT32(num_server_conflicts);
1019 SET_INT32(num_updates_downloaded);
1020 SET_INT32(num_reflected_updates_downloaded);
1021 SET(caller_info, GetUpdatesCallerInfoToValue);
1022 return value;
1025 base::DictionaryValue* ClientConfigParamsToValue(
1026 const sync_pb::ClientConfigParams& proto) {
1027 base::DictionaryValue* value = new base::DictionaryValue();
1028 SET_INT32_REP(enabled_type_ids);
1029 SET_BOOL(tabs_datatype_enabled);
1030 return value;
1033 base::DictionaryValue* SyncAttachmentIdToValue(
1034 const sync_pb::SyncAttachmentId& proto) {
1035 base::DictionaryValue* value = new base::DictionaryValue();
1036 SET_STR(unique_id);
1037 return value;
1040 #undef SET
1041 #undef SET_REP
1043 #undef SET_BOOL
1044 #undef SET_BYTES
1045 #undef SET_INT32
1046 #undef SET_INT64
1047 #undef SET_INT64_REP
1048 #undef SET_STR
1049 #undef SET_STR_REP
1051 #undef SET_FIELD
1053 } // namespace syncer