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 #ifndef SYNC_SYNCABLE_ENTRY_KERNEL_H_ | 5 #ifndef SYNC_SYNCABLE_ENTRY_KERNEL_H_ |
6 #define SYNC_SYNCABLE_ENTRY_KERNEL_H_ | 6 #define SYNC_SYNCABLE_ENTRY_KERNEL_H_ |
7 | 7 |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "sync/internal_api/public/base/model_type.h" | 10 #include "sync/internal_api/public/base/model_type.h" |
11 #include "sync/internal_api/public/base/node_ordinal.h" | 11 #include "sync/internal_api/public/base/unique_position.h" |
12 #include "sync/internal_api/public/util/immutable.h" | 12 #include "sync/internal_api/public/util/immutable.h" |
13 #include "sync/protocol/sync.pb.h" | 13 #include "sync/protocol/sync.pb.h" |
14 #include "sync/syncable/metahandle_set.h" | 14 #include "sync/syncable/metahandle_set.h" |
15 #include "sync/syncable/syncable_id.h" | 15 #include "sync/syncable/syncable_id.h" |
16 #include "sync/util/time.h" | 16 #include "sync/util/time.h" |
17 | 17 |
18 namespace syncer { | 18 namespace syncer { |
19 | 19 |
20 class Cryptographer; | 20 class Cryptographer; |
21 | 21 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 enum { | 73 enum { |
74 TIME_FIELDS_COUNT = TIME_FIELDS_END - TIME_FIELDS_BEGIN, | 74 TIME_FIELDS_COUNT = TIME_FIELDS_END - TIME_FIELDS_BEGIN, |
75 ID_FIELDS_BEGIN = TIME_FIELDS_END, | 75 ID_FIELDS_BEGIN = TIME_FIELDS_END, |
76 }; | 76 }; |
77 | 77 |
78 enum IdField { | 78 enum IdField { |
79 // Code in InitializeTables relies on ID being the first IdField value. | 79 // Code in InitializeTables relies on ID being the first IdField value. |
80 ID = ID_FIELDS_BEGIN, | 80 ID = ID_FIELDS_BEGIN, |
81 PARENT_ID, | 81 PARENT_ID, |
82 SERVER_PARENT_ID, | 82 SERVER_PARENT_ID, |
83 | |
84 PREV_ID, | |
85 NEXT_ID, | |
86 ID_FIELDS_END | 83 ID_FIELDS_END |
87 }; | 84 }; |
88 | 85 |
89 enum { | 86 enum { |
90 ID_FIELDS_COUNT = ID_FIELDS_END - ID_FIELDS_BEGIN, | 87 ID_FIELDS_COUNT = ID_FIELDS_END - ID_FIELDS_BEGIN, |
91 BIT_FIELDS_BEGIN = ID_FIELDS_END | 88 BIT_FIELDS_BEGIN = ID_FIELDS_END |
92 }; | 89 }; |
93 | 90 |
94 enum IndexedBitField { | 91 enum IndexedBitField { |
95 IS_UNSYNCED = BIT_FIELDS_BEGIN, | 92 IS_UNSYNCED = BIT_FIELDS_BEGIN, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // seems the overhead for storing a NULL blob is very small. | 133 // seems the overhead for storing a NULL blob is very small. |
137 enum ProtoField { | 134 enum ProtoField { |
138 SPECIFICS = PROTO_FIELDS_BEGIN, | 135 SPECIFICS = PROTO_FIELDS_BEGIN, |
139 SERVER_SPECIFICS, | 136 SERVER_SPECIFICS, |
140 BASE_SERVER_SPECIFICS, | 137 BASE_SERVER_SPECIFICS, |
141 PROTO_FIELDS_END, | 138 PROTO_FIELDS_END, |
142 }; | 139 }; |
143 | 140 |
144 enum { | 141 enum { |
145 PROTO_FIELDS_COUNT = PROTO_FIELDS_END - PROTO_FIELDS_BEGIN, | 142 PROTO_FIELDS_COUNT = PROTO_FIELDS_END - PROTO_FIELDS_BEGIN, |
146 ORDINAL_FIELDS_BEGIN = PROTO_FIELDS_END | 143 UNIQUE_POSITION_FIELDS_BEGIN = PROTO_FIELDS_END |
147 }; | 144 }; |
148 | 145 |
149 enum OrdinalField { | 146 enum UniquePositionField { |
150 // An Ordinal that identifies the relative ordering of this object | 147 SERVER_UNIQUE_POSITION = UNIQUE_POSITION_FIELDS_BEGIN, |
151 // among its siblings. | 148 UNIQUE_POSITION, |
152 SERVER_ORDINAL_IN_PARENT = ORDINAL_FIELDS_BEGIN, | 149 UNIQUE_POSITION_FIELDS_END |
153 ORDINAL_FIELDS_END | |
154 }; | 150 }; |
155 | 151 |
156 enum { | 152 enum { |
157 ORDINAL_FIELDS_COUNT = ORDINAL_FIELDS_END - ORDINAL_FIELDS_BEGIN, | 153 UNIQUE_POSITION_FIELDS_COUNT = |
158 FIELD_COUNT = ORDINAL_FIELDS_END - BEGIN_FIELDS, | 154 UNIQUE_POSITION_FIELDS_END - UNIQUE_POSITION_FIELDS_BEGIN, |
| 155 BYTES_FIELDS_BEGIN = UNIQUE_POSITION_FIELDS_END |
| 156 }; |
| 157 |
| 158 enum BytesField { |
| 159 // A unique tag for bookmarks. |
| 160 UNIQUE_BOOKMARK_TAG = BYTES_FIELDS_BEGIN, |
| 161 BYTES_FIELDS_END |
| 162 }; |
| 163 |
| 164 enum { |
| 165 BYTES_FIELDS_COUNT = BYTES_FIELDS_END - BYTES_FIELDS_BEGIN, |
| 166 FIELD_COUNT = BYTES_FIELDS_END - BEGIN_FIELDS, |
159 // Past this point we have temporaries, stored in memory only. | 167 // Past this point we have temporaries, stored in memory only. |
160 BEGIN_TEMPS = ORDINAL_FIELDS_END, | 168 BEGIN_TEMPS = BYTES_FIELDS_END, |
161 BIT_TEMPS_BEGIN = BEGIN_TEMPS, | 169 BIT_TEMPS_BEGIN = BEGIN_TEMPS, |
162 }; | 170 }; |
163 | 171 |
164 enum BitTemp { | 172 enum BitTemp { |
165 // Not to be confused with IS_UNSYNCED, this bit is used to detect local | 173 // Not to be confused with IS_UNSYNCED, this bit is used to detect local |
166 // changes to items that happen during the server Commit operation. | 174 // changes to items that happen during the server Commit operation. |
167 SYNCING = BIT_TEMPS_BEGIN, | 175 SYNCING = BIT_TEMPS_BEGIN, |
168 BIT_TEMPS_END, | 176 BIT_TEMPS_END, |
169 }; | 177 }; |
170 | 178 |
171 enum { | 179 enum { |
172 BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN | 180 BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN |
173 }; | 181 }; |
174 | 182 |
175 | 183 |
176 | 184 |
177 struct EntryKernel { | 185 struct EntryKernel { |
178 private: | 186 private: |
179 std::string string_fields[STRING_FIELDS_COUNT]; | 187 std::string string_fields[STRING_FIELDS_COUNT]; |
180 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT]; | 188 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT]; |
181 int64 int64_fields[INT64_FIELDS_COUNT]; | 189 int64 int64_fields[INT64_FIELDS_COUNT]; |
182 base::Time time_fields[TIME_FIELDS_COUNT]; | 190 base::Time time_fields[TIME_FIELDS_COUNT]; |
183 Id id_fields[ID_FIELDS_COUNT]; | 191 Id id_fields[ID_FIELDS_COUNT]; |
184 NodeOrdinal ordinal_fields[ORDINAL_FIELDS_COUNT]; | 192 std::string bytes_fields[BYTES_FIELDS_COUNT]; |
| 193 UniquePosition unique_position_fields[UNIQUE_POSITION_FIELDS_COUNT]; |
185 std::bitset<BIT_FIELDS_COUNT> bit_fields; | 194 std::bitset<BIT_FIELDS_COUNT> bit_fields; |
186 std::bitset<BIT_TEMPS_COUNT> bit_temps; | 195 std::bitset<BIT_TEMPS_COUNT> bit_temps; |
187 | 196 |
188 public: | 197 public: |
189 EntryKernel(); | 198 EntryKernel(); |
190 ~EntryKernel(); | 199 ~EntryKernel(); |
191 | 200 |
192 // Set the dirty bit, and optionally add this entry's metahandle to | 201 // Set the dirty bit, and optionally add this entry's metahandle to |
193 // a provided index on dirty bits in |dirty_index|. Parameter may be null, | 202 // a provided index on dirty bits in |dirty_index|. Parameter may be null, |
194 // and will result only in setting the dirty bit of this entry. | 203 // and will result only in setting the dirty bit of this entry. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 251 } |
243 inline void put(BitField field, bool value) { | 252 inline void put(BitField field, bool value) { |
244 bit_fields[field - BIT_FIELDS_BEGIN] = value; | 253 bit_fields[field - BIT_FIELDS_BEGIN] = value; |
245 } | 254 } |
246 inline void put(StringField field, const std::string& value) { | 255 inline void put(StringField field, const std::string& value) { |
247 string_fields[field - STRING_FIELDS_BEGIN] = value; | 256 string_fields[field - STRING_FIELDS_BEGIN] = value; |
248 } | 257 } |
249 inline void put(ProtoField field, const sync_pb::EntitySpecifics& value) { | 258 inline void put(ProtoField field, const sync_pb::EntitySpecifics& value) { |
250 specifics_fields[field - PROTO_FIELDS_BEGIN].CopyFrom(value); | 259 specifics_fields[field - PROTO_FIELDS_BEGIN].CopyFrom(value); |
251 } | 260 } |
252 inline void put(OrdinalField field, const NodeOrdinal& value) { | 261 inline void put(UniquePositionField field, const UniquePosition& value) { |
253 ordinal_fields[field - ORDINAL_FIELDS_BEGIN] = value; | 262 unique_position_fields[field - UNIQUE_POSITION_FIELDS_BEGIN] = value; |
| 263 } |
| 264 inline void put(BytesField field, const std::string& value) { |
| 265 bytes_fields[field - BYTES_FIELDS_BEGIN] = value; |
254 } | 266 } |
255 inline void put(BitTemp field, bool value) { | 267 inline void put(BitTemp field, bool value) { |
256 bit_temps[field - BIT_TEMPS_BEGIN] = value; | 268 bit_temps[field - BIT_TEMPS_BEGIN] = value; |
257 } | 269 } |
258 | 270 |
259 // Const ref getters. | 271 // Const ref getters. |
260 inline int64 ref(MetahandleField field) const { | 272 inline int64 ref(MetahandleField field) const { |
261 return int64_fields[field - INT64_FIELDS_BEGIN]; | 273 return int64_fields[field - INT64_FIELDS_BEGIN]; |
262 } | 274 } |
263 inline int64 ref(Int64Field field) const { | 275 inline int64 ref(Int64Field field) const { |
(...skipping 16 matching lines...) Expand all Loading... |
280 } | 292 } |
281 inline bool ref(BitField field) const { | 293 inline bool ref(BitField field) const { |
282 return bit_fields[field - BIT_FIELDS_BEGIN]; | 294 return bit_fields[field - BIT_FIELDS_BEGIN]; |
283 } | 295 } |
284 inline const std::string& ref(StringField field) const { | 296 inline const std::string& ref(StringField field) const { |
285 return string_fields[field - STRING_FIELDS_BEGIN]; | 297 return string_fields[field - STRING_FIELDS_BEGIN]; |
286 } | 298 } |
287 inline const sync_pb::EntitySpecifics& ref(ProtoField field) const { | 299 inline const sync_pb::EntitySpecifics& ref(ProtoField field) const { |
288 return specifics_fields[field - PROTO_FIELDS_BEGIN]; | 300 return specifics_fields[field - PROTO_FIELDS_BEGIN]; |
289 } | 301 } |
290 inline const NodeOrdinal& ref(OrdinalField field) const { | 302 inline const UniquePosition& ref(UniquePositionField field) const { |
291 return ordinal_fields[field - ORDINAL_FIELDS_BEGIN]; | 303 return unique_position_fields[field - UNIQUE_POSITION_FIELDS_BEGIN]; |
| 304 } |
| 305 inline const std::string& ref(BytesField field) const { |
| 306 return bytes_fields[field - BYTES_FIELDS_BEGIN]; |
292 } | 307 } |
293 inline bool ref(BitTemp field) const { | 308 inline bool ref(BitTemp field) const { |
294 return bit_temps[field - BIT_TEMPS_BEGIN]; | 309 return bit_temps[field - BIT_TEMPS_BEGIN]; |
295 } | 310 } |
296 | 311 |
297 // Non-const, mutable ref getters for object types only. | 312 // Non-const, mutable ref getters for object types only. |
298 inline std::string& mutable_ref(StringField field) { | 313 inline std::string& mutable_ref(StringField field) { |
299 return string_fields[field - STRING_FIELDS_BEGIN]; | 314 return string_fields[field - STRING_FIELDS_BEGIN]; |
300 } | 315 } |
301 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) { | 316 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) { |
302 return specifics_fields[field - PROTO_FIELDS_BEGIN]; | 317 return specifics_fields[field - PROTO_FIELDS_BEGIN]; |
303 } | 318 } |
304 inline Id& mutable_ref(IdField field) { | 319 inline Id& mutable_ref(IdField field) { |
305 return id_fields[field - ID_FIELDS_BEGIN]; | 320 return id_fields[field - ID_FIELDS_BEGIN]; |
306 } | 321 } |
307 inline NodeOrdinal& mutable_ref(OrdinalField field) { | 322 inline UniquePosition& mutable_ref(UniquePositionField field) { |
308 return ordinal_fields[field - ORDINAL_FIELDS_BEGIN]; | 323 return unique_position_fields[field - UNIQUE_POSITION_FIELDS_BEGIN]; |
309 } | 324 } |
310 | 325 |
| 326 ModelType GetModelType() const; |
311 ModelType GetServerModelType() const; | 327 ModelType GetServerModelType() const; |
312 | 328 |
313 // Dumps all kernel info into a DictionaryValue and returns it. | 329 // Dumps all kernel info into a DictionaryValue and returns it. |
314 // Transfers ownership of the DictionaryValue to the caller. | 330 // Transfers ownership of the DictionaryValue to the caller. |
315 // Note: |cryptographer| is an optional parameter for use in decrypting | 331 // Note: |cryptographer| is an optional parameter for use in decrypting |
316 // encrypted specifics. If it is NULL or the specifics are not decryptsble, | 332 // encrypted specifics. If it is NULL or the specifics are not decryptsble, |
317 // they will be serialized as empty proto's. | 333 // they will be serialized as empty proto's. |
318 base::DictionaryValue* ToValue(Cryptographer* cryptographer) const; | 334 base::DictionaryValue* ToValue(Cryptographer* cryptographer) const; |
319 | 335 |
320 private: | 336 private: |
(...skipping 14 matching lines...) Expand all Loading... |
335 const EntryKernelMutation& mutation); | 351 const EntryKernelMutation& mutation); |
336 | 352 |
337 // Caller owns the return value. | 353 // Caller owns the return value. |
338 base::ListValue* EntryKernelMutationMapToValue( | 354 base::ListValue* EntryKernelMutationMapToValue( |
339 const EntryKernelMutationMap& mutations); | 355 const EntryKernelMutationMap& mutations); |
340 | 356 |
341 } // namespace syncable | 357 } // namespace syncable |
342 } // namespace syncer | 358 } // namespace syncer |
343 | 359 |
344 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_ | 360 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_ |
OLD | NEW |