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 "sync/syncable/entry_kernel.h" | 5 #include "sync/syncable/entry_kernel.h" |
6 | 6 |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "sync/protocol/proto_value_conversions.h" | 8 #include "sync/protocol/proto_value_conversions.h" |
9 #include "sync/syncable/syncable_enum_conversions.h" | 9 #include "sync/syncable/syncable_enum_conversions.h" |
10 #include "sync/util/cryptographer.h" | 10 #include "sync/util/cryptographer.h" |
11 | 11 |
12 namespace syncer { | 12 namespace syncer { |
13 namespace syncable { | 13 namespace syncable { |
14 | 14 |
15 EntryKernel::EntryKernel() : dirty_(false) { | 15 EntryKernel::EntryKernel() : dirty_(false) { |
16 // Everything else should already be default-initialized. | 16 // Everything else should already be default-initialized. |
17 for (int i = INT64_FIELDS_BEGIN; i < INT64_FIELDS_END; ++i) { | 17 for (int i = INT64_FIELDS_BEGIN; i < INT64_FIELDS_END; ++i) { |
18 int64_fields[i] = 0; | 18 int64_fields[i] = 0; |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
22 EntryKernel::~EntryKernel() {} | 22 EntryKernel::~EntryKernel() {} |
23 | 23 |
| 24 ModelType EntryKernel::GetModelType() const { |
| 25 ModelType specifics_type = GetModelTypeFromSpecifics(ref(SPECIFICS)); |
| 26 if (specifics_type != UNSPECIFIED) |
| 27 return specifics_type; |
| 28 if (ref(ID).IsRoot()) |
| 29 return TOP_LEVEL_FOLDER; |
| 30 // Loose check for server-created top-level folders that aren't |
| 31 // bound to a particular model type. |
| 32 if (!ref(UNIQUE_SERVER_TAG).empty() && ref(SERVER_IS_DIR)) |
| 33 return TOP_LEVEL_FOLDER; |
| 34 |
| 35 return UNSPECIFIED; |
| 36 } |
| 37 |
24 ModelType EntryKernel::GetServerModelType() const { | 38 ModelType EntryKernel::GetServerModelType() const { |
25 ModelType specifics_type = GetModelTypeFromSpecifics(ref(SERVER_SPECIFICS)); | 39 ModelType specifics_type = GetModelTypeFromSpecifics(ref(SERVER_SPECIFICS)); |
26 if (specifics_type != UNSPECIFIED) | 40 if (specifics_type != UNSPECIFIED) |
27 return specifics_type; | 41 return specifics_type; |
28 if (ref(ID).IsRoot()) | 42 if (ref(ID).IsRoot()) |
29 return TOP_LEVEL_FOLDER; | 43 return TOP_LEVEL_FOLDER; |
30 // Loose check for server-created top-level folders that aren't | 44 // Loose check for server-created top-level folders that aren't |
31 // bound to a particular model type. | 45 // bound to a particular model type. |
32 if (!ref(UNIQUE_SERVER_TAG).empty() && ref(SERVER_IS_DIR)) | 46 if (!ref(UNIQUE_SERVER_TAG).empty() && ref(SERVER_IS_DIR)) |
33 return TOP_LEVEL_FOLDER; | 47 return TOP_LEVEL_FOLDER; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 103 } |
90 | 104 |
91 StringValue* TimeToValue(const base::Time& t) { | 105 StringValue* TimeToValue(const base::Time& t) { |
92 return Value::CreateStringValue(GetTimeDebugString(t)); | 106 return Value::CreateStringValue(GetTimeDebugString(t)); |
93 } | 107 } |
94 | 108 |
95 StringValue* IdToValue(const Id& id) { | 109 StringValue* IdToValue(const Id& id) { |
96 return id.ToValue(); | 110 return id.ToValue(); |
97 } | 111 } |
98 | 112 |
99 StringValue* OrdinalToValue(const NodeOrdinal& ord) { | 113 StringValue* UniquePositionToValue(const UniquePosition& pos) { |
100 return Value::CreateStringValue(ord.ToDebugString()); | 114 return Value::CreateStringValue(pos.ToDebugString()); |
| 115 } |
| 116 |
| 117 StringValue* BytesToValue(const std::string& bytes) { |
| 118 return Value::CreateStringValue( |
| 119 base::HexEncode(bytes.data(), bytes.length())); |
101 } | 120 } |
102 | 121 |
103 } // namespace | 122 } // namespace |
104 | 123 |
105 DictionaryValue* EntryKernel::ToValue(Cryptographer* cryptographer) const { | 124 DictionaryValue* EntryKernel::ToValue(Cryptographer* cryptographer) const { |
106 DictionaryValue* kernel_info = new DictionaryValue(); | 125 DictionaryValue* kernel_info = new DictionaryValue(); |
107 kernel_info->SetBoolean("isDirty", is_dirty()); | 126 kernel_info->SetBoolean("isDirty", is_dirty()); |
108 kernel_info->Set("serverModelType", ModelTypeToValue(GetServerModelType())); | 127 kernel_info->Set("serverModelType", ModelTypeToValue(GetServerModelType())); |
109 | 128 |
110 // Int64 fields. | 129 // Int64 fields. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 &Value::CreateStringValue; | 165 &Value::CreateStringValue; |
147 SetFieldValues(*this, kernel_info, | 166 SetFieldValues(*this, kernel_info, |
148 &GetStringFieldString, string_to_value, | 167 &GetStringFieldString, string_to_value, |
149 STRING_FIELDS_BEGIN, STRING_FIELDS_END - 1); | 168 STRING_FIELDS_BEGIN, STRING_FIELDS_END - 1); |
150 } | 169 } |
151 | 170 |
152 // Proto fields. | 171 // Proto fields. |
153 SetEncryptableProtoValues(*this, cryptographer, kernel_info, | 172 SetEncryptableProtoValues(*this, cryptographer, kernel_info, |
154 PROTO_FIELDS_BEGIN, PROTO_FIELDS_END - 1); | 173 PROTO_FIELDS_BEGIN, PROTO_FIELDS_END - 1); |
155 | 174 |
156 // Ordinal fields | 175 // UniquePosition fields |
157 SetFieldValues(*this, kernel_info, | 176 SetFieldValues(*this, kernel_info, |
158 &GetOrdinalFieldString, &OrdinalToValue, | 177 &GetUniquePositionFieldString, &UniquePositionToValue, |
159 ORDINAL_FIELDS_BEGIN, ORDINAL_FIELDS_END - 1); | 178 UNIQUE_POSITION_FIELDS_BEGIN, UNIQUE_POSITION_FIELDS_END - 1); |
| 179 |
| 180 // Bytes fields |
| 181 SetFieldValues(*this, kernel_info, |
| 182 &GetBytesFieldString, &BytesToValue, |
| 183 BYTES_FIELDS_BEGIN, BYTES_FIELDS_END - 1); |
160 | 184 |
161 // Bit temps. | 185 // Bit temps. |
162 SetFieldValues(*this, kernel_info, | 186 SetFieldValues(*this, kernel_info, |
163 &GetBitTempString, &Value::CreateBooleanValue, | 187 &GetBitTempString, &Value::CreateBooleanValue, |
164 BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1); | 188 BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1); |
165 | 189 |
166 return kernel_info; | 190 return kernel_info; |
167 } | 191 } |
168 | 192 |
169 ListValue* EntryKernelMutationMapToValue( | 193 ListValue* EntryKernelMutationMapToValue( |
170 const EntryKernelMutationMap& mutations) { | 194 const EntryKernelMutationMap& mutations) { |
171 ListValue* list = new ListValue(); | 195 ListValue* list = new ListValue(); |
172 for (EntryKernelMutationMap::const_iterator it = mutations.begin(); | 196 for (EntryKernelMutationMap::const_iterator it = mutations.begin(); |
173 it != mutations.end(); ++it) { | 197 it != mutations.end(); ++it) { |
174 list->Append(EntryKernelMutationToValue(it->second)); | 198 list->Append(EntryKernelMutationToValue(it->second)); |
175 } | 199 } |
176 return list; | 200 return list; |
177 } | 201 } |
178 | 202 |
179 DictionaryValue* EntryKernelMutationToValue( | 203 DictionaryValue* EntryKernelMutationToValue( |
180 const EntryKernelMutation& mutation) { | 204 const EntryKernelMutation& mutation) { |
181 DictionaryValue* dict = new DictionaryValue(); | 205 DictionaryValue* dict = new DictionaryValue(); |
182 dict->Set("original", mutation.original.ToValue(NULL)); | 206 dict->Set("original", mutation.original.ToValue(NULL)); |
183 dict->Set("mutated", mutation.mutated.ToValue(NULL)); | 207 dict->Set("mutated", mutation.mutated.ToValue(NULL)); |
184 return dict; | 208 return dict; |
185 } | 209 } |
186 | 210 |
187 } // namespace syncer | 211 } // namespace syncer |
188 } // namespace syncable | 212 } // namespace syncable |
OLD | NEW |