| 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 "sync/protocol/proto_value_conversions.h" | 7 #include "sync/protocol/proto_value_conversions.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/i18n/time_formatting.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/time/time.h" |
| 15 #include "base/values.h" | 17 #include "base/values.h" |
| 16 #include "sync/internal_api/public/base/unique_position.h" | 18 #include "sync/internal_api/public/base/unique_position.h" |
| 17 #include "sync/protocol/app_list_specifics.pb.h" | 19 #include "sync/protocol/app_list_specifics.pb.h" |
| 18 #include "sync/protocol/app_notification_specifics.pb.h" | 20 #include "sync/protocol/app_notification_specifics.pb.h" |
| 19 #include "sync/protocol/app_setting_specifics.pb.h" | 21 #include "sync/protocol/app_setting_specifics.pb.h" |
| 20 #include "sync/protocol/app_specifics.pb.h" | 22 #include "sync/protocol/app_specifics.pb.h" |
| 21 #include "sync/protocol/autofill_specifics.pb.h" | 23 #include "sync/protocol/autofill_specifics.pb.h" |
| 22 #include "sync/protocol/bookmark_specifics.pb.h" | 24 #include "sync/protocol/bookmark_specifics.pb.h" |
| 23 #include "sync/protocol/dictionary_specifics.pb.h" | 25 #include "sync/protocol/dictionary_specifics.pb.h" |
| 24 #include "sync/protocol/encryption.pb.h" | 26 #include "sync/protocol/encryption.pb.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 template <class T, class F, class V> | 77 template <class T, class F, class V> |
| 76 base::ListValue* MakeRepeatedValue(const F& fields, V* (*converter_fn)(T)) { | 78 base::ListValue* MakeRepeatedValue(const F& fields, V* (*converter_fn)(T)) { |
| 77 base::ListValue* list = new base::ListValue(); | 79 base::ListValue* list = new base::ListValue(); |
| 78 for (typename F::const_iterator it = fields.begin(); it != fields.end(); | 80 for (typename F::const_iterator it = fields.begin(); it != fields.end(); |
| 79 ++it) { | 81 ++it) { |
| 80 list->Append(converter_fn(*it)); | 82 list->Append(converter_fn(*it)); |
| 81 } | 83 } |
| 82 return list; | 84 return list; |
| 83 } | 85 } |
| 84 | 86 |
| 87 base::StringValue* MakeTimestampValue(int64 tm) { |
| 88 return new base::StringValue( |
| 89 base::TimeFormatShortDateAndTime(base::Time::FromInternalValue(tm))); |
| 90 } |
| 91 |
| 85 } // namespace | 92 } // namespace |
| 86 | 93 |
| 87 // Helper macros to reduce the amount of boilerplate. | 94 // Helper macros to reduce the amount of boilerplate. |
| 88 | 95 |
| 89 #define SET(field, fn) \ | 96 #define SET(field, fn) \ |
| 90 if (proto.has_##field()) { \ | 97 if (proto.has_##field()) { \ |
| 91 value->Set(#field, fn(proto.field())); \ | 98 value->Set(#field, fn(proto.field())); \ |
| 92 } | 99 } |
| 93 #define SET_REP(field, fn) \ | 100 #define SET_REP(field, fn) \ |
| 94 value->Set(#field, MakeRepeatedValue(proto.field(), fn)) | 101 value->Set(#field, MakeRepeatedValue(proto.field(), fn)) |
| 95 #define SET_ENUM(field, fn) \ | 102 #define SET_ENUM(field, fn) \ |
| 96 value->Set(#field, MakeEnumValue(proto.field(), fn)) | 103 value->Set(#field, MakeEnumValue(proto.field(), fn)) |
| 97 | 104 |
| 98 #define SET_BOOL(field) SET(field, new base::FundamentalValue) | 105 #define SET_BOOL(field) SET(field, new base::FundamentalValue) |
| 99 #define SET_BYTES(field) SET(field, MakeBytesValue) | 106 #define SET_BYTES(field) SET(field, MakeBytesValue) |
| 100 #define SET_INT32(field) SET(field, MakeInt64Value) | 107 #define SET_INT32(field) SET(field, MakeInt64Value) |
| 101 #define SET_INT32_REP(field) SET_REP(field, MakeInt64Value) | 108 #define SET_INT32_REP(field) SET_REP(field, MakeInt64Value) |
| 102 #define SET_INT64(field) SET(field, MakeInt64Value) | 109 #define SET_INT64(field) SET(field, MakeInt64Value) |
| 103 #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value) | 110 #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value) |
| 104 #define SET_STR(field) SET(field, new base::StringValue) | 111 #define SET_STR(field) SET(field, new base::StringValue) |
| 112 #define SET_TIME_STR(field) SET(field, MakeTimestampValue) |
| 105 #define SET_STR_REP(field) \ | 113 #define SET_STR_REP(field) \ |
| 106 value->Set(#field, \ | 114 value->Set(#field, \ |
| 107 MakeRepeatedValue<const std::string&, \ | 115 MakeRepeatedValue<const std::string&, \ |
| 108 google::protobuf::RepeatedPtrField< \ | 116 google::protobuf::RepeatedPtrField< \ |
| 109 std::string >, \ | 117 std::string >, \ |
| 110 base::StringValue>(proto.field(), \ | 118 base::StringValue>(proto.field(), \ |
| 111 MakeStringValue)) | 119 MakeStringValue)) |
| 112 #define SET_EXPERIMENT_ENABLED_FIELD(field) \ | 120 #define SET_EXPERIMENT_ENABLED_FIELD(field) \ |
| 113 do { \ | 121 do { \ |
| 114 if (proto.has_##field() && \ | 122 if (proto.has_##field() && \ |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 } | 489 } |
| 482 | 490 |
| 483 base::DictionaryValue* DeviceInfoSpecificsToValue( | 491 base::DictionaryValue* DeviceInfoSpecificsToValue( |
| 484 const sync_pb::DeviceInfoSpecifics& proto) { | 492 const sync_pb::DeviceInfoSpecifics& proto) { |
| 485 base::DictionaryValue* value = new base::DictionaryValue(); | 493 base::DictionaryValue* value = new base::DictionaryValue(); |
| 486 SET_STR(cache_guid); | 494 SET_STR(cache_guid); |
| 487 SET_STR(client_name); | 495 SET_STR(client_name); |
| 488 SET_ENUM(device_type, GetDeviceTypeString); | 496 SET_ENUM(device_type, GetDeviceTypeString); |
| 489 SET_STR(sync_user_agent); | 497 SET_STR(sync_user_agent); |
| 490 SET_STR(chrome_version); | 498 SET_STR(chrome_version); |
| 499 SET_TIME_STR(backup_timestamp); |
| 491 return value; | 500 return value; |
| 492 } | 501 } |
| 493 | 502 |
| 494 base::DictionaryValue* DictionarySpecificsToValue( | 503 base::DictionaryValue* DictionarySpecificsToValue( |
| 495 const sync_pb::DictionarySpecifics& proto) { | 504 const sync_pb::DictionarySpecifics& proto) { |
| 496 base::DictionaryValue* value = new base::DictionaryValue(); | 505 base::DictionaryValue* value = new base::DictionaryValue(); |
| 497 SET_STR(word); | 506 SET_STR(word); |
| 498 return value; | 507 return value; |
| 499 } | 508 } |
| 500 | 509 |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 #undef SET_BYTES | 1117 #undef SET_BYTES |
| 1109 #undef SET_INT32 | 1118 #undef SET_INT32 |
| 1110 #undef SET_INT64 | 1119 #undef SET_INT64 |
| 1111 #undef SET_INT64_REP | 1120 #undef SET_INT64_REP |
| 1112 #undef SET_STR | 1121 #undef SET_STR |
| 1113 #undef SET_STR_REP | 1122 #undef SET_STR_REP |
| 1114 | 1123 |
| 1115 #undef SET_FIELD | 1124 #undef SET_FIELD |
| 1116 | 1125 |
| 1117 } // namespace syncer | 1126 } // namespace syncer |
| OLD | NEW |