| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 COMPONENTS_SYNC_SYNCABLE_ENTRY_KERNEL_H_ |
| 6 #define SYNC_SYNCABLE_ENTRY_KERNEL_H_ | 6 #define COMPONENTS_SYNC_SYNCABLE_ENTRY_KERNEL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "sync/base/sync_export.h" | 17 #include "components/sync/base/immutable.h" |
| 18 #include "sync/internal_api/public/base/model_type.h" | 18 #include "components/sync/base/model_type.h" |
| 19 #include "sync/internal_api/public/base/unique_position.h" | 19 #include "components/sync/base/proto_value_ptr.h" |
| 20 #include "sync/internal_api/public/util/immutable.h" | 20 #include "components/sync/base/sync_export.h" |
| 21 #include "sync/internal_api/public/util/proto_value_ptr.h" | 21 #include "components/sync/base/time.h" |
| 22 #include "sync/protocol/attachments.pb.h" | 22 #include "components/sync/base/unique_position.h" |
| 23 #include "sync/protocol/sync.pb.h" | 23 #include "components/sync/protocol/attachments.pb.h" |
| 24 #include "sync/syncable/metahandle_set.h" | 24 #include "components/sync/protocol/sync.pb.h" |
| 25 #include "sync/syncable/syncable_id.h" | 25 #include "components/sync/syncable/metahandle_set.h" |
| 26 #include "sync/util/time.h" | 26 #include "components/sync/syncable/syncable_id.h" |
| 27 | 27 |
| 28 namespace syncer { | 28 namespace syncer { |
| 29 | 29 |
| 30 class Cryptographer; | 30 class Cryptographer; |
| 31 | 31 |
| 32 namespace syncable { | 32 namespace syncable { |
| 33 | 33 |
| 34 // Things you need to update if you change any of the fields below: | 34 // Things you need to update if you change any of the fields below: |
| 35 // - EntryKernel struct in this file | 35 // - EntryKernel struct in this file |
| 36 // - syncable_columns.h | 36 // - syncable_columns.h |
| 37 // - syncable_enum_conversions{.h,.cc,_unittest.cc} | 37 // - syncable_enum_conversions{.h,.cc,_unittest.cc} |
| 38 // - EntryKernel::EntryKernel(), EntryKernel::ToValue() in entry_kernel.cc | 38 // - EntryKernel::EntryKernel(), EntryKernel::ToValue() in entry_kernel.cc |
| 39 // - operator<< in Entry.cc | 39 // - operator<< in Entry.cc |
| 40 // - BindFields() and UnpackEntry() in directory_backing_store.cc | 40 // - BindFields() and UnpackEntry() in directory_backing_store.cc |
| 41 // - kCurrentDBVersion, DirectoryBackingStore::InitializeTables in | 41 // - kCurrentDBVersion, DirectoryBackingStore::InitializeTables in |
| 42 // directory_backing_store.cc | 42 // directory_backing_store.cc |
| 43 // - TestSimpleFieldsPreservedDuringSaveChanges in syncable_unittest.cc | 43 // - TestSimpleFieldsPreservedDuringSaveChanges in syncable_unittest.cc |
| 44 | 44 |
| 45 static const int64_t kInvalidMetaHandle = 0; | 45 static const int64_t kInvalidMetaHandle = 0; |
| 46 | 46 |
| 47 enum { | 47 enum { BEGIN_FIELDS = 0, INT64_FIELDS_BEGIN = BEGIN_FIELDS }; |
| 48 BEGIN_FIELDS = 0, | |
| 49 INT64_FIELDS_BEGIN = BEGIN_FIELDS | |
| 50 }; | |
| 51 | 48 |
| 52 enum MetahandleField { | 49 enum MetahandleField { |
| 53 // Primary key into the table. Keep this as a handle to the meta entry | 50 // Primary key into the table. Keep this as a handle to the meta entry |
| 54 // across transactions. | 51 // across transactions. |
| 55 META_HANDLE = INT64_FIELDS_BEGIN | 52 META_HANDLE = INT64_FIELDS_BEGIN |
| 56 }; | 53 }; |
| 57 | 54 |
| 58 enum BaseVersion { | 55 enum BaseVersion { |
| 59 // After initial upload, the version is controlled by the server, and is | 56 // After initial upload, the version is controlled by the server, and is |
| 60 // increased whenever the data or metadata changes on the server. | 57 // increased whenever the data or metadata changes on the server. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // Whether a server commit operation was started and has not yet completed | 184 // Whether a server commit operation was started and has not yet completed |
| 188 // for this entity. | 185 // for this entity. |
| 189 SYNCING = BIT_TEMPS_BEGIN, | 186 SYNCING = BIT_TEMPS_BEGIN, |
| 190 // Whether a local change was made to an entity that had SYNCING set to true, | 187 // Whether a local change was made to an entity that had SYNCING set to true, |
| 191 // and was therefore in the middle of a commit operation. | 188 // and was therefore in the middle of a commit operation. |
| 192 // Note: must only be set if SYNCING is true. | 189 // Note: must only be set if SYNCING is true. |
| 193 DIRTY_SYNC, | 190 DIRTY_SYNC, |
| 194 BIT_TEMPS_END, | 191 BIT_TEMPS_END, |
| 195 }; | 192 }; |
| 196 | 193 |
| 197 enum { | 194 enum { BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN }; |
| 198 BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN | |
| 199 }; | |
| 200 | 195 |
| 201 struct SYNC_EXPORT EntryKernel { | 196 struct SYNC_EXPORT EntryKernel { |
| 202 private: | 197 private: |
| 203 typedef syncer::ProtoValuePtr<sync_pb::EntitySpecifics> EntitySpecificsPtr; | 198 typedef syncer::ProtoValuePtr<sync_pb::EntitySpecifics> EntitySpecificsPtr; |
| 204 typedef syncer::ProtoValuePtr<sync_pb::AttachmentMetadata> | 199 typedef syncer::ProtoValuePtr<sync_pb::AttachmentMetadata> |
| 205 AttachmentMetadataPtr; | 200 AttachmentMetadataPtr; |
| 206 | 201 |
| 207 std::string string_fields[STRING_FIELDS_COUNT]; | 202 std::string string_fields[STRING_FIELDS_COUNT]; |
| 208 EntitySpecificsPtr specifics_fields[PROTO_FIELDS_COUNT]; | 203 EntitySpecificsPtr specifics_fields[PROTO_FIELDS_COUNT]; |
| 209 int64_t int64_fields[INT64_FIELDS_COUNT]; | 204 int64_t int64_fields[INT64_FIELDS_COUNT]; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 237 // a provided index on dirty bits in |dirty_index|. Parameter may be null, | 232 // a provided index on dirty bits in |dirty_index|. Parameter may be null, |
| 238 // and will result only in clearing dirty bit of this entry. | 233 // and will result only in clearing dirty bit of this entry. |
| 239 inline void clear_dirty(syncable::MetahandleSet* dirty_index) { | 234 inline void clear_dirty(syncable::MetahandleSet* dirty_index) { |
| 240 if (dirty_ && dirty_index) { | 235 if (dirty_ && dirty_index) { |
| 241 DCHECK_NE(0, ref(META_HANDLE)); | 236 DCHECK_NE(0, ref(META_HANDLE)); |
| 242 dirty_index->erase(ref(META_HANDLE)); | 237 dirty_index->erase(ref(META_HANDLE)); |
| 243 } | 238 } |
| 244 dirty_ = false; | 239 dirty_ = false; |
| 245 } | 240 } |
| 246 | 241 |
| 247 inline bool is_dirty() const { | 242 inline bool is_dirty() const { return dirty_; } |
| 248 return dirty_; | |
| 249 } | |
| 250 | 243 |
| 251 // Setters. | 244 // Setters. |
| 252 inline void put(MetahandleField field, int64_t value) { | 245 inline void put(MetahandleField field, int64_t value) { |
| 253 int64_fields[field - INT64_FIELDS_BEGIN] = value; | 246 int64_fields[field - INT64_FIELDS_BEGIN] = value; |
| 254 } | 247 } |
| 255 inline void put(Int64Field field, int64_t value) { | 248 inline void put(Int64Field field, int64_t value) { |
| 256 int64_fields[field - INT64_FIELDS_BEGIN] = value; | 249 int64_fields[field - INT64_FIELDS_BEGIN] = value; |
| 257 } | 250 } |
| 258 inline void put(TimeField field, const base::Time& value) { | 251 inline void put(TimeField field, const base::Time& value) { |
| 259 // Round-trip to proto time format and back so that we have | 252 // Round-trip to proto time format and back so that we have |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 // they will be serialized as empty proto's. | 378 // they will be serialized as empty proto's. |
| 386 base::DictionaryValue* ToValue(Cryptographer* cryptographer) const; | 379 base::DictionaryValue* ToValue(Cryptographer* cryptographer) const; |
| 387 | 380 |
| 388 private: | 381 private: |
| 389 // Tracks whether this entry needs to be saved to the database. | 382 // Tracks whether this entry needs to be saved to the database. |
| 390 bool dirty_; | 383 bool dirty_; |
| 391 }; | 384 }; |
| 392 | 385 |
| 393 class EntryKernelLessByMetaHandle { | 386 class EntryKernelLessByMetaHandle { |
| 394 public: | 387 public: |
| 395 inline bool operator()(const EntryKernel* a, | 388 inline bool operator()(const EntryKernel* a, const EntryKernel* b) const { |
| 396 const EntryKernel* b) const { | |
| 397 return a->ref(META_HANDLE) < b->ref(META_HANDLE); | 389 return a->ref(META_HANDLE) < b->ref(META_HANDLE); |
| 398 } | 390 } |
| 399 }; | 391 }; |
| 400 | 392 |
| 401 typedef std::set<const EntryKernel*, EntryKernelLessByMetaHandle> | 393 typedef std::set<const EntryKernel*, EntryKernelLessByMetaHandle> |
| 402 EntryKernelSet; | 394 EntryKernelSet; |
| 403 | 395 |
| 404 struct EntryKernelMutation { | 396 struct EntryKernelMutation { |
| 405 EntryKernel original, mutated; | 397 EntryKernel original, mutated; |
| 406 }; | 398 }; |
| 407 | 399 |
| 408 typedef std::map<int64_t, EntryKernelMutation> EntryKernelMutationMap; | 400 typedef std::map<int64_t, EntryKernelMutation> EntryKernelMutationMap; |
| 409 | 401 |
| 410 typedef Immutable<EntryKernelMutationMap> ImmutableEntryKernelMutationMap; | 402 typedef Immutable<EntryKernelMutationMap> ImmutableEntryKernelMutationMap; |
| 411 | 403 |
| 412 // Caller owns the return value. | 404 // Caller owns the return value. |
| 413 base::DictionaryValue* EntryKernelMutationToValue( | 405 base::DictionaryValue* EntryKernelMutationToValue( |
| 414 const EntryKernelMutation& mutation); | 406 const EntryKernelMutation& mutation); |
| 415 | 407 |
| 416 // Caller owns the return value. | 408 // Caller owns the return value. |
| 417 base::ListValue* EntryKernelMutationMapToValue( | 409 base::ListValue* EntryKernelMutationMapToValue( |
| 418 const EntryKernelMutationMap& mutations); | 410 const EntryKernelMutationMap& mutations); |
| 419 | 411 |
| 420 std::ostream& operator<<(std::ostream& os, const EntryKernel& entry_kernel); | 412 std::ostream& operator<<(std::ostream& os, const EntryKernel& entry_kernel); |
| 421 | 413 |
| 422 } // namespace syncable | 414 } // namespace syncable |
| 423 } // namespace syncer | 415 } // namespace syncer |
| 424 | 416 |
| 425 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_ | 417 #endif // COMPONENTS_SYNC_SYNCABLE_ENTRY_KERNEL_H_ |
| OLD | NEW |