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

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: Changed server_position to server_ordinal in DB 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
rlarocque 2012/10/05 19:02:55 nit: Might as well delete this line, too, to keep
vishwath 2012/10/05 21:05:48 Done.
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 FIELD_COUNT = ORDINAL_FIELDS_END,
147 // Past this point we have temporaries, stored in memory only. 155 // Past this point we have temporaries, stored in memory only.
148 BEGIN_TEMPS = PROTO_FIELDS_END, 156 BEGIN_TEMPS = ORDINAL_FIELDS_END,
149 BIT_TEMPS_BEGIN = BEGIN_TEMPS, 157 BIT_TEMPS_BEGIN = BEGIN_TEMPS,
150 }; 158 };
151 159
152 enum BitTemp { 160 enum BitTemp {
153 // Not to be confused with IS_UNSYNCED, this bit is used to detect local 161 // 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. 162 // changes to items that happen during the server Commit operation.
155 SYNCING = BIT_TEMPS_BEGIN, 163 SYNCING = BIT_TEMPS_BEGIN,
156 BIT_TEMPS_END, 164 BIT_TEMPS_END,
157 }; 165 };
158 166
159 enum { 167 enum {
160 BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN 168 BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN
161 }; 169 };
162 170
163 enum { 171 enum {
164 PROTO_FIELDS_COUNT = PROTO_FIELDS_END - PROTO_FIELDS_BEGIN 172 PROTO_FIELDS_COUNT = PROTO_FIELDS_END - PROTO_FIELDS_BEGIN
akalin 2012/10/05 00:57:59 move this line right above ORDINAL_FIELDS_BEGIN =
vishwath 2012/10/05 21:05:48 Done.
165 }; 173 };
166 174
167 175
168 struct EntryKernel { 176 struct EntryKernel {
169 private: 177 private:
170 std::string string_fields[STRING_FIELDS_COUNT]; 178 std::string string_fields[STRING_FIELDS_COUNT];
171 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT]; 179 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT];
172 int64 int64_fields[INT64_FIELDS_COUNT]; 180 int64 int64_fields[INT64_FIELDS_COUNT];
173 base::Time time_fields[TIME_FIELDS_COUNT]; 181 base::Time time_fields[TIME_FIELDS_COUNT];
174 Id id_fields[ID_FIELDS_COUNT]; 182 Id id_fields[ID_FIELDS_COUNT];
183 NodeOrdinal ordinal_fields[ORDINAL_FIELDS_COUNT];
175 std::bitset<BIT_FIELDS_COUNT> bit_fields; 184 std::bitset<BIT_FIELDS_COUNT> bit_fields;
176 std::bitset<BIT_TEMPS_COUNT> bit_temps; 185 std::bitset<BIT_TEMPS_COUNT> bit_temps;
177 186
178 public: 187 public:
179 EntryKernel(); 188 EntryKernel();
180 ~EntryKernel(); 189 ~EntryKernel();
181 190
182 // Set the dirty bit, and optionally add this entry's metahandle to 191 // 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, 192 // 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. 193 // 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 } 241 }
233 inline void put(BitField field, bool value) { 242 inline void put(BitField field, bool value) {
234 bit_fields[field - BIT_FIELDS_BEGIN] = value; 243 bit_fields[field - BIT_FIELDS_BEGIN] = value;
235 } 244 }
236 inline void put(StringField field, const std::string& value) { 245 inline void put(StringField field, const std::string& value) {
237 string_fields[field - STRING_FIELDS_BEGIN] = value; 246 string_fields[field - STRING_FIELDS_BEGIN] = value;
238 } 247 }
239 inline void put(ProtoField field, const sync_pb::EntitySpecifics& value) { 248 inline void put(ProtoField field, const sync_pb::EntitySpecifics& value) {
240 specifics_fields[field - PROTO_FIELDS_BEGIN].CopyFrom(value); 249 specifics_fields[field - PROTO_FIELDS_BEGIN].CopyFrom(value);
241 } 250 }
251 inline void put(OrdinalField field, const NodeOrdinal& value) {
252 ordinal_fields[field - ORDINAL_FIELDS_BEGIN] = value;
253 }
242 inline void put(BitTemp field, bool value) { 254 inline void put(BitTemp field, bool value) {
243 bit_temps[field - BIT_TEMPS_BEGIN] = value; 255 bit_temps[field - BIT_TEMPS_BEGIN] = value;
244 } 256 }
245 257
246 // Const ref getters. 258 // Const ref getters.
247 inline int64 ref(MetahandleField field) const { 259 inline int64 ref(MetahandleField field) const {
248 return int64_fields[field - INT64_FIELDS_BEGIN]; 260 return int64_fields[field - INT64_FIELDS_BEGIN];
249 } 261 }
250 inline int64 ref(Int64Field field) const { 262 inline int64 ref(Int64Field field) const {
251 return int64_fields[field - INT64_FIELDS_BEGIN]; 263 return int64_fields[field - INT64_FIELDS_BEGIN];
(...skipping 15 matching lines...) Expand all
267 } 279 }
268 inline bool ref(BitField field) const { 280 inline bool ref(BitField field) const {
269 return bit_fields[field - BIT_FIELDS_BEGIN]; 281 return bit_fields[field - BIT_FIELDS_BEGIN];
270 } 282 }
271 inline const std::string& ref(StringField field) const { 283 inline const std::string& ref(StringField field) const {
272 return string_fields[field - STRING_FIELDS_BEGIN]; 284 return string_fields[field - STRING_FIELDS_BEGIN];
273 } 285 }
274 inline const sync_pb::EntitySpecifics& ref(ProtoField field) const { 286 inline const sync_pb::EntitySpecifics& ref(ProtoField field) const {
275 return specifics_fields[field - PROTO_FIELDS_BEGIN]; 287 return specifics_fields[field - PROTO_FIELDS_BEGIN];
276 } 288 }
289 inline const NodeOrdinal& ref(OrdinalField field) const {
290 return ordinal_fields[field - ORDINAL_FIELDS_BEGIN];
291 }
277 inline bool ref(BitTemp field) const { 292 inline bool ref(BitTemp field) const {
278 return bit_temps[field - BIT_TEMPS_BEGIN]; 293 return bit_temps[field - BIT_TEMPS_BEGIN];
279 } 294 }
280 295
281 // Non-const, mutable ref getters for object types only. 296 // Non-const, mutable ref getters for object types only.
282 inline std::string& mutable_ref(StringField field) { 297 inline std::string& mutable_ref(StringField field) {
283 return string_fields[field - STRING_FIELDS_BEGIN]; 298 return string_fields[field - STRING_FIELDS_BEGIN];
284 } 299 }
285 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) { 300 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) {
286 return specifics_fields[field - PROTO_FIELDS_BEGIN]; 301 return specifics_fields[field - PROTO_FIELDS_BEGIN];
287 } 302 }
288 inline Id& mutable_ref(IdField field) { 303 inline Id& mutable_ref(IdField field) {
289 return id_fields[field - ID_FIELDS_BEGIN]; 304 return id_fields[field - ID_FIELDS_BEGIN];
290 } 305 }
306 inline NodeOrdinal& mutable_ref(OrdinalField field) {
307 return ordinal_fields[field - ORDINAL_FIELDS_BEGIN];
308 }
291 309
292 ModelType GetServerModelType() const; 310 ModelType GetServerModelType() const;
293 311
294 // Dumps all kernel info into a DictionaryValue and returns it. 312 // Dumps all kernel info into a DictionaryValue and returns it.
295 // Transfers ownership of the DictionaryValue to the caller. 313 // Transfers ownership of the DictionaryValue to the caller.
296 base::DictionaryValue* ToValue() const; 314 base::DictionaryValue* ToValue() const;
297 315
298 private: 316 private:
299 // Tracks whether this entry needs to be saved to the database. 317 // Tracks whether this entry needs to be saved to the database.
300 bool dirty_; 318 bool dirty_;
(...skipping 12 matching lines...) Expand all
313 const EntryKernelMutation& mutation); 331 const EntryKernelMutation& mutation);
314 332
315 // Caller owns the return value. 333 // Caller owns the return value.
316 base::ListValue* EntryKernelMutationMapToValue( 334 base::ListValue* EntryKernelMutationMapToValue(
317 const EntryKernelMutationMap& mutations); 335 const EntryKernelMutationMap& mutations);
318 336
319 } // namespace syncable 337 } // namespace syncable
320 } // namespace syncer 338 } // namespace syncer
321 339
322 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_ 340 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698