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

Side by Side Diff: chrome/browser/sync/syncable/syncable.h

Issue 7977034: Revert 102184 - [Sync] use base::Time in sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 5 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <bitset> 10 #include <bitset>
(...skipping 16 matching lines...) Expand all
27 #include "base/synchronization/lock.h" 27 #include "base/synchronization/lock.h"
28 #include "base/time.h" 28 #include "base/time.h"
29 #include "chrome/browser/sync/protocol/sync.pb.h" 29 #include "chrome/browser/sync/protocol/sync.pb.h"
30 #include "chrome/browser/sync/syncable/blob.h" 30 #include "chrome/browser/sync/syncable/blob.h"
31 #include "chrome/browser/sync/syncable/dir_open_result.h" 31 #include "chrome/browser/sync/syncable/dir_open_result.h"
32 #include "chrome/browser/sync/syncable/directory_event.h" 32 #include "chrome/browser/sync/syncable/directory_event.h"
33 #include "chrome/browser/sync/syncable/syncable_id.h" 33 #include "chrome/browser/sync/syncable/syncable_id.h"
34 #include "chrome/browser/sync/syncable/model_type.h" 34 #include "chrome/browser/sync/syncable/model_type.h"
35 #include "chrome/browser/sync/util/dbgq.h" 35 #include "chrome/browser/sync/util/dbgq.h"
36 #include "chrome/browser/sync/util/immutable.h" 36 #include "chrome/browser/sync/util/immutable.h"
37 #include "chrome/browser/sync/util/time.h"
38 37
39 struct PurgeInfo; 38 struct PurgeInfo;
40 39
41 namespace base { 40 namespace base {
42 class DictionaryValue; 41 class DictionaryValue;
43 class ListValue; 42 class ListValue;
44 } 43 }
45 44
46 namespace sync_api { 45 namespace sync_api {
47 class ReadTransaction; 46 class ReadTransaction;
48 class WriteNode; 47 class WriteNode;
49 class ReadNode; 48 class ReadNode;
50 } // sync_api 49 } // sync_api
51 50
52 namespace syncable { 51 namespace syncable {
53 class DirectoryChangeDelegate; 52 class DirectoryChangeDelegate;
54 class TransactionObserver; 53 class TransactionObserver;
55 class Entry; 54 class Entry;
56 55
57 std::ostream& operator<<(std::ostream& s, const Entry& e); 56 std::ostream& operator<<(std::ostream& s, const Entry& e);
58 57
59 class DirectoryBackingStore; 58 class DirectoryBackingStore;
60 59
61 static const int64 kInvalidMetaHandle = 0; 60 static const int64 kInvalidMetaHandle = 0;
62 61
63 // Things you need to update if you change any of the fields below: 62 // Update syncable_enum_conversions{.h,.cc,_unittest.cc} if you change
64 // - EntryKernel struct in syncable.h (this file) 63 // any fields in this file.
65 // - syncable_columns.h
66 // - syncable_enum_conversions{.h,.cc,_unittest.cc}
67 // - EntryKernel::EntryKernel(), EntryKernel::ToValue(), operator<<
68 // for Entry in syncable.cc
69 // - BindFields() and UnpackEntry() in directory_backing_store.cc
70 // - TestSimpleFieldsPreservedDuringSaveChanges in syncable_unittest.cc
71 64
72 enum { 65 enum {
73 BEGIN_FIELDS = 0, 66 BEGIN_FIELDS = 0,
74 INT64_FIELDS_BEGIN = BEGIN_FIELDS 67 INT64_FIELDS_BEGIN = BEGIN_FIELDS
75 }; 68 };
76 69
77 enum MetahandleField { 70 enum MetahandleField {
78 // Primary key into the table. Keep this as a handle to the meta entry 71 // Primary key into the table. Keep this as a handle to the meta entry
79 // across transactions. 72 // across transactions.
80 META_HANDLE = INT64_FIELDS_BEGIN 73 META_HANDLE = INT64_FIELDS_BEGIN
81 }; 74 };
82 75
83 enum BaseVersion { 76 enum BaseVersion {
84 // After initial upload, the version is controlled by the server, and is 77 // After initial upload, the version is controlled by the server, and is
85 // increased whenever the data or metadata changes on the server. 78 // increased whenever the data or metadata changes on the server.
86 BASE_VERSION = META_HANDLE + 1, 79 BASE_VERSION = META_HANDLE + 1,
87 }; 80 };
88 81
89 enum Int64Field { 82 enum Int64Field {
90 SERVER_VERSION = BASE_VERSION + 1, 83 SERVER_VERSION = BASE_VERSION + 1,
84 MTIME,
85 SERVER_MTIME,
86 CTIME,
87 SERVER_CTIME,
91 88
92 // A numeric position value that indicates the relative ordering of 89 // A numeric position value that indicates the relative ordering of
93 // this object among its siblings. 90 // this object among its siblings.
94 SERVER_POSITION_IN_PARENT, 91 SERVER_POSITION_IN_PARENT,
95 92
96 LOCAL_EXTERNAL_ID, // ID of an item in the external local storage that this 93 LOCAL_EXTERNAL_ID, // ID of an item in the external local storage that this
97 // entry is associated with. (such as bookmarks.js) 94 // entry is associated with. (such as bookmarks.js)
98 95
99 INT64_FIELDS_END 96 INT64_FIELDS_END
100 }; 97 };
101 98
102 enum { 99 enum {
103 INT64_FIELDS_COUNT = INT64_FIELDS_END - INT64_FIELDS_BEGIN, 100 INT64_FIELDS_COUNT = INT64_FIELDS_END,
104 TIME_FIELDS_BEGIN = INT64_FIELDS_END, 101 ID_FIELDS_BEGIN = INT64_FIELDS_END,
105 };
106
107 enum TimeField {
108 MTIME = TIME_FIELDS_BEGIN,
109 SERVER_MTIME,
110 CTIME,
111 SERVER_CTIME,
112 TIME_FIELDS_END,
113 };
114
115 enum {
116 TIME_FIELDS_COUNT = TIME_FIELDS_END - TIME_FIELDS_BEGIN,
117 ID_FIELDS_BEGIN = TIME_FIELDS_END,
118 }; 102 };
119 103
120 enum IdField { 104 enum IdField {
121 // Code in InitializeTables relies on ID being the first IdField value. 105 // Code in InitializeTables relies on ID being the first IdField value.
122 ID = ID_FIELDS_BEGIN, 106 ID = ID_FIELDS_BEGIN,
123 PARENT_ID, 107 PARENT_ID,
124 SERVER_PARENT_ID, 108 SERVER_PARENT_ID,
125 109
126 PREV_ID, 110 PREV_ID,
127 NEXT_ID, 111 NEXT_ID,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 230
247 // Why the singular enums? So the code compile-time dispatches instead of 231 // Why the singular enums? So the code compile-time dispatches instead of
248 // runtime dispatches as it would with a single enum and an if() statement. 232 // runtime dispatches as it would with a single enum and an if() statement.
249 233
250 // The EntryKernel class contains the actual data for an entry. 234 // The EntryKernel class contains the actual data for an entry.
251 struct EntryKernel { 235 struct EntryKernel {
252 private: 236 private:
253 std::string string_fields[STRING_FIELDS_COUNT]; 237 std::string string_fields[STRING_FIELDS_COUNT];
254 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT]; 238 sync_pb::EntitySpecifics specifics_fields[PROTO_FIELDS_COUNT];
255 int64 int64_fields[INT64_FIELDS_COUNT]; 239 int64 int64_fields[INT64_FIELDS_COUNT];
256 base::Time time_fields[TIME_FIELDS_COUNT];
257 Id id_fields[ID_FIELDS_COUNT]; 240 Id id_fields[ID_FIELDS_COUNT];
258 std::bitset<BIT_FIELDS_COUNT> bit_fields; 241 std::bitset<BIT_FIELDS_COUNT> bit_fields;
259 std::bitset<BIT_TEMPS_COUNT> bit_temps; 242 std::bitset<BIT_TEMPS_COUNT> bit_temps;
260 243
261 public: 244 public:
262 EntryKernel(); 245 EntryKernel();
263 ~EntryKernel(); 246 ~EntryKernel();
264 247
265 // Set the dirty bit, and optionally add this entry's metahandle to 248 // Set the dirty bit, and optionally add this entry's metahandle to
266 // a provided index on dirty bits in |dirty_index|. Parameter may be null, 249 // a provided index on dirty bits in |dirty_index|. Parameter may be null,
(...skipping 21 matching lines...) Expand all
288 return dirty_; 271 return dirty_;
289 } 272 }
290 273
291 // Setters. 274 // Setters.
292 inline void put(MetahandleField field, int64 value) { 275 inline void put(MetahandleField field, int64 value) {
293 int64_fields[field - INT64_FIELDS_BEGIN] = value; 276 int64_fields[field - INT64_FIELDS_BEGIN] = value;
294 } 277 }
295 inline void put(Int64Field field, int64 value) { 278 inline void put(Int64Field field, int64 value) {
296 int64_fields[field - INT64_FIELDS_BEGIN] = value; 279 int64_fields[field - INT64_FIELDS_BEGIN] = value;
297 } 280 }
298 inline void put(TimeField field, const base::Time& value) {
299 // Round-trip to proto time format and back so that we have
300 // consistent time resolutions (ms).
301 time_fields[field - TIME_FIELDS_BEGIN] =
302 browser_sync::ProtoTimeToTime(
303 browser_sync::TimeToProtoTime(value));
304 }
305 inline void put(IdField field, const Id& value) { 281 inline void put(IdField field, const Id& value) {
306 id_fields[field - ID_FIELDS_BEGIN] = value; 282 id_fields[field - ID_FIELDS_BEGIN] = value;
307 } 283 }
308 inline void put(BaseVersion field, int64 value) { 284 inline void put(BaseVersion field, int64 value) {
309 int64_fields[field - INT64_FIELDS_BEGIN] = value; 285 int64_fields[field - INT64_FIELDS_BEGIN] = value;
310 } 286 }
311 inline void put(IndexedBitField field, bool value) { 287 inline void put(IndexedBitField field, bool value) {
312 bit_fields[field - BIT_FIELDS_BEGIN] = value; 288 bit_fields[field - BIT_FIELDS_BEGIN] = value;
313 } 289 }
314 inline void put(IsDelField field, bool value) { 290 inline void put(IsDelField field, bool value) {
(...skipping 12 matching lines...) Expand all
327 bit_temps[field - BIT_TEMPS_BEGIN] = value; 303 bit_temps[field - BIT_TEMPS_BEGIN] = value;
328 } 304 }
329 305
330 // Const ref getters. 306 // Const ref getters.
331 inline int64 ref(MetahandleField field) const { 307 inline int64 ref(MetahandleField field) const {
332 return int64_fields[field - INT64_FIELDS_BEGIN]; 308 return int64_fields[field - INT64_FIELDS_BEGIN];
333 } 309 }
334 inline int64 ref(Int64Field field) const { 310 inline int64 ref(Int64Field field) const {
335 return int64_fields[field - INT64_FIELDS_BEGIN]; 311 return int64_fields[field - INT64_FIELDS_BEGIN];
336 } 312 }
337 inline const base::Time& ref(TimeField field) const {
338 return time_fields[field - TIME_FIELDS_BEGIN];
339 }
340 inline const Id& ref(IdField field) const { 313 inline const Id& ref(IdField field) const {
341 return id_fields[field - ID_FIELDS_BEGIN]; 314 return id_fields[field - ID_FIELDS_BEGIN];
342 } 315 }
343 inline int64 ref(BaseVersion field) const { 316 inline int64 ref(BaseVersion field) const {
344 return int64_fields[field - INT64_FIELDS_BEGIN]; 317 return int64_fields[field - INT64_FIELDS_BEGIN];
345 } 318 }
346 inline bool ref(IndexedBitField field) const { 319 inline bool ref(IndexedBitField field) const {
347 return bit_fields[field - BIT_FIELDS_BEGIN]; 320 return bit_fields[field - BIT_FIELDS_BEGIN];
348 } 321 }
349 inline bool ref(IsDelField field) const { 322 inline bool ref(IsDelField field) const {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 return kernel_->ref(field); 382 return kernel_->ref(field);
410 } 383 }
411 inline Id Get(IdField field) const { 384 inline Id Get(IdField field) const {
412 DCHECK(kernel_); 385 DCHECK(kernel_);
413 return kernel_->ref(field); 386 return kernel_->ref(field);
414 } 387 }
415 inline int64 Get(Int64Field field) const { 388 inline int64 Get(Int64Field field) const {
416 DCHECK(kernel_); 389 DCHECK(kernel_);
417 return kernel_->ref(field); 390 return kernel_->ref(field);
418 } 391 }
419 inline const base::Time& Get(TimeField field) const {
420 DCHECK(kernel_);
421 return kernel_->ref(field);
422 }
423 inline int64 Get(BaseVersion field) const { 392 inline int64 Get(BaseVersion field) const {
424 DCHECK(kernel_); 393 DCHECK(kernel_);
425 return kernel_->ref(field); 394 return kernel_->ref(field);
426 } 395 }
427 inline bool Get(IndexedBitField field) const { 396 inline bool Get(IndexedBitField field) const {
428 DCHECK(kernel_); 397 DCHECK(kernel_);
429 return kernel_->ref(field); 398 return kernel_->ref(field);
430 } 399 }
431 inline bool Get(IsDelField field) const { 400 inline bool Get(IsDelField field) const {
432 DCHECK(kernel_); 401 DCHECK(kernel_);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 483
515 inline WriteTransaction* write_transaction() const { 484 inline WriteTransaction* write_transaction() const {
516 return write_transaction_; 485 return write_transaction_;
517 } 486 }
518 487
519 // Field Accessors. Some of them trigger the re-indexing of the entry. 488 // Field Accessors. Some of them trigger the re-indexing of the entry.
520 // Return true on success, return false on failure, which means 489 // Return true on success, return false on failure, which means
521 // that putting the value would have caused a duplicate in the index. 490 // that putting the value would have caused a duplicate in the index.
522 // TODO(chron): Remove some of these unecessary return values. 491 // TODO(chron): Remove some of these unecessary return values.
523 bool Put(Int64Field field, const int64& value); 492 bool Put(Int64Field field, const int64& value);
524 bool Put(TimeField field, const base::Time& value);
525 bool Put(IdField field, const Id& value); 493 bool Put(IdField field, const Id& value);
526 494
527 // Do a simple property-only update if the PARENT_ID field. Use with caution. 495 // Do a simple property-only update if the PARENT_ID field. Use with caution.
528 // 496 //
529 // The normal Put(IS_PARENT) call will move the item to the front of the 497 // The normal Put(IS_PARENT) call will move the item to the front of the
530 // sibling order to maintain the linked list invariants when the parent 498 // sibling order to maintain the linked list invariants when the parent
531 // changes. That's usually what you want to do, but it's inappropriate 499 // changes. That's usually what you want to do, but it's inappropriate
532 // when the caller is trying to change the parent ID of a the whole set 500 // when the caller is trying to change the parent ID of a the whole set
533 // of children (e.g. because the ID changed during a commit). For those 501 // of children (e.g. because the ID changed during a commit). For those
534 // cases, there's this function. It will corrupt the sibling ordering 502 // cases, there's this function. It will corrupt the sibling ordering
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 1206
1239 // Only the original fields are filled in until |RecordMutations()|. 1207 // Only the original fields are filled in until |RecordMutations()|.
1240 // We use a mutation map instead of a kernel set to avoid copying. 1208 // We use a mutation map instead of a kernel set to avoid copying.
1241 EntryKernelMutationMap mutations_; 1209 EntryKernelMutationMap mutations_;
1242 1210
1243 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); 1211 DISALLOW_COPY_AND_ASSIGN(WriteTransaction);
1244 }; 1212 };
1245 1213
1246 bool IsLegalNewParent(BaseTransaction* trans, const Id& id, const Id& parentid); 1214 bool IsLegalNewParent(BaseTransaction* trans, const Id& id, const Id& parentid);
1247 1215
1216 int64 Now();
1217
1248 // This function sets only the flags needed to get this entry to sync. 1218 // This function sets only the flags needed to get this entry to sync.
1249 void MarkForSyncing(syncable::MutableEntry* e); 1219 void MarkForSyncing(syncable::MutableEntry* e);
1250 1220
1221 // This is not a reset. It just sets the numeric fields which are not
1222 // initialized by the constructor to zero.
1223 void ZeroFields(EntryKernel* entry, int first_field);
1224
1251 } // namespace syncable 1225 } // namespace syncable
1252 1226
1253 std::ostream& operator <<(std::ostream&, const syncable::Blob&); 1227 std::ostream& operator <<(std::ostream&, const syncable::Blob&);
1254 1228
1255 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 1229 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/directory_backing_store_unittest.cc ('k') | chrome/browser/sync/syncable/syncable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698