Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: sync/protocol/proto_value_conversions.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 // Keep this file in sync with the .proto files in this directory.
6
7 #include "sync/protocol/proto_value_conversions.h"
8
9 #include <stdint.h>
10
11 #include <algorithm>
12 #include <string>
13
14 #include "base/base64.h"
15 #include "base/i18n/time_formatting.h"
16 #include "base/logging.h"
17 #include "base/memory/ptr_util.h"
18 #include "base/strings/string_number_conversions.h"
19 #include "base/time/time.h"
20 #include "base/values.h"
21 #include "sync/internal_api/public/base/unique_position.h"
22 #include "sync/protocol/app_list_specifics.pb.h"
23 #include "sync/protocol/app_notification_specifics.pb.h"
24 #include "sync/protocol/app_setting_specifics.pb.h"
25 #include "sync/protocol/app_specifics.pb.h"
26 #include "sync/protocol/arc_package_specifics.pb.h"
27 #include "sync/protocol/autofill_specifics.pb.h"
28 #include "sync/protocol/bookmark_specifics.pb.h"
29 #include "sync/protocol/dictionary_specifics.pb.h"
30 #include "sync/protocol/encryption.pb.h"
31 #include "sync/protocol/experiments_specifics.pb.h"
32 #include "sync/protocol/extension_setting_specifics.pb.h"
33 #include "sync/protocol/extension_specifics.pb.h"
34 #include "sync/protocol/favicon_image_specifics.pb.h"
35 #include "sync/protocol/favicon_tracking_specifics.pb.h"
36 #include "sync/protocol/history_delete_directive_specifics.pb.h"
37 #include "sync/protocol/nigori_specifics.pb.h"
38 #include "sync/protocol/password_specifics.pb.h"
39 #include "sync/protocol/preference_specifics.pb.h"
40 #include "sync/protocol/priority_preference_specifics.pb.h"
41 #include "sync/protocol/proto_enum_conversions.h"
42 #include "sync/protocol/search_engine_specifics.pb.h"
43 #include "sync/protocol/session_specifics.pb.h"
44 #include "sync/protocol/sync.pb.h"
45 #include "sync/protocol/theme_specifics.pb.h"
46 #include "sync/protocol/typed_url_specifics.pb.h"
47 #include "sync/protocol/unique_position.pb.h"
48 #include "sync/util/time.h"
49
50 namespace syncer {
51
52 namespace {
53
54 // Basic Type -> Value functions.
55
56 std::unique_ptr<base::StringValue> MakeInt64Value(int64_t x) {
57 return base::WrapUnique(new base::StringValue(base::Int64ToString(x)));
58 }
59
60 // TODO(akalin): Perhaps make JSONWriter support BinaryValue and use
61 // that instead of a StringValue.
62 std::string Base64EncodeString(const std::string& bytes) {
63 std::string bytes_base64;
64 base::Base64Encode(bytes, &bytes_base64);
65 return bytes_base64;
66 }
67
68 std::unique_ptr<base::StringValue> MakeStringValue(const std::string& str) {
69 return base::WrapUnique(new base::StringValue(str));
70 }
71
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 std::unique_ptr<base::ListValue> MakeRepeatedValue(const F& fields,
76 V (*converter_fn)(T)) {
77 std::unique_ptr<base::ListValue> list(new base::ListValue());
78 for (typename F::const_iterator it = fields.begin(); it != fields.end();
79 ++it) {
80 list->Append(converter_fn(*it));
81 }
82 return list;
83 }
84
85 } // namespace
86
87 // Helper macros to reduce the amount of boilerplate.
88
89 #define SET_TYPE(field, set_fn, transform) \
90 if (proto.has_##field()) { \
91 value->set_fn(#field, transform(proto.field())); \
92 }
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)
97
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 std::unique_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())); \
120 } \
121 } while (0)
122
123 #define SET_FIELD(field, fn) \
124 do { \
125 if (specifics.has_##field()) { \
126 value->Set(#field, fn(specifics.field())); \
127 } \
128 } while (0)
129
130 // If you add another macro, don't forget to add an #undef at the end
131 // of this file, too.
132
133 std::unique_ptr<base::DictionaryValue> EncryptedDataToValue(
134 const sync_pb::EncryptedData& proto) {
135 std::unique_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;
140 }
141
142 std::unique_ptr<base::DictionaryValue> AppSettingsToValue(
143 const sync_pb::AppNotificationSettings& proto) {
144 std::unique_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;
149 }
150
151 std::unique_ptr<base::DictionaryValue> SessionHeaderToValue(
152 const sync_pb::SessionHeader& proto) {
153 std::unique_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;
158 }
159
160 std::unique_ptr<base::DictionaryValue> SessionTabToValue(
161 const sync_pb::SessionTab& proto) {
162 std::unique_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;
175 }
176
177 std::unique_ptr<base::DictionaryValue> SessionWindowToValue(
178 const sync_pb::SessionWindow& proto) {
179 std::unique_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;
185 }
186
187 std::unique_ptr<base::DictionaryValue> TabNavigationToValue(
188 const sync_pb::TabNavigation& proto) {
189 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
190 SET_STR(virtual_url);
191 SET_STR(referrer);
192 SET_STR(title);
193 SET_ENUM(page_transition, GetPageTransitionString);
194 SET_ENUM(redirect_type, GetPageTransitionRedirectTypeString);
195 SET_INT32(unique_id);
196 SET_INT64(timestamp_msec);
197 SET_BOOL(navigation_forward_back);
198 SET_BOOL(navigation_from_address_bar);
199 SET_BOOL(navigation_home_page);
200 SET_BOOL(navigation_chain_start);
201 SET_BOOL(navigation_chain_end);
202 SET_INT64(global_id);
203 SET_STR(search_terms);
204 SET_STR(favicon_url);
205 SET_ENUM(blocked_state, GetBlockedStateString);
206 SET_STR_REP(content_pack_categories);
207 SET_INT32(http_status_code);
208 SET_INT32(obsolete_referrer_policy);
209 SET_BOOL(is_restored);
210 SET_REP(navigation_redirect, NavigationRedirectToValue);
211 SET_STR(last_navigation_redirect_url);
212 SET_INT32(correct_referrer_policy);
213 return value;
214 }
215
216 std::unique_ptr<base::DictionaryValue> NavigationRedirectToValue(
217 const sync_pb::NavigationRedirect& proto) {
218 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
219 SET_STR(url);
220 return value;
221 }
222
223 std::unique_ptr<base::DictionaryValue> PasswordSpecificsDataToValue(
224 const sync_pb::PasswordSpecificsData& proto) {
225 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
226 SET_INT32(scheme);
227 SET_STR(signon_realm);
228 SET_STR(origin);
229 SET_STR(action);
230 SET_STR(username_element);
231 SET_STR(username_value);
232 SET_STR(password_element);
233 value->SetString("password_value", "<redacted>");
234 SET_BOOL(preferred);
235 SET_INT64(date_created);
236 SET_BOOL(blacklisted);
237 SET_INT32(type);
238 SET_INT32(times_used);
239 SET_STR(display_name);
240 SET_STR(avatar_url);
241 SET_STR(federation_url);
242 return value;
243 }
244
245 std::unique_ptr<base::DictionaryValue> GlobalIdDirectiveToValue(
246 const sync_pb::GlobalIdDirective& proto) {
247 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
248 SET_INT64_REP(global_id);
249 SET_INT64(start_time_usec);
250 SET_INT64(end_time_usec);
251 return value;
252 }
253
254 std::unique_ptr<base::DictionaryValue> TimeRangeDirectiveToValue(
255 const sync_pb::TimeRangeDirective& proto) {
256 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
257 SET_INT64(start_time_usec);
258 SET_INT64(end_time_usec);
259 return value;
260 }
261
262 std::unique_ptr<base::DictionaryValue> AppListSpecificsToValue(
263 const sync_pb::AppListSpecifics& proto) {
264 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
265 SET_STR(item_id);
266 SET_ENUM(item_type, GetAppListItemTypeString);
267 SET_STR(item_name);
268 SET_STR(parent_id);
269 SET_STR(item_ordinal);
270 SET_STR(item_pin_ordinal);
271
272 return value;
273 }
274
275 std::unique_ptr<base::DictionaryValue> ArcPackageSpecificsToValue(
276 const sync_pb::ArcPackageSpecifics& proto) {
277 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
278 SET_STR(package_name);
279 SET_INT32(package_version);
280 SET_INT64(last_backup_android_id);
281 SET_INT64(last_backup_time);
282
283 return value;
284 }
285
286 std::unique_ptr<base::DictionaryValue> AppNotificationToValue(
287 const sync_pb::AppNotification& proto) {
288 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
289 SET_STR(guid);
290 SET_STR(app_id);
291 SET_INT64(creation_timestamp_ms);
292 SET_STR(title);
293 SET_STR(body_text);
294 SET_STR(link_url);
295 SET_STR(link_text);
296 return value;
297 }
298
299 std::unique_ptr<base::DictionaryValue> AppSettingSpecificsToValue(
300 const sync_pb::AppSettingSpecifics& proto) {
301 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
302 SET(extension_setting, ExtensionSettingSpecificsToValue);
303 return value;
304 }
305
306 std::unique_ptr<base::DictionaryValue> LinkedAppIconInfoToValue(
307 const sync_pb::LinkedAppIconInfo& proto) {
308 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
309 SET_STR(url);
310 SET_INT32(size);
311 return value;
312 }
313
314 std::unique_ptr<base::DictionaryValue> AppSpecificsToValue(
315 const sync_pb::AppSpecifics& proto) {
316 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
317 SET(extension, ExtensionSpecificsToValue);
318 SET(notification_settings, AppSettingsToValue);
319 SET_STR(app_launch_ordinal);
320 SET_STR(page_ordinal);
321 SET_ENUM(launch_type, GetLaunchTypeString);
322 SET_STR(bookmark_app_url);
323 SET_STR(bookmark_app_description);
324 SET_STR(bookmark_app_icon_color);
325 SET_REP(linked_app_icons, LinkedAppIconInfoToValue);
326
327 return value;
328 }
329
330 std::unique_ptr<base::DictionaryValue> AutofillSpecificsToValue(
331 const sync_pb::AutofillSpecifics& proto) {
332 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
333 SET_STR(name);
334 SET_STR(value);
335 SET_INT64_REP(usage_timestamp);
336 SET(profile, AutofillProfileSpecificsToValue);
337 return value;
338 }
339
340 std::unique_ptr<base::DictionaryValue> AutofillProfileSpecificsToValue(
341 const sync_pb::AutofillProfileSpecifics& proto) {
342 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
343 SET_STR(guid);
344 SET_STR(origin);
345 SET_INT64(use_count);
346 SET_INT64(use_date);
347
348 SET_STR_REP(name_first);
349 SET_STR_REP(name_middle);
350 SET_STR_REP(name_last);
351 SET_STR_REP(name_full);
352 SET_STR_REP(email_address);
353 SET_STR(company_name);
354
355 SET_STR(address_home_line1);
356 SET_STR(address_home_line2);
357 SET_STR(address_home_city);
358 SET_STR(address_home_state);
359 SET_STR(address_home_zip);
360 SET_STR(address_home_country);
361
362 SET_STR(address_home_street_address);
363 SET_STR(address_home_sorting_code);
364 SET_STR(address_home_dependent_locality);
365 SET_STR(address_home_language_code);
366
367 SET_STR_REP(phone_home_whole_number);
368 return value;
369 }
370
371 std::unique_ptr<base::DictionaryValue> WalletMetadataSpecificsToValue(
372 const sync_pb::WalletMetadataSpecifics& proto) {
373 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
374 SET_ENUM(type, GetWalletMetadataTypeString);
375 SET_STR(id);
376 SET_INT64(use_count);
377 SET_INT64(use_date);
378 return value;
379 }
380
381 std::unique_ptr<base::DictionaryValue> AutofillWalletSpecificsToValue(
382 const sync_pb::AutofillWalletSpecifics& proto) {
383 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
384
385 SET_ENUM(type, GetWalletInfoTypeString);
386 if (proto.type() == sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD) {
387 value->Set("masked_card",
388 WalletMaskedCreditCardToValue(proto.masked_card()));
389 } else if (proto.type() == sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS) {
390 value->Set("address",
391 WalletPostalAddressToValue(proto.address()));
392 }
393 return value;
394 }
395
396 std::unique_ptr<base::DictionaryValue> MetaInfoToValue(
397 const sync_pb::MetaInfo& proto) {
398 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
399 SET_STR(key);
400 SET_STR(value);
401 return value;
402 }
403
404 std::unique_ptr<base::DictionaryValue> BookmarkSpecificsToValue(
405 const sync_pb::BookmarkSpecifics& proto) {
406 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
407 SET_STR(url);
408 SET_BYTES(favicon);
409 SET_STR(title);
410 SET_INT64(creation_time_us);
411 SET_STR(icon_url);
412 SET_REP(meta_info, &MetaInfoToValue);
413 return value;
414 }
415
416 std::unique_ptr<base::DictionaryValue> DeviceInfoSpecificsToValue(
417 const sync_pb::DeviceInfoSpecifics& proto) {
418 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
419 SET_STR(cache_guid);
420 SET_STR(client_name);
421 SET_ENUM(device_type, GetDeviceTypeString);
422 SET_STR(sync_user_agent);
423 SET_STR(chrome_version);
424 SET_STR(signin_scoped_device_id);
425 return value;
426 }
427
428 std::unique_ptr<base::DictionaryValue> DictionarySpecificsToValue(
429 const sync_pb::DictionarySpecifics& proto) {
430 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
431 SET_STR(word);
432 return value;
433 }
434
435 namespace {
436
437 std::unique_ptr<base::DictionaryValue> FaviconSyncFlagsToValue(
438 const sync_pb::FaviconSyncFlags& proto) {
439 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
440 SET_BOOL(enabled);
441 SET_INT32(favicon_sync_limit);
442 return value;
443 }
444
445 } // namespace
446
447 std::unique_ptr<base::DictionaryValue> ExperimentsSpecificsToValue(
448 const sync_pb::ExperimentsSpecifics& proto) {
449 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
450 SET_EXPERIMENT_ENABLED_FIELD(keystore_encryption);
451 SET_EXPERIMENT_ENABLED_FIELD(history_delete_directives);
452 SET_EXPERIMENT_ENABLED_FIELD(autofill_culling);
453 SET_EXPERIMENT_ENABLED_FIELD(pre_commit_update_avoidance);
454 SET(favicon_sync, FaviconSyncFlagsToValue);
455 SET_EXPERIMENT_ENABLED_FIELD(gcm_channel);
456 SET_EXPERIMENT_ENABLED_FIELD(gcm_invalidations);
457 return value;
458 }
459
460 std::unique_ptr<base::DictionaryValue> ExtensionSettingSpecificsToValue(
461 const sync_pb::ExtensionSettingSpecifics& proto) {
462 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
463 SET_STR(extension_id);
464 SET_STR(key);
465 SET_STR(value);
466 return value;
467 }
468
469 std::unique_ptr<base::DictionaryValue> ExtensionSpecificsToValue(
470 const sync_pb::ExtensionSpecifics& proto) {
471 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
472 SET_STR(id);
473 SET_STR(version);
474 SET_STR(update_url);
475 SET_BOOL(enabled);
476 SET_BOOL(incognito_enabled);
477 SET_STR(name);
478 SET_BOOL(remote_install);
479 SET_BOOL(installed_by_custodian);
480 SET_BOOL(all_urls_enabled);
481 SET_INT32(disable_reasons);
482 return value;
483 }
484
485 namespace {
486 std::unique_ptr<base::DictionaryValue> FaviconDataToValue(
487 const sync_pb::FaviconData& proto) {
488 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
489 SET_BYTES(favicon);
490 SET_INT32(width);
491 SET_INT32(height);
492 return value;
493 }
494 } // namespace
495
496 std::unique_ptr<base::DictionaryValue> FaviconImageSpecificsToValue(
497 const sync_pb::FaviconImageSpecifics& proto) {
498 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
499 SET_STR(favicon_url);
500 SET(favicon_web, FaviconDataToValue);
501 SET(favicon_web_32, FaviconDataToValue);
502 SET(favicon_touch_64, FaviconDataToValue);
503 SET(favicon_touch_precomposed_64, FaviconDataToValue);
504 return value;
505 }
506
507 std::unique_ptr<base::DictionaryValue> FaviconTrackingSpecificsToValue(
508 const sync_pb::FaviconTrackingSpecifics& proto) {
509 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
510 SET_STR(favicon_url);
511 SET_INT64(last_visit_time_ms)
512 SET_BOOL(is_bookmarked);
513 return value;
514 }
515
516 std::unique_ptr<base::DictionaryValue> HistoryDeleteDirectiveSpecificsToValue(
517 const sync_pb::HistoryDeleteDirectiveSpecifics& proto) {
518 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
519 SET(global_id_directive, GlobalIdDirectiveToValue);
520 SET(time_range_directive, TimeRangeDirectiveToValue);
521 return value;
522 }
523
524 std::unique_ptr<base::DictionaryValue> ManagedUserSettingSpecificsToValue(
525 const sync_pb::ManagedUserSettingSpecifics& proto) {
526 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
527 SET_STR(name);
528 SET_STR(value);
529 return value;
530 }
531
532 std::unique_ptr<base::DictionaryValue> ManagedUserSpecificsToValue(
533 const sync_pb::ManagedUserSpecifics& proto) {
534 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
535 SET_STR(id);
536 SET_STR(name);
537 SET_BOOL(acknowledged);
538 SET_STR(master_key);
539 SET_STR(chrome_avatar);
540 SET_STR(chromeos_avatar);
541 return value;
542 }
543
544 std::unique_ptr<base::DictionaryValue> ManagedUserSharedSettingSpecificsToValue(
545 const sync_pb::ManagedUserSharedSettingSpecifics& proto) {
546 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
547 SET_STR(mu_id);
548 SET_STR(key);
549 SET_STR(value);
550 SET_BOOL(acknowledged);
551 return value;
552 }
553
554 std::unique_ptr<base::DictionaryValue> ManagedUserWhitelistSpecificsToValue(
555 const sync_pb::ManagedUserWhitelistSpecifics& proto) {
556 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
557 SET_STR(id);
558 SET_STR(name);
559 return value;
560 }
561
562 std::unique_ptr<base::DictionaryValue> NigoriSpecificsToValue(
563 const sync_pb::NigoriSpecifics& proto) {
564 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
565 SET(encryption_keybag, EncryptedDataToValue);
566 SET_BOOL(keybag_is_frozen);
567 SET_BOOL(encrypt_bookmarks);
568 SET_BOOL(encrypt_preferences);
569 SET_BOOL(encrypt_autofill_profile);
570 SET_BOOL(encrypt_autofill);
571 SET_BOOL(encrypt_themes);
572 SET_BOOL(encrypt_typed_urls);
573 SET_BOOL(encrypt_extension_settings);
574 SET_BOOL(encrypt_extensions);
575 SET_BOOL(encrypt_sessions);
576 SET_BOOL(encrypt_app_settings);
577 SET_BOOL(encrypt_apps);
578 SET_BOOL(encrypt_search_engines);
579 SET_BOOL(encrypt_dictionary);
580 SET_BOOL(encrypt_articles);
581 SET_BOOL(encrypt_app_list);
582 SET_BOOL(encrypt_arc_package);
583 SET_BOOL(encrypt_everything);
584 SET_BOOL(server_only_was_missing_keystore_migration_time);
585 SET_BOOL(sync_tab_favicons);
586 SET_ENUM(passphrase_type, PassphraseTypeString);
587 SET(keystore_decryptor_token, EncryptedDataToValue);
588 SET_INT64(keystore_migration_time);
589 SET_INT64(custom_passphrase_time);
590 return value;
591 }
592
593 std::unique_ptr<base::DictionaryValue> ArticlePageToValue(
594 const sync_pb::ArticlePage& proto) {
595 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
596 SET_STR(url);
597 return value;
598 }
599
600 std::unique_ptr<base::DictionaryValue> ArticleSpecificsToValue(
601 const sync_pb::ArticleSpecifics& proto) {
602 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
603 SET_STR(entry_id);
604 SET_STR(title);
605 SET_REP(pages, ArticlePageToValue);
606 return value;
607 }
608
609 std::unique_ptr<base::DictionaryValue> PasswordSpecificsToValue(
610 const sync_pb::PasswordSpecifics& proto) {
611 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
612 SET(encrypted, EncryptedDataToValue);
613 return value;
614 }
615
616 std::unique_ptr<base::DictionaryValue> PreferenceSpecificsToValue(
617 const sync_pb::PreferenceSpecifics& proto) {
618 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
619 SET_STR(name);
620 SET_STR(value);
621 return value;
622 }
623
624 std::unique_ptr<base::DictionaryValue> PriorityPreferenceSpecificsToValue(
625 const sync_pb::PriorityPreferenceSpecifics& specifics) {
626 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
627 SET_FIELD(preference, PreferenceSpecificsToValue);
628 return value;
629 }
630
631 std::unique_ptr<base::DictionaryValue>
632 SyncedNotificationAppInfoSpecificsToValue(
633 const sync_pb::SyncedNotificationAppInfoSpecifics& proto) {
634 return base::WrapUnique(new base::DictionaryValue());
635 }
636
637 std::unique_ptr<base::DictionaryValue> SyncedNotificationSpecificsToValue(
638 const sync_pb::SyncedNotificationSpecifics& proto) {
639 return base::WrapUnique(new base::DictionaryValue());
640 }
641
642 std::unique_ptr<base::DictionaryValue> SearchEngineSpecificsToValue(
643 const sync_pb::SearchEngineSpecifics& proto) {
644 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
645 SET_STR(short_name);
646 SET_STR(keyword);
647 SET_STR(favicon_url);
648 SET_STR(url);
649 SET_BOOL(safe_for_autoreplace);
650 SET_STR(originating_url);
651 SET_INT64(date_created);
652 SET_STR(input_encodings);
653 SET_BOOL(show_in_default_list);
654 SET_STR(suggestions_url);
655 SET_INT32(prepopulate_id);
656 SET_BOOL(autogenerate_keyword);
657 SET_STR(instant_url);
658 SET_INT64(last_modified);
659 SET_STR(sync_guid);
660 SET_STR_REP(alternate_urls);
661 SET_STR(search_terms_replacement_key);
662 SET_STR(image_url);
663 SET_STR(search_url_post_params);
664 SET_STR(suggestions_url_post_params);
665 SET_STR(instant_url_post_params);
666 SET_STR(image_url_post_params);
667 SET_STR(new_tab_url);
668 return value;
669 }
670
671 std::unique_ptr<base::DictionaryValue> SessionSpecificsToValue(
672 const sync_pb::SessionSpecifics& proto) {
673 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
674 SET_STR(session_tag);
675 SET(header, SessionHeaderToValue);
676 SET(tab, SessionTabToValue);
677 SET_INT32(tab_node_id);
678 return value;
679 }
680
681 std::unique_ptr<base::DictionaryValue> ThemeSpecificsToValue(
682 const sync_pb::ThemeSpecifics& proto) {
683 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
684 SET_BOOL(use_custom_theme);
685 SET_BOOL(use_system_theme_by_default);
686 SET_STR(custom_theme_name);
687 SET_STR(custom_theme_id);
688 SET_STR(custom_theme_update_url);
689 return value;
690 }
691
692 std::unique_ptr<base::DictionaryValue> TypedUrlSpecificsToValue(
693 const sync_pb::TypedUrlSpecifics& proto) {
694 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
695 SET_STR(url);
696 SET_STR(title);
697 SET_BOOL(hidden);
698 SET_INT64_REP(visits);
699 SET_INT32_REP(visit_transitions);
700 return value;
701 }
702
703 std::unique_ptr<base::DictionaryValue> WalletMaskedCreditCardToValue(
704 const sync_pb::WalletMaskedCreditCard& proto) {
705 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
706 SET_STR(id);
707 SET_ENUM(status, GetWalletCardStatusString);
708 SET_STR(name_on_card);
709 SET_ENUM(type, GetWalletCardTypeString);
710 SET_STR(last_four);
711 SET_INT32(exp_month);
712 SET_INT32(exp_year);
713 SET_STR(billing_address_id);
714 return value;
715 }
716
717 std::unique_ptr<base::DictionaryValue> WalletPostalAddressToValue(
718 const sync_pb::WalletPostalAddress& proto) {
719 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
720 SET_STR(id);
721 SET_STR(recipient_name);
722 SET_STR(company_name);
723 SET_STR_REP(street_address);
724 SET_STR(address_1);
725 SET_STR(address_2);
726 SET_STR(address_3);
727 SET_STR(address_4);
728 SET_STR(postal_code);
729 SET_STR(sorting_code);
730 SET_STR(country_code);
731 SET_STR(phone_number);
732 SET_STR(language_code);
733 return value;
734 }
735
736 std::unique_ptr<base::DictionaryValue> WifiCredentialSpecificsToValue(
737 const sync_pb::WifiCredentialSpecifics& proto) {
738 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
739 SET_BYTES(ssid);
740 SET_ENUM(security_class, GetWifiCredentialSecurityClassString);
741 SET_BYTES(passphrase);
742 return value;
743 }
744
745 std::unique_ptr<base::DictionaryValue> EntitySpecificsToValue(
746 const sync_pb::EntitySpecifics& specifics) {
747 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
748 SET_FIELD(app, AppSpecificsToValue);
749 SET_FIELD(app_list, AppListSpecificsToValue);
750 SET_FIELD(app_notification, AppNotificationToValue);
751 SET_FIELD(app_setting, AppSettingSpecificsToValue);
752 SET_FIELD(arc_package, ArcPackageSpecificsToValue);
753 SET_FIELD(article, ArticleSpecificsToValue);
754 SET_FIELD(autofill, AutofillSpecificsToValue);
755 SET_FIELD(autofill_profile, AutofillProfileSpecificsToValue);
756 SET_FIELD(autofill_wallet, AutofillWalletSpecificsToValue);
757 SET_FIELD(wallet_metadata, WalletMetadataSpecificsToValue);
758 SET_FIELD(bookmark, BookmarkSpecificsToValue);
759 SET_FIELD(device_info, DeviceInfoSpecificsToValue);
760 SET_FIELD(dictionary, DictionarySpecificsToValue);
761 SET_FIELD(experiments, ExperimentsSpecificsToValue);
762 SET_FIELD(extension, ExtensionSpecificsToValue);
763 SET_FIELD(extension_setting, ExtensionSettingSpecificsToValue);
764 SET_FIELD(favicon_image, FaviconImageSpecificsToValue);
765 SET_FIELD(favicon_tracking, FaviconTrackingSpecificsToValue);
766 SET_FIELD(history_delete_directive, HistoryDeleteDirectiveSpecificsToValue);
767 SET_FIELD(managed_user_setting, ManagedUserSettingSpecificsToValue);
768 SET_FIELD(managed_user_shared_setting,
769 ManagedUserSharedSettingSpecificsToValue);
770 SET_FIELD(managed_user, ManagedUserSpecificsToValue);
771 SET_FIELD(managed_user_whitelist, ManagedUserWhitelistSpecificsToValue);
772 SET_FIELD(nigori, NigoriSpecificsToValue);
773 SET_FIELD(password, PasswordSpecificsToValue);
774 SET_FIELD(preference, PreferenceSpecificsToValue);
775 SET_FIELD(priority_preference, PriorityPreferenceSpecificsToValue);
776 SET_FIELD(search_engine, SearchEngineSpecificsToValue);
777 SET_FIELD(session, SessionSpecificsToValue);
778 SET_FIELD(synced_notification, SyncedNotificationSpecificsToValue);
779 SET_FIELD(synced_notification_app_info,
780 SyncedNotificationAppInfoSpecificsToValue);
781 SET_FIELD(theme, ThemeSpecificsToValue);
782 SET_FIELD(typed_url, TypedUrlSpecificsToValue);
783 SET_FIELD(wifi_credential, WifiCredentialSpecificsToValue);
784 return value;
785 }
786
787 namespace {
788
789 base::StringValue* UniquePositionToStringValue(
790 const sync_pb::UniquePosition& proto) {
791 UniquePosition pos = UniquePosition::FromProto(proto);
792 return new base::StringValue(pos.ToDebugString());
793 }
794
795 } // namespace
796
797 std::unique_ptr<base::DictionaryValue> SyncEntityToValue(
798 const sync_pb::SyncEntity& proto,
799 bool include_specifics) {
800 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
801 SET_STR(id_string);
802 SET_STR(parent_id_string);
803 SET_STR(old_parent_id);
804 SET_INT64(version);
805 SET_INT64(mtime);
806 SET_INT64(ctime);
807 SET_STR(name);
808 SET_STR(non_unique_name);
809 SET_INT64(sync_timestamp);
810 SET_STR(server_defined_unique_tag);
811 SET_INT64(position_in_parent);
812 SET(unique_position, UniquePositionToStringValue);
813 SET_STR(insert_after_item_id);
814 SET_BOOL(deleted);
815 SET_STR(originator_cache_guid);
816 SET_STR(originator_client_item_id);
817 if (include_specifics)
818 SET(specifics, EntitySpecificsToValue);
819 SET_BOOL(folder);
820 SET_STR(client_defined_unique_tag);
821 SET_REP(attachment_id, AttachmentIdProtoToValue);
822 return value;
823 }
824
825 namespace {
826
827 base::ListValue* SyncEntitiesToValue(
828 const ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities,
829 bool include_specifics) {
830 base::ListValue* list = new base::ListValue();
831 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it;
832 for (it = entities.begin(); it != entities.end(); ++it) {
833 list->Append(SyncEntityToValue(*it, include_specifics));
834 }
835
836 return list;
837 }
838
839 std::unique_ptr<base::DictionaryValue> ChromiumExtensionActivityToValue(
840 const sync_pb::ChromiumExtensionsActivity& proto) {
841 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
842 SET_STR(extension_id);
843 SET_INT32(bookmark_writes_since_last_commit);
844 return value;
845 }
846
847 std::unique_ptr<base::DictionaryValue> CommitMessageToValue(
848 const sync_pb::CommitMessage& proto,
849 bool include_specifics) {
850 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
851 value->Set("entries",
852 SyncEntitiesToValue(proto.entries(), include_specifics));
853 SET_STR(cache_guid);
854 SET_REP(extensions_activity, ChromiumExtensionActivityToValue);
855 SET(config_params, ClientConfigParamsToValue);
856 return value;
857 }
858
859 std::unique_ptr<base::DictionaryValue> GetUpdateTriggersToValue(
860 const sync_pb::GetUpdateTriggers& proto) {
861 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
862 SET_STR_REP(notification_hint);
863 SET_BOOL(client_dropped_hints);
864 SET_BOOL(invalidations_out_of_sync);
865 SET_INT64(local_modification_nudges);
866 SET_INT64(datatype_refresh_nudges);
867 return value;
868 }
869
870 std::unique_ptr<base::DictionaryValue> DataTypeProgressMarkerToValue(
871 const sync_pb::DataTypeProgressMarker& proto) {
872 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
873 SET_INT32(data_type_id);
874 SET_BYTES(token);
875 SET_INT64(timestamp_token_for_migration);
876 SET_STR(notification_hint);
877 SET(get_update_triggers, GetUpdateTriggersToValue);
878 return value;
879 }
880
881 std::unique_ptr<base::DictionaryValue> DataTypeContextToValue(
882 const sync_pb::DataTypeContext& proto) {
883 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
884 SET_INT32(data_type_id);
885 SET_STR(context);
886 SET_INT64(version);
887 return value;
888 }
889
890 std::unique_ptr<base::DictionaryValue> GetUpdatesCallerInfoToValue(
891 const sync_pb::GetUpdatesCallerInfo& proto) {
892 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
893 SET_ENUM(source, GetUpdatesSourceString);
894 SET_BOOL(notifications_enabled);
895 return value;
896 }
897
898 std::unique_ptr<base::DictionaryValue> GetUpdatesMessageToValue(
899 const sync_pb::GetUpdatesMessage& proto) {
900 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
901 SET(caller_info, GetUpdatesCallerInfoToValue);
902 SET_BOOL(fetch_folders);
903 SET_INT32(batch_size);
904 SET_REP(from_progress_marker, DataTypeProgressMarkerToValue);
905 SET_BOOL(streaming);
906 SET_BOOL(need_encryption_key);
907 SET_BOOL(create_mobile_bookmarks_folder);
908 SET_ENUM(get_updates_origin, GetUpdatesOriginString);
909 SET_REP(client_contexts, DataTypeContextToValue);
910 return value;
911 }
912
913 std::unique_ptr<base::DictionaryValue> ClientStatusToValue(
914 const sync_pb::ClientStatus& proto) {
915 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
916 SET_BOOL(hierarchy_conflict_detected);
917 return value;
918 }
919
920 std::unique_ptr<base::DictionaryValue> EntryResponseToValue(
921 const sync_pb::CommitResponse::EntryResponse& proto) {
922 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
923 SET_ENUM(response_type, GetResponseTypeString);
924 SET_STR(id_string);
925 SET_STR(parent_id_string);
926 SET_INT64(position_in_parent);
927 SET_INT64(version);
928 SET_STR(name);
929 SET_STR(error_message);
930 SET_INT64(mtime);
931 return value;
932 }
933
934 std::unique_ptr<base::DictionaryValue> CommitResponseToValue(
935 const sync_pb::CommitResponse& proto) {
936 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
937 SET_REP(entryresponse, EntryResponseToValue);
938 return value;
939 }
940
941 std::unique_ptr<base::DictionaryValue> GetUpdatesResponseToValue(
942 const sync_pb::GetUpdatesResponse& proto,
943 bool include_specifics) {
944 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
945 value->Set("entries",
946 SyncEntitiesToValue(proto.entries(), include_specifics));
947 SET_INT64(changes_remaining);
948 SET_REP(new_progress_marker, DataTypeProgressMarkerToValue);
949 SET_REP(context_mutations, DataTypeContextToValue);
950 return value;
951 }
952
953 std::unique_ptr<base::DictionaryValue> ClientCommandToValue(
954 const sync_pb::ClientCommand& proto) {
955 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
956 SET_INT32(set_sync_poll_interval);
957 SET_INT32(set_sync_long_poll_interval);
958 SET_INT32(max_commit_batch_size);
959 SET_INT32(sessions_commit_delay_seconds);
960 SET_INT32(throttle_delay_seconds);
961 SET_INT32(client_invalidation_hint_buffer_size);
962 return value;
963 }
964
965 std::unique_ptr<base::DictionaryValue> ErrorToValue(
966 const sync_pb::ClientToServerResponse::Error& proto) {
967 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
968 SET_ENUM(error_type, GetErrorTypeString);
969 SET_STR(error_description);
970 SET_STR(url);
971 SET_ENUM(action, GetActionString);
972 return value;
973 }
974
975 } // namespace
976
977 std::unique_ptr<base::DictionaryValue> ClientToServerResponseToValue(
978 const sync_pb::ClientToServerResponse& proto,
979 bool include_specifics) {
980 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
981 SET(commit, CommitResponseToValue);
982 if (proto.has_get_updates()) {
983 value->Set("get_updates", GetUpdatesResponseToValue(proto.get_updates(),
984 include_specifics));
985 }
986
987 SET(error, ErrorToValue);
988 SET_ENUM(error_code, GetErrorTypeString);
989 SET_STR(error_message);
990 SET_STR(store_birthday);
991 SET(client_command, ClientCommandToValue);
992 SET_INT32_REP(migrated_data_type_id);
993 return value;
994 }
995
996 std::unique_ptr<base::DictionaryValue> ClientToServerMessageToValue(
997 const sync_pb::ClientToServerMessage& proto,
998 bool include_specifics) {
999 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1000 SET_STR(share);
1001 SET_INT32(protocol_version);
1002 if (proto.has_commit()) {
1003 value->Set("commit",
1004 CommitMessageToValue(proto.commit(), include_specifics));
1005 }
1006
1007 SET(get_updates, GetUpdatesMessageToValue);
1008 SET_STR(store_birthday);
1009 SET_BOOL(sync_problem_detected);
1010 SET(debug_info, DebugInfoToValue);
1011 SET(client_status, ClientStatusToValue);
1012 return value;
1013 }
1014
1015 std::unique_ptr<base::DictionaryValue> DatatypeAssociationStatsToValue(
1016 const sync_pb::DatatypeAssociationStats& proto) {
1017 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1018 SET_INT32(data_type_id);
1019 SET_INT32(num_local_items_before_association);
1020 SET_INT32(num_sync_items_before_association);
1021 SET_INT32(num_local_items_after_association);
1022 SET_INT32(num_sync_items_after_association);
1023 SET_INT32(num_local_items_added);
1024 SET_INT32(num_local_items_deleted);
1025 SET_INT32(num_local_items_modified);
1026 SET_INT32(num_sync_items_added);
1027 SET_INT32(num_sync_items_deleted);
1028 SET_INT32(num_sync_items_modified);
1029 SET_INT64(local_version_pre_association);
1030 SET_INT64(sync_version_pre_association)
1031 SET_BOOL(had_error);
1032 SET_INT64(download_wait_time_us);
1033 SET_INT64(download_time_us);
1034 SET_INT64(association_wait_time_for_high_priority_us);
1035 SET_INT64(association_wait_time_for_same_priority_us);
1036 return value;
1037 }
1038
1039 std::unique_ptr<base::DictionaryValue> DebugEventInfoToValue(
1040 const sync_pb::DebugEventInfo& proto) {
1041 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1042 SET_ENUM(singleton_event, SingletonDebugEventTypeString);
1043 SET(sync_cycle_completed_event_info, SyncCycleCompletedEventInfoToValue);
1044 SET_INT32(nudging_datatype);
1045 SET_INT32_REP(datatypes_notified_from_server);
1046 SET(datatype_association_stats, DatatypeAssociationStatsToValue);
1047 return value;
1048 }
1049
1050 std::unique_ptr<base::DictionaryValue> DebugInfoToValue(
1051 const sync_pb::DebugInfo& proto) {
1052 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1053 SET_REP(events, DebugEventInfoToValue);
1054 SET_BOOL(cryptographer_ready);
1055 SET_BOOL(cryptographer_has_pending_keys);
1056 SET_BOOL(events_dropped);
1057 return value;
1058 }
1059
1060 std::unique_ptr<base::DictionaryValue> SyncCycleCompletedEventInfoToValue(
1061 const sync_pb::SyncCycleCompletedEventInfo& proto) {
1062 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1063 SET_INT32(num_encryption_conflicts);
1064 SET_INT32(num_hierarchy_conflicts);
1065 SET_INT32(num_server_conflicts);
1066 SET_INT32(num_updates_downloaded);
1067 SET_INT32(num_reflected_updates_downloaded);
1068 SET(caller_info, GetUpdatesCallerInfoToValue);
1069 return value;
1070 }
1071
1072 std::unique_ptr<base::DictionaryValue> ClientConfigParamsToValue(
1073 const sync_pb::ClientConfigParams& proto) {
1074 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1075 SET_INT32_REP(enabled_type_ids);
1076 SET_BOOL(tabs_datatype_enabled);
1077 SET_BOOL(cookie_jar_mismatch);
1078 return value;
1079 }
1080
1081 std::unique_ptr<base::DictionaryValue> AttachmentIdProtoToValue(
1082 const sync_pb::AttachmentIdProto& proto) {
1083 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1084 SET_STR(unique_id);
1085 return value;
1086 }
1087
1088 #undef SET_TYPE
1089 #undef SET
1090 #undef SET_REP
1091
1092 #undef SET_BOOL
1093 #undef SET_BYTES
1094 #undef SET_INT32
1095 #undef SET_INT64
1096 #undef SET_INT64_REP
1097 #undef SET_STR
1098 #undef SET_STR_REP
1099
1100 #undef SET_FIELD
1101
1102 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/protocol/proto_value_conversions.h ('k') | sync/protocol/proto_value_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698