Chromium Code Reviews| 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 SYNC_SYNCABLE_ENTRY_KERNEL_H_ |
| 6 #define SYNC_SYNCABLE_ENTRY_KERNEL_H_ | 6 #define SYNC_SYNCABLE_ENTRY_KERNEL_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "sync/base/sync_export.h" | 12 #include "sync/base/sync_export.h" |
| 13 #include "sync/internal_api/public/base/model_type.h" | 13 #include "sync/internal_api/public/base/model_type.h" |
| 14 #include "sync/internal_api/public/base/unique_position.h" | 14 #include "sync/internal_api/public/base/unique_position.h" |
| 15 #include "sync/internal_api/public/util/immutable.h" | 15 #include "sync/internal_api/public/util/immutable.h" |
| 16 #include "sync/syncable/metahandle_set.h" | 16 #include "sync/syncable/metahandle_set.h" |
| 17 #include "sync/syncable/proto_value_ptr.h" | 17 #include "sync/syncable/proto_value_ptr.h" |
| 18 #include "sync/syncable/syncable_columns.h" | |
|
stanisc
2015/08/07 18:24:04
Instead of including syncable_columns.h in entry_k
Gang Wu
2015/08/07 20:50:57
Done.
| |
| 18 #include "sync/syncable/syncable_id.h" | 19 #include "sync/syncable/syncable_id.h" |
| 19 #include "sync/util/time.h" | 20 #include "sync/util/time.h" |
| 20 | 21 |
| 21 namespace syncer { | 22 namespace syncer { |
| 22 | 23 |
| 23 class Cryptographer; | 24 class Cryptographer; |
| 24 | 25 |
| 25 namespace syncable { | 26 namespace syncable { |
| 26 | 27 |
| 27 // Things you need to update if you change any of the fields below: | 28 // Things you need to update if you change any of the fields below: |
| 28 // - EntryKernel struct in this file | 29 // - EntryKernel struct in this file |
| 29 // - syncable_columns.h | 30 // - syncable_columns.h |
| 30 // - syncable_enum_conversions{.h,.cc,_unittest.cc} | 31 // - syncable_enum_conversions{.h,.cc,_unittest.cc} |
| 31 // - EntryKernel::EntryKernel(), EntryKernel::ToValue() in entry_kernel.cc | 32 // - EntryKernel::EntryKernel(), EntryKernel::ToValue() in entry_kernel.cc |
| 32 // - operator<< in Entry.cc | 33 // - operator<< in Entry.cc |
| 33 // - BindFields() and UnpackEntry() in directory_backing_store.cc | 34 // - BindFields() and UnpackEntry() in directory_backing_store.cc |
| 34 // - kCurrentDBVersion, DirectoryBackingStore::InitializeTables in | 35 // - kCurrentDBVersion, DirectoryBackingStore::InitializeTables in |
| 35 // directory_backing_store.cc | 36 // directory_backing_store.cc |
| 36 // - TestSimpleFieldsPreservedDuringSaveChanges in syncable_unittest.cc | 37 // - TestSimpleFieldsPreservedDuringSaveChanges in syncable_unittest.cc |
| 37 | 38 |
| 38 static const int64 kInvalidMetaHandle = 0; | 39 static const int64 kInvalidMetaHandle = 0; |
| 39 | 40 |
| 40 enum { | |
| 41 BEGIN_FIELDS = 0, | |
| 42 INT64_FIELDS_BEGIN = BEGIN_FIELDS | |
| 43 }; | |
| 44 | |
| 45 enum MetahandleField { | |
| 46 // Primary key into the table. Keep this as a handle to the meta entry | |
| 47 // across transactions. | |
| 48 META_HANDLE = INT64_FIELDS_BEGIN | |
| 49 }; | |
| 50 | |
| 51 enum BaseVersion { | |
| 52 // After initial upload, the version is controlled by the server, and is | |
| 53 // increased whenever the data or metadata changes on the server. | |
| 54 BASE_VERSION = META_HANDLE + 1, | |
| 55 }; | |
| 56 | |
| 57 enum Int64Field { | |
| 58 SERVER_VERSION = BASE_VERSION + 1, | |
| 59 LOCAL_EXTERNAL_ID, // ID of an item in the external local storage that this | |
| 60 // entry is associated with. (such as bookmarks.js) | |
| 61 TRANSACTION_VERSION, | |
| 62 INT64_FIELDS_END | |
| 63 }; | |
| 64 | |
| 65 enum { | |
| 66 INT64_FIELDS_COUNT = INT64_FIELDS_END - INT64_FIELDS_BEGIN, | |
| 67 TIME_FIELDS_BEGIN = INT64_FIELDS_END, | |
| 68 }; | |
| 69 | |
| 70 enum TimeField { | |
| 71 MTIME = TIME_FIELDS_BEGIN, | |
| 72 SERVER_MTIME, | |
| 73 CTIME, | |
| 74 SERVER_CTIME, | |
| 75 TIME_FIELDS_END, | |
| 76 }; | |
| 77 | |
| 78 enum { | |
| 79 TIME_FIELDS_COUNT = TIME_FIELDS_END - TIME_FIELDS_BEGIN, | |
| 80 ID_FIELDS_BEGIN = TIME_FIELDS_END, | |
| 81 }; | |
| 82 | |
| 83 enum IdField { | |
| 84 // Code in InitializeTables relies on ID being the first IdField value. | |
| 85 ID = ID_FIELDS_BEGIN, | |
| 86 PARENT_ID, | |
| 87 SERVER_PARENT_ID, | |
| 88 ID_FIELDS_END | |
| 89 }; | |
| 90 | |
| 91 enum { | |
| 92 ID_FIELDS_COUNT = ID_FIELDS_END - ID_FIELDS_BEGIN, | |
| 93 BIT_FIELDS_BEGIN = ID_FIELDS_END | |
| 94 }; | |
| 95 | |
| 96 enum IndexedBitField { | |
| 97 IS_UNSYNCED = BIT_FIELDS_BEGIN, | |
| 98 IS_UNAPPLIED_UPDATE, | |
| 99 INDEXED_BIT_FIELDS_END, | |
| 100 }; | |
| 101 | |
| 102 enum IsDelField { | |
| 103 IS_DEL = INDEXED_BIT_FIELDS_END, | |
| 104 }; | |
| 105 | |
| 106 enum BitField { | |
| 107 IS_DIR = IS_DEL + 1, | |
| 108 SERVER_IS_DIR, | |
| 109 SERVER_IS_DEL, | |
| 110 BIT_FIELDS_END | |
| 111 }; | |
| 112 | |
| 113 enum { | |
| 114 BIT_FIELDS_COUNT = BIT_FIELDS_END - BIT_FIELDS_BEGIN, | |
| 115 STRING_FIELDS_BEGIN = BIT_FIELDS_END | |
| 116 }; | |
| 117 | |
| 118 enum StringField { | |
| 119 // Name, will be truncated by server. Can be duplicated in a folder. | |
| 120 NON_UNIQUE_NAME = STRING_FIELDS_BEGIN, | |
| 121 // The server version of |NON_UNIQUE_NAME|. | |
| 122 SERVER_NON_UNIQUE_NAME, | |
| 123 | |
| 124 // A tag string which identifies this node as a particular top-level | |
| 125 // permanent object. The tag can be thought of as a unique key that | |
| 126 // identifies a singleton instance. | |
| 127 UNIQUE_SERVER_TAG, // Tagged by the server | |
| 128 UNIQUE_CLIENT_TAG, // Tagged by the client | |
| 129 UNIQUE_BOOKMARK_TAG, // Client tags for bookmark items | |
| 130 STRING_FIELDS_END, | |
| 131 }; | |
| 132 | |
| 133 enum { | |
| 134 STRING_FIELDS_COUNT = STRING_FIELDS_END - STRING_FIELDS_BEGIN, | |
| 135 PROTO_FIELDS_BEGIN = STRING_FIELDS_END | |
| 136 }; | |
| 137 | |
| 138 // From looking at the sqlite3 docs, it's not directly stated, but it | |
| 139 // seems the overhead for storing a NULL blob is very small. | |
| 140 enum ProtoField { | |
| 141 SPECIFICS = PROTO_FIELDS_BEGIN, | |
| 142 SERVER_SPECIFICS, | |
| 143 BASE_SERVER_SPECIFICS, | |
| 144 PROTO_FIELDS_END, | |
| 145 }; | |
| 146 | |
| 147 enum { | |
| 148 PROTO_FIELDS_COUNT = PROTO_FIELDS_END - PROTO_FIELDS_BEGIN, | |
| 149 UNIQUE_POSITION_FIELDS_BEGIN = PROTO_FIELDS_END | |
| 150 }; | |
| 151 | |
| 152 enum UniquePositionField { | |
| 153 SERVER_UNIQUE_POSITION = UNIQUE_POSITION_FIELDS_BEGIN, | |
| 154 UNIQUE_POSITION, | |
| 155 UNIQUE_POSITION_FIELDS_END | |
| 156 }; | |
| 157 | |
| 158 enum { | |
| 159 UNIQUE_POSITION_FIELDS_COUNT = | |
| 160 UNIQUE_POSITION_FIELDS_END - UNIQUE_POSITION_FIELDS_BEGIN, | |
| 161 ATTACHMENT_METADATA_FIELDS_BEGIN = UNIQUE_POSITION_FIELDS_END | |
| 162 }; | |
| 163 | |
| 164 enum AttachmentMetadataField { | |
| 165 ATTACHMENT_METADATA = ATTACHMENT_METADATA_FIELDS_BEGIN, | |
| 166 SERVER_ATTACHMENT_METADATA, | |
| 167 ATTACHMENT_METADATA_FIELDS_END | |
| 168 }; | |
| 169 | |
| 170 enum { | |
| 171 ATTACHMENT_METADATA_FIELDS_COUNT = | |
| 172 ATTACHMENT_METADATA_FIELDS_END - ATTACHMENT_METADATA_FIELDS_BEGIN, | |
| 173 FIELD_COUNT = ATTACHMENT_METADATA_FIELDS_END - BEGIN_FIELDS, | |
| 174 // Past this point we have temporaries, stored in memory only. | |
| 175 BEGIN_TEMPS = ATTACHMENT_METADATA_FIELDS_END, | |
| 176 BIT_TEMPS_BEGIN = BEGIN_TEMPS, | |
| 177 }; | |
| 178 | |
| 179 enum BitTemp { | |
| 180 // Whether a server commit operation was started and has not yet completed | |
| 181 // for this entity. | |
| 182 SYNCING = BIT_TEMPS_BEGIN, | |
| 183 // Whether a local change was made to an entity that had SYNCING set to true, | |
| 184 // and was therefore in the middle of a commit operation. | |
| 185 // Note: must only be set if SYNCING is true. | |
| 186 DIRTY_SYNC, | |
| 187 BIT_TEMPS_END, | |
| 188 }; | |
| 189 | |
| 190 enum { | |
| 191 BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN | |
| 192 }; | |
| 193 | |
| 194 | |
| 195 | |
| 196 struct SYNC_EXPORT_PRIVATE EntryKernel { | 41 struct SYNC_EXPORT_PRIVATE EntryKernel { |
| 197 private: | 42 private: |
| 198 std::string string_fields[STRING_FIELDS_COUNT]; | 43 std::string string_fields[STRING_FIELDS_COUNT]; |
| 199 EntitySpecificsPtr specifics_fields[PROTO_FIELDS_COUNT]; | 44 EntitySpecificsPtr specifics_fields[PROTO_FIELDS_COUNT]; |
| 200 int64 int64_fields[INT64_FIELDS_COUNT]; | 45 int64 int64_fields[INT64_FIELDS_COUNT]; |
| 201 base::Time time_fields[TIME_FIELDS_COUNT]; | 46 base::Time time_fields[TIME_FIELDS_COUNT]; |
| 202 Id id_fields[ID_FIELDS_COUNT]; | 47 Id id_fields[ID_FIELDS_COUNT]; |
| 203 UniquePosition unique_position_fields[UNIQUE_POSITION_FIELDS_COUNT]; | 48 UniquePosition unique_position_fields[UNIQUE_POSITION_FIELDS_COUNT]; |
| 204 AttachmentMetadataPtr | 49 AttachmentMetadataPtr |
| 205 attachment_metadata_fields[ATTACHMENT_METADATA_FIELDS_COUNT]; | 50 attachment_metadata_fields[ATTACHMENT_METADATA_FIELDS_COUNT]; |
| 206 std::bitset<BIT_FIELDS_COUNT> bit_fields; | 51 std::bitset<BIT_FIELDS_COUNT> bit_fields; |
| 207 std::bitset<BIT_TEMPS_COUNT> bit_temps; | 52 std::bitset<BIT_TEMPS_COUNT> bit_temps; |
| 208 | 53 |
| 54 friend std::ostream& operator<<(std::ostream& s, const EntryKernel& e); | |
| 55 | |
| 209 public: | 56 public: |
| 210 EntryKernel(); | 57 EntryKernel(); |
| 211 ~EntryKernel(); | 58 ~EntryKernel(); |
| 212 | 59 |
| 213 // Set the dirty bit, and optionally add this entry's metahandle to | 60 // Set the dirty bit, and optionally add this entry's metahandle to |
| 214 // a provided index on dirty bits in |dirty_index|. Parameter may be null, | 61 // a provided index on dirty bits in |dirty_index|. Parameter may be null, |
| 215 // and will result only in setting the dirty bit of this entry. | 62 // and will result only in setting the dirty bit of this entry. |
| 216 inline void mark_dirty(syncable::MetahandleSet* dirty_index) { | 63 inline void mark_dirty(syncable::MetahandleSet* dirty_index) { |
| 217 if (!dirty_ && dirty_index) { | 64 if (!dirty_ && dirty_index) { |
| 218 DCHECK_NE(0, ref(META_HANDLE)); | 65 DCHECK_NE(0, ref(META_HANDLE)); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 typedef Immutable<EntryKernelMutationMap> ImmutableEntryKernelMutationMap; | 233 typedef Immutable<EntryKernelMutationMap> ImmutableEntryKernelMutationMap; |
| 387 | 234 |
| 388 // Caller owns the return value. | 235 // Caller owns the return value. |
| 389 base::DictionaryValue* EntryKernelMutationToValue( | 236 base::DictionaryValue* EntryKernelMutationToValue( |
| 390 const EntryKernelMutation& mutation); | 237 const EntryKernelMutation& mutation); |
| 391 | 238 |
| 392 // Caller owns the return value. | 239 // Caller owns the return value. |
| 393 base::ListValue* EntryKernelMutationMapToValue( | 240 base::ListValue* EntryKernelMutationMapToValue( |
| 394 const EntryKernelMutationMap& mutations); | 241 const EntryKernelMutationMap& mutations); |
| 395 | 242 |
| 243 std::ostream& operator<<(std::ostream& os, const EntryKernel& entry_kernel); | |
| 244 | |
| 396 } // namespace syncable | 245 } // namespace syncable |
| 397 } // namespace syncer | 246 } // namespace syncer |
| 398 | 247 |
| 399 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_ | 248 #endif // SYNC_SYNCABLE_ENTRY_KERNEL_H_ |
| OLD | NEW |