Clean up extension confirmation prompts and make them consistent between Views and...
[chromium-blink-merge.git] / sync / protocol / proto_value_conversions.cc
blobb6b23edef8f24daf8420383e4834110bd400b90a
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Keep this file in sync with the .proto files in this directory.
7 #include "sync/protocol/proto_value_conversions.h"
9 #include <string>
11 #include "base/base64.h"
12 #include "base/basictypes.h"
13 #include "base/i18n/time_formatting.h"
14 #include "base/logging.h"
15 #include "base/strings/string_number_conversions.h"
16 #include "base/time/time.h"
17 #include "base/values.h"
18 #include "sync/internal_api/public/base/unique_position.h"
19 #include "sync/protocol/app_list_specifics.pb.h"
20 #include "sync/protocol/app_notification_specifics.pb.h"
21 #include "sync/protocol/app_setting_specifics.pb.h"
22 #include "sync/protocol/app_specifics.pb.h"
23 #include "sync/protocol/autofill_specifics.pb.h"
24 #include "sync/protocol/bookmark_specifics.pb.h"
25 #include "sync/protocol/dictionary_specifics.pb.h"
26 #include "sync/protocol/encryption.pb.h"
27 #include "sync/protocol/experiments_specifics.pb.h"
28 #include "sync/protocol/extension_setting_specifics.pb.h"
29 #include "sync/protocol/extension_specifics.pb.h"
30 #include "sync/protocol/favicon_image_specifics.pb.h"
31 #include "sync/protocol/favicon_tracking_specifics.pb.h"
32 #include "sync/protocol/history_delete_directive_specifics.pb.h"
33 #include "sync/protocol/nigori_specifics.pb.h"
34 #include "sync/protocol/password_specifics.pb.h"
35 #include "sync/protocol/preference_specifics.pb.h"
36 #include "sync/protocol/priority_preference_specifics.pb.h"
37 #include "sync/protocol/proto_enum_conversions.h"
38 #include "sync/protocol/search_engine_specifics.pb.h"
39 #include "sync/protocol/session_specifics.pb.h"
40 #include "sync/protocol/sync.pb.h"
41 #include "sync/protocol/theme_specifics.pb.h"
42 #include "sync/protocol/typed_url_specifics.pb.h"
43 #include "sync/protocol/unique_position.pb.h"
44 #include "sync/util/time.h"
46 namespace syncer {
48 namespace {
50 // Basic Type -> Value functions.
52 scoped_ptr<base::StringValue> MakeInt64Value(int64 x) {
53 return make_scoped_ptr(new base::StringValue(base::Int64ToString(x)));
56 // TODO(akalin): Perhaps make JSONWriter support BinaryValue and use
57 // that instead of a StringValue.
58 std::string Base64EncodeString(const std::string& bytes) {
59 std::string bytes_base64;
60 base::Base64Encode(bytes, &bytes_base64);
61 return bytes_base64;
64 scoped_ptr<base::StringValue> MakeStringValue(const std::string& str) {
65 return make_scoped_ptr(new base::StringValue(str));
68 // T is the field type, F is either RepeatedField or RepeatedPtrField,
69 // and V is a subclass of Value.
70 template <class T, class F, class V>
71 scoped_ptr<base::ListValue> MakeRepeatedValue(const F& fields,
72 V (*converter_fn)(T)) {
73 scoped_ptr<base::ListValue> list(new base::ListValue());
74 for (typename F::const_iterator it = fields.begin(); it != fields.end();
75 ++it) {
76 list->Append(converter_fn(*it));
78 return list;
81 base::string16 TimestampToString(int64 tm) {
82 return base::TimeFormatShortDateAndTime(syncer::ProtoTimeToTime(tm));
85 } // namespace
87 // Helper macros to reduce the amount of boilerplate.
89 #define SET_TYPE(field, set_fn, transform) \
90 if (proto.has_##field()) { \
91 value->set_fn(#field, transform(proto.field())); \
93 #define SET(field, fn) SET_TYPE(field, Set, fn)
94 #define SET_REP(field, fn) \
95 value->Set(#field, MakeRepeatedValue(proto.field(), fn))
96 #define SET_ENUM(field, fn) SET_TYPE(field, SetString, fn)
98 #define SET_BOOL(field) SET_TYPE(field, SetBoolean, )
99 #define SET_BYTES(field) SET_TYPE(field, SetString, Base64EncodeString)
100 #define SET_INT32(field) SET_TYPE(field, SetString, base::Int64ToString)
101 #define SET_INT32_REP(field) SET_REP(field, MakeInt64Value)
102 #define SET_INT64(field) SET_TYPE(field, SetString, base::Int64ToString)
103 #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value)
104 #define SET_STR(field) SET_TYPE(field, SetString, )
105 #define SET_TIME_STR(field) SET_TYPE(field, SetString, TimestampToString)
106 #define SET_STR_REP(field) \
107 value->Set( \
108 #field, \
109 MakeRepeatedValue<const std::string&, \
110 google::protobuf::RepeatedPtrField<std::string>, \
111 scoped_ptr<base::StringValue>>(proto.field(), \
112 MakeStringValue))
113 #define SET_EXPERIMENT_ENABLED_FIELD(field) \
114 do { \
115 if (proto.has_##field() && \
116 proto.field().has_enabled()) { \
117 value->Set(#field, \
118 new base::FundamentalValue( \
119 proto.field().enabled())); \
121 } while (0)
123 #define SET_FIELD(field, fn) \
124 do { \
125 if (specifics.has_##field()) { \
126 value->Set(#field, fn(specifics.field())); \
128 } while (0)
130 // If you add another macro, don't forget to add an #undef at the end
131 // of this file, too.
133 scoped_ptr<base::DictionaryValue> EncryptedDataToValue(
134 const sync_pb::EncryptedData& proto) {
135 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
136 SET_STR(key_name);
137 // TODO(akalin): Shouldn't blob be of type bytes instead of string?
138 SET_BYTES(blob);
139 return value;
142 scoped_ptr<base::DictionaryValue> AppSettingsToValue(
143 const sync_pb::AppNotificationSettings& proto) {
144 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
145 SET_BOOL(initial_setup_done);
146 SET_BOOL(disabled);
147 SET_STR(oauth_client_id);
148 return value;
151 scoped_ptr<base::DictionaryValue> SessionHeaderToValue(
152 const sync_pb::SessionHeader& proto) {
153 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
154 SET_REP(window, SessionWindowToValue);
155 SET_STR(client_name);
156 SET_ENUM(device_type, GetDeviceTypeString);
157 return value;
160 scoped_ptr<base::DictionaryValue> SessionTabToValue(
161 const sync_pb::SessionTab& proto) {
162 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
163 SET_INT32(tab_id);
164 SET_INT32(window_id);
165 SET_INT32(tab_visual_index);
166 SET_INT32(current_navigation_index);
167 SET_BOOL(pinned);
168 SET_STR(extension_app_id);
169 SET_REP(navigation, TabNavigationToValue);
170 SET_BYTES(favicon);
171 SET_ENUM(favicon_type, GetFaviconTypeString);
172 SET_STR(favicon_source);
173 SET_REP(variation_id, MakeInt64Value);
174 return value;
177 scoped_ptr<base::DictionaryValue> SessionWindowToValue(
178 const sync_pb::SessionWindow& proto) {
179 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
180 SET_INT32(window_id);
181 SET_INT32(selected_tab_index);
182 SET_INT32_REP(tab);
183 SET_ENUM(browser_type, GetBrowserTypeString);
184 return value;
187 scoped_ptr<base::DictionaryValue> TabNavigationToValue(
188 const sync_pb::TabNavigation& proto) {
189 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
190 SET_STR(virtual_url);
191 SET_STR(referrer);
192 SET_STR(title);
193 SET_STR(state);
194 SET_ENUM(page_transition, GetPageTransitionString);
195 SET_ENUM(redirect_type, GetPageTransitionRedirectTypeString);
196 SET_INT32(unique_id);
197 SET_INT64(timestamp_msec);
198 SET_BOOL(navigation_forward_back);
199 SET_BOOL(navigation_from_address_bar);
200 SET_BOOL(navigation_home_page);
201 SET_BOOL(navigation_chain_start);
202 SET_BOOL(navigation_chain_end);
203 SET_INT64(global_id);
204 SET_STR(search_terms);
205 SET_STR(favicon_url);
206 SET_ENUM(blocked_state, GetBlockedStateString);
207 SET_STR_REP(content_pack_categories);
208 SET_INT32(http_status_code);
209 SET_INT32(obsolete_referrer_policy);
210 SET_BOOL(is_restored);
211 SET_REP(navigation_redirect, NavigationRedirectToValue);
212 SET_STR(last_navigation_redirect_url);
213 SET_INT32(correct_referrer_policy);
214 return value;
217 scoped_ptr<base::DictionaryValue> NavigationRedirectToValue(
218 const sync_pb::NavigationRedirect& proto) {
219 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
220 SET_STR(url);
221 return value;
224 scoped_ptr<base::DictionaryValue> PasswordSpecificsDataToValue(
225 const sync_pb::PasswordSpecificsData& proto) {
226 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
227 SET_INT32(scheme);
228 SET_STR(signon_realm);
229 SET_STR(origin);
230 SET_STR(action);
231 SET_STR(username_element);
232 SET_STR(username_value);
233 SET_STR(password_element);
234 value->SetString("password_value", "<redacted>");
235 SET_BOOL(ssl_valid);
236 SET_BOOL(preferred);
237 SET_INT64(date_created);
238 SET_BOOL(blacklisted);
239 SET_INT32(type);
240 SET_INT32(times_used);
241 SET_STR(display_name);
242 SET_STR(avatar_url);
243 SET_STR(federation_url);
244 return value;
247 scoped_ptr<base::DictionaryValue> GlobalIdDirectiveToValue(
248 const sync_pb::GlobalIdDirective& proto) {
249 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
250 SET_INT64_REP(global_id);
251 SET_INT64(start_time_usec);
252 SET_INT64(end_time_usec);
253 return value;
256 scoped_ptr<base::DictionaryValue> TimeRangeDirectiveToValue(
257 const sync_pb::TimeRangeDirective& proto) {
258 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
259 SET_INT64(start_time_usec);
260 SET_INT64(end_time_usec);
261 return value;
264 scoped_ptr<base::DictionaryValue> AppListSpecificsToValue(
265 const sync_pb::AppListSpecifics& proto) {
266 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
267 SET_STR(item_id);
268 SET_ENUM(item_type, GetAppListItemTypeString);
269 SET_STR(item_name);
270 SET_STR(parent_id);
271 SET_STR(item_ordinal);
273 return value;
276 scoped_ptr<base::DictionaryValue> AppNotificationToValue(
277 const sync_pb::AppNotification& proto) {
278 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
279 SET_STR(guid);
280 SET_STR(app_id);
281 SET_INT64(creation_timestamp_ms);
282 SET_STR(title);
283 SET_STR(body_text);
284 SET_STR(link_url);
285 SET_STR(link_text);
286 return value;
289 scoped_ptr<base::DictionaryValue> AppSettingSpecificsToValue(
290 const sync_pb::AppSettingSpecifics& proto) {
291 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
292 SET(extension_setting, ExtensionSettingSpecificsToValue);
293 return value;
296 scoped_ptr<base::DictionaryValue> LinkedAppIconInfoToValue(
297 const sync_pb::LinkedAppIconInfo& proto) {
298 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
299 SET_STR(url);
300 SET_INT32(size);
301 return value;
304 scoped_ptr<base::DictionaryValue> AppSpecificsToValue(
305 const sync_pb::AppSpecifics& proto) {
306 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
307 SET(extension, ExtensionSpecificsToValue);
308 SET(notification_settings, AppSettingsToValue);
309 SET_STR(app_launch_ordinal);
310 SET_STR(page_ordinal);
311 SET_ENUM(launch_type, GetLaunchTypeString);
312 SET_STR(bookmark_app_url);
313 SET_STR(bookmark_app_description);
314 SET_STR(bookmark_app_icon_color);
315 SET_REP(linked_app_icons, LinkedAppIconInfoToValue);
317 return value;
320 scoped_ptr<base::DictionaryValue> AutofillSpecificsToValue(
321 const sync_pb::AutofillSpecifics& proto) {
322 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
323 SET_STR(name);
324 SET_STR(value);
325 SET_INT64_REP(usage_timestamp);
326 SET(profile, AutofillProfileSpecificsToValue);
327 return value;
330 scoped_ptr<base::DictionaryValue> AutofillProfileSpecificsToValue(
331 const sync_pb::AutofillProfileSpecifics& proto) {
332 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
333 SET_STR(guid);
334 SET_STR(origin);
335 SET_INT64(use_count);
336 SET_INT64(use_date);
338 SET_STR_REP(name_first);
339 SET_STR_REP(name_middle);
340 SET_STR_REP(name_last);
341 SET_STR_REP(name_full);
342 SET_STR_REP(email_address);
343 SET_STR(company_name);
345 SET_STR(address_home_line1);
346 SET_STR(address_home_line2);
347 SET_STR(address_home_city);
348 SET_STR(address_home_state);
349 SET_STR(address_home_zip);
350 SET_STR(address_home_country);
352 SET_STR(address_home_street_address);
353 SET_STR(address_home_sorting_code);
354 SET_STR(address_home_dependent_locality);
355 SET_STR(address_home_language_code);
357 SET_STR_REP(phone_home_whole_number);
358 return value;
361 scoped_ptr<base::DictionaryValue> WalletMetadataSpecificsToValue(
362 const sync_pb::WalletMetadataSpecifics& proto) {
363 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
364 SET_ENUM(type, GetWalletMetadataTypeString);
365 SET_STR(id);
366 SET_INT64(use_count);
367 SET_INT64(use_date);
368 return value;
371 scoped_ptr<base::DictionaryValue> AutofillWalletSpecificsToValue(
372 const sync_pb::AutofillWalletSpecifics& proto) {
373 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
375 SET_ENUM(type, GetWalletInfoTypeString);
376 if (proto.type() == sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD) {
377 value->Set("masked_card",
378 WalletMaskedCreditCardToValue(proto.masked_card()));
379 } else if (proto.type() == sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS) {
380 value->Set("address",
381 WalletPostalAddressToValue(proto.address()));
383 return value;
386 scoped_ptr<base::DictionaryValue> MetaInfoToValue(
387 const sync_pb::MetaInfo& proto) {
388 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
389 SET_STR(key);
390 SET_STR(value);
391 return value;
394 scoped_ptr<base::DictionaryValue> BookmarkSpecificsToValue(
395 const sync_pb::BookmarkSpecifics& proto) {
396 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
397 SET_STR(url);
398 SET_BYTES(favicon);
399 SET_STR(title);
400 SET_INT64(creation_time_us);
401 SET_STR(icon_url);
402 SET_REP(meta_info, &MetaInfoToValue);
403 return value;
406 scoped_ptr<base::DictionaryValue> DeviceInfoSpecificsToValue(
407 const sync_pb::DeviceInfoSpecifics& proto) {
408 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
409 SET_STR(cache_guid);
410 SET_STR(client_name);
411 SET_ENUM(device_type, GetDeviceTypeString);
412 SET_STR(sync_user_agent);
413 SET_STR(chrome_version);
414 SET_TIME_STR(backup_timestamp);
415 SET_STR(signin_scoped_device_id);
416 return value;
419 scoped_ptr<base::DictionaryValue> DictionarySpecificsToValue(
420 const sync_pb::DictionarySpecifics& proto) {
421 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
422 SET_STR(word);
423 return value;
426 namespace {
428 scoped_ptr<base::DictionaryValue> FaviconSyncFlagsToValue(
429 const sync_pb::FaviconSyncFlags& proto) {
430 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
431 SET_BOOL(enabled);
432 SET_INT32(favicon_sync_limit);
433 return value;
436 } // namespace
438 scoped_ptr<base::DictionaryValue> ExperimentsSpecificsToValue(
439 const sync_pb::ExperimentsSpecifics& proto) {
440 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
441 SET_EXPERIMENT_ENABLED_FIELD(keystore_encryption);
442 SET_EXPERIMENT_ENABLED_FIELD(history_delete_directives);
443 SET_EXPERIMENT_ENABLED_FIELD(autofill_culling);
444 SET_EXPERIMENT_ENABLED_FIELD(pre_commit_update_avoidance);
445 SET(favicon_sync, FaviconSyncFlagsToValue);
446 SET_EXPERIMENT_ENABLED_FIELD(gcm_channel);
447 SET_EXPERIMENT_ENABLED_FIELD(gcm_invalidations);
448 SET_EXPERIMENT_ENABLED_FIELD(wallet_sync);
449 return value;
452 scoped_ptr<base::DictionaryValue> ExtensionSettingSpecificsToValue(
453 const sync_pb::ExtensionSettingSpecifics& proto) {
454 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
455 SET_STR(extension_id);
456 SET_STR(key);
457 SET_STR(value);
458 return value;
461 scoped_ptr<base::DictionaryValue> ExtensionSpecificsToValue(
462 const sync_pb::ExtensionSpecifics& proto) {
463 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
464 SET_STR(id);
465 SET_STR(version);
466 SET_STR(update_url);
467 SET_BOOL(enabled);
468 SET_BOOL(incognito_enabled);
469 SET_STR(name);
470 SET_BOOL(remote_install);
471 SET_BOOL(installed_by_custodian);
472 SET_BOOL(all_urls_enabled);
473 SET_INT32(disable_reasons);
474 return value;
477 namespace {
478 scoped_ptr<base::DictionaryValue> FaviconDataToValue(
479 const sync_pb::FaviconData& proto) {
480 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
481 SET_BYTES(favicon);
482 SET_INT32(width);
483 SET_INT32(height);
484 return value;
486 } // namespace
488 scoped_ptr<base::DictionaryValue> FaviconImageSpecificsToValue(
489 const sync_pb::FaviconImageSpecifics& proto) {
490 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
491 SET_STR(favicon_url);
492 SET(favicon_web, FaviconDataToValue);
493 SET(favicon_web_32, FaviconDataToValue);
494 SET(favicon_touch_64, FaviconDataToValue);
495 SET(favicon_touch_precomposed_64, FaviconDataToValue);
496 return value;
499 scoped_ptr<base::DictionaryValue> FaviconTrackingSpecificsToValue(
500 const sync_pb::FaviconTrackingSpecifics& proto) {
501 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
502 SET_STR(favicon_url);
503 SET_INT64(last_visit_time_ms)
504 SET_BOOL(is_bookmarked);
505 return value;
508 scoped_ptr<base::DictionaryValue> HistoryDeleteDirectiveSpecificsToValue(
509 const sync_pb::HistoryDeleteDirectiveSpecifics& proto) {
510 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
511 SET(global_id_directive, GlobalIdDirectiveToValue);
512 SET(time_range_directive, TimeRangeDirectiveToValue);
513 return value;
516 scoped_ptr<base::DictionaryValue> ManagedUserSettingSpecificsToValue(
517 const sync_pb::ManagedUserSettingSpecifics& proto) {
518 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
519 SET_STR(name);
520 SET_STR(value);
521 return value;
524 scoped_ptr<base::DictionaryValue> ManagedUserSpecificsToValue(
525 const sync_pb::ManagedUserSpecifics& proto) {
526 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
527 SET_STR(id);
528 SET_STR(name);
529 SET_BOOL(acknowledged);
530 SET_STR(master_key);
531 SET_STR(chrome_avatar);
532 SET_STR(chromeos_avatar);
533 return value;
536 scoped_ptr<base::DictionaryValue> ManagedUserSharedSettingSpecificsToValue(
537 const sync_pb::ManagedUserSharedSettingSpecifics& proto) {
538 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
539 SET_STR(mu_id);
540 SET_STR(key);
541 SET_STR(value);
542 SET_BOOL(acknowledged);
543 return value;
546 scoped_ptr<base::DictionaryValue> ManagedUserWhitelistSpecificsToValue(
547 const sync_pb::ManagedUserWhitelistSpecifics& proto) {
548 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
549 SET_STR(id);
550 SET_STR(name);
551 return value;
554 scoped_ptr<base::DictionaryValue> NigoriSpecificsToValue(
555 const sync_pb::NigoriSpecifics& proto) {
556 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
557 SET(encryption_keybag, EncryptedDataToValue);
558 SET_BOOL(keybag_is_frozen);
559 SET_BOOL(encrypt_bookmarks);
560 SET_BOOL(encrypt_preferences);
561 SET_BOOL(encrypt_autofill_profile);
562 SET_BOOL(encrypt_autofill);
563 SET_BOOL(encrypt_themes);
564 SET_BOOL(encrypt_typed_urls);
565 SET_BOOL(encrypt_extension_settings);
566 SET_BOOL(encrypt_extensions);
567 SET_BOOL(encrypt_sessions);
568 SET_BOOL(encrypt_app_settings);
569 SET_BOOL(encrypt_apps);
570 SET_BOOL(encrypt_search_engines);
571 SET_BOOL(encrypt_dictionary);
572 SET_BOOL(encrypt_articles);
573 SET_BOOL(encrypt_app_list);
574 SET_BOOL(encrypt_everything);
575 SET_BOOL(sync_tab_favicons);
576 SET_ENUM(passphrase_type, PassphraseTypeString);
577 SET(keystore_decryptor_token, EncryptedDataToValue);
578 SET_INT64(keystore_migration_time);
579 SET_INT64(custom_passphrase_time);
580 return value;
583 scoped_ptr<base::DictionaryValue> ArticlePageToValue(
584 const sync_pb::ArticlePage& proto) {
585 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
586 SET_STR(url);
587 return value;
590 scoped_ptr<base::DictionaryValue> ArticleSpecificsToValue(
591 const sync_pb::ArticleSpecifics& proto) {
592 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
593 SET_STR(entry_id);
594 SET_STR(title);
595 SET_REP(pages, ArticlePageToValue);
596 return value;
599 scoped_ptr<base::DictionaryValue> PasswordSpecificsToValue(
600 const sync_pb::PasswordSpecifics& proto) {
601 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
602 SET(encrypted, EncryptedDataToValue);
603 return value;
606 scoped_ptr<base::DictionaryValue> PreferenceSpecificsToValue(
607 const sync_pb::PreferenceSpecifics& proto) {
608 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
609 SET_STR(name);
610 SET_STR(value);
611 return value;
614 scoped_ptr<base::DictionaryValue> PriorityPreferenceSpecificsToValue(
615 const sync_pb::PriorityPreferenceSpecifics& specifics) {
616 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
617 SET_FIELD(preference, PreferenceSpecificsToValue);
618 return value;
621 scoped_ptr<base::DictionaryValue> SyncedNotificationAppInfoSpecificsToValue(
622 const sync_pb::SyncedNotificationAppInfoSpecifics& proto) {
623 return make_scoped_ptr(new base::DictionaryValue());
626 scoped_ptr<base::DictionaryValue> SyncedNotificationSpecificsToValue(
627 const sync_pb::SyncedNotificationSpecifics& proto) {
628 return make_scoped_ptr(new base::DictionaryValue());
631 scoped_ptr<base::DictionaryValue> SearchEngineSpecificsToValue(
632 const sync_pb::SearchEngineSpecifics& proto) {
633 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
634 SET_STR(short_name);
635 SET_STR(keyword);
636 SET_STR(favicon_url);
637 SET_STR(url);
638 SET_BOOL(safe_for_autoreplace);
639 SET_STR(originating_url);
640 SET_INT64(date_created);
641 SET_STR(input_encodings);
642 SET_BOOL(show_in_default_list);
643 SET_STR(suggestions_url);
644 SET_INT32(prepopulate_id);
645 SET_BOOL(autogenerate_keyword);
646 SET_STR(instant_url);
647 SET_INT64(last_modified);
648 SET_STR(sync_guid);
649 SET_STR_REP(alternate_urls);
650 SET_STR(search_terms_replacement_key);
651 SET_STR(image_url);
652 SET_STR(search_url_post_params);
653 SET_STR(suggestions_url_post_params);
654 SET_STR(instant_url_post_params);
655 SET_STR(image_url_post_params);
656 SET_STR(new_tab_url);
657 return value;
660 scoped_ptr<base::DictionaryValue> SessionSpecificsToValue(
661 const sync_pb::SessionSpecifics& proto) {
662 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
663 SET_STR(session_tag);
664 SET(header, SessionHeaderToValue);
665 SET(tab, SessionTabToValue);
666 SET_INT32(tab_node_id);
667 return value;
670 scoped_ptr<base::DictionaryValue> ThemeSpecificsToValue(
671 const sync_pb::ThemeSpecifics& proto) {
672 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
673 SET_BOOL(use_custom_theme);
674 SET_BOOL(use_system_theme_by_default);
675 SET_STR(custom_theme_name);
676 SET_STR(custom_theme_id);
677 SET_STR(custom_theme_update_url);
678 return value;
681 scoped_ptr<base::DictionaryValue> TypedUrlSpecificsToValue(
682 const sync_pb::TypedUrlSpecifics& proto) {
683 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
684 SET_STR(url);
685 SET_STR(title);
686 SET_BOOL(hidden);
687 SET_INT64_REP(visits);
688 SET_INT32_REP(visit_transitions);
689 return value;
692 scoped_ptr<base::DictionaryValue> WalletMaskedCreditCardToValue(
693 const sync_pb::WalletMaskedCreditCard& proto) {
694 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
695 SET_STR(id);
696 SET_ENUM(status, GetWalletCardStatusString);
697 SET_STR(name_on_card);
698 SET_ENUM(type, GetWalletCardTypeString);
699 SET_STR(last_four);
700 SET_INT32(exp_month);
701 SET_INT32(exp_year);
702 return value;
705 scoped_ptr<base::DictionaryValue> WalletPostalAddressToValue(
706 const sync_pb::WalletPostalAddress& proto) {
707 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
708 SET_STR(recipient_name);
709 SET_STR(company_name);
710 SET_STR_REP(street_address);
711 SET_STR(address_1);
712 SET_STR(address_2);
713 SET_STR(address_3);
714 SET_STR(address_4);
715 SET_STR(postal_code);
716 SET_STR(sorting_code);
717 SET_STR(country_code);
718 SET_STR(phone_number);
719 SET_STR(language_code);
720 return value;
723 scoped_ptr<base::DictionaryValue> WifiCredentialSpecificsToValue(
724 const sync_pb::WifiCredentialSpecifics& proto) {
725 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
726 SET_BYTES(ssid);
727 SET_ENUM(security_class, GetWifiCredentialSecurityClassString);
728 SET_BYTES(passphrase);
729 return value;
732 scoped_ptr<base::DictionaryValue> EntitySpecificsToValue(
733 const sync_pb::EntitySpecifics& specifics) {
734 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
735 SET_FIELD(app, AppSpecificsToValue);
736 SET_FIELD(app_list, AppListSpecificsToValue);
737 SET_FIELD(app_notification, AppNotificationToValue);
738 SET_FIELD(app_setting, AppSettingSpecificsToValue);
739 SET_FIELD(article, ArticleSpecificsToValue);
740 SET_FIELD(autofill, AutofillSpecificsToValue);
741 SET_FIELD(autofill_profile, AutofillProfileSpecificsToValue);
742 SET_FIELD(autofill_wallet, AutofillWalletSpecificsToValue);
743 SET_FIELD(wallet_metadata, WalletMetadataSpecificsToValue);
744 SET_FIELD(bookmark, BookmarkSpecificsToValue);
745 SET_FIELD(device_info, DeviceInfoSpecificsToValue);
746 SET_FIELD(dictionary, DictionarySpecificsToValue);
747 SET_FIELD(experiments, ExperimentsSpecificsToValue);
748 SET_FIELD(extension, ExtensionSpecificsToValue);
749 SET_FIELD(extension_setting, ExtensionSettingSpecificsToValue);
750 SET_FIELD(favicon_image, FaviconImageSpecificsToValue);
751 SET_FIELD(favicon_tracking, FaviconTrackingSpecificsToValue);
752 SET_FIELD(history_delete_directive, HistoryDeleteDirectiveSpecificsToValue);
753 SET_FIELD(managed_user_setting, ManagedUserSettingSpecificsToValue);
754 SET_FIELD(managed_user_shared_setting,
755 ManagedUserSharedSettingSpecificsToValue);
756 SET_FIELD(managed_user, ManagedUserSpecificsToValue);
757 SET_FIELD(managed_user_whitelist, ManagedUserWhitelistSpecificsToValue);
758 SET_FIELD(nigori, NigoriSpecificsToValue);
759 SET_FIELD(password, PasswordSpecificsToValue);
760 SET_FIELD(preference, PreferenceSpecificsToValue);
761 SET_FIELD(priority_preference, PriorityPreferenceSpecificsToValue);
762 SET_FIELD(search_engine, SearchEngineSpecificsToValue);
763 SET_FIELD(session, SessionSpecificsToValue);
764 SET_FIELD(synced_notification, SyncedNotificationSpecificsToValue);
765 SET_FIELD(synced_notification_app_info,
766 SyncedNotificationAppInfoSpecificsToValue);
767 SET_FIELD(theme, ThemeSpecificsToValue);
768 SET_FIELD(typed_url, TypedUrlSpecificsToValue);
769 SET_FIELD(wifi_credential, WifiCredentialSpecificsToValue);
770 return value;
773 namespace {
775 base::StringValue* UniquePositionToStringValue(
776 const sync_pb::UniquePosition& proto) {
777 UniquePosition pos = UniquePosition::FromProto(proto);
778 return new base::StringValue(pos.ToDebugString());
781 } // namespace
783 scoped_ptr<base::DictionaryValue> SyncEntityToValue(
784 const sync_pb::SyncEntity& proto,
785 bool include_specifics) {
786 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
787 SET_STR(id_string);
788 SET_STR(parent_id_string);
789 SET_STR(old_parent_id);
790 SET_INT64(version);
791 SET_INT64(mtime);
792 SET_INT64(ctime);
793 SET_STR(name);
794 SET_STR(non_unique_name);
795 SET_INT64(sync_timestamp);
796 SET_STR(server_defined_unique_tag);
797 SET_INT64(position_in_parent);
798 SET(unique_position, UniquePositionToStringValue);
799 SET_STR(insert_after_item_id);
800 SET_BOOL(deleted);
801 SET_STR(originator_cache_guid);
802 SET_STR(originator_client_item_id);
803 if (include_specifics)
804 SET(specifics, EntitySpecificsToValue);
805 SET_BOOL(folder);
806 SET_STR(client_defined_unique_tag);
807 SET_REP(attachment_id, AttachmentIdProtoToValue);
808 return value;
811 namespace {
813 base::ListValue* SyncEntitiesToValue(
814 const ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities,
815 bool include_specifics) {
816 base::ListValue* list = new base::ListValue();
817 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it;
818 for (it = entities.begin(); it != entities.end(); ++it) {
819 list->Append(SyncEntityToValue(*it, include_specifics));
822 return list;
825 scoped_ptr<base::DictionaryValue> ChromiumExtensionActivityToValue(
826 const sync_pb::ChromiumExtensionsActivity& proto) {
827 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
828 SET_STR(extension_id);
829 SET_INT32(bookmark_writes_since_last_commit);
830 return value;
833 scoped_ptr<base::DictionaryValue> CommitMessageToValue(
834 const sync_pb::CommitMessage& proto,
835 bool include_specifics) {
836 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
837 value->Set("entries",
838 SyncEntitiesToValue(proto.entries(), include_specifics));
839 SET_STR(cache_guid);
840 SET_REP(extensions_activity, ChromiumExtensionActivityToValue);
841 SET(config_params, ClientConfigParamsToValue);
842 return value;
845 scoped_ptr<base::DictionaryValue> GetUpdateTriggersToValue(
846 const sync_pb::GetUpdateTriggers& proto) {
847 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
848 SET_STR_REP(notification_hint);
849 SET_BOOL(client_dropped_hints);
850 SET_BOOL(invalidations_out_of_sync);
851 SET_INT64(local_modification_nudges);
852 SET_INT64(datatype_refresh_nudges);
853 return value;
856 scoped_ptr<base::DictionaryValue> DataTypeProgressMarkerToValue(
857 const sync_pb::DataTypeProgressMarker& proto) {
858 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
859 SET_INT32(data_type_id);
860 SET_BYTES(token);
861 SET_INT64(timestamp_token_for_migration);
862 SET_STR(notification_hint);
863 SET(get_update_triggers, GetUpdateTriggersToValue);
864 return value;
867 scoped_ptr<base::DictionaryValue> DataTypeContextToValue(
868 const sync_pb::DataTypeContext& proto) {
869 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
870 SET_INT32(data_type_id);
871 SET_STR(context);
872 SET_INT64(version);
873 return value;
876 scoped_ptr<base::DictionaryValue> GetUpdatesCallerInfoToValue(
877 const sync_pb::GetUpdatesCallerInfo& proto) {
878 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
879 SET_ENUM(source, GetUpdatesSourceString);
880 SET_BOOL(notifications_enabled);
881 return value;
884 scoped_ptr<base::DictionaryValue> GetUpdatesMessageToValue(
885 const sync_pb::GetUpdatesMessage& proto) {
886 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
887 SET(caller_info, GetUpdatesCallerInfoToValue);
888 SET_BOOL(fetch_folders);
889 SET_INT32(batch_size);
890 SET_REP(from_progress_marker, DataTypeProgressMarkerToValue);
891 SET_BOOL(streaming);
892 SET_BOOL(need_encryption_key);
893 SET_BOOL(create_mobile_bookmarks_folder);
894 SET_ENUM(get_updates_origin, GetUpdatesOriginString);
895 SET_REP(client_contexts, DataTypeContextToValue);
896 return value;
899 scoped_ptr<base::DictionaryValue> ClientStatusToValue(
900 const sync_pb::ClientStatus& proto) {
901 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
902 SET_BOOL(hierarchy_conflict_detected);
903 return value;
906 scoped_ptr<base::DictionaryValue> EntryResponseToValue(
907 const sync_pb::CommitResponse::EntryResponse& proto) {
908 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
909 SET_ENUM(response_type, GetResponseTypeString);
910 SET_STR(id_string);
911 SET_STR(parent_id_string);
912 SET_INT64(position_in_parent);
913 SET_INT64(version);
914 SET_STR(name);
915 SET_STR(error_message);
916 SET_INT64(mtime);
917 return value;
920 scoped_ptr<base::DictionaryValue> CommitResponseToValue(
921 const sync_pb::CommitResponse& proto) {
922 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
923 SET_REP(entryresponse, EntryResponseToValue);
924 return value;
927 scoped_ptr<base::DictionaryValue> GetUpdatesResponseToValue(
928 const sync_pb::GetUpdatesResponse& proto,
929 bool include_specifics) {
930 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
931 value->Set("entries",
932 SyncEntitiesToValue(proto.entries(), include_specifics));
933 SET_INT64(changes_remaining);
934 SET_REP(new_progress_marker, DataTypeProgressMarkerToValue);
935 SET_REP(context_mutations, DataTypeContextToValue);
936 return value;
939 scoped_ptr<base::DictionaryValue> ClientCommandToValue(
940 const sync_pb::ClientCommand& proto) {
941 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
942 SET_INT32(set_sync_poll_interval);
943 SET_INT32(set_sync_long_poll_interval);
944 SET_INT32(max_commit_batch_size);
945 SET_INT32(sessions_commit_delay_seconds);
946 SET_INT32(throttle_delay_seconds);
947 SET_INT32(client_invalidation_hint_buffer_size);
948 return value;
951 scoped_ptr<base::DictionaryValue> ErrorToValue(
952 const sync_pb::ClientToServerResponse::Error& proto) {
953 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
954 SET_ENUM(error_type, GetErrorTypeString);
955 SET_STR(error_description);
956 SET_STR(url);
957 SET_ENUM(action, GetActionString);
958 return value;
961 } // namespace
963 scoped_ptr<base::DictionaryValue> ClientToServerResponseToValue(
964 const sync_pb::ClientToServerResponse& proto,
965 bool include_specifics) {
966 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
967 SET(commit, CommitResponseToValue);
968 if (proto.has_get_updates()) {
969 value->Set("get_updates", GetUpdatesResponseToValue(proto.get_updates(),
970 include_specifics));
973 SET(error, ErrorToValue);
974 SET_ENUM(error_code, GetErrorTypeString);
975 SET_STR(error_message);
976 SET_STR(store_birthday);
977 SET(client_command, ClientCommandToValue);
978 SET_INT32_REP(migrated_data_type_id);
979 return value;
982 scoped_ptr<base::DictionaryValue> ClientToServerMessageToValue(
983 const sync_pb::ClientToServerMessage& proto,
984 bool include_specifics) {
985 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
986 SET_STR(share);
987 SET_INT32(protocol_version);
988 if (proto.has_commit()) {
989 value->Set("commit",
990 CommitMessageToValue(proto.commit(), include_specifics));
993 SET(get_updates, GetUpdatesMessageToValue);
994 SET_STR(store_birthday);
995 SET_BOOL(sync_problem_detected);
996 SET(debug_info, DebugInfoToValue);
997 SET(client_status, ClientStatusToValue);
998 return value;
1001 scoped_ptr<base::DictionaryValue> DatatypeAssociationStatsToValue(
1002 const sync_pb::DatatypeAssociationStats& proto) {
1003 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1004 SET_INT32(data_type_id);
1005 SET_INT32(num_local_items_before_association);
1006 SET_INT32(num_sync_items_before_association);
1007 SET_INT32(num_local_items_after_association);
1008 SET_INT32(num_sync_items_after_association);
1009 SET_INT32(num_local_items_added);
1010 SET_INT32(num_local_items_deleted);
1011 SET_INT32(num_local_items_modified);
1012 SET_INT32(num_sync_items_added);
1013 SET_INT32(num_sync_items_deleted);
1014 SET_INT32(num_sync_items_modified);
1015 SET_INT64(local_version_pre_association);
1016 SET_INT64(sync_version_pre_association)
1017 SET_BOOL(had_error);
1018 SET_INT64(download_wait_time_us);
1019 SET_INT64(download_time_us);
1020 SET_INT64(association_wait_time_for_high_priority_us);
1021 SET_INT64(association_wait_time_for_same_priority_us);
1022 return value;
1025 scoped_ptr<base::DictionaryValue> DebugEventInfoToValue(
1026 const sync_pb::DebugEventInfo& proto) {
1027 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1028 SET_ENUM(singleton_event, SingletonDebugEventTypeString);
1029 SET(sync_cycle_completed_event_info, SyncCycleCompletedEventInfoToValue);
1030 SET_INT32(nudging_datatype);
1031 SET_INT32_REP(datatypes_notified_from_server);
1032 SET(datatype_association_stats, DatatypeAssociationStatsToValue);
1033 return value;
1036 scoped_ptr<base::DictionaryValue> DebugInfoToValue(
1037 const sync_pb::DebugInfo& proto) {
1038 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1039 SET_REP(events, DebugEventInfoToValue);
1040 SET_BOOL(cryptographer_ready);
1041 SET_BOOL(cryptographer_has_pending_keys);
1042 SET_BOOL(events_dropped);
1043 return value;
1046 scoped_ptr<base::DictionaryValue> SyncCycleCompletedEventInfoToValue(
1047 const sync_pb::SyncCycleCompletedEventInfo& proto) {
1048 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1049 SET_INT32(num_encryption_conflicts);
1050 SET_INT32(num_hierarchy_conflicts);
1051 SET_INT32(num_server_conflicts);
1052 SET_INT32(num_updates_downloaded);
1053 SET_INT32(num_reflected_updates_downloaded);
1054 SET(caller_info, GetUpdatesCallerInfoToValue);
1055 return value;
1058 scoped_ptr<base::DictionaryValue> ClientConfigParamsToValue(
1059 const sync_pb::ClientConfigParams& proto) {
1060 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1061 SET_INT32_REP(enabled_type_ids);
1062 SET_BOOL(tabs_datatype_enabled);
1063 return value;
1066 scoped_ptr<base::DictionaryValue> AttachmentIdProtoToValue(
1067 const sync_pb::AttachmentIdProto& proto) {
1068 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1069 SET_STR(unique_id);
1070 return value;
1073 #undef SET_TYPE
1074 #undef SET
1075 #undef SET_REP
1077 #undef SET_BOOL
1078 #undef SET_BYTES
1079 #undef SET_INT32
1080 #undef SET_INT64
1081 #undef SET_INT64_REP
1082 #undef SET_STR
1083 #undef SET_STR_REP
1085 #undef SET_FIELD
1087 } // namespace syncer