Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: sync/syncable/entry_kernel.h

Issue 10989063: Changed DB to store node positions as Ordinals. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Invalid ordinals handling and minor fixes Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/util/immutable.h" 12 #include "sync/internal_api/public/util/immutable.h"
12 #include "sync/protocol/sync.pb.h" 13 #include "sync/protocol/sync.pb.h"
13 #include "sync/syncable/metahandle_set.h" 14 #include "sync/syncable/metahandle_set.h"
14 #include "sync/syncable/syncable_id.h" 15 #include "sync/syncable/syncable_id.h"
15 #include "sync/util/time.h" 16 #include "sync/util/time.h"
16 17
17 namespace syncer { 18 namespace syncer {
18 namespace syncable { 19 namespace syncable {
19 20
20 // Things you need to update if you change any of the fields below: 21 // Things you need to update if you change any of the fields below:
21 // - EntryKernel struct in this file 22 // - EntryKernel struct in this file
22 // - syncable_columns.h 23 // - syncable_columns.h
23 // - syncable_enum_conversions{.h,.cc,_unittest.cc} 24 // - syncable_enum_conversions{.h,.cc,_unittest.cc}
24 // - EntryKernel::EntryKernel(), EntryKernel::ToValue(), operator<< 25 // - EntryKernel::EntryKernel(), EntryKernel::ToValue() in entry_kernel.cc
25 // for Entry in syncable.cc 26 // - operator<< in Entry.cc
26 // - BindFields() and UnpackEntry() in directory_backing_store.cc 27 // - BindFields() and UnpackEntry() in directory_backing_store.cc
27 // - TestSimpleFieldsPreservedDuringSaveChanges in syncable_unittest.cc 28 // - TestSimpleFieldsPreservedDuringSaveChanges in syncable_unittest.cc
28 29
29 static const int64 kInvalidMetaHandle = 0; 30 static const int64 kInvalidMetaHandle = 0;
30 31
31 enum { 32 enum {
32 BEGIN_FIELDS = 0, 33 BEGIN_FIELDS = 0,
33 INT64_FIELDS_BEGIN = BEGIN_FIELDS 34 INT64_FIELDS_BEGIN = BEGIN_FIELDS
34 }; 35 };
35 36
36 enum MetahandleField { 37 enum MetahandleField {
37 // Primary key into the table. Keep this as a handle to the meta entry 38 // Primary key into the table. Keep this as a handle to the meta entry
38 // across transactions. 39 // across transactions.
39 META_HANDLE = INT64_FIELDS_BEGIN 40 META_HANDLE = INT64_FIELDS_BEGIN
40 }; 41 };
41 42
42 enum BaseVersion { 43 enum BaseVersion {
43 // After initial upload, the version is controlled by the server, and is 44 // After initial upload, the version is controlled by the server, and is
44 // increased whenever the data or metadata changes on the server. 45 // increased whenever the data or metadata changes on the server.
45 BASE_VERSION = META_HANDLE + 1, 46 BASE_VERSION = META_HANDLE + 1,
46 }; 47 };
47 48
48 enum Int64Field { 49 enum Int64Field {
49 SERVER_VERSION = BASE_VERSION + 1, 50 SERVER_VERSION = BASE_VERSION + 1,
50 51
51 // A numeric position value that indicates the relative ordering of
52 // this object among its siblings.
53 SERVER_POSITION_IN_PARENT,
54
55 LOCAL_EXTERNAL_ID, // ID of an item in the external local storage that this 52 LOCAL_EXTERNAL_ID, // ID of an item in the external local storage that this
56 // entry is associated with. (such as bookmarks.js) 53 // entry is associated with. (such as bookmarks.js)
57
58 INT64_FIELDS_END 54 INT64_FIELDS_END
59 }; 55 };
60 56
61 enum { 57 enum {
62 INT64_FIELDS_COUNT = INT64_FIELDS_END - INT64_FIELDS_BEGIN, 58 INT64_FIELDS_COUNT = INT64_FIELDS_END - INT64_FIELDS_BEGIN,
63 TIME_FIELDS_BEGIN = INT64_FIELDS_END, 59 TIME_FIELDS_BEGIN = INT64_FIELDS_END,
64 }; 60 };
65 61
66 enum TimeField { 62 enum TimeField {
67 MTIME = TIME_FIELDS_BEGIN, 63 MTIME = TIME_FIELDS_BEGIN,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // From looking at the sqlite3 docs, it's not directly stated, but it 132 // From looking at the sqlite3 docs, it's not directly stated, but it
137 // seems the overhead for storing a NULL blob is very small. 133 // seems the overhead for storing a NULL blob is very small.
138 enum ProtoField { 134 enum ProtoField {
139 SPECIFICS = PROTO_FIELDS_BEGIN, 135 SPECIFICS = PROTO_FIELDS_BEGIN,
140 SERVER_SPECIFICS, 136 SERVER_SPECIFICS,
141 BASE_SERVER_SPECIFICS, 137 BASE_SERVER_SPECIFICS,
142 PROTO_FIELDS_END, 138 PROTO_FIELDS_END,
143 }; 139 };
144 140
145 enum { 141 enum {
146 FIELD_COUNT = PROTO_FIELDS_END, 142 ORDINAL_FIELDS_BEGIN = PROTO_FIELDS_END
143 };
144
145 enum OrdinalField {
146 // An Ordinal that identifies the relative ordering of this object
147 // among its siblings.
148 SERVER_ORDINAL_IN_PARENT = ORDINAL_FIELDS_BEGIN,
149 ORDINAL_FIELDS_END
150 };
151
152 enum {
153 ORDINAL_FIELDS_COUNT = ORDINAL_FIELDS_END - ORDINAL_FIELDS_BEGIN,
154 END_FIELDS = ORDINAL_FIELDS_END,
155 FIELD_COUNT = END_FIELDS,
147 // Past this point we have temporaries, stored in memory only. 156 // Past this point we have temporaries, stored in memory only.
148 BEGIN_TEMPS = PROTO_FIELDS_END, 157 BEGIN_TEMPS = ORDINAL_FIELDS_END,
149 BIT_TEMPS_BEGIN = BEGIN_TEMPS, 158 BIT_TEMPS_BEGIN = BEGIN_TEMPS,
150 }; 159 };
151 160
152 enum BitTemp { 161 enum BitTemp {
153 // Not to be confused with IS_UNSYNCED, this bit is used to detect local 162 // Not to be confused with IS_UNSYNCED, this bit is used to detect local
154 // changes to items that happen during the server Commit operation. 163 // changes to items that happen during the server Commit operation.
155 SYNCING = BIT_TEMPS_BEGIN, 164 SYNCING = BIT_TEMPS_BEGIN,
156 BIT_TEMPS_END, 165 BIT_TEMPS_END,
157 }; 166 };
158 167
159 enum { 168 enum {
160 BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN 169 BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN
161 }; 170 };
162 171
163 enum { 172 enum {
164 PROTO_FIELDS_COUNT = PROTO_FIELDS_END - PROTO_FIELDS_BEGIN 173 PROTO_FIELDS_COUNT = PROTO_FIELDS_END - PROTO_FIELDS_BEGIN
165 }; 174 };
166 175
167 176
168 struct EntryKernel { 177 struct EntryKernel {
169 private: 178 private:
170 std::string string_fields[STRING_FIELDS_COUNT]; 179 std::string string_fields[STRING_FIELDS_COUNT];
171 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT]; 180 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT];
172 int64 int64_fields[INT64_FIELDS_COUNT]; 181 int64 int64_fields[INT64_FIELDS_COUNT];
173 base::Time time_fields[TIME_FIELDS_COUNT]; 182 base::Time time_fields[TIME_FIELDS_COUNT];
174 Id id_fields[ID_FIELDS_COUNT]; 183 Id id_fields[ID_FIELDS_COUNT];
184 NodeOrdinal ordinal_fields[ORDINAL_FIELDS_COUNT];
175 std::bitset<BIT_FIELDS_COUNT> bit_fields; 185 std::bitset<BIT_FIELDS_COUNT> bit_fields;
176 std::bitset<BIT_TEMPS_COUNT> bit_temps; 186 std::bitset<BIT_TEMPS_COUNT> bit_temps;
177 187
178 public: 188 public:
179 EntryKernel(); 189 EntryKernel();
180 ~EntryKernel(); 190 ~EntryKernel();
181 191
182 // Set the dirty bit, and optionally add this entry's metahandle to 192 // Set the dirty bit, and optionally add this entry's metahandle to
183 // a provided index on dirty bits in |dirty_index|. Parameter may be null, 193 // a provided index on dirty bits in |dirty_index|. Parameter may be null,
184 // and will result only in setting the dirty bit of this entry. 194 // and will result only in setting the dirty bit of this entry.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 242 }
233 inline void put(BitField field, bool value) { 243 inline void put(BitField field, bool value) {
234 bit_fields[field - BIT_FIELDS_BEGIN] = value; 244 bit_fields[field - BIT_FIELDS_BEGIN] = value;
235 } 245 }
236 inline void put(StringField field, const std::string& value) { 246 inline void put(StringField field, const std::string& value) {
237 string_fields[field - STRING_FIELDS_BEGIN] = value; 247 string_fields[field - STRING_FIELDS_BEGIN] = value;
238 } 248 }
239 inline void put(ProtoField field, const sync_pb::EntitySpecifics& value) { 249 inline void put(ProtoField field, const sync_pb::EntitySpecifics& value) {
240 specifics_fields[field - PROTO_FIELDS_BEGIN].CopyFrom(value); 250 specifics_fields[field - PROTO_FIELDS_BEGIN].CopyFrom(value);
241 } 251 }
252 inline void put(OrdinalField field, const NodeOrdinal& value) {
253 ordinal_fields[field - ORDINAL_FIELDS_BEGIN] = value;
254 }
242 inline void put(BitTemp field, bool value) { 255 inline void put(BitTemp field, bool value) {
243 bit_temps[field - BIT_TEMPS_BEGIN] = value; 256 bit_temps[field - BIT_TEMPS_BEGIN] = value;
244 } 257 }
245 258
246 // Const ref getters. 259 // Const ref getters.
247 inline int64 ref(MetahandleField field) const { 260 inline int64 ref(MetahandleField field) const {
248 return int64_fields[field - INT64_FIELDS_BEGIN]; 261 return int64_fields[field - INT64_FIELDS_BEGIN];
249 } 262 }
250 inline int64 ref(Int64Field field) const { 263 inline int64 ref(Int64Field field) const {
251 return int64_fields[field - INT64_FIELDS_BEGIN]; 264 return int64_fields[field - INT64_FIELDS_BEGIN];
(...skipping 15 matching lines...) Expand all
267 } 280 }
268 inline bool ref(BitField field) const { 281 inline bool ref(BitField field) const {
269 return bit_fields[field - BIT_FIELDS_BEGIN]; 282 return bit_fields[field - BIT_FIELDS_BEGIN];
270 } 283 }
271 inline const std::string& ref(StringField field) const { 284 inline const std::string& ref(StringField field) const {
272 return string_fields[field - STRING_FIELDS_BEGIN]; 285 return string_fields[field - STRING_FIELDS_BEGIN];
273 } 286 }
274 inline const sync_pb::EntitySpecifics& ref(ProtoField field) const { 287 inline const sync_pb::EntitySpecifics& ref(ProtoField field) const {
275 return specifics_fields[field - PROTO_FIELDS_BEGIN]; 288 return specifics_fields[field - PROTO_FIELDS_BEGIN];
276 } 289 }
290 inline const NodeOrdinal& ref(OrdinalField field) const {
291 return ordinal_fields[field - ORDINAL_FIELDS_BEGIN];
292 }
277 inline bool ref(BitTemp field) const { 293 inline bool ref(BitTemp field) const {
278 return bit_temps[field - BIT_TEMPS_BEGIN]; 294 return bit_temps[field - BIT_TEMPS_BEGIN];
279 } 295 }
280 296
281 // Non-const, mutable ref getters for object types only. 297 // Non-const, mutable ref getters for object types only.
282 inline std::string& mutable_ref(StringField field) { 298 inline std::string& mutable_ref(StringField field) {
283 return string_fields[field - STRING_FIELDS_BEGIN]; 299 return string_fields[field - STRING_FIELDS_BEGIN];
284 } 300 }
285 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) { 301 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) {
286 return specifics_fields[field - PROTO_FIELDS_BEGIN]; 302 return specifics_fields[field - PROTO_FIELDS_BEGIN];
287 } 303 }
288 inline Id& mutable_ref(IdField field) { 304 inline Id& mutable_ref(IdField field) {
289 return id_fields[field - ID_FIELDS_BEGIN]; 305 return id_fields[field - ID_FIELDS_BEGIN];
290 } 306 }
307 inline NodeOrdinal& mutable_ref(OrdinalField field) {
308 return ordinal_fields[field - ORDINAL_FIELDS_BEGIN];
309 }
291 310
292 ModelType GetServerModelType() const; 311 ModelType GetServerModelType() const;
293 312
294 // Dumps all kernel info into a DictionaryValue and returns it. 313 // Dumps all kernel info into a DictionaryValue and returns it.
295 // Transfers ownership of the DictionaryValue to the caller. 314 // Transfers ownership of the DictionaryValue to the caller.
296 base::DictionaryValue* ToValue() const; 315 base::DictionaryValue* ToValue() const;
297 316
298 private: 317 private:
299 // Tracks whether this entry needs to be saved to the database. 318 // Tracks whether this entry needs to be saved to the database.
300 bool dirty_; 319 bool dirty_;
(...skipping 12 matching lines...) Expand all
313 const EntryKernelMutation& mutation); 332 const EntryKernelMutation& mutation);
314 333
315 // Caller owns the return value. 334 // Caller owns the return value.
316 base::ListValue* EntryKernelMutationMapToValue( 335 base::ListValue* EntryKernelMutationMapToValue(
317 const EntryKernelMutationMap& mutations); 336 const EntryKernelMutationMap& mutations);
318 337
319 } // namespace syncable 338 } // namespace syncable
320 } // namespace syncer 339 } // namespace syncer
321 340
322 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_ 341 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698