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

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: Remove temporary tests 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(PrinterPPDReference)
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> PrinterPPDReferenceToValue(
293 const sync_pb::PrinterPPDReference& proto) {
294 std::unique_ptr<base::DictionaryValue> value =
295 base::MakeUnique<base::DictionaryValue>();
296 SET_STR(user_supplied_ppd_url);
297 SET_STR(effective_manufacturer);
298 SET_STR(effective_model);
299 return value;
300 }
301
302 std::unique_ptr<base::DictionaryValue> ReadingListSpecificsToValue(
303 const sync_pb::ReadingListSpecifics& proto) {
304 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
305 SET_STR(entry_id);
306 SET_STR(title);
307 SET_STR(url);
308 SET_INT64(creation_time_us);
309 SET_INT64(update_time_us);
310 SET_ENUM(status, GetReadingListEntryStatusString);
311
312 return value;
313 }
314
315 std::unique_ptr<base::DictionaryValue> AppNotificationToValue(
316 const sync_pb::AppNotification& proto) {
317 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
318 SET_STR(guid);
319 SET_STR(app_id);
320 SET_INT64(creation_timestamp_ms);
321 SET_STR(title);
322 SET_STR(body_text);
323 SET_STR(link_url);
324 SET_STR(link_text);
325 return value;
326 }
327
328 std::unique_ptr<base::DictionaryValue> AppSettingSpecificsToValue(
329 const sync_pb::AppSettingSpecifics& proto) {
330 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
331 SET(extension_setting, ExtensionSettingSpecificsToValue);
332 return value;
333 }
334
335 std::unique_ptr<base::DictionaryValue> LinkedAppIconInfoToValue(
336 const sync_pb::LinkedAppIconInfo& proto) {
337 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
338 SET_STR(url);
339 SET_INT32(size);
340 return value;
341 }
342
343 std::unique_ptr<base::DictionaryValue> AppSpecificsToValue(
344 const sync_pb::AppSpecifics& proto) {
345 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
346 SET(extension, ExtensionSpecificsToValue);
347 SET(notification_settings, AppSettingsToValue);
348 SET_STR(app_launch_ordinal);
349 SET_STR(page_ordinal);
350 SET_ENUM(launch_type, GetLaunchTypeString);
351 SET_STR(bookmark_app_url);
352 SET_STR(bookmark_app_description);
353 SET_STR(bookmark_app_icon_color);
354 SET_REP(linked_app_icons, LinkedAppIconInfoToValue);
355
356 return value;
357 }
358
359 std::unique_ptr<base::DictionaryValue> AutofillSpecificsToValue(
360 const sync_pb::AutofillSpecifics& proto) {
361 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
362 SET_STR(name);
363 SET_STR(value);
364 SET_INT64_REP(usage_timestamp);
365 SET(profile, AutofillProfileSpecificsToValue);
366 return value;
367 }
368
369 std::unique_ptr<base::DictionaryValue> AutofillProfileSpecificsToValue(
370 const sync_pb::AutofillProfileSpecifics& proto) {
371 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
372 SET_STR(guid);
373 SET_STR(origin);
374 SET_INT64(use_count);
375 SET_INT64(use_date);
376
377 SET_STR_REP(name_first);
378 SET_STR_REP(name_middle);
379 SET_STR_REP(name_last);
380 SET_STR_REP(name_full);
381 SET_STR_REP(email_address);
382 SET_STR(company_name);
383
384 SET_STR(address_home_line1);
385 SET_STR(address_home_line2);
386 SET_STR(address_home_city);
387 SET_STR(address_home_state);
388 SET_STR(address_home_zip);
389 SET_STR(address_home_country);
390
391 SET_STR(address_home_street_address);
392 SET_STR(address_home_sorting_code);
393 SET_STR(address_home_dependent_locality);
394 SET_STR(address_home_language_code);
395
396 SET_STR_REP(phone_home_whole_number);
397 return value;
398 }
399
400 std::unique_ptr<base::DictionaryValue> WalletMetadataSpecificsToValue(
401 const sync_pb::WalletMetadataSpecifics& proto) {
402 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
403 SET_ENUM(type, GetWalletMetadataTypeString);
404 SET_STR(id);
405 SET_INT64(use_count);
406 SET_INT64(use_date);
407 return value;
408 }
409
410 std::unique_ptr<base::DictionaryValue> AutofillWalletSpecificsToValue(
411 const sync_pb::AutofillWalletSpecifics& proto) {
412 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
413
414 SET_ENUM(type, GetWalletInfoTypeString);
415 if (proto.type() == sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD) {
416 value->Set("masked_card",
417 WalletMaskedCreditCardToValue(proto.masked_card()));
418 } else if (proto.type() == sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS) {
419 value->Set("address", WalletPostalAddressToValue(proto.address()));
420 }
421 return value;
422 }
423
424 std::unique_ptr<base::DictionaryValue> MetaInfoToValue(
425 const sync_pb::MetaInfo& proto) {
426 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
427 SET_STR(key);
428 SET_STR(value);
429 return value;
430 }
431
432 std::unique_ptr<base::DictionaryValue> BookmarkSpecificsToValue(
433 const sync_pb::BookmarkSpecifics& proto) {
434 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
435 SET_STR(url);
436 SET_BYTES(favicon);
437 SET_STR(title);
438 SET_INT64(creation_time_us);
439 SET_STR(icon_url);
440 SET_REP(meta_info, &MetaInfoToValue);
441 return value;
442 }
443
444 std::unique_ptr<base::DictionaryValue> DeviceInfoSpecificsToValue(
445 const sync_pb::DeviceInfoSpecifics& proto) {
446 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
447 SET_STR(cache_guid);
448 SET_STR(client_name);
449 SET_ENUM(device_type, GetDeviceTypeString);
450 SET_STR(sync_user_agent);
451 SET_STR(chrome_version);
452 SET_STR(signin_scoped_device_id);
453 return value;
454 }
455
456 std::unique_ptr<base::DictionaryValue> DictionarySpecificsToValue(
457 const sync_pb::DictionarySpecifics& proto) {
458 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
459 SET_STR(word);
460 return value;
461 }
462
463 namespace {
464
465 std::unique_ptr<base::DictionaryValue> FaviconSyncFlagsToValue(
466 const sync_pb::FaviconSyncFlags& proto) {
467 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
468 SET_BOOL(enabled);
469 SET_INT32(favicon_sync_limit);
470 return value;
471 }
472
473 } // namespace
474
475 std::unique_ptr<base::DictionaryValue> ExperimentsSpecificsToValue(
476 const sync_pb::ExperimentsSpecifics& proto) {
477 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
478 SET_EXPERIMENT_ENABLED_FIELD(keystore_encryption);
479 SET_EXPERIMENT_ENABLED_FIELD(history_delete_directives);
480 SET_EXPERIMENT_ENABLED_FIELD(autofill_culling);
481 SET_EXPERIMENT_ENABLED_FIELD(pre_commit_update_avoidance);
482 SET(favicon_sync, FaviconSyncFlagsToValue);
483 SET_EXPERIMENT_ENABLED_FIELD(gcm_channel);
484 SET_EXPERIMENT_ENABLED_FIELD(gcm_invalidations);
485 return value;
486 }
487
488 std::unique_ptr<base::DictionaryValue> ExtensionSettingSpecificsToValue(
489 const sync_pb::ExtensionSettingSpecifics& proto) {
490 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
491 SET_STR(extension_id);
492 SET_STR(key);
493 SET_STR(value);
494 return value;
495 }
496
497 std::unique_ptr<base::DictionaryValue> ExtensionSpecificsToValue(
498 const sync_pb::ExtensionSpecifics& proto) {
499 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
500 SET_STR(id);
501 SET_STR(version);
502 SET_STR(update_url);
503 SET_BOOL(enabled);
504 SET_BOOL(incognito_enabled);
505 SET_STR(name);
506 SET_BOOL(remote_install);
507 SET_BOOL(installed_by_custodian);
508 SET_BOOL(all_urls_enabled);
509 SET_INT32(disable_reasons);
510 return value;
511 }
512
513 namespace {
514 std::unique_ptr<base::DictionaryValue> FaviconDataToValue(
515 const sync_pb::FaviconData& proto) {
516 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
517 SET_BYTES(favicon);
518 SET_INT32(width);
519 SET_INT32(height);
520 return value;
521 }
522 } // namespace
523
524 std::unique_ptr<base::DictionaryValue> FaviconImageSpecificsToValue(
525 const sync_pb::FaviconImageSpecifics& proto) {
526 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
527 SET_STR(favicon_url);
528 SET(favicon_web, FaviconDataToValue);
529 SET(favicon_web_32, FaviconDataToValue);
530 SET(favicon_touch_64, FaviconDataToValue);
531 SET(favicon_touch_precomposed_64, FaviconDataToValue);
532 return value;
533 }
534
535 std::unique_ptr<base::DictionaryValue> FaviconTrackingSpecificsToValue(
536 const sync_pb::FaviconTrackingSpecifics& proto) {
537 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
538 SET_STR(favicon_url);
539 SET_INT64(last_visit_time_ms)
540 SET_BOOL(is_bookmarked);
541 return value;
542 }
543
544 std::unique_ptr<base::DictionaryValue> HistoryDeleteDirectiveSpecificsToValue(
545 const sync_pb::HistoryDeleteDirectiveSpecifics& proto) {
546 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
547 SET(global_id_directive, GlobalIdDirectiveToValue);
548 SET(time_range_directive, TimeRangeDirectiveToValue);
549 return value;
550 }
551
552 std::unique_ptr<base::DictionaryValue> ManagedUserSettingSpecificsToValue(
553 const sync_pb::ManagedUserSettingSpecifics& proto) {
554 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
555 SET_STR(name);
556 SET_STR(value);
557 return value;
558 }
559
560 std::unique_ptr<base::DictionaryValue> ManagedUserSpecificsToValue(
561 const sync_pb::ManagedUserSpecifics& proto) {
562 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
563 SET_STR(id);
564 SET_STR(name);
565 SET_BOOL(acknowledged);
566 SET_STR(master_key);
567 SET_STR(chrome_avatar);
568 SET_STR(chromeos_avatar);
569 return value;
570 }
571
572 std::unique_ptr<base::DictionaryValue> ManagedUserSharedSettingSpecificsToValue(
573 const sync_pb::ManagedUserSharedSettingSpecifics& proto) {
574 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
575 SET_STR(mu_id);
576 SET_STR(key);
577 SET_STR(value);
578 SET_BOOL(acknowledged);
579 return value;
580 }
581
582 std::unique_ptr<base::DictionaryValue> ManagedUserWhitelistSpecificsToValue(
583 const sync_pb::ManagedUserWhitelistSpecifics& proto) {
584 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
585 SET_STR(id);
586 SET_STR(name);
587 return value;
588 }
589
590 std::unique_ptr<base::DictionaryValue> NigoriSpecificsToValue(
591 const sync_pb::NigoriSpecifics& proto) {
592 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
593 SET(encryption_keybag, EncryptedDataToValue);
594 SET_BOOL(keybag_is_frozen);
595 SET_BOOL(encrypt_bookmarks);
596 SET_BOOL(encrypt_preferences);
597 SET_BOOL(encrypt_autofill_profile);
598 SET_BOOL(encrypt_autofill);
599 SET_BOOL(encrypt_themes);
600 SET_BOOL(encrypt_typed_urls);
601 SET_BOOL(encrypt_extension_settings);
602 SET_BOOL(encrypt_extensions);
603 SET_BOOL(encrypt_sessions);
604 SET_BOOL(encrypt_app_settings);
605 SET_BOOL(encrypt_apps);
606 SET_BOOL(encrypt_search_engines);
607 SET_BOOL(encrypt_dictionary);
608 SET_BOOL(encrypt_articles);
609 SET_BOOL(encrypt_app_list);
610 SET_BOOL(encrypt_arc_package);
611 SET_BOOL(encrypt_reading_list);
612 SET_BOOL(encrypt_everything);
613 SET_BOOL(server_only_was_missing_keystore_migration_time);
614 SET_BOOL(sync_tab_favicons);
615 SET_ENUM(passphrase_type, PassphraseTypeString);
616 SET(keystore_decryptor_token, EncryptedDataToValue);
617 SET_INT64(keystore_migration_time);
618 SET_INT64(custom_passphrase_time);
619 return value;
620 }
621
622 std::unique_ptr<base::DictionaryValue> ArticlePageToValue(
623 const sync_pb::ArticlePage& proto) {
624 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
625 SET_STR(url);
626 return value;
627 }
628
629 std::unique_ptr<base::DictionaryValue> ArticleSpecificsToValue(
630 const sync_pb::ArticleSpecifics& proto) {
631 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
632 SET_STR(entry_id);
633 SET_STR(title);
634 SET_REP(pages, ArticlePageToValue);
635 return value;
636 }
637
638 std::unique_ptr<base::DictionaryValue> PasswordSpecificsToValue(
639 const sync_pb::PasswordSpecifics& proto) {
640 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
641 SET(encrypted, EncryptedDataToValue);
642 SET(unencrypted_metadata, PasswordSpecificsMetadataToValue);
643 return value;
644 }
645
646 std::unique_ptr<base::DictionaryValue> PreferenceSpecificsToValue(
647 const sync_pb::PreferenceSpecifics& proto) {
648 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
649 SET_STR(name);
650 SET_STR(value);
651 return value;
652 }
653
654 std::unique_ptr<base::DictionaryValue> PrinterSpecificsToValue(
655 const sync_pb::PrinterSpecifics& proto) {
656 std::unique_ptr<base::DictionaryValue> value =
657 base::MakeUnique<base::DictionaryValue>();
658 SET_STR(id);
659 SET_STR(display_name);
660 SET_STR(description);
661 SET_STR(manufacturer);
662 SET_STR(model);
663 SET_STR(uri);
664 SET_STR(uuid);
665 SET(ppd_reference, PrinterPPDReferenceToValue);
666 return value;
667 }
668
669 std::unique_ptr<base::DictionaryValue> PriorityPreferenceSpecificsToValue(
670 const sync_pb::PriorityPreferenceSpecifics& specifics) {
671 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
672 SET_FIELD(preference, PreferenceSpecificsToValue);
673 return value;
674 }
675
676 std::unique_ptr<base::DictionaryValue>
677 SyncedNotificationAppInfoSpecificsToValue(
678 const sync_pb::SyncedNotificationAppInfoSpecifics& proto) {
679 return base::MakeUnique<base::DictionaryValue>();
680 }
681
682 std::unique_ptr<base::DictionaryValue> SyncedNotificationSpecificsToValue(
683 const sync_pb::SyncedNotificationSpecifics& proto) {
684 return base::MakeUnique<base::DictionaryValue>();
685 }
686
687 std::unique_ptr<base::DictionaryValue> SearchEngineSpecificsToValue(
688 const sync_pb::SearchEngineSpecifics& proto) {
689 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
690 SET_STR(short_name);
691 SET_STR(keyword);
692 SET_STR(favicon_url);
693 SET_STR(url);
694 SET_BOOL(safe_for_autoreplace);
695 SET_STR(originating_url);
696 SET_INT64(date_created);
697 SET_STR(input_encodings);
698 SET_BOOL(show_in_default_list);
699 SET_STR(suggestions_url);
700 SET_INT32(prepopulate_id);
701 SET_BOOL(autogenerate_keyword);
702 SET_STR(instant_url);
703 SET_INT64(last_modified);
704 SET_STR(sync_guid);
705 SET_STR_REP(alternate_urls);
706 SET_STR(search_terms_replacement_key);
707 SET_STR(image_url);
708 SET_STR(search_url_post_params);
709 SET_STR(suggestions_url_post_params);
710 SET_STR(instant_url_post_params);
711 SET_STR(image_url_post_params);
712 SET_STR(new_tab_url);
713 return value;
714 }
715
716 std::unique_ptr<base::DictionaryValue> SessionSpecificsToValue(
717 const sync_pb::SessionSpecifics& proto) {
718 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
719 SET_STR(session_tag);
720 SET(header, SessionHeaderToValue);
721 SET(tab, SessionTabToValue);
722 SET_INT32(tab_node_id);
723 return value;
724 }
725
726 std::unique_ptr<base::DictionaryValue> ThemeSpecificsToValue(
727 const sync_pb::ThemeSpecifics& proto) {
728 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
729 SET_BOOL(use_custom_theme);
730 SET_BOOL(use_system_theme_by_default);
731 SET_STR(custom_theme_name);
732 SET_STR(custom_theme_id);
733 SET_STR(custom_theme_update_url);
734 return value;
735 }
736
737 std::unique_ptr<base::DictionaryValue> TypedUrlSpecificsToValue(
738 const sync_pb::TypedUrlSpecifics& proto) {
739 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
740 SET_STR(url);
741 SET_STR(title);
742 SET_BOOL(hidden);
743 SET_INT64_REP(visits);
744 SET_INT32_REP(visit_transitions);
745 return value;
746 }
747
748 std::unique_ptr<base::DictionaryValue> WalletMaskedCreditCardToValue(
749 const sync_pb::WalletMaskedCreditCard& proto) {
750 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
751 SET_STR(id);
752 SET_ENUM(status, GetWalletCardStatusString);
753 SET_STR(name_on_card);
754 SET_ENUM(type, GetWalletCardTypeString);
755 SET_STR(last_four);
756 SET_INT32(exp_month);
757 SET_INT32(exp_year);
758 SET_STR(billing_address_id);
759 return value;
760 }
761
762 std::unique_ptr<base::DictionaryValue> WalletPostalAddressToValue(
763 const sync_pb::WalletPostalAddress& proto) {
764 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
765 SET_STR(id);
766 SET_STR(recipient_name);
767 SET_STR(company_name);
768 SET_STR_REP(street_address);
769 SET_STR(address_1);
770 SET_STR(address_2);
771 SET_STR(address_3);
772 SET_STR(address_4);
773 SET_STR(postal_code);
774 SET_STR(sorting_code);
775 SET_STR(country_code);
776 SET_STR(phone_number);
777 SET_STR(language_code);
778 return value;
779 }
780
781 std::unique_ptr<base::DictionaryValue> WifiCredentialSpecificsToValue(
782 const sync_pb::WifiCredentialSpecifics& proto) {
783 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
784 SET_BYTES(ssid);
785 SET_ENUM(security_class, GetWifiCredentialSecurityClassString);
786 SET_BYTES(passphrase);
787 return value;
788 }
789
790 std::unique_ptr<base::DictionaryValue> EntitySpecificsToValue(
791 const sync_pb::EntitySpecifics& specifics) {
792 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
793 SET_FIELD(app, AppSpecificsToValue);
794 SET_FIELD(app_list, AppListSpecificsToValue);
795 SET_FIELD(app_notification, AppNotificationToValue);
796 SET_FIELD(app_setting, AppSettingSpecificsToValue);
797 SET_FIELD(arc_package, ArcPackageSpecificsToValue);
798 SET_FIELD(article, ArticleSpecificsToValue);
799 SET_FIELD(autofill, AutofillSpecificsToValue);
800 SET_FIELD(autofill_profile, AutofillProfileSpecificsToValue);
801 SET_FIELD(autofill_wallet, AutofillWalletSpecificsToValue);
802 SET_FIELD(wallet_metadata, WalletMetadataSpecificsToValue);
803 SET_FIELD(bookmark, BookmarkSpecificsToValue);
804 SET_FIELD(device_info, DeviceInfoSpecificsToValue);
805 SET_FIELD(dictionary, DictionarySpecificsToValue);
806 SET_FIELD(experiments, ExperimentsSpecificsToValue);
807 SET_FIELD(extension, ExtensionSpecificsToValue);
808 SET_FIELD(extension_setting, ExtensionSettingSpecificsToValue);
809 SET_FIELD(favicon_image, FaviconImageSpecificsToValue);
810 SET_FIELD(favicon_tracking, FaviconTrackingSpecificsToValue);
811 SET_FIELD(history_delete_directive, HistoryDeleteDirectiveSpecificsToValue);
812 SET_FIELD(managed_user_setting, ManagedUserSettingSpecificsToValue);
813 SET_FIELD(managed_user_shared_setting,
814 ManagedUserSharedSettingSpecificsToValue);
815 SET_FIELD(managed_user, ManagedUserSpecificsToValue);
816 SET_FIELD(managed_user_whitelist, ManagedUserWhitelistSpecificsToValue);
817 SET_FIELD(nigori, NigoriSpecificsToValue);
818 SET_FIELD(password, PasswordSpecificsToValue);
819 SET_FIELD(preference, PreferenceSpecificsToValue);
820 SET_FIELD(printer, PrinterSpecificsToValue);
821 SET_FIELD(priority_preference, PriorityPreferenceSpecificsToValue);
822 SET_FIELD(reading_list, ReadingListSpecificsToValue);
823 SET_FIELD(search_engine, SearchEngineSpecificsToValue);
824 SET_FIELD(session, SessionSpecificsToValue);
825 SET_FIELD(synced_notification, SyncedNotificationSpecificsToValue);
826 SET_FIELD(synced_notification_app_info,
827 SyncedNotificationAppInfoSpecificsToValue);
828 SET_FIELD(theme, ThemeSpecificsToValue);
829 SET_FIELD(typed_url, TypedUrlSpecificsToValue);
830 SET_FIELD(wifi_credential, WifiCredentialSpecificsToValue);
831 return value;
832 }
833
834 namespace {
835
836 base::StringValue* UniquePositionToStringValue(
837 const sync_pb::UniquePosition& proto) {
838 UniquePosition pos = UniquePosition::FromProto(proto);
839 return new base::StringValue(pos.ToDebugString());
840 }
841
842 } // namespace
843
844 std::unique_ptr<base::DictionaryValue> SyncEntityToValue(
845 const sync_pb::SyncEntity& proto,
846 bool include_specifics) {
847 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
848 SET_STR(id_string);
849 SET_STR(parent_id_string);
850 SET_STR(old_parent_id);
851 SET_INT64(version);
852 SET_INT64(mtime);
853 SET_INT64(ctime);
854 SET_STR(name);
855 SET_STR(non_unique_name);
856 SET_INT64(sync_timestamp);
857 SET_STR(server_defined_unique_tag);
858 SET_INT64(position_in_parent);
859 SET(unique_position, UniquePositionToStringValue);
860 SET_STR(insert_after_item_id);
861 SET_BOOL(deleted);
862 SET_STR(originator_cache_guid);
863 SET_STR(originator_client_item_id);
864 if (include_specifics)
865 SET(specifics, EntitySpecificsToValue);
866 SET_BOOL(folder);
867 SET_STR(client_defined_unique_tag);
868 SET_REP(attachment_id, AttachmentIdProtoToValue);
869 return value;
870 }
871
872 namespace {
873
874 base::ListValue* SyncEntitiesToValue(
875 const ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities,
876 bool include_specifics) {
877 base::ListValue* list = new base::ListValue();
878 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it;
879 for (it = entities.begin(); it != entities.end(); ++it) {
880 list->Append(SyncEntityToValue(*it, include_specifics));
881 }
882
883 return list;
884 }
885
886 std::unique_ptr<base::DictionaryValue> ChromiumExtensionActivityToValue(
887 const sync_pb::ChromiumExtensionsActivity& proto) {
888 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
889 SET_STR(extension_id);
890 SET_INT32(bookmark_writes_since_last_commit);
891 return value;
892 }
893
894 std::unique_ptr<base::DictionaryValue> CommitMessageToValue(
895 const sync_pb::CommitMessage& proto,
896 bool include_specifics) {
897 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
898 value->Set("entries",
899 SyncEntitiesToValue(proto.entries(), include_specifics));
900 SET_STR(cache_guid);
901 SET_REP(extensions_activity, ChromiumExtensionActivityToValue);
902 SET(config_params, ClientConfigParamsToValue);
903 return value;
904 }
905
906 std::unique_ptr<base::DictionaryValue> GetUpdateTriggersToValue(
907 const sync_pb::GetUpdateTriggers& proto) {
908 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
909 SET_STR_REP(notification_hint);
910 SET_BOOL(client_dropped_hints);
911 SET_BOOL(invalidations_out_of_sync);
912 SET_INT64(local_modification_nudges);
913 SET_INT64(datatype_refresh_nudges);
914 return value;
915 }
916
917 std::unique_ptr<base::DictionaryValue> DataTypeProgressMarkerToValue(
918 const sync_pb::DataTypeProgressMarker& proto) {
919 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
920 SET_INT32(data_type_id);
921 SET_BYTES(token);
922 SET_INT64(timestamp_token_for_migration);
923 SET_STR(notification_hint);
924 SET(get_update_triggers, GetUpdateTriggersToValue);
925 return value;
926 }
927
928 std::unique_ptr<base::DictionaryValue> DataTypeContextToValue(
929 const sync_pb::DataTypeContext& proto) {
930 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
931 SET_INT32(data_type_id);
932 SET_STR(context);
933 SET_INT64(version);
934 return value;
935 }
936
937 std::unique_ptr<base::DictionaryValue> GetUpdatesCallerInfoToValue(
938 const sync_pb::GetUpdatesCallerInfo& proto) {
939 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
940 SET_ENUM(source, GetUpdatesSourceString);
941 SET_BOOL(notifications_enabled);
942 return value;
943 }
944
945 std::unique_ptr<base::DictionaryValue> GetUpdatesMessageToValue(
946 const sync_pb::GetUpdatesMessage& proto) {
947 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
948 SET(caller_info, GetUpdatesCallerInfoToValue);
949 SET_BOOL(fetch_folders);
950 SET_INT32(batch_size);
951 SET_REP(from_progress_marker, DataTypeProgressMarkerToValue);
952 SET_BOOL(streaming);
953 SET_BOOL(need_encryption_key);
954 SET_BOOL(create_mobile_bookmarks_folder);
955 SET_ENUM(get_updates_origin, GetUpdatesOriginString);
956 SET_REP(client_contexts, DataTypeContextToValue);
957 return value;
958 }
959
960 std::unique_ptr<base::DictionaryValue> ClientStatusToValue(
961 const sync_pb::ClientStatus& proto) {
962 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
963 SET_BOOL(hierarchy_conflict_detected);
964 return value;
965 }
966
967 std::unique_ptr<base::DictionaryValue> EntryResponseToValue(
968 const sync_pb::CommitResponse::EntryResponse& proto) {
969 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
970 SET_ENUM(response_type, GetResponseTypeString);
971 SET_STR(id_string);
972 SET_STR(parent_id_string);
973 SET_INT64(position_in_parent);
974 SET_INT64(version);
975 SET_STR(name);
976 SET_STR(error_message);
977 SET_INT64(mtime);
978 return value;
979 }
980
981 std::unique_ptr<base::DictionaryValue> CommitResponseToValue(
982 const sync_pb::CommitResponse& proto) {
983 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
984 SET_REP(entryresponse, EntryResponseToValue);
985 return value;
986 }
987
988 std::unique_ptr<base::DictionaryValue> GetUpdatesResponseToValue(
989 const sync_pb::GetUpdatesResponse& proto,
990 bool include_specifics) {
991 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
992 value->Set("entries",
993 SyncEntitiesToValue(proto.entries(), include_specifics));
994 SET_INT64(changes_remaining);
995 SET_REP(new_progress_marker, DataTypeProgressMarkerToValue);
996 SET_REP(context_mutations, DataTypeContextToValue);
997 return value;
998 }
999
1000 std::unique_ptr<base::DictionaryValue> ClientCommandToValue(
1001 const sync_pb::ClientCommand& proto) {
1002 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1003 SET_INT32(set_sync_poll_interval);
1004 SET_INT32(set_sync_long_poll_interval);
1005 SET_INT32(max_commit_batch_size);
1006 SET_INT32(sessions_commit_delay_seconds);
1007 SET_INT32(throttle_delay_seconds);
1008 SET_INT32(client_invalidation_hint_buffer_size);
1009 return value;
1010 }
1011
1012 std::unique_ptr<base::DictionaryValue> ErrorToValue(
1013 const sync_pb::ClientToServerResponse::Error& proto) {
1014 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1015 SET_ENUM(error_type, GetErrorTypeString);
1016 SET_STR(error_description);
1017 SET_STR(url);
1018 SET_ENUM(action, GetActionString);
1019 return value;
1020 }
1021
1022 } // namespace
1023
1024 std::unique_ptr<base::DictionaryValue> ClientToServerResponseToValue(
1025 const sync_pb::ClientToServerResponse& proto,
1026 bool include_specifics) {
1027 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1028 SET(commit, CommitResponseToValue);
1029 if (proto.has_get_updates()) {
1030 value->Set("get_updates", GetUpdatesResponseToValue(proto.get_updates(),
1031 include_specifics));
1032 }
1033
1034 SET(error, ErrorToValue);
1035 SET_ENUM(error_code, GetErrorTypeString);
1036 SET_STR(error_message);
1037 SET_STR(store_birthday);
1038 SET(client_command, ClientCommandToValue);
1039 SET_INT32_REP(migrated_data_type_id);
1040 return value;
1041 }
1042
1043 std::unique_ptr<base::DictionaryValue> ClientToServerMessageToValue(
1044 const sync_pb::ClientToServerMessage& proto,
1045 bool include_specifics) {
1046 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1047 SET_STR(share);
1048 SET_INT32(protocol_version);
1049 if (proto.has_commit()) {
1050 value->Set("commit",
1051 CommitMessageToValue(proto.commit(), include_specifics));
1052 }
1053
1054 SET(get_updates, GetUpdatesMessageToValue);
1055 SET_STR(store_birthday);
1056 SET_BOOL(sync_problem_detected);
1057 SET(debug_info, DebugInfoToValue);
1058 SET(client_status, ClientStatusToValue);
1059 return value;
1060 }
1061
1062 std::unique_ptr<base::DictionaryValue> DatatypeAssociationStatsToValue(
1063 const sync_pb::DatatypeAssociationStats& proto) {
1064 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1065 SET_INT32(data_type_id);
1066 SET_INT32(num_local_items_before_association);
1067 SET_INT32(num_sync_items_before_association);
1068 SET_INT32(num_local_items_after_association);
1069 SET_INT32(num_sync_items_after_association);
1070 SET_INT32(num_local_items_added);
1071 SET_INT32(num_local_items_deleted);
1072 SET_INT32(num_local_items_modified);
1073 SET_INT32(num_sync_items_added);
1074 SET_INT32(num_sync_items_deleted);
1075 SET_INT32(num_sync_items_modified);
1076 SET_INT64(local_version_pre_association);
1077 SET_INT64(sync_version_pre_association)
1078 SET_BOOL(had_error);
1079 SET_INT64(download_wait_time_us);
1080 SET_INT64(download_time_us);
1081 SET_INT64(association_wait_time_for_high_priority_us);
1082 SET_INT64(association_wait_time_for_same_priority_us);
1083 return value;
1084 }
1085
1086 std::unique_ptr<base::DictionaryValue> DebugEventInfoToValue(
1087 const sync_pb::DebugEventInfo& proto) {
1088 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1089 SET_ENUM(singleton_event, SingletonDebugEventTypeString);
1090 SET(sync_cycle_completed_event_info, SyncCycleCompletedEventInfoToValue);
1091 SET_INT32(nudging_datatype);
1092 SET_INT32_REP(datatypes_notified_from_server);
1093 SET(datatype_association_stats, DatatypeAssociationStatsToValue);
1094 return value;
1095 }
1096
1097 std::unique_ptr<base::DictionaryValue> DebugInfoToValue(
1098 const sync_pb::DebugInfo& proto) {
1099 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1100 SET_REP(events, DebugEventInfoToValue);
1101 SET_BOOL(cryptographer_ready);
1102 SET_BOOL(cryptographer_has_pending_keys);
1103 SET_BOOL(events_dropped);
1104 return value;
1105 }
1106
1107 std::unique_ptr<base::DictionaryValue> SyncCycleCompletedEventInfoToValue(
1108 const sync_pb::SyncCycleCompletedEventInfo& proto) {
1109 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1110 SET_INT32(num_encryption_conflicts);
1111 SET_INT32(num_hierarchy_conflicts);
1112 SET_INT32(num_server_conflicts);
1113 SET_INT32(num_updates_downloaded);
1114 SET_INT32(num_reflected_updates_downloaded);
1115 SET(caller_info, GetUpdatesCallerInfoToValue);
1116 return value;
1117 }
1118
1119 std::unique_ptr<base::DictionaryValue> ClientConfigParamsToValue(
1120 const sync_pb::ClientConfigParams& proto) {
1121 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1122 SET_INT32_REP(enabled_type_ids);
1123 SET_BOOL(tabs_datatype_enabled);
1124 SET_BOOL(cookie_jar_mismatch);
1125 return value;
1126 }
1127
1128 std::unique_ptr<base::DictionaryValue> AttachmentIdProtoToValue(
1129 const sync_pb::AttachmentIdProto& proto) {
1130 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1131 SET_STR(unique_id);
1132 return value;
1133 }
1134
1135 std::unique_ptr<base::DictionaryValue> EntityMetadataToValue(
1136 const sync_pb::EntityMetadata& proto) {
1137 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
1138 SET_STR(client_tag_hash);
1139 SET_STR(server_id);
1140 SET_BOOL(is_deleted);
1141 SET_INT64(sequence_number);
1142 SET_INT64(acked_sequence_number);
1143 SET_INT64(server_version);
1144 SET_INT64(creation_time);
1145 SET_INT64(modification_time);
1146 SET_STR(specifics_hash);
1147 SET_STR(base_specifics_hash);
1148 return value;
1149 }
1150
1151 #undef SET_TYPE
1152 #undef SET
1153 #undef SET_REP
1154
1155 #undef SET_BOOL
1156 #undef SET_BYTES
1157 #undef SET_INT32
1158 #undef SET_INT64
1159 #undef SET_INT64_REP
1160 #undef SET_STR
1161 #undef SET_STR_REP
1162
1163 #undef SET_FIELD
1164 336
1165 } // namespace syncer 337 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/protocol/proto_value_conversions.h ('k') | components/sync/protocol/proto_value_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698