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

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: Added SetUpVersion81Database() fn. 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 // 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 51 LOCAL_EXTERNAL_ID, // ID of an item in the external local storage that this
56 // entry is associated with. (such as bookmarks.js) 52 // entry is associated with. (such as bookmarks.js)
57
58 INT64_FIELDS_END 53 INT64_FIELDS_END
59 }; 54 };
60 55
61 enum { 56 enum {
62 INT64_FIELDS_COUNT = INT64_FIELDS_END - INT64_FIELDS_BEGIN, 57 INT64_FIELDS_COUNT = INT64_FIELDS_END - INT64_FIELDS_BEGIN,
63 TIME_FIELDS_BEGIN = INT64_FIELDS_END, 58 TIME_FIELDS_BEGIN = INT64_FIELDS_END,
64 }; 59 };
65 60
66 enum TimeField { 61 enum TimeField {
67 MTIME = TIME_FIELDS_BEGIN, 62 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 131 // 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. 132 // seems the overhead for storing a NULL blob is very small.
138 enum ProtoField { 133 enum ProtoField {
139 SPECIFICS = PROTO_FIELDS_BEGIN, 134 SPECIFICS = PROTO_FIELDS_BEGIN,
140 SERVER_SPECIFICS, 135 SERVER_SPECIFICS,
141 BASE_SERVER_SPECIFICS, 136 BASE_SERVER_SPECIFICS,
142 PROTO_FIELDS_END, 137 PROTO_FIELDS_END,
143 }; 138 };
144 139
145 enum { 140 enum {
146 FIELD_COUNT = PROTO_FIELDS_END, 141 PROTO_FIELDS_COUNT = PROTO_FIELDS_END - PROTO_FIELDS_BEGIN,
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,
rlarocque 2012/10/08 20:48:38 Is it necessary to have both FIELD_COUNT and END_F
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 {
164 PROTO_FIELDS_COUNT = PROTO_FIELDS_END - PROTO_FIELDS_BEGIN
165 };
166 172
167 173
168 struct EntryKernel { 174 struct EntryKernel {
169 private: 175 private:
170 std::string string_fields[STRING_FIELDS_COUNT]; 176 std::string string_fields[STRING_FIELDS_COUNT];
171 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT]; 177 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT];
172 int64 int64_fields[INT64_FIELDS_COUNT]; 178 int64 int64_fields[INT64_FIELDS_COUNT];
173 base::Time time_fields[TIME_FIELDS_COUNT]; 179 base::Time time_fields[TIME_FIELDS_COUNT];
174 Id id_fields[ID_FIELDS_COUNT]; 180 Id id_fields[ID_FIELDS_COUNT];
181 NodeOrdinal ordinal_fields[ORDINAL_FIELDS_COUNT];
175 std::bitset<BIT_FIELDS_COUNT> bit_fields; 182 std::bitset<BIT_FIELDS_COUNT> bit_fields;
176 std::bitset<BIT_TEMPS_COUNT> bit_temps; 183 std::bitset<BIT_TEMPS_COUNT> bit_temps;
177 184
178 public: 185 public:
179 EntryKernel(); 186 EntryKernel();
180 ~EntryKernel(); 187 ~EntryKernel();
181 188
182 // Set the dirty bit, and optionally add this entry's metahandle to 189 // 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, 190 // 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. 191 // 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 } 239 }
233 inline void put(BitField field, bool value) { 240 inline void put(BitField field, bool value) {
234 bit_fields[field - BIT_FIELDS_BEGIN] = value; 241 bit_fields[field - BIT_FIELDS_BEGIN] = value;
235 } 242 }
236 inline void put(StringField field, const std::string& value) { 243 inline void put(StringField field, const std::string& value) {
237 string_fields[field - STRING_FIELDS_BEGIN] = value; 244 string_fields[field - STRING_FIELDS_BEGIN] = value;
238 } 245 }
239 inline void put(ProtoField field, const sync_pb::EntitySpecifics& value) { 246 inline void put(ProtoField field, const sync_pb::EntitySpecifics& value) {
240 specifics_fields[field - PROTO_FIELDS_BEGIN].CopyFrom(value); 247 specifics_fields[field - PROTO_FIELDS_BEGIN].CopyFrom(value);
241 } 248 }
249 inline void put(OrdinalField field, const NodeOrdinal& value) {
250 ordinal_fields[field - ORDINAL_FIELDS_BEGIN] = value;
251 }
242 inline void put(BitTemp field, bool value) { 252 inline void put(BitTemp field, bool value) {
243 bit_temps[field - BIT_TEMPS_BEGIN] = value; 253 bit_temps[field - BIT_TEMPS_BEGIN] = value;
244 } 254 }
245 255
246 // Const ref getters. 256 // Const ref getters.
247 inline int64 ref(MetahandleField field) const { 257 inline int64 ref(MetahandleField field) const {
248 return int64_fields[field - INT64_FIELDS_BEGIN]; 258 return int64_fields[field - INT64_FIELDS_BEGIN];
249 } 259 }
250 inline int64 ref(Int64Field field) const { 260 inline int64 ref(Int64Field field) const {
251 return int64_fields[field - INT64_FIELDS_BEGIN]; 261 return int64_fields[field - INT64_FIELDS_BEGIN];
(...skipping 15 matching lines...) Expand all
267 } 277 }
268 inline bool ref(BitField field) const { 278 inline bool ref(BitField field) const {
269 return bit_fields[field - BIT_FIELDS_BEGIN]; 279 return bit_fields[field - BIT_FIELDS_BEGIN];
270 } 280 }
271 inline const std::string& ref(StringField field) const { 281 inline const std::string& ref(StringField field) const {
272 return string_fields[field - STRING_FIELDS_BEGIN]; 282 return string_fields[field - STRING_FIELDS_BEGIN];
273 } 283 }
274 inline const sync_pb::EntitySpecifics& ref(ProtoField field) const { 284 inline const sync_pb::EntitySpecifics& ref(ProtoField field) const {
275 return specifics_fields[field - PROTO_FIELDS_BEGIN]; 285 return specifics_fields[field - PROTO_FIELDS_BEGIN];
276 } 286 }
287 inline const NodeOrdinal& ref(OrdinalField field) const {
288 return ordinal_fields[field - ORDINAL_FIELDS_BEGIN];
289 }
277 inline bool ref(BitTemp field) const { 290 inline bool ref(BitTemp field) const {
278 return bit_temps[field - BIT_TEMPS_BEGIN]; 291 return bit_temps[field - BIT_TEMPS_BEGIN];
279 } 292 }
280 293
281 // Non-const, mutable ref getters for object types only. 294 // Non-const, mutable ref getters for object types only.
282 inline std::string& mutable_ref(StringField field) { 295 inline std::string& mutable_ref(StringField field) {
283 return string_fields[field - STRING_FIELDS_BEGIN]; 296 return string_fields[field - STRING_FIELDS_BEGIN];
284 } 297 }
285 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) { 298 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) {
286 return specifics_fields[field - PROTO_FIELDS_BEGIN]; 299 return specifics_fields[field - PROTO_FIELDS_BEGIN];
287 } 300 }
288 inline Id& mutable_ref(IdField field) { 301 inline Id& mutable_ref(IdField field) {
289 return id_fields[field - ID_FIELDS_BEGIN]; 302 return id_fields[field - ID_FIELDS_BEGIN];
290 } 303 }
304 inline NodeOrdinal& mutable_ref(OrdinalField field) {
305 return ordinal_fields[field - ORDINAL_FIELDS_BEGIN];
306 }
291 307
292 ModelType GetServerModelType() const; 308 ModelType GetServerModelType() const;
293 309
294 // Dumps all kernel info into a DictionaryValue and returns it. 310 // Dumps all kernel info into a DictionaryValue and returns it.
295 // Transfers ownership of the DictionaryValue to the caller. 311 // Transfers ownership of the DictionaryValue to the caller.
296 base::DictionaryValue* ToValue() const; 312 base::DictionaryValue* ToValue() const;
297 313
298 private: 314 private:
299 // Tracks whether this entry needs to be saved to the database. 315 // Tracks whether this entry needs to be saved to the database.
300 bool dirty_; 316 bool dirty_;
(...skipping 12 matching lines...) Expand all
313 const EntryKernelMutation& mutation); 329 const EntryKernelMutation& mutation);
314 330
315 // Caller owns the return value. 331 // Caller owns the return value.
316 base::ListValue* EntryKernelMutationMapToValue( 332 base::ListValue* EntryKernelMutationMapToValue(
317 const EntryKernelMutationMap& mutations); 333 const EntryKernelMutationMap& mutations);
318 334
319 } // namespace syncable 335 } // namespace syncable
320 } // namespace syncer 336 } // namespace syncer
321 337
322 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_ 338 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698