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 <stdint.h> |
| 10 |
9 #include <algorithm> | 11 #include <algorithm> |
10 #include <string> | 12 #include <string> |
11 | 13 |
12 #include "base/base64.h" | 14 #include "base/base64.h" |
13 #include "base/basictypes.h" | |
14 #include "base/i18n/time_formatting.h" | 15 #include "base/i18n/time_formatting.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "sync/internal_api/public/base/unique_position.h" | 20 #include "sync/internal_api/public/base/unique_position.h" |
20 #include "sync/protocol/app_list_specifics.pb.h" | 21 #include "sync/protocol/app_list_specifics.pb.h" |
21 #include "sync/protocol/app_notification_specifics.pb.h" | 22 #include "sync/protocol/app_notification_specifics.pb.h" |
22 #include "sync/protocol/app_setting_specifics.pb.h" | 23 #include "sync/protocol/app_setting_specifics.pb.h" |
23 #include "sync/protocol/app_specifics.pb.h" | 24 #include "sync/protocol/app_specifics.pb.h" |
(...skipping 19 matching lines...) Expand all Loading... |
43 #include "sync/protocol/typed_url_specifics.pb.h" | 44 #include "sync/protocol/typed_url_specifics.pb.h" |
44 #include "sync/protocol/unique_position.pb.h" | 45 #include "sync/protocol/unique_position.pb.h" |
45 #include "sync/util/time.h" | 46 #include "sync/util/time.h" |
46 | 47 |
47 namespace syncer { | 48 namespace syncer { |
48 | 49 |
49 namespace { | 50 namespace { |
50 | 51 |
51 // Basic Type -> Value functions. | 52 // Basic Type -> Value functions. |
52 | 53 |
53 scoped_ptr<base::StringValue> MakeInt64Value(int64 x) { | 54 scoped_ptr<base::StringValue> MakeInt64Value(int64_t x) { |
54 return make_scoped_ptr(new base::StringValue(base::Int64ToString(x))); | 55 return make_scoped_ptr(new base::StringValue(base::Int64ToString(x))); |
55 } | 56 } |
56 | 57 |
57 // TODO(akalin): Perhaps make JSONWriter support BinaryValue and use | 58 // TODO(akalin): Perhaps make JSONWriter support BinaryValue and use |
58 // that instead of a StringValue. | 59 // that instead of a StringValue. |
59 std::string Base64EncodeString(const std::string& bytes) { | 60 std::string Base64EncodeString(const std::string& bytes) { |
60 std::string bytes_base64; | 61 std::string bytes_base64; |
61 base::Base64Encode(bytes, &bytes_base64); | 62 base::Base64Encode(bytes, &bytes_base64); |
62 return bytes_base64; | 63 return bytes_base64; |
63 } | 64 } |
64 | 65 |
65 scoped_ptr<base::StringValue> MakeStringValue(const std::string& str) { | 66 scoped_ptr<base::StringValue> MakeStringValue(const std::string& str) { |
66 return make_scoped_ptr(new base::StringValue(str)); | 67 return make_scoped_ptr(new base::StringValue(str)); |
67 } | 68 } |
68 | 69 |
69 // T is the field type, F is either RepeatedField or RepeatedPtrField, | 70 // T is the field type, F is either RepeatedField or RepeatedPtrField, |
70 // and V is a subclass of Value. | 71 // and V is a subclass of Value. |
71 template <class T, class F, class V> | 72 template <class T, class F, class V> |
72 scoped_ptr<base::ListValue> MakeRepeatedValue(const F& fields, | 73 scoped_ptr<base::ListValue> MakeRepeatedValue(const F& fields, |
73 V (*converter_fn)(T)) { | 74 V (*converter_fn)(T)) { |
74 scoped_ptr<base::ListValue> list(new base::ListValue()); | 75 scoped_ptr<base::ListValue> list(new base::ListValue()); |
75 for (typename F::const_iterator it = fields.begin(); it != fields.end(); | 76 for (typename F::const_iterator it = fields.begin(); it != fields.end(); |
76 ++it) { | 77 ++it) { |
77 list->Append(converter_fn(*it)); | 78 list->Append(converter_fn(*it)); |
78 } | 79 } |
79 return list; | 80 return list; |
80 } | 81 } |
81 | 82 |
82 base::string16 TimestampToString(int64 tm) { | 83 base::string16 TimestampToString(int64_t tm) { |
83 return base::TimeFormatShortDateAndTime(syncer::ProtoTimeToTime(tm)); | 84 return base::TimeFormatShortDateAndTime(syncer::ProtoTimeToTime(tm)); |
84 } | 85 } |
85 | 86 |
86 } // namespace | 87 } // namespace |
87 | 88 |
88 // Helper macros to reduce the amount of boilerplate. | 89 // Helper macros to reduce the amount of boilerplate. |
89 | 90 |
90 #define SET_TYPE(field, set_fn, transform) \ | 91 #define SET_TYPE(field, set_fn, transform) \ |
91 if (proto.has_##field()) { \ | 92 if (proto.has_##field()) { \ |
92 value->set_fn(#field, transform(proto.field())); \ | 93 value->set_fn(#field, transform(proto.field())); \ |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 #undef SET_BYTES | 1080 #undef SET_BYTES |
1080 #undef SET_INT32 | 1081 #undef SET_INT32 |
1081 #undef SET_INT64 | 1082 #undef SET_INT64 |
1082 #undef SET_INT64_REP | 1083 #undef SET_INT64_REP |
1083 #undef SET_STR | 1084 #undef SET_STR |
1084 #undef SET_STR_REP | 1085 #undef SET_STR_REP |
1085 | 1086 |
1086 #undef SET_FIELD | 1087 #undef SET_FIELD |
1087 | 1088 |
1088 } // namespace syncer | 1089 } // namespace syncer |
OLD | NEW |