Add a FrameHostMsg_BeginNavigation IPC
[chromium-blink-merge.git] / sync / protocol / proto_value_conversions.cc
blob2716210a56af9a522af042cc0a9a90a581428a97
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 return value;
249 base::DictionaryValue* GlobalIdDirectiveToValue(
250 const sync_pb::GlobalIdDirective& proto) {
251 base::DictionaryValue* value = new base::DictionaryValue();
252 SET_INT64_REP(global_id);
253 SET_INT64(start_time_usec);
254 SET_INT64(end_time_usec);
255 return value;
258 base::DictionaryValue* TimeRangeDirectiveToValue(
259 const sync_pb::TimeRangeDirective& proto) {
260 base::DictionaryValue* value = new base::DictionaryValue();
261 SET_INT64(start_time_usec);
262 SET_INT64(end_time_usec);
263 return value;
266 base::DictionaryValue* SyncedNotificationAppInfoToValue(
267 const sync_pb::SyncedNotificationAppInfo& proto) {
268 base::DictionaryValue* value = new base::DictionaryValue();
269 SET_STR_REP(app_id);
270 SET_STR(settings_display_name);
271 SET_STR(app_name);
272 SET_STR(settings_url);
273 SET_STR(info_url);
274 SET(icon, SyncedNotificationImageToValue);
275 // TODO(petewil): Add fields for the monochrome icon when it is available.
276 return value;
279 base::DictionaryValue* SyncedNotificationImageToValue(
280 const sync_pb::SyncedNotificationImage& proto) {
281 base::DictionaryValue* value = new base::DictionaryValue();
282 SET_STR(url);
283 SET_STR(alt_text);
284 SET_INT32(preferred_width);
285 SET_INT32(preferred_height);
286 return value;
289 base::DictionaryValue* SyncedNotificationProfileImageToValue(
290 const sync_pb::SyncedNotificationProfileImage& proto) {
291 base::DictionaryValue* value = new base::DictionaryValue();
292 SET_STR(image_url);
293 SET_STR(oid);
294 SET_STR(display_name);
295 return value;
298 base::DictionaryValue* MediaToValue(
299 const sync_pb::Media& proto) {
300 base::DictionaryValue* value = new base::DictionaryValue();
301 SET(image, SyncedNotificationImageToValue);
302 return value;
305 base::DictionaryValue* SyncedNotificationActionToValue(
306 const sync_pb::SyncedNotificationAction& proto) {
307 base::DictionaryValue* value = new base::DictionaryValue();
308 SET_STR(text);
309 SET(icon, SyncedNotificationImageToValue);
310 SET_STR(url);
311 SET_STR(request_data);
312 SET_STR(accessibility_label);
313 return value;
316 base::DictionaryValue* SyncedNotificationDestiationToValue(
317 const sync_pb::SyncedNotificationDestination& proto) {
318 base::DictionaryValue* value = new base::DictionaryValue();
319 SET_STR(text);
320 SET(icon, SyncedNotificationImageToValue);
321 SET_STR(url);
322 SET_STR(accessibility_label);
323 return value;
326 base::DictionaryValue* TargetToValue(
327 const sync_pb::Target& proto) {
328 base::DictionaryValue* value = new base::DictionaryValue();
329 SET(destination, SyncedNotificationDestiationToValue);
330 SET(action, SyncedNotificationActionToValue);
331 SET_STR(target_key);
332 return value;
335 base::DictionaryValue* SimpleCollapsedLayoutToValue(
336 const sync_pb::SimpleCollapsedLayout& proto) {
337 base::DictionaryValue* value = new base::DictionaryValue();
338 SET(app_icon, SyncedNotificationImageToValue);
339 SET_REP(profile_image, SyncedNotificationProfileImageToValue);
340 SET_STR(heading);
341 SET_STR(description);
342 SET_STR(annotation);
343 SET_REP(media, MediaToValue);
344 return value;
347 base::DictionaryValue* CollapsedInfoToValue(
348 const sync_pb::CollapsedInfo& proto) {
349 base::DictionaryValue* value = new base::DictionaryValue();
350 SET(simple_collapsed_layout, SimpleCollapsedLayoutToValue);
351 SET_INT64(creation_timestamp_usec);
352 SET(default_destination, SyncedNotificationDestiationToValue);
353 SET_REP(target, TargetToValue);
354 return value;
357 base::DictionaryValue* SyncedNotificationToValue(
358 const sync_pb::SyncedNotification& proto) {
359 base::DictionaryValue* value = new base::DictionaryValue();
360 SET_STR(type);
361 SET_STR(external_id);
362 // TODO(petewil) Add SyncedNotificationCreator here if we ever need it.
363 return value;
366 base::DictionaryValue* RenderInfoToValue(
367 const sync_pb::SyncedNotificationRenderInfo& proto) {
368 base::DictionaryValue* value = new base::DictionaryValue();
369 // TODO(petewil): Add the expanded info values once we start using them.
370 SET(collapsed_info, CollapsedInfoToValue);
371 return value;
374 base::DictionaryValue* CoalescedNotificationToValue(
375 const sync_pb::CoalescedSyncedNotification& proto) {
376 base::DictionaryValue* value = new base::DictionaryValue();
377 SET_STR(key);
378 SET_STR(app_id);
379 SET_REP(notification, SyncedNotificationToValue);
380 SET(render_info, RenderInfoToValue);
381 SET_INT32(read_state);
382 SET_INT64(creation_time_msec);
383 SET_INT32(priority);
384 return value;
387 base::DictionaryValue* AppListSpecificsToValue(
388 const sync_pb::AppListSpecifics& proto) {
389 base::DictionaryValue* value = new base::DictionaryValue();
390 SET_STR(item_id);
391 SET_ENUM(item_type, GetAppListItemTypeString);
392 SET_STR(item_name);
393 SET_STR(parent_id);
394 SET_STR(page_ordinal);
395 SET_STR(item_ordinal);
397 return value;
400 base::DictionaryValue* AppNotificationToValue(
401 const sync_pb::AppNotification& proto) {
402 base::DictionaryValue* value = new base::DictionaryValue();
403 SET_STR(guid);
404 SET_STR(app_id);
405 SET_INT64(creation_timestamp_ms);
406 SET_STR(title);
407 SET_STR(body_text);
408 SET_STR(link_url);
409 SET_STR(link_text);
410 return value;
413 base::DictionaryValue* AppSettingSpecificsToValue(
414 const sync_pb::AppSettingSpecifics& proto) {
415 base::DictionaryValue* value = new base::DictionaryValue();
416 SET(extension_setting, ExtensionSettingSpecificsToValue);
417 return value;
420 base::DictionaryValue* AppSpecificsToValue(
421 const sync_pb::AppSpecifics& proto) {
422 base::DictionaryValue* value = new base::DictionaryValue();
423 SET(extension, ExtensionSpecificsToValue);
424 SET(notification_settings, AppSettingsToValue);
425 SET_STR(app_launch_ordinal);
426 SET_STR(page_ordinal);
427 SET_ENUM(launch_type, GetLaunchTypeString);
428 SET_STR(bookmark_app_url);
429 SET_STR(bookmark_app_description);
431 return value;
434 base::DictionaryValue* AutofillSpecificsToValue(
435 const sync_pb::AutofillSpecifics& proto) {
436 base::DictionaryValue* value = new base::DictionaryValue();
437 SET_STR(name);
438 SET_STR(value);
439 SET_INT64_REP(usage_timestamp);
440 SET(profile, AutofillProfileSpecificsToValue);
441 return value;
444 base::DictionaryValue* AutofillProfileSpecificsToValue(
445 const sync_pb::AutofillProfileSpecifics& proto) {
446 base::DictionaryValue* value = new base::DictionaryValue();
447 SET_STR(guid);
448 SET_STR(origin);
450 SET_STR_REP(name_first);
451 SET_STR_REP(name_middle);
452 SET_STR_REP(name_last);
453 SET_STR_REP(name_full);
454 SET_STR_REP(email_address);
455 SET_STR(company_name);
457 SET_STR(address_home_line1);
458 SET_STR(address_home_line2);
459 SET_STR(address_home_city);
460 SET_STR(address_home_state);
461 SET_STR(address_home_zip);
462 SET_STR(address_home_country);
464 SET_STR(address_home_street_address);
465 SET_STR(address_home_sorting_code);
466 SET_STR(address_home_dependent_locality);
467 SET_STR(address_home_language_code);
469 SET_STR_REP(phone_home_whole_number);
470 return value;
473 base::DictionaryValue* MetaInfoToValue(
474 const sync_pb::MetaInfo& proto) {
475 base::DictionaryValue* value = new base::DictionaryValue();
476 SET_STR(key);
477 SET_STR(value);
478 return value;
481 base::DictionaryValue* BookmarkSpecificsToValue(
482 const sync_pb::BookmarkSpecifics& proto) {
483 base::DictionaryValue* value = new base::DictionaryValue();
484 SET_STR(url);
485 SET_BYTES(favicon);
486 SET_STR(title);
487 SET_INT64(creation_time_us);
488 SET_STR(icon_url);
489 SET_REP(meta_info, &MetaInfoToValue);
490 return value;
493 base::DictionaryValue* DeviceInfoSpecificsToValue(
494 const sync_pb::DeviceInfoSpecifics& proto) {
495 base::DictionaryValue* value = new base::DictionaryValue();
496 SET_STR(cache_guid);
497 SET_STR(client_name);
498 SET_ENUM(device_type, GetDeviceTypeString);
499 SET_STR(sync_user_agent);
500 SET_STR(chrome_version);
501 SET_TIME_STR(backup_timestamp);
502 return value;
505 base::DictionaryValue* DictionarySpecificsToValue(
506 const sync_pb::DictionarySpecifics& proto) {
507 base::DictionaryValue* value = new base::DictionaryValue();
508 SET_STR(word);
509 return value;
512 namespace {
514 base::DictionaryValue* FaviconSyncFlagsToValue(
515 const sync_pb::FaviconSyncFlags& proto) {
516 base::DictionaryValue* value = new base::DictionaryValue();
517 SET_BOOL(enabled);
518 SET_INT32(favicon_sync_limit);
519 return value;
522 base::DictionaryValue* EnhancedBookmarksFlagsToValue(
523 const sync_pb::EnhancedBookmarksFlags& proto) {
524 base::DictionaryValue* value = new base::DictionaryValue();
525 SET_BOOL(enabled);
526 SET_STR(extension_id);
527 return value;
530 } // namespace
532 base::DictionaryValue* ExperimentsSpecificsToValue(
533 const sync_pb::ExperimentsSpecifics& proto) {
534 base::DictionaryValue* value = new base::DictionaryValue();
535 SET_EXPERIMENT_ENABLED_FIELD(keystore_encryption);
536 SET_EXPERIMENT_ENABLED_FIELD(history_delete_directives);
537 SET_EXPERIMENT_ENABLED_FIELD(autofill_culling);
538 SET_EXPERIMENT_ENABLED_FIELD(pre_commit_update_avoidance);
539 SET(favicon_sync, FaviconSyncFlagsToValue);
540 SET_EXPERIMENT_ENABLED_FIELD(gcm_channel);
541 SET(enhanced_bookmarks, EnhancedBookmarksFlagsToValue);
542 SET_EXPERIMENT_ENABLED_FIELD(gcm_invalidations);
543 return value;
546 base::DictionaryValue* ExtensionSettingSpecificsToValue(
547 const sync_pb::ExtensionSettingSpecifics& proto) {
548 base::DictionaryValue* value = new base::DictionaryValue();
549 SET_STR(extension_id);
550 SET_STR(key);
551 SET_STR(value);
552 return value;
555 base::DictionaryValue* ExtensionSpecificsToValue(
556 const sync_pb::ExtensionSpecifics& proto) {
557 base::DictionaryValue* value = new base::DictionaryValue();
558 SET_STR(id);
559 SET_STR(version);
560 SET_STR(update_url);
561 SET_BOOL(enabled);
562 SET_BOOL(incognito_enabled);
563 SET_BOOL(remote_install);
564 SET_STR(name);
565 return value;
568 namespace {
569 base::DictionaryValue* FaviconDataToValue(
570 const sync_pb::FaviconData& proto) {
571 base::DictionaryValue* value = new base::DictionaryValue();
572 SET_BYTES(favicon);
573 SET_INT32(width);
574 SET_INT32(height);
575 return value;
577 } // namespace
579 base::DictionaryValue* FaviconImageSpecificsToValue(
580 const sync_pb::FaviconImageSpecifics& proto) {
581 base::DictionaryValue* value = new base::DictionaryValue();
582 SET_STR(favicon_url);
583 SET(favicon_web, FaviconDataToValue);
584 SET(favicon_web_32, FaviconDataToValue);
585 SET(favicon_touch_64, FaviconDataToValue);
586 SET(favicon_touch_precomposed_64, FaviconDataToValue);
587 return value;
590 base::DictionaryValue* FaviconTrackingSpecificsToValue(
591 const sync_pb::FaviconTrackingSpecifics& proto) {
592 base::DictionaryValue* value = new base::DictionaryValue();
593 SET_STR(favicon_url);
594 SET_INT64(last_visit_time_ms)
595 SET_BOOL(is_bookmarked);
596 return value;
599 base::DictionaryValue* HistoryDeleteDirectiveSpecificsToValue(
600 const sync_pb::HistoryDeleteDirectiveSpecifics& proto) {
601 base::DictionaryValue* value = new base::DictionaryValue();
602 SET(global_id_directive, GlobalIdDirectiveToValue);
603 SET(time_range_directive, TimeRangeDirectiveToValue);
604 return value;
607 base::DictionaryValue* ManagedUserSettingSpecificsToValue(
608 const sync_pb::ManagedUserSettingSpecifics& proto) {
609 base::DictionaryValue* value = new base::DictionaryValue();
610 SET_STR(name);
611 SET_STR(value);
612 return value;
615 base::DictionaryValue* ManagedUserSpecificsToValue(
616 const sync_pb::ManagedUserSpecifics& proto) {
617 base::DictionaryValue* value = new base::DictionaryValue();
618 SET_STR(id);
619 SET_STR(name);
620 SET_BOOL(acknowledged);
621 SET_STR(master_key);
622 SET_STR(chrome_avatar);
623 SET_STR(chromeos_avatar);
624 return value;
627 base::DictionaryValue* ManagedUserSharedSettingSpecificsToValue(
628 const sync_pb::ManagedUserSharedSettingSpecifics& proto) {
629 base::DictionaryValue* value = new base::DictionaryValue();
630 SET_STR(mu_id);
631 SET_STR(key);
632 SET_STR(value);
633 SET_BOOL(acknowledged);
634 return value;
637 base::DictionaryValue* NigoriSpecificsToValue(
638 const sync_pb::NigoriSpecifics& proto) {
639 base::DictionaryValue* value = new base::DictionaryValue();
640 SET(encryption_keybag, EncryptedDataToValue);
641 SET_BOOL(keybag_is_frozen);
642 SET_BOOL(encrypt_bookmarks);
643 SET_BOOL(encrypt_preferences);
644 SET_BOOL(encrypt_autofill_profile);
645 SET_BOOL(encrypt_autofill);
646 SET_BOOL(encrypt_themes);
647 SET_BOOL(encrypt_typed_urls);
648 SET_BOOL(encrypt_extension_settings);
649 SET_BOOL(encrypt_extensions);
650 SET_BOOL(encrypt_sessions);
651 SET_BOOL(encrypt_app_settings);
652 SET_BOOL(encrypt_apps);
653 SET_BOOL(encrypt_search_engines);
654 SET_BOOL(encrypt_dictionary);
655 SET_BOOL(encrypt_articles);
656 SET_BOOL(encrypt_app_list);
657 SET_BOOL(encrypt_everything);
658 SET_BOOL(sync_tab_favicons);
659 SET_ENUM(passphrase_type, PassphraseTypeString);
660 SET(keystore_decryptor_token, EncryptedDataToValue);
661 SET_INT64(keystore_migration_time);
662 SET_INT64(custom_passphrase_time);
663 return value;
666 base::DictionaryValue* ArticlePageToValue(
667 const sync_pb::ArticlePage& proto) {
668 base::DictionaryValue* value = new base::DictionaryValue();
669 SET_STR(url);
670 return value;
673 base::DictionaryValue* ArticleSpecificsToValue(
674 const sync_pb::ArticleSpecifics& proto) {
675 base::DictionaryValue* value = new base::DictionaryValue();
676 SET_STR(entry_id);
677 SET_STR(title);
678 SET_REP(pages, ArticlePageToValue);
679 return value;
682 base::DictionaryValue* PasswordSpecificsToValue(
683 const sync_pb::PasswordSpecifics& proto) {
684 base::DictionaryValue* value = new base::DictionaryValue();
685 SET(encrypted, EncryptedDataToValue);
686 return value;
689 base::DictionaryValue* PreferenceSpecificsToValue(
690 const sync_pb::PreferenceSpecifics& proto) {
691 base::DictionaryValue* value = new base::DictionaryValue();
692 SET_STR(name);
693 SET_STR(value);
694 return value;
697 base::DictionaryValue* PriorityPreferenceSpecificsToValue(
698 const sync_pb::PriorityPreferenceSpecifics& specifics) {
699 base::DictionaryValue* value = new base::DictionaryValue();
700 SET_FIELD(preference, PreferenceSpecificsToValue);
701 return value;
704 base::DictionaryValue* SyncedNotificationAppInfoSpecificsToValue(
705 const sync_pb::SyncedNotificationAppInfoSpecifics& proto) {
706 base::DictionaryValue* value = new base::DictionaryValue();
707 SET_REP(synced_notification_app_info, SyncedNotificationAppInfoToValue);
708 return value;
711 base::DictionaryValue* SyncedNotificationSpecificsToValue(
712 const sync_pb::SyncedNotificationSpecifics& proto) {
713 // There is a lot of data, for now just use heading, description, key, and
714 // the read state.
715 // TODO(petewil): Eventually add more data here.
716 base::DictionaryValue* value = new base::DictionaryValue();
717 SET(coalesced_notification, CoalescedNotificationToValue);
718 return value;
721 base::DictionaryValue* SearchEngineSpecificsToValue(
722 const sync_pb::SearchEngineSpecifics& proto) {
723 base::DictionaryValue* value = new base::DictionaryValue();
724 SET_STR(short_name);
725 SET_STR(keyword);
726 SET_STR(favicon_url);
727 SET_STR(url);
728 SET_BOOL(safe_for_autoreplace);
729 SET_STR(originating_url);
730 SET_INT64(date_created);
731 SET_STR(input_encodings);
732 SET_BOOL(show_in_default_list);
733 SET_STR(suggestions_url);
734 SET_INT32(prepopulate_id);
735 SET_BOOL(autogenerate_keyword);
736 SET_STR(instant_url);
737 SET_INT64(last_modified);
738 SET_STR(sync_guid);
739 SET_STR_REP(alternate_urls);
740 SET_STR(search_terms_replacement_key);
741 SET_STR(image_url);
742 SET_STR(search_url_post_params);
743 SET_STR(suggestions_url_post_params);
744 SET_STR(instant_url_post_params);
745 SET_STR(image_url_post_params);
746 SET_STR(new_tab_url);
747 return value;
750 base::DictionaryValue* SessionSpecificsToValue(
751 const sync_pb::SessionSpecifics& proto) {
752 base::DictionaryValue* value = new base::DictionaryValue();
753 SET_STR(session_tag);
754 SET(header, SessionHeaderToValue);
755 SET(tab, SessionTabToValue);
756 SET_INT32(tab_node_id);
757 return value;
760 base::DictionaryValue* ThemeSpecificsToValue(
761 const sync_pb::ThemeSpecifics& proto) {
762 base::DictionaryValue* value = new base::DictionaryValue();
763 SET_BOOL(use_custom_theme);
764 SET_BOOL(use_system_theme_by_default);
765 SET_STR(custom_theme_name);
766 SET_STR(custom_theme_id);
767 SET_STR(custom_theme_update_url);
768 return value;
771 base::DictionaryValue* TypedUrlSpecificsToValue(
772 const sync_pb::TypedUrlSpecifics& proto) {
773 base::DictionaryValue* value = new base::DictionaryValue();
774 SET_STR(url);
775 SET_STR(title);
776 SET_BOOL(hidden);
777 SET_INT64_REP(visits);
778 SET_INT32_REP(visit_transitions);
779 return value;
782 base::DictionaryValue* EntitySpecificsToValue(
783 const sync_pb::EntitySpecifics& specifics) {
784 base::DictionaryValue* value = new base::DictionaryValue();
785 SET_FIELD(app, AppSpecificsToValue);
786 SET_FIELD(app_list, AppListSpecificsToValue);
787 SET_FIELD(app_notification, AppNotificationToValue);
788 SET_FIELD(app_setting, AppSettingSpecificsToValue);
789 SET_FIELD(article, ArticleSpecificsToValue);
790 SET_FIELD(autofill, AutofillSpecificsToValue);
791 SET_FIELD(autofill_profile, AutofillProfileSpecificsToValue);
792 SET_FIELD(bookmark, BookmarkSpecificsToValue);
793 SET_FIELD(device_info, DeviceInfoSpecificsToValue);
794 SET_FIELD(dictionary, DictionarySpecificsToValue);
795 SET_FIELD(experiments, ExperimentsSpecificsToValue);
796 SET_FIELD(extension, ExtensionSpecificsToValue);
797 SET_FIELD(extension_setting, ExtensionSettingSpecificsToValue);
798 SET_FIELD(favicon_image, FaviconImageSpecificsToValue);
799 SET_FIELD(favicon_tracking, FaviconTrackingSpecificsToValue);
800 SET_FIELD(history_delete_directive, HistoryDeleteDirectiveSpecificsToValue);
801 SET_FIELD(managed_user_setting, ManagedUserSettingSpecificsToValue);
802 SET_FIELD(managed_user_shared_setting,
803 ManagedUserSharedSettingSpecificsToValue);
804 SET_FIELD(managed_user, ManagedUserSpecificsToValue);
805 SET_FIELD(nigori, NigoriSpecificsToValue);
806 SET_FIELD(password, PasswordSpecificsToValue);
807 SET_FIELD(preference, PreferenceSpecificsToValue);
808 SET_FIELD(priority_preference, PriorityPreferenceSpecificsToValue);
809 SET_FIELD(search_engine, SearchEngineSpecificsToValue);
810 SET_FIELD(session, SessionSpecificsToValue);
811 SET_FIELD(synced_notification, SyncedNotificationSpecificsToValue);
812 SET_FIELD(synced_notification_app_info,
813 SyncedNotificationAppInfoSpecificsToValue);
814 SET_FIELD(theme, ThemeSpecificsToValue);
815 SET_FIELD(typed_url, TypedUrlSpecificsToValue);
816 return value;
819 namespace {
821 base::StringValue* UniquePositionToStringValue(
822 const sync_pb::UniquePosition& proto) {
823 UniquePosition pos = UniquePosition::FromProto(proto);
824 return new base::StringValue(pos.ToDebugString());
827 } // namespace
829 base::DictionaryValue* SyncEntityToValue(const sync_pb::SyncEntity& proto,
830 bool include_specifics) {
831 base::DictionaryValue* value = new base::DictionaryValue();
832 SET_STR(id_string);
833 SET_STR(parent_id_string);
834 SET_STR(old_parent_id);
835 SET_INT64(version);
836 SET_INT64(mtime);
837 SET_INT64(ctime);
838 SET_STR(name);
839 SET_STR(non_unique_name);
840 SET_INT64(sync_timestamp);
841 SET_STR(server_defined_unique_tag);
842 SET_INT64(position_in_parent);
843 SET(unique_position, UniquePositionToStringValue);
844 SET_STR(insert_after_item_id);
845 SET_BOOL(deleted);
846 SET_STR(originator_cache_guid);
847 SET_STR(originator_client_item_id);
848 if (include_specifics)
849 SET(specifics, EntitySpecificsToValue);
850 SET_BOOL(folder);
851 SET_STR(client_defined_unique_tag);
852 return value;
855 namespace {
857 base::ListValue* SyncEntitiesToValue(
858 const ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities,
859 bool include_specifics) {
860 base::ListValue* list = new base::ListValue();
861 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it;
862 for (it = entities.begin(); it != entities.end(); ++it) {
863 list->Append(SyncEntityToValue(*it, include_specifics));
866 return list;
869 base::DictionaryValue* ChromiumExtensionActivityToValue(
870 const sync_pb::ChromiumExtensionsActivity& proto) {
871 base::DictionaryValue* value = new base::DictionaryValue();
872 SET_STR(extension_id);
873 SET_INT32(bookmark_writes_since_last_commit);
874 return value;
877 base::DictionaryValue* CommitMessageToValue(
878 const sync_pb::CommitMessage& proto,
879 bool include_specifics) {
880 base::DictionaryValue* value = new base::DictionaryValue();
881 value->Set("entries",
882 SyncEntitiesToValue(proto.entries(), include_specifics));
883 SET_STR(cache_guid);
884 SET_REP(extensions_activity, ChromiumExtensionActivityToValue);
885 SET(config_params, ClientConfigParamsToValue);
886 return value;
889 base::DictionaryValue* GetUpdateTriggersToValue(
890 const sync_pb::GetUpdateTriggers& proto) {
891 base::DictionaryValue* value = new base::DictionaryValue();
892 SET_STR_REP(notification_hint);
893 SET_BOOL(client_dropped_hints);
894 SET_BOOL(invalidations_out_of_sync);
895 SET_INT64(local_modification_nudges);
896 SET_INT64(datatype_refresh_nudges);
897 return value;
900 base::DictionaryValue* DataTypeProgressMarkerToValue(
901 const sync_pb::DataTypeProgressMarker& proto) {
902 base::DictionaryValue* value = new base::DictionaryValue();
903 SET_INT32(data_type_id);
904 SET_BYTES(token);
905 SET_INT64(timestamp_token_for_migration);
906 SET_STR(notification_hint);
907 SET(get_update_triggers, GetUpdateTriggersToValue);
908 return value;
911 base::DictionaryValue* DataTypeContextToValue(
912 const sync_pb::DataTypeContext& proto) {
913 base::DictionaryValue* value = new base::DictionaryValue();
914 SET_INT32(data_type_id);
915 SET_STR(context);
916 SET_INT64(version);
917 return value;
920 base::DictionaryValue* GetUpdatesCallerInfoToValue(
921 const sync_pb::GetUpdatesCallerInfo& proto) {
922 base::DictionaryValue* value = new base::DictionaryValue();
923 SET_ENUM(source, GetUpdatesSourceString);
924 SET_BOOL(notifications_enabled);
925 return value;
928 base::DictionaryValue* GetUpdatesMessageToValue(
929 const sync_pb::GetUpdatesMessage& proto) {
930 base::DictionaryValue* value = new base::DictionaryValue();
931 SET(caller_info, GetUpdatesCallerInfoToValue);
932 SET_BOOL(fetch_folders);
933 SET_INT32(batch_size);
934 SET_REP(from_progress_marker, DataTypeProgressMarkerToValue);
935 SET_BOOL(streaming);
936 SET_BOOL(need_encryption_key);
937 SET_BOOL(create_mobile_bookmarks_folder);
938 SET_ENUM(get_updates_origin, GetUpdatesOriginString);
939 SET_REP(client_contexts, DataTypeContextToValue);
940 return value;
943 base::DictionaryValue* ClientStatusToValue(const sync_pb::ClientStatus& proto) {
944 base::DictionaryValue* value = new base::DictionaryValue();
945 SET_BOOL(hierarchy_conflict_detected);
946 return value;
949 base::DictionaryValue* EntryResponseToValue(
950 const sync_pb::CommitResponse::EntryResponse& proto) {
951 base::DictionaryValue* value = new base::DictionaryValue();
952 SET_ENUM(response_type, GetResponseTypeString);
953 SET_STR(id_string);
954 SET_STR(parent_id_string);
955 SET_INT64(position_in_parent);
956 SET_INT64(version);
957 SET_STR(name);
958 SET_STR(error_message);
959 SET_INT64(mtime);
960 return value;
963 base::DictionaryValue* CommitResponseToValue(
964 const sync_pb::CommitResponse& proto) {
965 base::DictionaryValue* value = new base::DictionaryValue();
966 SET_REP(entryresponse, EntryResponseToValue);
967 return value;
970 base::DictionaryValue* GetUpdatesResponseToValue(
971 const sync_pb::GetUpdatesResponse& proto,
972 bool include_specifics) {
973 base::DictionaryValue* value = new base::DictionaryValue();
974 value->Set("entries",
975 SyncEntitiesToValue(proto.entries(), include_specifics));
976 SET_INT64(changes_remaining);
977 SET_REP(new_progress_marker, DataTypeProgressMarkerToValue);
978 SET_REP(context_mutations, DataTypeContextToValue);
979 return value;
982 base::DictionaryValue* ClientCommandToValue(
983 const sync_pb::ClientCommand& proto) {
984 base::DictionaryValue* value = new base::DictionaryValue();
985 SET_INT32(set_sync_poll_interval);
986 SET_INT32(set_sync_long_poll_interval);
987 SET_INT32(max_commit_batch_size);
988 SET_INT32(sessions_commit_delay_seconds);
989 SET_INT32(throttle_delay_seconds);
990 SET_INT32(client_invalidation_hint_buffer_size);
991 return value;
994 base::DictionaryValue* ErrorToValue(
995 const sync_pb::ClientToServerResponse::Error& proto) {
996 base::DictionaryValue* value = new base::DictionaryValue();
997 SET_ENUM(error_type, GetErrorTypeString);
998 SET_STR(error_description);
999 SET_STR(url);
1000 SET_ENUM(action, GetActionString);
1001 return value;
1004 } // namespace
1006 base::DictionaryValue* ClientToServerResponseToValue(
1007 const sync_pb::ClientToServerResponse& proto,
1008 bool include_specifics) {
1009 base::DictionaryValue* value = new base::DictionaryValue();
1010 SET(commit, CommitResponseToValue);
1011 if (proto.has_get_updates()) {
1012 value->Set("get_updates", GetUpdatesResponseToValue(proto.get_updates(),
1013 include_specifics));
1016 SET(error, ErrorToValue);
1017 SET_ENUM(error_code, GetErrorTypeString);
1018 SET_STR(error_message);
1019 SET_STR(store_birthday);
1020 SET(client_command, ClientCommandToValue);
1021 SET_INT32_REP(migrated_data_type_id);
1022 return value;
1025 base::DictionaryValue* ClientToServerMessageToValue(
1026 const sync_pb::ClientToServerMessage& proto,
1027 bool include_specifics) {
1028 base::DictionaryValue* value = new base::DictionaryValue();
1029 SET_STR(share);
1030 SET_INT32(protocol_version);
1031 if (proto.has_commit()) {
1032 value->Set("commit",
1033 CommitMessageToValue(proto.commit(), include_specifics));
1036 SET(get_updates, GetUpdatesMessageToValue);
1037 SET_STR(store_birthday);
1038 SET_BOOL(sync_problem_detected);
1039 SET(debug_info, DebugInfoToValue);
1040 SET(client_status, ClientStatusToValue);
1041 return value;
1044 base::DictionaryValue* DatatypeAssociationStatsToValue(
1045 const sync_pb::DatatypeAssociationStats& proto) {
1046 base::DictionaryValue* value = new base::DictionaryValue();
1047 SET_INT32(data_type_id);
1048 SET_INT32(num_local_items_before_association);
1049 SET_INT32(num_sync_items_before_association);
1050 SET_INT32(num_local_items_after_association);
1051 SET_INT32(num_sync_items_after_association);
1052 SET_INT32(num_local_items_added);
1053 SET_INT32(num_local_items_deleted);
1054 SET_INT32(num_local_items_modified);
1055 SET_INT32(num_sync_items_added);
1056 SET_INT32(num_sync_items_deleted);
1057 SET_INT32(num_sync_items_modified);
1058 SET_INT64(local_version_pre_association);
1059 SET_INT64(sync_version_pre_association)
1060 SET_BOOL(had_error);
1061 SET_INT64(download_wait_time_us);
1062 SET_INT64(download_time_us);
1063 SET_INT64(association_wait_time_for_high_priority_us);
1064 SET_INT64(association_wait_time_for_same_priority_us);
1065 return value;
1068 base::DictionaryValue* DebugEventInfoToValue(
1069 const sync_pb::DebugEventInfo& proto) {
1070 base::DictionaryValue* value = new base::DictionaryValue();
1071 SET_ENUM(singleton_event, SingletonDebugEventTypeString);
1072 SET(sync_cycle_completed_event_info, SyncCycleCompletedEventInfoToValue);
1073 SET_INT32(nudging_datatype);
1074 SET_INT32_REP(datatypes_notified_from_server);
1075 SET(datatype_association_stats, DatatypeAssociationStatsToValue);
1076 return value;
1079 base::DictionaryValue* DebugInfoToValue(const sync_pb::DebugInfo& proto) {
1080 base::DictionaryValue* value = new base::DictionaryValue();
1081 SET_REP(events, DebugEventInfoToValue);
1082 SET_BOOL(cryptographer_ready);
1083 SET_BOOL(cryptographer_has_pending_keys);
1084 SET_BOOL(events_dropped);
1085 return value;
1088 base::DictionaryValue* SyncCycleCompletedEventInfoToValue(
1089 const sync_pb::SyncCycleCompletedEventInfo& proto) {
1090 base::DictionaryValue* value = new base::DictionaryValue();
1091 SET_INT32(num_encryption_conflicts);
1092 SET_INT32(num_hierarchy_conflicts);
1093 SET_INT32(num_server_conflicts);
1094 SET_INT32(num_updates_downloaded);
1095 SET_INT32(num_reflected_updates_downloaded);
1096 SET(caller_info, GetUpdatesCallerInfoToValue);
1097 return value;
1100 base::DictionaryValue* ClientConfigParamsToValue(
1101 const sync_pb::ClientConfigParams& proto) {
1102 base::DictionaryValue* value = new base::DictionaryValue();
1103 SET_INT32_REP(enabled_type_ids);
1104 SET_BOOL(tabs_datatype_enabled);
1105 return value;
1108 base::DictionaryValue* AttachmentIdProtoToValue(
1109 const sync_pb::AttachmentIdProto& proto) {
1110 base::DictionaryValue* value = new base::DictionaryValue();
1111 SET_STR(unique_id);
1112 return value;
1115 #undef SET
1116 #undef SET_REP
1118 #undef SET_BOOL
1119 #undef SET_BYTES
1120 #undef SET_INT32
1121 #undef SET_INT64
1122 #undef SET_INT64_REP
1123 #undef SET_STR
1124 #undef SET_STR_REP
1126 #undef SET_FIELD
1128 } // namespace syncer