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
{
59 typedef std::vector
<int64
> Metahandles
;
61 // Be careful when using these hash_map containers. According to the spec,
62 // inserting into them may invalidate all iterators.
64 // It gets worse, though. The Anroid STL library has a bug that means it may
65 // invalidate all iterators when you erase from the map, too. That means that
66 // you can't iterate while erasing. STLDeleteElements(), std::remove_if(),
67 // and other similar functions are off-limits too, until this bug is fixed.
69 // See http://sourceforge.net/p/stlport/bugs/239/.
70 typedef base::hash_map
<int64
, EntryKernel
*> MetahandlesMap
;
71 typedef base::hash_map
<std::string
, EntryKernel
*> IdsMap
;
72 typedef base::hash_map
<std::string
, EntryKernel
*> TagsMap
;
73 typedef std::string AttachmentIdUniqueId
;
74 typedef base::hash_map
<AttachmentIdUniqueId
, MetahandleSet
>
77 static const base::FilePath::CharType kSyncDatabaseFilename
[];
79 // The dirty/clean state of kernel fields backed by the share_info table.
80 // This is public so it can be used in SaveChangesSnapshot for persistence.
81 enum KernelShareInfoStatus
{
82 KERNEL_SHARE_INFO_INVALID
,
83 KERNEL_SHARE_INFO_VALID
,
84 KERNEL_SHARE_INFO_DIRTY
87 // Various data that the Directory::Kernel we are backing (persisting data
88 // for) needs saved across runs of the application.
89 struct SYNC_EXPORT_PRIVATE PersistedKernelInfo
{
90 PersistedKernelInfo();
91 ~PersistedKernelInfo();
93 // Set the |download_progress| entry for the given model to a
94 // "first sync" start point. When such a value is sent to the server,
95 // a full download of all objects of the model will be initiated.
96 void ResetDownloadProgress(ModelType model_type
);
98 // Whether a valid progress marker exists for |model_type|.
99 bool HasEmptyDownloadProgress(ModelType model_type
);
101 // Last sync timestamp fetched from the server.
102 sync_pb::DataTypeProgressMarker download_progress
[MODEL_TYPE_COUNT
];
103 // Sync-side transaction version per data type. Monotonically incremented
104 // when updating native model. A copy is also saved in native model.
105 // Later out-of-sync models can be detected and fixed by comparing
106 // transaction versions of sync model and native model.
107 // TODO(hatiaol): implement detection and fixing of out-of-sync models.
109 int64 transaction_version
[MODEL_TYPE_COUNT
];
110 // The store birthday we were given by the server. Contents are opaque to
112 std::string store_birthday
;
113 // The next local ID that has not been used with this cache-GUID.
115 // The serialized bag of chips we were given by the server. Contents are
116 // opaque to the client. This is the serialization of a message of type
117 // ChipBag defined in sync.proto. It can contains NULL characters.
118 std::string bag_of_chips
;
119 // The per-datatype context.
120 sync_pb::DataTypeContext datatype_context
[MODEL_TYPE_COUNT
];
123 // What the Directory needs on initialization to create itself and its Kernel.
124 // Filled by DirectoryBackingStore::Load.
125 struct KernelLoadInfo
{
126 PersistedKernelInfo kernel_info
;
127 std::string cache_guid
; // Created on first initialization, never changes.
128 int64 max_metahandle
; // Computed (using sql MAX aggregate) on init.
129 KernelLoadInfo() : max_metahandle(0) {
133 // When the Directory is told to SaveChanges, a SaveChangesSnapshot is
134 // constructed and forms a consistent snapshot of what needs to be sent to
135 // the backing store.
136 struct SYNC_EXPORT_PRIVATE SaveChangesSnapshot
{
137 SaveChangesSnapshot();
138 ~SaveChangesSnapshot();
140 // Returns true if this snapshot has any unsaved metahandle changes.
141 bool HasUnsavedMetahandleChanges() const;
143 KernelShareInfoStatus kernel_info_status
;
144 PersistedKernelInfo kernel_info
;
145 EntryKernelSet dirty_metas
;
146 MetahandleSet metahandles_to_purge
;
147 EntryKernelSet delete_journals
;
148 MetahandleSet delete_journals_to_purge
;
152 // |delegate| must not be NULL. |transaction_observer| must be
154 Kernel(const std::string
& name
, const KernelLoadInfo
& info
,
155 DirectoryChangeDelegate
* delegate
,
156 const WeakHandle
<TransactionObserver
>& transaction_observer
);
160 // Implements ReadTransaction / WriteTransaction using a simple lock.
161 base::Lock transaction_mutex
;
163 // Protected by transaction_mutex. Used by WriteTransactions.
164 int64 next_write_transaction_id
;
166 // The name of this directory.
167 std::string
const name
;
169 // Protects all members below.
170 // The mutex effectively protects all the indices, but not the
171 // entries themselves. So once a pointer to an entry is pulled
172 // from the index, the mutex can be unlocked and entry read or written.
174 // Never hold the mutex and do anything with the database or any
175 // other buffered IO. Violating this rule will result in deadlock.
176 mutable base::Lock mutex
;
178 // Entries indexed by metahandle. This container is considered to be the
179 // owner of all EntryKernels, which may be referened by the other
180 // containers. If you remove an EntryKernel from this map, you probably
181 // want to remove it from all other containers and delete it, too.
182 MetahandlesMap metahandles_map
;
184 // Entries indexed by id
187 // Entries indexed by server tag.
188 // This map does not include any entries with non-existent server tags.
189 TagsMap server_tags_map
;
191 // Entries indexed by client tag.
192 // This map does not include any entries with non-existent client tags.
193 // IS_DEL items are included.
194 TagsMap client_tags_map
;
196 // Contains non-deleted items, indexed according to parent and position
197 // within parent. Protected by the ScopedKernelLock.
198 ParentChildIndex parent_child_index
;
200 // This index keeps track of which metahandles refer to a given attachment.
201 // Think of it as the inverse of EntryKernel's AttachmentMetadata Records.
203 // Because entries can be undeleted (e.g. PutIsDel(false)), entries should
204 // not removed from the index until they are actually deleted from memory.
206 // All access should go through IsAttachmentLinked,
207 // RemoveFromAttachmentIndex, AddToAttachmentIndex, and
208 // UpdateAttachmentIndex methods to avoid iterator invalidation errors.
209 IndexByAttachmentId index_by_attachment_id
;
211 // 3 in-memory indices on bits used extremely frequently by the syncer.
212 // |unapplied_update_metahandles| is keyed by the server model type.
213 MetahandleSet unapplied_update_metahandles
[MODEL_TYPE_COUNT
];
214 MetahandleSet unsynced_metahandles
;
215 // Contains metahandles that are most likely dirty (though not
216 // necessarily). Dirtyness is confirmed in TakeSnapshotForSaveChanges().
217 MetahandleSet dirty_metahandles
;
219 // When a purge takes place, we remove items from all our indices and stash
220 // them in here so that SaveChanges can persist their permanent deletion.
221 MetahandleSet metahandles_to_purge
;
223 KernelShareInfoStatus info_status
;
225 // These 3 members are backed in the share_info table, and
226 // their state is marked by the flag above.
228 // A structure containing the Directory state that is written back into the
229 // database on SaveChanges.
230 PersistedKernelInfo persisted_info
;
232 // A unique identifier for this account's cache db, used to generate
233 // unique server IDs. No need to lock, only written at init time.
234 const std::string cache_guid
;
236 // It doesn't make sense for two threads to run SaveChanges at the same
237 // time; this mutex protects that activity.
238 base::Lock save_changes_mutex
;
240 // The next metahandle is protected by kernel mutex.
241 int64 next_metahandle
;
243 // The delegate for directory change events. Must not be NULL.
244 DirectoryChangeDelegate
* const delegate
;
246 // The transaction observer.
247 const WeakHandle
<TransactionObserver
> transaction_observer
;
250 // Does not take ownership of |encryptor|.
251 // |report_unrecoverable_error_function| may be NULL.
252 // Takes ownership of |store|.
254 DirectoryBackingStore
* store
,
255 UnrecoverableErrorHandler
* unrecoverable_error_handler
,
256 ReportUnrecoverableErrorFunction
257 report_unrecoverable_error_function
,
258 NigoriHandler
* nigori_handler
,
259 Cryptographer
* cryptographer
);
260 virtual ~Directory();
262 // Does not take ownership of |delegate|, which must not be NULL.
263 // Starts sending events to |delegate| if the returned result is
264 // OPENED. Note that events to |delegate| may be sent from *any*
265 // thread. |transaction_observer| must be initialized.
266 DirOpenResult
Open(const std::string
& name
,
267 DirectoryChangeDelegate
* delegate
,
268 const WeakHandle
<TransactionObserver
>&
269 transaction_observer
);
271 int64
NextMetahandle();
272 // Returns a negative integer unique to this client.
273 syncable::Id
NextId();
275 bool good() const { return NULL
!= kernel_
; }
277 // The download progress is an opaque token provided by the sync server
278 // to indicate the continuation state of the next GetUpdates operation.
279 void GetDownloadProgress(
281 sync_pb::DataTypeProgressMarker
* value_out
) const;
282 void GetDownloadProgressAsString(
284 std::string
* value_out
) const;
285 void SetDownloadProgress(
287 const sync_pb::DataTypeProgressMarker
& value
);
288 bool HasEmptyDownloadProgress(ModelType type
) const;
290 // Gets the total number of entries in the directory.
291 size_t GetEntriesCount() const;
293 // Gets/Increments transaction version of a model type. Must be called when
294 // holding kernel mutex.
295 int64
GetTransactionVersion(ModelType type
) const;
296 void IncrementTransactionVersion(ModelType type
);
298 // Getter/setters for the per datatype context.
299 void GetDataTypeContext(BaseTransaction
* trans
,
301 sync_pb::DataTypeContext
* context
) const;
302 void SetDataTypeContext(BaseWriteTransaction
* trans
,
304 const sync_pb::DataTypeContext
& context
);
306 ModelTypeSet
InitialSyncEndedTypes();
307 bool InitialSyncEndedForType(ModelType type
);
309 // (Account) Store birthday is opaque to the client, so we keep it in the
310 // format it is in the proto buffer in case we switch to a binary birthday
312 std::string
store_birthday() const;
313 void set_store_birthday(const std::string
& store_birthday
);
315 // (Account) Bag of chip is an opaque state used by the server to track the
317 std::string
bag_of_chips() const;
318 void set_bag_of_chips(const std::string
& bag_of_chips
);
320 // Unique to each account / client pair.
321 std::string
cache_guid() const;
323 // Returns a pointer to our Nigori node handler.
324 NigoriHandler
* GetNigoriHandler();
326 // Returns a pointer to our cryptographer. Does not transfer ownership.
327 // Not thread safe, so should only be accessed while holding a transaction.
328 Cryptographer
* GetCryptographer(const BaseTransaction
* trans
);
330 // Called to immediately report an unrecoverable error (but don't
332 void ReportUnrecoverableError() {
333 if (report_unrecoverable_error_function_
) {
334 report_unrecoverable_error_function_();
338 // Called to set the unrecoverable error on the directory and to propagate
339 // the error to upper layers.
340 void OnUnrecoverableError(const BaseTransaction
* trans
,
341 const tracked_objects::Location
& location
,
342 const std::string
& message
);
344 DeleteJournal
* delete_journal();
346 // Returns the child meta handles (even those for deleted/unlinked
347 // nodes) for given parent id. Clears |result| if there are no
349 bool GetChildHandlesById(BaseTransaction
*, const Id
& parent_id
,
350 Metahandles
* result
);
352 // Counts all items under the given node, including the node itself.
353 int GetTotalNodeCount(BaseTransaction
*, EntryKernel
* kernel_
) const;
355 // Returns this item's position within its parent folder.
356 // The left-most item is 0, second left-most is 1, etc.
357 int GetPositionIndex(BaseTransaction
*, EntryKernel
* kernel_
) const;
359 // Returns true iff |id| has children.
360 bool HasChildren(BaseTransaction
* trans
, const Id
& id
);
362 // Find the first child in the positional ordering under a parent,
363 // and fill in |*first_child_id| with its id. Fills in a root Id if
364 // parent has no children. Returns true if the first child was
365 // successfully found, or false if an error was encountered.
366 Id
GetFirstChildId(BaseTransaction
* trans
, const EntryKernel
* parent
);
368 // These functions allow one to fetch the next or previous item under
369 // the same folder. Returns the "root" ID if there is no predecessor
372 // TODO(rlarocque): These functions are used mainly for tree traversal. We
373 // should replace these with an iterator API. See crbug.com/178275.
374 syncable::Id
GetPredecessorId(EntryKernel
*);
375 syncable::Id
GetSuccessorId(EntryKernel
*);
377 // Places |e| as a successor to |predecessor|. If |predecessor| is NULL,
378 // |e| will be placed as the left-most item in its folder.
380 // Both |e| and |predecessor| must be valid entries under the same parent.
382 // TODO(rlarocque): This function includes limited support for placing items
383 // with valid positions (ie. Bookmarks) as siblings of items that have no set
384 // ordering (ie. Autofill items). This support is required only for tests,
385 // and should be removed. See crbug.com/178282.
386 void PutPredecessor(EntryKernel
* e
, EntryKernel
* predecessor
);
388 // SaveChanges works by taking a consistent snapshot of the current Directory
389 // state and indices (by deep copy) under a ReadTransaction, passing this
390 // snapshot to the backing store under no transaction, and finally cleaning
391 // up by either purging entries no longer needed (this part done under a
392 // WriteTransaction) or rolling back the dirty bits. It also uses
393 // internal locking to enforce SaveChanges operations are mutually exclusive.
395 // WARNING: THIS METHOD PERFORMS SYNCHRONOUS I/O VIA SQLITE.
398 // Returns the number of entities with the unsynced bit set.
399 int64
unsynced_entity_count() const;
401 // Get GetUnsyncedMetaHandles should only be called after SaveChanges and
402 // before any new entries have been created. The intention is that the
403 // syncer should call it from its PerformSyncQueries member.
404 void GetUnsyncedMetaHandles(BaseTransaction
* trans
,
405 Metahandles
* result
);
407 // Returns whether or not this |type| has unapplied updates.
408 bool TypeHasUnappliedUpdates(ModelType type
);
410 // Get all the metahandles for unapplied updates for a given set of
412 void GetUnappliedUpdateMetaHandles(BaseTransaction
* trans
,
413 FullModelTypeSet server_types
,
414 std::vector
<int64
>* result
);
416 // Get all the metahandles of entries of |type|.
417 void GetMetaHandlesOfType(BaseTransaction
* trans
,
419 Metahandles
* result
);
421 // Get metahandle counts for various criteria to show on the
422 // about:sync page. The information is computed on the fly
423 // each time. If this results in a significant performance hit,
424 // additional data structures can be added to cache results.
425 void CollectMetaHandleCounts(std::vector
<int>* num_entries_by_type
,
426 std::vector
<int>* num_to_delete_entries_by_type
);
428 // Returns a ListValue serialization of all nodes for the given type.
429 scoped_ptr
<base::ListValue
> GetNodeDetailsForType(
430 BaseTransaction
* trans
,
433 // Sets the level of invariant checking performed after transactions.
434 void SetInvariantCheckLevel(InvariantCheckLevel check_level
);
436 // Checks tree metadata consistency following a transaction. It is intended
437 // to provide a reasonable tradeoff between performance and comprehensiveness
438 // and may be used in release code.
439 bool CheckInvariantsOnTransactionClose(
440 syncable::BaseTransaction
* trans
,
441 const MetahandleSet
& modified_handles
);
443 // Forces a full check of the directory. This operation may be slow and
444 // should not be invoked outside of tests.
445 bool FullyCheckTreeInvariants(BaseTransaction
*trans
);
447 // Purges data associated with any entries whose ModelType or ServerModelType
448 // is found in |disabled_types|, from sync directory _both_ in memory and on
449 // disk. Only valid, "real" model types are allowed in |disabled_types| (see
450 // model_type.h for definitions).
451 // 1. Data associated with |types_to_journal| is saved in the delete journal
452 // to help prevent back-from-dead problem due to offline delete in the next
453 // sync session. |types_to_journal| must be a subset of |disabled_types|.
454 // 2. Data associated with |types_to_unapply| is reset to an "unapplied"
455 // state, wherein all local data is deleted and IS_UNAPPLIED is set to true.
456 // This is useful when there's no benefit in discarding the currently
457 // downloaded state, such as when there are cryptographer errors.
458 // |types_to_unapply| must be a subset of |disabled_types|.
459 // 3. All other data is purged entirely.
460 // Note: "Purge" is just meant to distinguish from "deleting" entries, which
461 // means something different in the syncable namespace.
462 // WARNING! This can be real slow, as it iterates over all entries.
463 // WARNING! Performs synchronous I/O.
464 // Returns: true on success, false if an error was encountered.
465 virtual bool PurgeEntriesWithTypeIn(ModelTypeSet disabled_types
,
466 ModelTypeSet types_to_journal
,
467 ModelTypeSet types_to_unapply
);
469 // Resets the base_versions and server_versions of all synced entities
470 // associated with |type| to 1.
471 // WARNING! This can be slow, as it iterates over all entries for a type.
472 bool ResetVersionsForType(BaseWriteTransaction
* trans
, ModelType type
);
474 // Returns true iff the attachment identified by |attachment_id_proto| is
475 // linked to an entry.
477 // An attachment linked to a deleted entry is still considered linked if the
478 // entry hasn't yet been purged.
479 bool IsAttachmentLinked(
480 const sync_pb::AttachmentIdProto
& attachment_id_proto
) const;
482 // Given attachment id return metahandles to all entries that reference this
484 void GetMetahandlesByAttachmentId(
485 BaseTransaction
* trans
,
486 const sync_pb::AttachmentIdProto
& attachment_id_proto
,
487 Metahandles
* result
);
489 // Change entry to not dirty. Used in special case when we don't want to
490 // persist modified entry on disk. e.g. SyncBackupManager uses this to
491 // preserve sync preferences in DB on disk.
492 void UnmarkDirtyEntry(WriteTransaction
* trans
, Entry
* entry
);
494 // Clears |ids| and fills it with the ids of attachments that need to be
495 // uploaded to the sync server.
496 void GetAttachmentIdsToUpload(BaseTransaction
* trans
,
498 AttachmentIdList
* ids
);
500 // For new entry creation only.
501 bool InsertEntry(BaseWriteTransaction
* trans
, EntryKernel
* entry
);
503 // Update the attachment index for |metahandle| removing it from the index
504 // under |old_metadata| entries and add it under |new_metadata| entries.
505 void UpdateAttachmentIndex(const int64 metahandle
,
506 const sync_pb::AttachmentMetadata
& old_metadata
,
507 const sync_pb::AttachmentMetadata
& new_metadata
);
509 virtual EntryKernel
* GetEntryById(const Id
& id
);
510 virtual EntryKernel
* GetEntryByClientTag(const std::string
& tag
);
511 EntryKernel
* GetEntryByServerTag(const std::string
& tag
);
513 virtual EntryKernel
* GetEntryByHandle(int64 handle
);
515 bool ReindexId(BaseWriteTransaction
* trans
, EntryKernel
* const entry
,
518 bool ReindexParentId(BaseWriteTransaction
* trans
, EntryKernel
* const entry
,
519 const Id
& new_parent_id
);
521 // Accessors for the underlying Kernel. Although these are public methods, the
522 // number of classes that call these should be limited.
524 const Kernel
* kernel() const;
527 friend class SyncableDirectoryTest
;
528 friend class syncer::TestUserShare
;
529 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest
, ManageDeleteJournals
);
530 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest
,
531 TakeSnapshotGetsAllDirtyHandlesTest
);
532 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest
,
533 TakeSnapshotGetsOnlyDirtyHandlesTest
);
534 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest
,
535 TakeSnapshotGetsMetahandlesToPurge
);
537 // You'll notice that some of the methods below are private overloads of the
538 // public ones declared above. The general pattern is that the public overload
539 // constructs a ScopedKernelLock before calling the corresponding private
540 // overload with the held ScopedKernelLock.
542 virtual EntryKernel
* GetEntryByHandle(const ScopedKernelLock
& lock
,
545 virtual EntryKernel
* GetEntryById(const ScopedKernelLock
& lock
, const Id
& id
);
547 bool InsertEntry(const ScopedKernelLock
& lock
,
548 BaseWriteTransaction
* trans
,
551 // Remove each of |metahandle|'s attachment ids from index_by_attachment_id.
552 void RemoveFromAttachmentIndex(
553 const ScopedKernelLock
& lock
,
554 const int64 metahandle
,
555 const sync_pb::AttachmentMetadata
& attachment_metadata
);
557 // Add each of |metahandle|'s attachment ids to the index_by_attachment_id.
558 void AddToAttachmentIndex(
559 const ScopedKernelLock
& lock
,
560 const int64 metahandle
,
561 const sync_pb::AttachmentMetadata
& attachment_metadata
);
563 void ClearDirtyMetahandles(const ScopedKernelLock
& lock
);
565 DirOpenResult
OpenImpl(
566 const std::string
& name
,
567 DirectoryChangeDelegate
* delegate
,
568 const WeakHandle
<TransactionObserver
>& transaction_observer
);
570 // A helper that implements the logic of checking tree invariants.
571 bool CheckTreeInvariants(syncable::BaseTransaction
* trans
,
572 const MetahandleSet
& handles
);
574 // Helper to prime metahandles_map, ids_map, parent_child_index,
575 // unsynced_metahandles, unapplied_update_metahandles, server_tags_map and
576 // client_tags_map from metahandles_index. The input |handles_map| will be
577 // cleared during the initialization process.
578 void InitializeIndices(MetahandlesMap
* handles_map
);
580 // Constructs a consistent snapshot of the current Directory state and
581 // indices (by deep copy) under a ReadTransaction for use in |snapshot|.
582 // See SaveChanges() for more information.
583 void TakeSnapshotForSaveChanges(SaveChangesSnapshot
* snapshot
);
585 // Purges from memory any unused, safe to remove entries that were
586 // successfully deleted on disk as a result of the SaveChanges that processed
587 // |snapshot|. See SaveChanges() for more information.
588 bool VacuumAfterSaveChanges(const SaveChangesSnapshot
& snapshot
);
590 // Rolls back dirty bits in the event that the SaveChanges that
591 // processed |snapshot| failed, for example, due to no disk space.
592 void HandleSaveChangesFailure(const SaveChangesSnapshot
& snapshot
);
594 // Used by CheckTreeInvariants.
595 void GetAllMetaHandles(BaseTransaction
* trans
, MetahandleSet
* result
);
597 // Used by VacuumAfterSaveChanges.
598 bool SafeToPurgeFromMemory(WriteTransaction
* trans
,
599 const EntryKernel
* const entry
) const;
600 // A helper used by GetTotalNodeCount.
601 void GetChildSetForKernel(
603 EntryKernel
* kernel_
,
604 std::deque
<const OrderedChildSet
*>* child_sets
) const;
606 // Append the handles of the children of |parent_id| to |result|.
607 void AppendChildHandles(const ScopedKernelLock
& lock
,
609 Directory::Metahandles
* result
);
611 // Helper methods used by PurgeDisabledTypes.
612 void UnapplyEntry(EntryKernel
* entry
);
613 void DeleteEntry(const ScopedKernelLock
& lock
,
614 bool save_to_journal
,
616 EntryKernelSet
* entries_to_journal
);
618 // A private version of the public GetMetaHandlesOfType for when you already
619 // have a ScopedKernelLock.
620 void GetMetaHandlesOfType(const ScopedKernelLock
& lock
,
621 BaseTransaction
* trans
,
623 std::vector
<int64
>* result
);
625 // Returns true if the initial sync for |type| has completed.
626 bool InitialSyncEndedForType(BaseTransaction
* trans
, ModelType type
);
628 // Stops sending events to the delegate and the transaction
632 // Returns true if the directory had encountered an unrecoverable error.
633 // Note: Any function in |Directory| that can be called without holding a
634 // transaction need to check if the Directory already has an unrecoverable
636 bool unrecoverable_error_set(const BaseTransaction
* trans
) const;
640 scoped_ptr
<DirectoryBackingStore
> store_
;
642 UnrecoverableErrorHandler
* const unrecoverable_error_handler_
;
643 const ReportUnrecoverableErrorFunction report_unrecoverable_error_function_
;
644 bool unrecoverable_error_set_
;
647 NigoriHandler
* const nigori_handler_
;
648 Cryptographer
* const cryptographer_
;
650 InvariantCheckLevel invariant_check_level_
;
652 // Maintain deleted entries not in |kernel_| until it's verified that they
653 // are deleted in native models as well.
654 scoped_ptr
<DeleteJournal
> delete_journal_
;
656 DISALLOW_COPY_AND_ASSIGN(Directory
);
659 } // namespace syncable
660 } // namespace syncer
662 #endif // SYNC_SYNCABLE_DIRECTORY_H_