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

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: Fixed memory leak error in unittest 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
« no previous file with comments | « sync/syncable/entry.cc ('k') | sync/syncable/entry_kernel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 FIELD_COUNT = ORDINAL_FIELDS_END - BEGIN_FIELDS,
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 {
164 PROTO_FIELDS_COUNT = PROTO_FIELDS_END - PROTO_FIELDS_BEGIN
165 };
166 171
167 172
168 struct EntryKernel { 173 struct EntryKernel {
169 private: 174 private:
170 std::string string_fields[STRING_FIELDS_COUNT]; 175 std::string string_fields[STRING_FIELDS_COUNT];
171 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT]; 176 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT];
172 int64 int64_fields[INT64_FIELDS_COUNT]; 177 int64 int64_fields[INT64_FIELDS_COUNT];
173 base::Time time_fields[TIME_FIELDS_COUNT]; 178 base::Time time_fields[TIME_FIELDS_COUNT];
174 Id id_fields[ID_FIELDS_COUNT]; 179 Id id_fields[ID_FIELDS_COUNT];
180 NodeOrdinal ordinal_fields[ORDINAL_FIELDS_COUNT];
175 std::bitset<BIT_FIELDS_COUNT> bit_fields; 181 std::bitset<BIT_FIELDS_COUNT> bit_fields;
176 std::bitset<BIT_TEMPS_COUNT> bit_temps; 182 std::bitset<BIT_TEMPS_COUNT> bit_temps;
177 183
178 public: 184 public:
179 EntryKernel(); 185 EntryKernel();
180 ~EntryKernel(); 186 ~EntryKernel();
181 187
182 // Set the dirty bit, and optionally add this entry's metahandle to 188 // 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, 189 // 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. 190 // 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 } 238 }
233 inline void put(BitField field, bool value) { 239 inline void put(BitField field, bool value) {
234 bit_fields[field - BIT_FIELDS_BEGIN] = value; 240 bit_fields[field - BIT_FIELDS_BEGIN] = value;
235 } 241 }
236 inline void put(StringField field, const std::string& value) { 242 inline void put(StringField field, const std::string& value) {
237 string_fields[field - STRING_FIELDS_BEGIN] = value; 243 string_fields[field - STRING_FIELDS_BEGIN] = value;
238 } 244 }
239 inline void put(ProtoField field, const sync_pb::EntitySpecifics& value) { 245 inline void put(ProtoField field, const sync_pb::EntitySpecifics& value) {
240 specifics_fields[field - PROTO_FIELDS_BEGIN].CopyFrom(value); 246 specifics_fields[field - PROTO_FIELDS_BEGIN].CopyFrom(value);
241 } 247 }
248 inline void put(OrdinalField field, const NodeOrdinal& value) {
249 ordinal_fields[field - ORDINAL_FIELDS_BEGIN] = value;
250 }
242 inline void put(BitTemp field, bool value) { 251 inline void put(BitTemp field, bool value) {
243 bit_temps[field - BIT_TEMPS_BEGIN] = value; 252 bit_temps[field - BIT_TEMPS_BEGIN] = value;
244 } 253 }
245 254
246 // Const ref getters. 255 // Const ref getters.
247 inline int64 ref(MetahandleField field) const { 256 inline int64 ref(MetahandleField field) const {
248 return int64_fields[field - INT64_FIELDS_BEGIN]; 257 return int64_fields[field - INT64_FIELDS_BEGIN];
249 } 258 }
250 inline int64 ref(Int64Field field) const { 259 inline int64 ref(Int64Field field) const {
251 return int64_fields[field - INT64_FIELDS_BEGIN]; 260 return int64_fields[field - INT64_FIELDS_BEGIN];
(...skipping 15 matching lines...) Expand all
267 } 276 }
268 inline bool ref(BitField field) const { 277 inline bool ref(BitField field) const {
269 return bit_fields[field - BIT_FIELDS_BEGIN]; 278 return bit_fields[field - BIT_FIELDS_BEGIN];
270 } 279 }
271 inline const std::string& ref(StringField field) const { 280 inline const std::string& ref(StringField field) const {
272 return string_fields[field - STRING_FIELDS_BEGIN]; 281 return string_fields[field - STRING_FIELDS_BEGIN];
273 } 282 }
274 inline const sync_pb::EntitySpecifics& ref(ProtoField field) const { 283 inline const sync_pb::EntitySpecifics& ref(ProtoField field) const {
275 return specifics_fields[field - PROTO_FIELDS_BEGIN]; 284 return specifics_fields[field - PROTO_FIELDS_BEGIN];
276 } 285 }
286 inline const NodeOrdinal& ref(OrdinalField field) const {
287 return ordinal_fields[field - ORDINAL_FIELDS_BEGIN];
288 }
277 inline bool ref(BitTemp field) const { 289 inline bool ref(BitTemp field) const {
278 return bit_temps[field - BIT_TEMPS_BEGIN]; 290 return bit_temps[field - BIT_TEMPS_BEGIN];
279 } 291 }
280 292
281 // Non-const, mutable ref getters for object types only. 293 // Non-const, mutable ref getters for object types only.
282 inline std::string& mutable_ref(StringField field) { 294 inline std::string& mutable_ref(StringField field) {
283 return string_fields[field - STRING_FIELDS_BEGIN]; 295 return string_fields[field - STRING_FIELDS_BEGIN];
284 } 296 }
285 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) { 297 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) {
286 return specifics_fields[field - PROTO_FIELDS_BEGIN]; 298 return specifics_fields[field - PROTO_FIELDS_BEGIN];
287 } 299 }
288 inline Id& mutable_ref(IdField field) { 300 inline Id& mutable_ref(IdField field) {
289 return id_fields[field - ID_FIELDS_BEGIN]; 301 return id_fields[field - ID_FIELDS_BEGIN];
290 } 302 }
303 inline NodeOrdinal& mutable_ref(OrdinalField field) {
304 return ordinal_fields[field - ORDINAL_FIELDS_BEGIN];
305 }
291 306
292 ModelType GetServerModelType() const; 307 ModelType GetServerModelType() const;
293 308
294 // Dumps all kernel info into a DictionaryValue and returns it. 309 // Dumps all kernel info into a DictionaryValue and returns it.
295 // Transfers ownership of the DictionaryValue to the caller. 310 // Transfers ownership of the DictionaryValue to the caller.
296 base::DictionaryValue* ToValue() const; 311 base::DictionaryValue* ToValue() const;
297 312
298 private: 313 private:
299 // Tracks whether this entry needs to be saved to the database. 314 // Tracks whether this entry needs to be saved to the database.
300 bool dirty_; 315 bool dirty_;
(...skipping 12 matching lines...) Expand all
313 const EntryKernelMutation& mutation); 328 const EntryKernelMutation& mutation);
314 329
315 // Caller owns the return value. 330 // Caller owns the return value.
316 base::ListValue* EntryKernelMutationMapToValue( 331 base::ListValue* EntryKernelMutationMapToValue(
317 const EntryKernelMutationMap& mutations); 332 const EntryKernelMutationMap& mutations);
318 333
319 } // namespace syncable 334 } // namespace syncable
320 } // namespace syncer 335 } // namespace syncer
321 336
322 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_ 337 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_
OLDNEW
« no previous file with comments | « sync/syncable/entry.cc ('k') | sync/syncable/entry_kernel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698