| 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 #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 <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 template <class P, class E> | 105 template <class P, class E> |
| 106 void VisitEnum(const P& parent_proto, const char* field_name, E field) { | 106 void VisitEnum(const P& parent_proto, const char* field_name, E field) { |
| 107 value_->Set(field_name, EnumToValue(field)); | 107 value_->Set(field_name, EnumToValue(field)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 template <class P, class F> | 110 template <class P, class F> |
| 111 void Visit(const P& parent_proto, | 111 void Visit(const P& parent_proto, |
| 112 const char* field_name, | 112 const char* field_name, |
| 113 const google::protobuf::RepeatedPtrField<F>& repeated_field) { | 113 const google::protobuf::RepeatedPtrField<F>& repeated_field) { |
| 114 std::unique_ptr<base::ListValue> list(new base::ListValue()); | 114 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
| 115 for (const auto& field: repeated_field) { | 115 for (const auto& field : repeated_field) { |
| 116 list->Append(ToValue(field)); | 116 list->Append(ToValue(field)); |
| 117 } | 117 } |
| 118 value_->Set(field_name, std::move(list)); | 118 value_->Set(field_name, std::move(list)); |
| 119 } | 119 } |
| 120 | 120 |
| 121 template <class P, class F> | 121 template <class P, class F> |
| 122 void Visit(const P& parent_proto, | 122 void Visit(const P& parent_proto, |
| 123 const char* field_name, | 123 const char* field_name, |
| 124 const google::protobuf::RepeatedField<F>& repeated_field) { | 124 const google::protobuf::RepeatedField<F>& repeated_field) { |
| 125 std::unique_ptr<base::ListValue> list(new base::ListValue()); | 125 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
| 126 for (const auto& field: repeated_field) { | 126 for (const auto& field : repeated_field) { |
| 127 list->Append(ToValue(field)); | 127 list->Append(ToValue(field)); |
| 128 } | 128 } |
| 129 value_->Set(field_name, std::move(list)); | 129 value_->Set(field_name, std::move(list)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 template <class P, class F> | 132 template <class P, class F> |
| 133 void Visit(const P& parent_proto, const char* field_name, const F& field) { | 133 void Visit(const P& parent_proto, const char* field_name, const F& field) { |
| 134 VisitImpl(parent_proto, field_name, field); | 134 VisitImpl(parent_proto, field_name, field); |
| 135 } | 135 } |
| 136 | 136 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 161 // EntitySpecifics | 161 // EntitySpecifics |
| 162 template <class P> | 162 template <class P> |
| 163 void Visit(const P& parent_proto, | 163 void Visit(const P& parent_proto, |
| 164 const char* field_name, | 164 const char* field_name, |
| 165 const sync_pb::EntitySpecifics& field) { | 165 const sync_pb::EntitySpecifics& field) { |
| 166 if (include_specifics_) { | 166 if (include_specifics_) { |
| 167 VisitImpl(parent_proto, field_name, field); | 167 VisitImpl(parent_proto, field_name, field); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 // EnhancedBookmarksFlags |
| 172 template <class P> |
| 173 void Visit(const P& parent_proto, |
| 174 const char* field_name, |
| 175 const sync_pb::EnhancedBookmarksFlags& field) { |
| 176 // Obsolete, don't visit |
| 177 } |
| 178 |
| 179 // WalletSyncFlags |
| 180 template <class P> |
| 181 void Visit(const P& parent_proto, |
| 182 const char* field_name, |
| 183 const sync_pb::WalletSyncFlags& field) { |
| 184 // Obsolete, don't visit |
| 185 } |
| 186 |
| 187 // PasswordSpecifics |
| 188 std::unique_ptr<base::DictionaryValue> ToValue( |
| 189 const sync_pb::PasswordSpecifics& proto) const { |
| 190 auto value = ToValueImpl(proto); |
| 191 value->Remove("client_only_encrypted_data", nullptr); |
| 192 return value; |
| 193 } |
| 194 |
| 171 // PasswordSpecificsData | 195 // PasswordSpecificsData |
| 172 std::unique_ptr<base::DictionaryValue> ToValue( | 196 std::unique_ptr<base::DictionaryValue> ToValue( |
| 173 const sync_pb::PasswordSpecificsData& proto) const { | 197 const sync_pb::PasswordSpecificsData& proto) const { |
| 174 auto value = ToValueImpl(proto); | 198 auto value = ToValueImpl(proto); |
| 175 value->SetString("password_value", "<redacted>"); | 199 value->SetString("password_value", "<redacted>"); |
| 176 return value; | 200 return value; |
| 177 } | 201 } |
| 178 | 202 |
| 179 // AutofillWalletSpecifics | 203 // AutofillWalletSpecifics |
| 180 std::unique_ptr<base::DictionaryValue> ToValue( | 204 std::unique_ptr<base::DictionaryValue> ToValue( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 } | 262 } |
| 239 std::unique_ptr<base::Value> ToValue(float value) const { | 263 std::unique_ptr<base::Value> ToValue(float value) const { |
| 240 return base::MakeUnique<base::FundamentalValue>(value); | 264 return base::MakeUnique<base::FundamentalValue>(value); |
| 241 } | 265 } |
| 242 std::unique_ptr<base::Value> ToValue(double value) const { | 266 std::unique_ptr<base::Value> ToValue(double value) const { |
| 243 return base::MakeUnique<base::FundamentalValue>(value); | 267 return base::MakeUnique<base::FundamentalValue>(value); |
| 244 } | 268 } |
| 245 | 269 |
| 246 // Needs to be here to see all ToValue() overloads above. | 270 // Needs to be here to see all ToValue() overloads above. |
| 247 template <class P, class F> | 271 template <class P, class F> |
| 248 void VisitImpl(P& proto, const char* field_name, const F& field) { | 272 void VisitImpl(P&, const char* field_name, const F& field) { |
| 249 value_->Set(field_name, ToValue(field)); | 273 value_->Set(field_name, ToValue(field)); |
| 250 } | 274 } |
| 251 | 275 |
| 252 base::DictionaryValue* value_; | 276 base::DictionaryValue* value_; |
| 253 bool include_specifics_; | 277 bool include_specifics_; |
| 254 }; | 278 }; |
| 255 | 279 |
| 256 } // namespace | 280 } // namespace |
| 257 | 281 |
| 258 #define IMPLEMENT_PROTO_TO_VALUE(Proto) \ | 282 #define IMPLEMENT_PROTO_TO_VALUE(Proto) \ |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 IMPLEMENT_PROTO_TO_VALUE(WifiCredentialSpecifics) | 352 IMPLEMENT_PROTO_TO_VALUE(WifiCredentialSpecifics) |
| 329 | 353 |
| 330 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(ClientToServerMessage) | 354 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(ClientToServerMessage) |
| 331 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(ClientToServerResponse) | 355 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(ClientToServerResponse) |
| 332 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(SyncEntity) | 356 IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS(SyncEntity) |
| 333 | 357 |
| 334 #undef IMPLEMENT_PROTO_TO_VALUE | 358 #undef IMPLEMENT_PROTO_TO_VALUE |
| 335 #undef IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS | 359 #undef IMPLEMENT_PROTO_TO_VALUE_INCLUDE_SPECIFICS |
| 336 | 360 |
| 337 } // namespace syncer | 361 } // namespace syncer |
| OLD | NEW |