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
3 // found in the LICENSE file.
5 #ifndef SYNC_SYNCABLE_DIRECTORY_H_
6 #define SYNC_SYNCABLE_DIRECTORY_H_
13 #include "base/basictypes.h"
14 #include "base/containers/hash_tables.h"
15 #include "base/files/file_util.h"
16 #include "base/gtest_prod_util.h"
17 #include "base/values.h"
18 #include "sync/api/attachments/attachment_id.h"
19 #include "sync/base/sync_export.h"
20 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h"
21 #include "sync/internal_api/public/util/weak_handle.h"
22 #include "sync/syncable/dir_open_result.h"
23 #include "sync/syncable/entry.h"
24 #include "sync/syncable/entry_kernel.h"
25 #include "sync/syncable/metahandle_set.h"
26 #include "sync/syncable/parent_child_index.h"
27 #include "sync/syncable/syncable_delete_journal.h"
33 class UnrecoverableErrorHandler
;
37 class BaseTransaction
;
38 class BaseWriteTransaction
;
39 class DirectoryChangeDelegate
;
40 class DirectoryBackingStore
;
42 class ScopedKernelLock
;
43 class TransactionObserver
;
44 class WriteTransaction
;
46 enum InvariantCheckLevel
{
47 OFF
= 0, // No checking.
48 VERIFY_CHANGES
= 1, // Checks only mutated entries. Does not check hierarchy.
49 FULL_DB_VERIFICATION
= 2 // Check every entry. This can be expensive.
52 // Directory stores and manages EntryKernels.
54 // This class is tightly coupled to several other classes via Directory::Kernel.
55 // Although Directory's kernel_ is exposed via public accessor it should be
56 // treated as pseudo-private.
57 class SYNC_EXPORT Directory
{
58 friend class SyncableDirectoryTest
;
59 friend class syncer::TestUserShare
;
60 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest
, ManageDeleteJournals
);
61 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest
,
62 TakeSnapshotGetsAllDirtyHandlesTest
);
63 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest
,
64 TakeSnapshotGetsOnlyDirtyHandlesTest
);
65 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest
,
66 TakeSnapshotGetsMetahandlesToPurge
);
69 typedef std::vector
<int64
> Metahandles
;
71 // Be careful when using these hash_map containers. According to the spec,
72 // inserting into them may invalidate all iterators.
74 // It gets worse, though. The Anroid STL library has a bug that means it may
75 // invalidate all iterators when you erase from the map, too. That means that
76 // you can't iterate while erasing. STLDeleteElements(), std::remove_if(),
77 // and other similar functions are off-limits too, until this bug is fixed.
79 // See http://sourceforge.net/p/stlport/bugs/239/.
80 typedef base::hash_map
<int64
, EntryKernel
*> MetahandlesMap
;
81 typedef base::hash_map
<std::string
, EntryKernel
*> IdsMap
;
82 typedef base::hash_map
<std::string
, EntryKernel
*> TagsMap
;
83 typedef std::string AttachmentIdUniqueId
;
84 typedef base::hash_map
<AttachmentIdUniqueId
, MetahandleSet
>
87 static const base::FilePath::CharType kSyncDatabaseFilename
[];
89 // The dirty/clean state of kernel fields backed by the share_info table.
90 // This is public so it can be used in SaveChangesSnapshot for persistence.
91 enum KernelShareInfoStatus
{
92 KERNEL_SHARE_INFO_INVALID
,
93 KERNEL_SHARE_INFO_VALID
,
94 KERNEL_SHARE_INFO_DIRTY
97 // Various data that the Directory::Kernel we are backing (persisting data
98 // for) needs saved across runs of the application.
99 struct SYNC_EXPORT_PRIVATE PersistedKernelInfo
{
100 PersistedKernelInfo();
101 ~PersistedKernelInfo();
103 // Set the |download_progress| entry for the given model to a
104 // "first sync" start point. When such a value is sent to the server,
105 // a full download of all objects of the model will be initiated.
106 void ResetDownloadProgress(ModelType model_type
);
108 // Whether a valid progress marker exists for |model_type|.
109 bool HasEmptyDownloadProgress(ModelType model_type
);
111 // Last sync timestamp fetched from the server.
112 sync_pb::DataTypeProgressMarker download_progress
[MODEL_TYPE_COUNT
];
113 // Sync-side transaction version per data type. Monotonically incremented
114 // when updating native model. A copy is also saved in native model.
115 // Later out-of-sync models can be detected and fixed by comparing
116 // transaction versions of sync model and native model.
117 // TODO(hatiaol): implement detection and fixing of out-of-sync models.
119 int64 transaction_version
[MODEL_TYPE_COUNT
];
120 // The store birthday we were given by the server. Contents are opaque to
122 std::string store_birthday
;
123 // The next local ID that has not been used with this cache-GUID.
125 // The serialized bag of chips we were given by the server. Contents are
126 // opaque to the client. This is the serialization of a message of type
127 // ChipBag defined in sync.proto. It can contains NULL characters.
128 std::string bag_of_chips
;
129 // The per-datatype context.
130 sync_pb::DataTypeContext datatype_context
[MODEL_TYPE_COUNT
];
133 // What the Directory needs on initialization to create itself and its Kernel.
134 // Filled by DirectoryBackingStore::Load.
135 struct KernelLoadInfo
{
136 PersistedKernelInfo kernel_info
;
137 std::string cache_guid
; // Created on first initialization, never changes.
138 int64 max_metahandle
; // Computed (using sql MAX aggregate) on init.
139 KernelLoadInfo() : max_metahandle(0) {
143 // When the Directory is told to SaveChanges, a SaveChangesSnapshot is
144 // constructed and forms a consistent snapshot of what needs to be sent to
145 // the backing store.
146 struct SYNC_EXPORT_PRIVATE SaveChangesSnapshot
{
147 SaveChangesSnapshot();
148 ~SaveChangesSnapshot();
150 KernelShareInfoStatus kernel_info_status
;
151 PersistedKernelInfo kernel_info
;
152 EntryKernelSet dirty_metas
;
153 MetahandleSet metahandles_to_purge
;
154 EntryKernelSet delete_journals
;
155 MetahandleSet delete_journals_to_purge
;
159 // |delegate| must not be NULL. |transaction_observer| must be
161 Kernel(const std::string
& name
, const KernelLoadInfo
& info
,
162 DirectoryChangeDelegate
* delegate
,
163 const WeakHandle
<TransactionObserver
>& transaction_observer
);
167 // Implements ReadTransaction / WriteTransaction using a simple lock.
168 base::Lock transaction_mutex
;
170 // Protected by transaction_mutex. Used by WriteTransactions.
171 int64 next_write_transaction_id
;
173 // The name of this directory.
174 std::string
const name
;
176 // Protects all members below.
177 // The mutex effectively protects all the indices, but not the
178 // entries themselves. So once a pointer to an entry is pulled
179 // from the index, the mutex can be unlocked and entry read or written.
181 // Never hold the mutex and do anything with the database or any
182 // other buffered IO. Violating this rule will result in deadlock.
183 mutable base::Lock mutex
;
185 // Entries indexed by metahandle. This container is considered to be the
186 // owner of all EntryKernels, which may be referened by the other
187 // containers. If you remove an EntryKernel from this map, you probably
188 // want to remove it from all other containers and delete it, too.
189 MetahandlesMap metahandles_map
;
191 // Entries indexed by id
194 // Entries indexed by server tag.
195 // This map does not include any entries with non-existent server tags.
196 TagsMap server_tags_map
;
198 // Entries indexed by client tag.
199 // This map does not include any entries with non-existent client tags.
200 // IS_DEL items are included.
201 TagsMap client_tags_map
;
203 // Contains non-deleted items, indexed according to parent and position
204 // within parent. Protected by the ScopedKernelLock.
205 ParentChildIndex parent_child_index
;
207 // This index keeps track of which metahandles refer to a given attachment.
208 // Think of it as the inverse of EntryKernel's AttachmentMetadata Records.
210 // Because entries can be undeleted (e.g. PutIsDel(false)), entries should
211 // not removed from the index until they are actually deleted from memory.
213 // All access should go through IsAttachmentLinked,
214 // RemoveFromAttachmentIndex, AddToAttachmentIndex, and
215 // UpdateAttachmentIndex methods to avoid iterator invalidation errors.
216 IndexByAttachmentId index_by_attachment_id
;
218 // 3 in-memory indices on bits used extremely frequently by the syncer.
219 // |unapplied_update_metahandles| is keyed by the server model type.
220 MetahandleSet unapplied_update_metahandles
[MODEL_TYPE_COUNT
];
221 MetahandleSet unsynced_metahandles
;
222 // Contains metahandles that are most likely dirty (though not
223 // necessarily). Dirtyness is confirmed in TakeSnapshotForSaveChanges().
224 MetahandleSet dirty_metahandles
;
226 // When a purge takes place, we remove items from all our indices and stash
227 // them in here so that SaveChanges can persist their permanent deletion.
228 MetahandleSet metahandles_to_purge
;
230 KernelShareInfoStatus info_status
;
232 // These 3 members are backed in the share_info table, and
233 // their state is marked by the flag above.
235 // A structure containing the Directory state that is written back into the
236 // database on SaveChanges.
237 PersistedKernelInfo persisted_info
;
239 // A unique identifier for this account's cache db, used to generate
240 // unique server IDs. No need to lock, only written at init time.
241 const std::string cache_guid
;
243 // It doesn't make sense for two threads to run SaveChanges at the same
244 // time; this mutex protects that activity.
245 base::Lock save_changes_mutex
;
247 // The next metahandle is protected by kernel mutex.
248 int64 next_metahandle
;
250 // The delegate for directory change events. Must not be NULL.
251 DirectoryChangeDelegate
* const delegate
;
253 // The transaction observer.
254 const WeakHandle
<TransactionObserver
> transaction_observer
;
257 // Does not take ownership of |encryptor|.
258 // |report_unrecoverable_error_function| may be NULL.
259 // Takes ownership of |store|.
261 DirectoryBackingStore
* store
,
262 UnrecoverableErrorHandler
* unrecoverable_error_handler
,
263 ReportUnrecoverableErrorFunction
264 report_unrecoverable_error_function
,
265 NigoriHandler
* nigori_handler
,
266 Cryptographer
* cryptographer
);
267 virtual ~Directory();
269 // Does not take ownership of |delegate|, which must not be NULL.
270 // Starts sending events to |delegate| if the returned result is
271 // OPENED. Note that events to |delegate| may be sent from *any*
272 // thread. |transaction_observer| must be initialized.
273 DirOpenResult
Open(const std::string
& name
,
274 DirectoryChangeDelegate
* delegate
,
275 const WeakHandle
<TransactionObserver
>&
276 transaction_observer
);
278 int64
NextMetahandle();
279 // Returns a negative integer unique to this client.
280 syncable::Id
NextId();
282 bool good() const { return NULL
!= kernel_
; }
284 // The download progress is an opaque token provided by the sync server
285 // to indicate the continuation state of the next GetUpdates operation.
286 void GetDownloadProgress(
288 sync_pb::DataTypeProgressMarker
* value_out
) const;
289 void GetDownloadProgressAsString(
291 std::string
* value_out
) const;
292 void SetDownloadProgress(
294 const sync_pb::DataTypeProgressMarker
& value
);
295 bool HasEmptyDownloadProgress(ModelType type
) const;
297 // Gets the total number of entries in the directory.
298 size_t GetEntriesCount() const;
300 // Gets/Increments transaction version of a model type. Must be called when
301 // holding kernel mutex.
302 int64
GetTransactionVersion(ModelType type
) const;
303 void IncrementTransactionVersion(ModelType type
);
305 // Getter/setters for the per datatype context.
306 void GetDataTypeContext(BaseTransaction
* trans
,
308 sync_pb::DataTypeContext
* context
) const;
309 void SetDataTypeContext(BaseWriteTransaction
* trans
,
311 const sync_pb::DataTypeContext
& context
);
313 ModelTypeSet
InitialSyncEndedTypes();
314 bool InitialSyncEndedForType(ModelType type
);
315 bool InitialSyncEndedForType(BaseTransaction
* trans
, ModelType type
);
317 const std::string
& name() const { return kernel_
->name
; }
319 // (Account) Store birthday is opaque to the client, so we keep it in the
320 // format it is in the proto buffer in case we switch to a binary birthday
322 std::string
store_birthday() const;
323 void set_store_birthday(const std::string
& store_birthday
);
325 // (Account) Bag of chip is an opaque state used by the server to track the
327 std::string
bag_of_chips() const;
328 void set_bag_of_chips(const std::string
& bag_of_chips
);
330 // Unique to each account / client pair.
331 std::string
cache_guid() const;
333 // Returns a pointer to our Nigori node handler.
334 NigoriHandler
* GetNigoriHandler();
336 // Returns a pointer to our cryptographer. Does not transfer ownership.
337 // Not thread safe, so should only be accessed while holding a transaction.
338 Cryptographer
* GetCryptographer(const BaseTransaction
* trans
);
340 // Returns true if the directory had encountered an unrecoverable error.
341 // Note: Any function in |Directory| that can be called without holding a
342 // transaction need to check if the Directory already has an unrecoverable
344 bool unrecoverable_error_set(const BaseTransaction
* trans
) const;
346 // Called to immediately report an unrecoverable error (but don't
348 void ReportUnrecoverableError() {
349 if (report_unrecoverable_error_function_
) {
350 report_unrecoverable_error_function_();
354 // Called to set the unrecoverable error on the directory and to propagate
355 // the error to upper layers.
356 void OnUnrecoverableError(const BaseTransaction
* trans
,
357 const tracked_objects::Location
& location
,
358 const std::string
& message
);
360 DeleteJournal
* delete_journal();
362 // Returns the child meta handles (even those for deleted/unlinked
363 // nodes) for given parent id. Clears |result| if there are no
365 bool GetChildHandlesById(BaseTransaction
*, const Id
& parent_id
,
366 Metahandles
* result
);
368 // Counts all items under the given node, including the node itself.
369 int GetTotalNodeCount(BaseTransaction
*, EntryKernel
* kernel_
) const;
371 // Returns this item's position within its parent folder.
372 // The left-most item is 0, second left-most is 1, etc.
373 int GetPositionIndex(BaseTransaction
*, EntryKernel
* kernel_
) const;
375 // Returns true iff |id| has children.
376 bool HasChildren(BaseTransaction
* trans
, const Id
& id
);
378 // Find the first child in the positional ordering under a parent,
379 // and fill in |*first_child_id| with its id. Fills in a root Id if
380 // parent has no children. Returns true if the first child was
381 // successfully found, or false if an error was encountered.
382 Id
GetFirstChildId(BaseTransaction
* trans
, const EntryKernel
* parent
);
384 // These functions allow one to fetch the next or previous item under
385 // the same folder. Returns the "root" ID if there is no predecessor
388 // TODO(rlarocque): These functions are used mainly for tree traversal. We
389 // should replace these with an iterator API. See crbug.com/178275.
390 syncable::Id
GetPredecessorId(EntryKernel
*);
391 syncable::Id
GetSuccessorId(EntryKernel
*);
393 // Places |e| as a successor to |predecessor|. If |predecessor| is NULL,
394 // |e| will be placed as the left-most item in its folder.
396 // Both |e| and |predecessor| must be valid entries under the same parent.
398 // TODO(rlarocque): This function includes limited support for placing items
399 // with valid positions (ie. Bookmarks) as siblings of items that have no set
400 // ordering (ie. Autofill items). This support is required only for tests,
401 // and should be removed. See crbug.com/178282.
402 void PutPredecessor(EntryKernel
* e
, EntryKernel
* predecessor
);
404 // SaveChanges works by taking a consistent snapshot of the current Directory
405 // state and indices (by deep copy) under a ReadTransaction, passing this
406 // snapshot to the backing store under no transaction, and finally cleaning
407 // up by either purging entries no longer needed (this part done under a
408 // WriteTransaction) or rolling back the dirty bits. It also uses
409 // internal locking to enforce SaveChanges operations are mutually exclusive.
411 // WARNING: THIS METHOD PERFORMS SYNCHRONOUS I/O VIA SQLITE.
414 // Returns the number of entities with the unsynced bit set.
415 int64
unsynced_entity_count() const;
417 // Get GetUnsyncedMetaHandles should only be called after SaveChanges and
418 // before any new entries have been created. The intention is that the
419 // syncer should call it from its PerformSyncQueries member.
420 void GetUnsyncedMetaHandles(BaseTransaction
* trans
,
421 Metahandles
* result
);
423 // Returns whether or not this |type| has unapplied updates.
424 bool TypeHasUnappliedUpdates(ModelType type
);
426 // Get all the metahandles for unapplied updates for a given set of
428 void GetUnappliedUpdateMetaHandles(BaseTransaction
* trans
,
429 FullModelTypeSet server_types
,
430 std::vector
<int64
>* result
);
432 // Get all the metahandles of entries of |type|.
433 void GetMetaHandlesOfType(BaseTransaction
* trans
,
435 Metahandles
* result
);
437 // Get metahandle counts for various criteria to show on the
438 // about:sync page. The information is computed on the fly
439 // each time. If this results in a significant performance hit,
440 // additional data structures can be added to cache results.
441 void CollectMetaHandleCounts(std::vector
<int>* num_entries_by_type
,
442 std::vector
<int>* num_to_delete_entries_by_type
);
444 // Returns a ListValue serialization of all nodes for the given type.
445 scoped_ptr
<base::ListValue
> GetNodeDetailsForType(
446 BaseTransaction
* trans
,
449 // Sets the level of invariant checking performed after transactions.
450 void SetInvariantCheckLevel(InvariantCheckLevel check_level
);
452 // Checks tree metadata consistency following a transaction. It is intended
453 // to provide a reasonable tradeoff between performance and comprehensiveness
454 // and may be used in release code.
455 bool CheckInvariantsOnTransactionClose(
456 syncable::BaseTransaction
* trans
,
457 const MetahandleSet
& modified_handles
);
459 // Forces a full check of the directory. This operation may be slow and
460 // should not be invoked outside of tests.
461 bool FullyCheckTreeInvariants(BaseTransaction
*trans
);
463 // Purges data associated with any entries whose ModelType or ServerModelType
464 // is found in |disabled_types|, from sync directory _both_ in memory and on
465 // disk. Only valid, "real" model types are allowed in |disabled_types| (see
466 // model_type.h for definitions).
467 // 1. Data associated with |types_to_journal| is saved in the delete journal
468 // to help prevent back-from-dead problem due to offline delete in the next
469 // sync session. |types_to_journal| must be a subset of |disabled_types|.
470 // 2. Data associated with |types_to_unapply| is reset to an "unapplied"
471 // state, wherein all local data is deleted and IS_UNAPPLIED is set to true.
472 // This is useful when there's no benefit in discarding the currently
473 // downloaded state, such as when there are cryptographer errors.
474 // |types_to_unapply| must be a subset of |disabled_types|.
475 // 3. All other data is purged entirely.
476 // Note: "Purge" is just meant to distinguish from "deleting" entries, which
477 // means something different in the syncable namespace.
478 // WARNING! This can be real slow, as it iterates over all entries.
479 // WARNING! Performs synchronous I/O.
480 // Returns: true on success, false if an error was encountered.
481 virtual bool PurgeEntriesWithTypeIn(ModelTypeSet disabled_types
,
482 ModelTypeSet types_to_journal
,
483 ModelTypeSet types_to_unapply
);
485 // Resets the base_versions and server_versions of all synced entities
486 // associated with |type| to 1.
487 // WARNING! This can be slow, as it iterates over all entries for a type.
488 bool ResetVersionsForType(BaseWriteTransaction
* trans
, ModelType type
);
490 // Returns true iff the attachment identified by |attachment_id_proto| is
491 // linked to an entry.
493 // An attachment linked to a deleted entry is still considered linked if the
494 // entry hasn't yet been purged.
495 bool IsAttachmentLinked(
496 const sync_pb::AttachmentIdProto
& attachment_id_proto
) const;
498 // Given attachment id return metahandles to all entries that reference this
500 void GetMetahandlesByAttachmentId(
501 BaseTransaction
* trans
,
502 const sync_pb::AttachmentIdProto
& attachment_id_proto
,
503 Metahandles
* result
);
505 // Change entry to not dirty. Used in special case when we don't want to
506 // persist modified entry on disk. e.g. SyncBackupManager uses this to
507 // preserve sync preferences in DB on disk.
508 void UnmarkDirtyEntry(WriteTransaction
* trans
, Entry
* entry
);
510 // Clears |ids| and fills it with the ids of attachments that need to be
511 // uploaded to the sync server.
512 void GetAttachmentIdsToUpload(BaseTransaction
* trans
,
514 AttachmentIdList
* ids
);
516 // For new entry creation only.
517 bool InsertEntry(BaseWriteTransaction
* trans
, EntryKernel
* entry
);
519 // Update the attachment index for |metahandle| removing it from the index
520 // under |old_metadata| entries and add it under |new_metadata| entries.
521 void UpdateAttachmentIndex(const int64 metahandle
,
522 const sync_pb::AttachmentMetadata
& old_metadata
,
523 const sync_pb::AttachmentMetadata
& new_metadata
);
525 virtual EntryKernel
* GetEntryById(const Id
& id
);
526 virtual EntryKernel
* GetEntryByClientTag(const std::string
& tag
);
527 EntryKernel
* GetEntryByServerTag(const std::string
& tag
);
529 virtual EntryKernel
* GetEntryByHandle(int64 handle
);
531 bool ReindexId(BaseWriteTransaction
* trans
, EntryKernel
* const entry
,
534 bool ReindexParentId(BaseWriteTransaction
* trans
, EntryKernel
* const entry
,
535 const Id
& new_parent_id
);
537 // Accessors for the underlying Kernel. Although these are public methods, the
538 // number of classes that call these should be limited.
540 const Kernel
* kernel() const;
543 // You'll notice that some of the methods below are private overloads of the
544 // public ones declared above. The general pattern is that the public overload
545 // constructs a ScopedKernelLock before calling the corresponding private
546 // overload with the held ScopedKernelLock.
548 virtual EntryKernel
* GetEntryByHandle(const ScopedKernelLock
& lock
,
551 virtual EntryKernel
* GetEntryById(const ScopedKernelLock
& lock
, const Id
& id
);
553 bool InsertEntry(const ScopedKernelLock
& lock
,
554 BaseWriteTransaction
* trans
,
557 // Remove each of |metahandle|'s attachment ids from index_by_attachment_id.
558 void RemoveFromAttachmentIndex(
559 const ScopedKernelLock
& lock
,
560 const int64 metahandle
,
561 const sync_pb::AttachmentMetadata
& attachment_metadata
);
563 // Add each of |metahandle|'s attachment ids to the index_by_attachment_id.
564 void AddToAttachmentIndex(
565 const ScopedKernelLock
& lock
,
566 const int64 metahandle
,
567 const sync_pb::AttachmentMetadata
& attachment_metadata
);
569 void ClearDirtyMetahandles(const ScopedKernelLock
& lock
);
571 DirOpenResult
OpenImpl(
572 const std::string
& name
,
573 DirectoryChangeDelegate
* delegate
,
574 const WeakHandle
<TransactionObserver
>& transaction_observer
);
576 // A helper that implements the logic of checking tree invariants.
577 bool CheckTreeInvariants(syncable::BaseTransaction
* trans
,
578 const MetahandleSet
& handles
);
580 // Helper to prime metahandles_map, ids_map, parent_child_index,
581 // unsynced_metahandles, unapplied_update_metahandles, server_tags_map and
582 // client_tags_map from metahandles_index. The input |handles_map| will be
583 // cleared during the initialization process.
584 void InitializeIndices(MetahandlesMap
* handles_map
);
586 // Constructs a consistent snapshot of the current Directory state and
587 // indices (by deep copy) under a ReadTransaction for use in |snapshot|.
588 // See SaveChanges() for more information.
589 void TakeSnapshotForSaveChanges(SaveChangesSnapshot
* snapshot
);
591 // Purges from memory any unused, safe to remove entries that were
592 // successfully deleted on disk as a result of the SaveChanges that processed
593 // |snapshot|. See SaveChanges() for more information.
594 bool VacuumAfterSaveChanges(const SaveChangesSnapshot
& snapshot
);
596 // Rolls back dirty bits in the event that the SaveChanges that
597 // processed |snapshot| failed, for example, due to no disk space.
598 void HandleSaveChangesFailure(const SaveChangesSnapshot
& snapshot
);
600 // Used by CheckTreeInvariants.
601 void GetAllMetaHandles(BaseTransaction
* trans
, MetahandleSet
* result
);
603 // Used by VacuumAfterSaveChanges.
604 bool SafeToPurgeFromMemory(WriteTransaction
* trans
,
605 const EntryKernel
* const entry
) const;
606 // A helper used by GetTotalNodeCount.
607 void GetChildSetForKernel(
609 EntryKernel
* kernel_
,
610 std::deque
<const OrderedChildSet
*>* child_sets
) const;
612 // Append the handles of the children of |parent_id| to |result|.
613 void AppendChildHandles(const ScopedKernelLock
& lock
,
615 Directory::Metahandles
* result
);
617 // Helper methods used by PurgeDisabledTypes.
618 void UnapplyEntry(EntryKernel
* entry
);
619 void DeleteEntry(const ScopedKernelLock
& lock
,
620 bool save_to_journal
,
622 EntryKernelSet
* entries_to_journal
);
624 // A private version of the public GetMetaHandlesOfType for when you already
625 // have a ScopedKernelLock.
626 void GetMetaHandlesOfType(const ScopedKernelLock
& lock
,
627 BaseTransaction
* trans
,
629 std::vector
<int64
>* result
);
631 // Stops sending events to the delegate and the transaction
637 scoped_ptr
<DirectoryBackingStore
> store_
;
639 UnrecoverableErrorHandler
* const unrecoverable_error_handler_
;
640 const ReportUnrecoverableErrorFunction report_unrecoverable_error_function_
;
641 bool unrecoverable_error_set_
;
644 NigoriHandler
* const nigori_handler_
;
645 Cryptographer
* const cryptographer_
;
647 InvariantCheckLevel invariant_check_level_
;
649 // Maintain deleted entries not in |kernel_| until it's verified that they
650 // are deleted in native models as well.
651 scoped_ptr
<DeleteJournal
> delete_journal_
;
653 DISALLOW_COPY_AND_ASSIGN(Directory
);
656 } // namespace syncable
657 } // namespace syncer
659 #endif // SYNC_SYNCABLE_DIRECTORY_H_