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

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

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

Powered by Google App Engine
This is Rietveld 408576698