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