| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ | 5 #ifndef COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ |
| 6 #define COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ | 6 #define COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Later out-of-sync models can be detected and fixed by comparing | 102 // Later out-of-sync models can be detected and fixed by comparing |
| 103 // transaction versions of sync model and native model. | 103 // transaction versions of sync model and native model. |
| 104 // TODO(hatiaol): implement detection and fixing of out-of-sync models. | 104 // TODO(hatiaol): implement detection and fixing of out-of-sync models. |
| 105 // Bug 154858. | 105 // Bug 154858. |
| 106 int64_t transaction_version[MODEL_TYPE_COUNT]; | 106 int64_t transaction_version[MODEL_TYPE_COUNT]; |
| 107 // The store birthday we were given by the server. Contents are opaque to | 107 // The store birthday we were given by the server. Contents are opaque to |
| 108 // the client. | 108 // the client. |
| 109 std::string store_birthday; | 109 std::string store_birthday; |
| 110 // The serialized bag of chips we were given by the server. Contents are | 110 // The serialized bag of chips we were given by the server. Contents are |
| 111 // opaque to the client. This is the serialization of a message of type | 111 // opaque to the client. This is the serialization of a message of type |
| 112 // ChipBag defined in sync.proto. It can contains NULL characters. | 112 // ChipBag defined in sync.proto. It can contains null characters. |
| 113 std::string bag_of_chips; | 113 std::string bag_of_chips; |
| 114 // The per-datatype context. | 114 // The per-datatype context. |
| 115 sync_pb::DataTypeContext datatype_context[MODEL_TYPE_COUNT]; | 115 sync_pb::DataTypeContext datatype_context[MODEL_TYPE_COUNT]; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 // What the Directory needs on initialization to create itself and its Kernel. | 118 // What the Directory needs on initialization to create itself and its Kernel. |
| 119 // Filled by DirectoryBackingStore::Load. | 119 // Filled by DirectoryBackingStore::Load. |
| 120 struct KernelLoadInfo { | 120 struct KernelLoadInfo { |
| 121 PersistedKernelInfo kernel_info; | 121 PersistedKernelInfo kernel_info; |
| 122 std::string cache_guid; // Created on first initialization, never changes. | 122 std::string cache_guid; // Created on first initialization, never changes. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 136 | 136 |
| 137 KernelShareInfoStatus kernel_info_status; | 137 KernelShareInfoStatus kernel_info_status; |
| 138 PersistedKernelInfo kernel_info; | 138 PersistedKernelInfo kernel_info; |
| 139 OwnedEntryKernelSet dirty_metas; | 139 OwnedEntryKernelSet dirty_metas; |
| 140 MetahandleSet metahandles_to_purge; | 140 MetahandleSet metahandles_to_purge; |
| 141 OwnedEntryKernelSet delete_journals; | 141 OwnedEntryKernelSet delete_journals; |
| 142 MetahandleSet delete_journals_to_purge; | 142 MetahandleSet delete_journals_to_purge; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 struct Kernel { | 145 struct Kernel { |
| 146 // |delegate| must not be NULL. |transaction_observer| must be | 146 // |delegate| must not be null. |transaction_observer| must be |
| 147 // initialized. | 147 // initialized. |
| 148 Kernel(const std::string& name, | 148 Kernel(const std::string& name, |
| 149 const KernelLoadInfo& info, | 149 const KernelLoadInfo& info, |
| 150 DirectoryChangeDelegate* delegate, | 150 DirectoryChangeDelegate* delegate, |
| 151 const WeakHandle<TransactionObserver>& transaction_observer); | 151 const WeakHandle<TransactionObserver>& transaction_observer); |
| 152 | 152 |
| 153 ~Kernel(); | 153 ~Kernel(); |
| 154 | 154 |
| 155 // Implements ReadTransaction / WriteTransaction using a simple lock. | 155 // Implements ReadTransaction / WriteTransaction using a simple lock. |
| 156 base::Lock transaction_mutex; | 156 base::Lock transaction_mutex; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // unique server IDs. No need to lock, only written at init time. | 228 // unique server IDs. No need to lock, only written at init time. |
| 229 const std::string cache_guid; | 229 const std::string cache_guid; |
| 230 | 230 |
| 231 // It doesn't make sense for two threads to run SaveChanges at the same | 231 // It doesn't make sense for two threads to run SaveChanges at the same |
| 232 // time; this mutex protects that activity. | 232 // time; this mutex protects that activity. |
| 233 base::Lock save_changes_mutex; | 233 base::Lock save_changes_mutex; |
| 234 | 234 |
| 235 // The next metahandle is protected by kernel mutex. | 235 // The next metahandle is protected by kernel mutex. |
| 236 int64_t next_metahandle; | 236 int64_t next_metahandle; |
| 237 | 237 |
| 238 // The delegate for directory change events. Must not be NULL. | 238 // The delegate for directory change events. Must not be null. |
| 239 DirectoryChangeDelegate* const delegate; | 239 DirectoryChangeDelegate* const delegate; |
| 240 | 240 |
| 241 // The transaction observer. | 241 // The transaction observer. |
| 242 const WeakHandle<TransactionObserver> transaction_observer; | 242 const WeakHandle<TransactionObserver> transaction_observer; |
| 243 }; | 243 }; |
| 244 | 244 |
| 245 // Does not take ownership of |encryptor|. | 245 // Does not take ownership of |encryptor|. |
| 246 // |report_unrecoverable_error_function| may be NULL. | 246 // |report_unrecoverable_error_function| may be null. |
| 247 // Takes ownership of |store|. | 247 // Takes ownership of |store|. |
| 248 Directory( | 248 Directory( |
| 249 DirectoryBackingStore* store, | 249 DirectoryBackingStore* store, |
| 250 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, | 250 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, |
| 251 const base::Closure& report_unrecoverable_error_function, | 251 const base::Closure& report_unrecoverable_error_function, |
| 252 NigoriHandler* nigori_handler, | 252 NigoriHandler* nigori_handler, |
| 253 Cryptographer* cryptographer); | 253 Cryptographer* cryptographer); |
| 254 virtual ~Directory(); | 254 virtual ~Directory(); |
| 255 | 255 |
| 256 // Does not take ownership of |delegate|, which must not be NULL. | 256 // Does not take ownership of |delegate|, which must not be null. |
| 257 // Starts sending events to |delegate| if the returned result is | 257 // Starts sending events to |delegate| if the returned result is |
| 258 // OPENED. Note that events to |delegate| may be sent from *any* | 258 // OPENED. Note that events to |delegate| may be sent from *any* |
| 259 // thread. |transaction_observer| must be initialized. | 259 // thread. |transaction_observer| must be initialized. |
| 260 DirOpenResult Open( | 260 DirOpenResult Open( |
| 261 const std::string& name, | 261 const std::string& name, |
| 262 DirectoryChangeDelegate* delegate, | 262 DirectoryChangeDelegate* delegate, |
| 263 const WeakHandle<TransactionObserver>& transaction_observer); | 263 const WeakHandle<TransactionObserver>& transaction_observer); |
| 264 | 264 |
| 265 int64_t NextMetahandle(); | 265 int64_t NextMetahandle(); |
| 266 // Generates next client ID based on a randomly generated GUID. | 266 // Generates next client ID based on a randomly generated GUID. |
| 267 syncable::Id NextId(); | 267 syncable::Id NextId(); |
| 268 | 268 |
| 269 bool good() const { return NULL != kernel_; } | 269 bool good() const { return nullptr != kernel_; } |
| 270 | 270 |
| 271 // The download progress is an opaque token provided by the sync server | 271 // The download progress is an opaque token provided by the sync server |
| 272 // to indicate the continuation state of the next GetUpdates operation. | 272 // to indicate the continuation state of the next GetUpdates operation. |
| 273 void GetDownloadProgress(ModelType type, | 273 void GetDownloadProgress(ModelType type, |
| 274 sync_pb::DataTypeProgressMarker* value_out) const; | 274 sync_pb::DataTypeProgressMarker* value_out) const; |
| 275 void GetDownloadProgressAsString(ModelType type, | 275 void GetDownloadProgressAsString(ModelType type, |
| 276 std::string* value_out) const; | 276 std::string* value_out) const; |
| 277 void SetDownloadProgress(ModelType type, | 277 void SetDownloadProgress(ModelType type, |
| 278 const sync_pb::DataTypeProgressMarker& value); | 278 const sync_pb::DataTypeProgressMarker& value); |
| 279 bool HasEmptyDownloadProgress(ModelType type) const; | 279 bool HasEmptyDownloadProgress(ModelType type) const; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 363 |
| 364 // These functions allow one to fetch the next or previous item under | 364 // These functions allow one to fetch the next or previous item under |
| 365 // the same folder. Returns the "root" ID if there is no predecessor | 365 // the same folder. Returns the "root" ID if there is no predecessor |
| 366 // or successor. | 366 // or successor. |
| 367 // | 367 // |
| 368 // TODO(rlarocque): These functions are used mainly for tree traversal. We | 368 // TODO(rlarocque): These functions are used mainly for tree traversal. We |
| 369 // should replace these with an iterator API. See crbug.com/178275. | 369 // should replace these with an iterator API. See crbug.com/178275. |
| 370 syncable::Id GetPredecessorId(EntryKernel* e); | 370 syncable::Id GetPredecessorId(EntryKernel* e); |
| 371 syncable::Id GetSuccessorId(EntryKernel* e); | 371 syncable::Id GetSuccessorId(EntryKernel* e); |
| 372 | 372 |
| 373 // Places |e| as a successor to |predecessor|. If |predecessor| is NULL, | 373 // Places |e| as a successor to |predecessor|. If |predecessor| is null, |
| 374 // |e| will be placed as the left-most item in its folder. | 374 // |e| will be placed as the left-most item in its folder. |
| 375 // | 375 // |
| 376 // Both |e| and |predecessor| must be valid entries under the same parent. | 376 // Both |e| and |predecessor| must be valid entries under the same parent. |
| 377 // | 377 // |
| 378 // TODO(rlarocque): This function includes limited support for placing items | 378 // TODO(rlarocque): This function includes limited support for placing items |
| 379 // with valid positions (ie. Bookmarks) as siblings of items that have no set | 379 // with valid positions (ie. Bookmarks) as siblings of items that have no set |
| 380 // ordering (ie. Autofill items). This support is required only for tests, | 380 // ordering (ie. Autofill items). This support is required only for tests, |
| 381 // and should be removed. See crbug.com/178282. | 381 // and should be removed. See crbug.com/178282. |
| 382 void PutPredecessor(EntryKernel* e, EntryKernel* predecessor); | 382 void PutPredecessor(EntryKernel* e, EntryKernel* predecessor); |
| 383 | 383 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 | 652 |
| 653 base::WeakPtrFactory<Directory> weak_ptr_factory_; | 653 base::WeakPtrFactory<Directory> weak_ptr_factory_; |
| 654 | 654 |
| 655 DISALLOW_COPY_AND_ASSIGN(Directory); | 655 DISALLOW_COPY_AND_ASSIGN(Directory); |
| 656 }; | 656 }; |
| 657 | 657 |
| 658 } // namespace syncable | 658 } // namespace syncable |
| 659 } // namespace syncer | 659 } // namespace syncer |
| 660 | 660 |
| 661 #endif // COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ | 661 #endif // COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ |
| OLD | NEW |