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