[chromedriver] Explicitly set page loading state when document.readyState != "complete".
[chromium-blink-merge.git] / sync / syncable / directory.h
blob7358f179bd94e0a53fb97ecb69eb3ae30c4e8235
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/callback.h"
15 #include "base/containers/hash_tables.h"
16 #include "base/files/file_util.h"
17 #include "base/gtest_prod_util.h"
18 #include "base/values.h"
19 #include "sync/api/attachments/attachment_id.h"
20 #include "sync/base/sync_export.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 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 public:
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>
75 IndexByAttachmentId;
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.
108 // Bug 154858.
109 int64 transaction_version[MODEL_TYPE_COUNT];
110 // The store birthday we were given by the server. Contents are opaque to
111 // the client.
112 std::string store_birthday;
113 // The serialized bag of chips we were given by the server. Contents are
114 // opaque to the client. This is the serialization of a message of type
115 // ChipBag defined in sync.proto. It can contains NULL characters.
116 std::string bag_of_chips;
117 // The per-datatype context.
118 sync_pb::DataTypeContext datatype_context[MODEL_TYPE_COUNT];
121 // What the Directory needs on initialization to create itself and its Kernel.
122 // Filled by DirectoryBackingStore::Load.
123 struct KernelLoadInfo {
124 PersistedKernelInfo kernel_info;
125 std::string cache_guid; // Created on first initialization, never changes.
126 int64 max_metahandle; // Computed (using sql MAX aggregate) on init.
127 KernelLoadInfo() : max_metahandle(0) {
131 // When the Directory is told to SaveChanges, a SaveChangesSnapshot is
132 // constructed and forms a consistent snapshot of what needs to be sent to
133 // the backing store.
134 struct SYNC_EXPORT_PRIVATE SaveChangesSnapshot {
135 SaveChangesSnapshot();
136 ~SaveChangesSnapshot();
138 // Returns true if this snapshot has any unsaved metahandle changes.
139 bool HasUnsavedMetahandleChanges() const;
141 KernelShareInfoStatus kernel_info_status;
142 PersistedKernelInfo kernel_info;
143 EntryKernelSet dirty_metas;
144 MetahandleSet metahandles_to_purge;
145 EntryKernelSet delete_journals;
146 MetahandleSet delete_journals_to_purge;
149 struct Kernel {
150 // |delegate| must not be NULL. |transaction_observer| must be
151 // initialized.
152 Kernel(const std::string& name, const KernelLoadInfo& info,
153 DirectoryChangeDelegate* delegate,
154 const WeakHandle<TransactionObserver>& transaction_observer);
156 ~Kernel();
158 // Implements ReadTransaction / WriteTransaction using a simple lock.
159 base::Lock transaction_mutex;
161 // Protected by transaction_mutex. Used by WriteTransactions.
162 int64 next_write_transaction_id;
164 // The name of this directory.
165 std::string const name;
167 // Protects all members below.
168 // The mutex effectively protects all the indices, but not the
169 // entries themselves. So once a pointer to an entry is pulled
170 // from the index, the mutex can be unlocked and entry read or written.
172 // Never hold the mutex and do anything with the database or any
173 // other buffered IO. Violating this rule will result in deadlock.
174 mutable base::Lock mutex;
176 // Entries indexed by metahandle. This container is considered to be the
177 // owner of all EntryKernels, which may be referened by the other
178 // containers. If you remove an EntryKernel from this map, you probably
179 // want to remove it from all other containers and delete it, too.
180 MetahandlesMap metahandles_map;
182 // Entries indexed by id
183 IdsMap ids_map;
185 // Entries indexed by server tag.
186 // This map does not include any entries with non-existent server tags.
187 TagsMap server_tags_map;
189 // Entries indexed by client tag.
190 // This map does not include any entries with non-existent client tags.
191 // IS_DEL items are included.
192 TagsMap client_tags_map;
194 // Contains non-deleted items, indexed according to parent and position
195 // within parent. Protected by the ScopedKernelLock.
196 ParentChildIndex parent_child_index;
198 // This index keeps track of which metahandles refer to a given attachment.
199 // Think of it as the inverse of EntryKernel's AttachmentMetadata Records.
201 // Because entries can be undeleted (e.g. PutIsDel(false)), entries should
202 // not removed from the index until they are actually deleted from memory.
204 // All access should go through IsAttachmentLinked,
205 // RemoveFromAttachmentIndex, AddToAttachmentIndex, and
206 // UpdateAttachmentIndex methods to avoid iterator invalidation errors.
207 IndexByAttachmentId index_by_attachment_id;
209 // 3 in-memory indices on bits used extremely frequently by the syncer.
210 // |unapplied_update_metahandles| is keyed by the server model type.
211 MetahandleSet unapplied_update_metahandles[MODEL_TYPE_COUNT];
212 MetahandleSet unsynced_metahandles;
213 // Contains metahandles that are most likely dirty (though not
214 // necessarily). Dirtyness is confirmed in TakeSnapshotForSaveChanges().
215 MetahandleSet dirty_metahandles;
217 // When a purge takes place, we remove items from all our indices and stash
218 // them in here so that SaveChanges can persist their permanent deletion.
219 MetahandleSet metahandles_to_purge;
221 KernelShareInfoStatus info_status;
223 // These 3 members are backed in the share_info table, and
224 // their state is marked by the flag above.
226 // A structure containing the Directory state that is written back into the
227 // database on SaveChanges.
228 PersistedKernelInfo persisted_info;
230 // A unique identifier for this account's cache db, used to generate
231 // unique server IDs. No need to lock, only written at init time.
232 const std::string cache_guid;
234 // It doesn't make sense for two threads to run SaveChanges at the same
235 // time; this mutex protects that activity.
236 base::Lock save_changes_mutex;
238 // The next metahandle is protected by kernel mutex.
239 int64 next_metahandle;
241 // The delegate for directory change events. Must not be NULL.
242 DirectoryChangeDelegate* const delegate;
244 // The transaction observer.
245 const WeakHandle<TransactionObserver> transaction_observer;
248 // Does not take ownership of |encryptor|.
249 // |report_unrecoverable_error_function| may be NULL.
250 // Takes ownership of |store|.
251 Directory(DirectoryBackingStore* store,
252 UnrecoverableErrorHandler* unrecoverable_error_handler,
253 const base::Closure& report_unrecoverable_error_function,
254 NigoriHandler* nigori_handler,
255 Cryptographer* cryptographer);
256 virtual ~Directory();
258 // Does not take ownership of |delegate|, which must not be NULL.
259 // Starts sending events to |delegate| if the returned result is
260 // OPENED. Note that events to |delegate| may be sent from *any*
261 // thread. |transaction_observer| must be initialized.
262 DirOpenResult Open(const std::string& name,
263 DirectoryChangeDelegate* delegate,
264 const WeakHandle<TransactionObserver>&
265 transaction_observer);
267 int64 NextMetahandle();
268 // Generates next client ID based on a randomly generated GUID.
269 syncable::Id NextId();
271 bool good() const { return NULL != kernel_; }
273 // The download progress is an opaque token provided by the sync server
274 // to indicate the continuation state of the next GetUpdates operation.
275 void GetDownloadProgress(
276 ModelType type,
277 sync_pb::DataTypeProgressMarker* value_out) const;
278 void GetDownloadProgressAsString(
279 ModelType type,
280 std::string* value_out) const;
281 void SetDownloadProgress(
282 ModelType type,
283 const sync_pb::DataTypeProgressMarker& value);
284 bool HasEmptyDownloadProgress(ModelType type) const;
286 // Gets the total number of entries in the directory.
287 size_t GetEntriesCount() const;
289 // Gets/Increments transaction version of a model type. Must be called when
290 // holding kernel mutex.
291 int64 GetTransactionVersion(ModelType type) const;
292 void IncrementTransactionVersion(ModelType type);
294 // Getter/setters for the per datatype context.
295 void GetDataTypeContext(BaseTransaction* trans,
296 ModelType type,
297 sync_pb::DataTypeContext* context) const;
298 void SetDataTypeContext(BaseWriteTransaction* trans,
299 ModelType type,
300 const sync_pb::DataTypeContext& context);
302 ModelTypeSet InitialSyncEndedTypes();
303 bool InitialSyncEndedForType(ModelType type);
305 // (Account) Store birthday is opaque to the client, so we keep it in the
306 // format it is in the proto buffer in case we switch to a binary birthday
307 // later.
308 std::string store_birthday() const;
309 void set_store_birthday(const std::string& store_birthday);
311 // (Account) Bag of chip is an opaque state used by the server to track the
312 // client.
313 std::string bag_of_chips() const;
314 void set_bag_of_chips(const std::string& bag_of_chips);
316 // Unique to each account / client pair.
317 std::string cache_guid() const;
319 // Returns a pointer to our Nigori node handler.
320 NigoriHandler* GetNigoriHandler();
322 // Returns a pointer to our cryptographer. Does not transfer ownership.
323 // Not thread safe, so should only be accessed while holding a transaction.
324 Cryptographer* GetCryptographer(const BaseTransaction* trans);
326 // Called to immediately report an unrecoverable error (but don't
327 // propagate it up).
328 void ReportUnrecoverableError();
330 // Called to set the unrecoverable error on the directory and to propagate
331 // the error to upper layers.
332 void OnUnrecoverableError(const BaseTransaction* trans,
333 const tracked_objects::Location& location,
334 const std::string & message);
336 DeleteJournal* delete_journal();
338 // Returns the child meta handles (even those for deleted/unlinked
339 // nodes) for given parent id. Clears |result| if there are no
340 // children.
341 bool GetChildHandlesById(BaseTransaction*, const Id& parent_id,
342 Metahandles* result);
344 // Counts all items under the given node, including the node itself.
345 int GetTotalNodeCount(BaseTransaction*, EntryKernel* kernel_) const;
347 // Returns this item's position within its parent folder.
348 // The left-most item is 0, second left-most is 1, etc.
349 int GetPositionIndex(BaseTransaction*, EntryKernel* kernel_) const;
351 // Returns true iff |id| has children.
352 bool HasChildren(BaseTransaction* trans, const Id& id);
354 // Find the first child in the positional ordering under a parent,
355 // and fill in |*first_child_id| with its id. Fills in a root Id if
356 // parent has no children. Returns true if the first child was
357 // successfully found, or false if an error was encountered.
358 Id GetFirstChildId(BaseTransaction* trans, const EntryKernel* parent);
360 // These functions allow one to fetch the next or previous item under
361 // the same folder. Returns the "root" ID if there is no predecessor
362 // or successor.
364 // TODO(rlarocque): These functions are used mainly for tree traversal. We
365 // should replace these with an iterator API. See crbug.com/178275.
366 syncable::Id GetPredecessorId(EntryKernel*);
367 syncable::Id GetSuccessorId(EntryKernel*);
369 // Places |e| as a successor to |predecessor|. If |predecessor| is NULL,
370 // |e| will be placed as the left-most item in its folder.
372 // Both |e| and |predecessor| must be valid entries under the same parent.
374 // TODO(rlarocque): This function includes limited support for placing items
375 // with valid positions (ie. Bookmarks) as siblings of items that have no set
376 // ordering (ie. Autofill items). This support is required only for tests,
377 // and should be removed. See crbug.com/178282.
378 void PutPredecessor(EntryKernel* e, EntryKernel* predecessor);
380 // SaveChanges works by taking a consistent snapshot of the current Directory
381 // state and indices (by deep copy) under a ReadTransaction, passing this
382 // snapshot to the backing store under no transaction, and finally cleaning
383 // up by either purging entries no longer needed (this part done under a
384 // WriteTransaction) or rolling back the dirty bits. It also uses
385 // internal locking to enforce SaveChanges operations are mutually exclusive.
387 // WARNING: THIS METHOD PERFORMS SYNCHRONOUS I/O VIA SQLITE.
388 bool SaveChanges();
390 // Returns the number of entities with the unsynced bit set.
391 int64 unsynced_entity_count() const;
393 // Get GetUnsyncedMetaHandles should only be called after SaveChanges and
394 // before any new entries have been created. The intention is that the
395 // syncer should call it from its PerformSyncQueries member.
396 void GetUnsyncedMetaHandles(BaseTransaction* trans,
397 Metahandles* result);
399 // Returns whether or not this |type| has unapplied updates.
400 bool TypeHasUnappliedUpdates(ModelType type);
402 // Get all the metahandles for unapplied updates for a given set of
403 // server types.
404 void GetUnappliedUpdateMetaHandles(BaseTransaction* trans,
405 FullModelTypeSet server_types,
406 std::vector<int64>* result);
408 // Get all the metahandles of entries of |type|.
409 void GetMetaHandlesOfType(BaseTransaction* trans,
410 ModelType type,
411 Metahandles* result);
413 // Get metahandle counts for various criteria to show on the
414 // about:sync page. The information is computed on the fly
415 // each time. If this results in a significant performance hit,
416 // additional data structures can be added to cache results.
417 void CollectMetaHandleCounts(std::vector<int>* num_entries_by_type,
418 std::vector<int>* num_to_delete_entries_by_type);
420 // Returns a ListValue serialization of all nodes for the given type.
421 scoped_ptr<base::ListValue> GetNodeDetailsForType(
422 BaseTransaction* trans,
423 ModelType type);
425 // Sets the level of invariant checking performed after transactions.
426 void SetInvariantCheckLevel(InvariantCheckLevel check_level);
428 // Checks tree metadata consistency following a transaction. It is intended
429 // to provide a reasonable tradeoff between performance and comprehensiveness
430 // and may be used in release code.
431 bool CheckInvariantsOnTransactionClose(
432 syncable::BaseTransaction* trans,
433 const MetahandleSet& modified_handles);
435 // Forces a full check of the directory. This operation may be slow and
436 // should not be invoked outside of tests.
437 bool FullyCheckTreeInvariants(BaseTransaction *trans);
439 // Purges data associated with any entries whose ModelType or ServerModelType
440 // is found in |disabled_types|, from sync directory _both_ in memory and on
441 // disk. Only valid, "real" model types are allowed in |disabled_types| (see
442 // model_type.h for definitions).
443 // 1. Data associated with |types_to_journal| is saved in the delete journal
444 // to help prevent back-from-dead problem due to offline delete in the next
445 // sync session. |types_to_journal| must be a subset of |disabled_types|.
446 // 2. Data associated with |types_to_unapply| is reset to an "unapplied"
447 // state, wherein all local data is deleted and IS_UNAPPLIED is set to true.
448 // This is useful when there's no benefit in discarding the currently
449 // downloaded state, such as when there are cryptographer errors.
450 // |types_to_unapply| must be a subset of |disabled_types|.
451 // 3. All other data is purged entirely.
452 // Note: "Purge" is just meant to distinguish from "deleting" entries, which
453 // means something different in the syncable namespace.
454 // WARNING! This can be real slow, as it iterates over all entries.
455 // WARNING! Performs synchronous I/O.
456 // Returns: true on success, false if an error was encountered.
457 virtual bool PurgeEntriesWithTypeIn(ModelTypeSet disabled_types,
458 ModelTypeSet types_to_journal,
459 ModelTypeSet types_to_unapply);
461 // Resets the base_versions and server_versions of all synced entities
462 // associated with |type| to 1.
463 // WARNING! This can be slow, as it iterates over all entries for a type.
464 bool ResetVersionsForType(BaseWriteTransaction* trans, ModelType type);
466 // Returns true iff the attachment identified by |attachment_id_proto| is
467 // linked to an entry.
469 // An attachment linked to a deleted entry is still considered linked if the
470 // entry hasn't yet been purged.
471 bool IsAttachmentLinked(
472 const sync_pb::AttachmentIdProto& attachment_id_proto) const;
474 // Given attachment id return metahandles to all entries that reference this
475 // attachment.
476 void GetMetahandlesByAttachmentId(
477 BaseTransaction* trans,
478 const sync_pb::AttachmentIdProto& attachment_id_proto,
479 Metahandles* result);
481 // Change entry to not dirty. Used in special case when we don't want to
482 // persist modified entry on disk. e.g. SyncBackupManager uses this to
483 // preserve sync preferences in DB on disk.
484 void UnmarkDirtyEntry(WriteTransaction* trans, Entry* entry);
486 // Clears |ids| and fills it with the ids of attachments that need to be
487 // uploaded to the sync server.
488 void GetAttachmentIdsToUpload(BaseTransaction* trans,
489 ModelType type,
490 AttachmentIdList* ids);
492 // For new entry creation only.
493 bool InsertEntry(BaseWriteTransaction* trans, EntryKernel* entry);
495 // Update the attachment index for |metahandle| removing it from the index
496 // under |old_metadata| entries and add it under |new_metadata| entries.
497 void UpdateAttachmentIndex(const int64 metahandle,
498 const sync_pb::AttachmentMetadata& old_metadata,
499 const sync_pb::AttachmentMetadata& new_metadata);
501 virtual EntryKernel* GetEntryById(const Id& id);
502 virtual EntryKernel* GetEntryByClientTag(const std::string& tag);
503 EntryKernel* GetEntryByServerTag(const std::string& tag);
505 virtual EntryKernel* GetEntryByHandle(int64 handle);
507 bool ReindexId(BaseWriteTransaction* trans, EntryKernel* const entry,
508 const Id& new_id);
510 bool ReindexParentId(BaseWriteTransaction* trans, EntryKernel* const entry,
511 const Id& new_parent_id);
513 // Accessors for the underlying Kernel. Although these are public methods, the
514 // number of classes that call these should be limited.
515 Kernel* kernel();
516 const Kernel* kernel() const;
518 private:
519 friend class SyncableDirectoryTest;
520 friend class syncer::TestUserShare;
521 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, ManageDeleteJournals);
522 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest,
523 TakeSnapshotGetsAllDirtyHandlesTest);
524 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest,
525 TakeSnapshotGetsOnlyDirtyHandlesTest);
526 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest,
527 TakeSnapshotGetsMetahandlesToPurge);
528 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, CatastrophicError);
530 // You'll notice that some of the methods below are private overloads of the
531 // public ones declared above. The general pattern is that the public overload
532 // constructs a ScopedKernelLock before calling the corresponding private
533 // overload with the held ScopedKernelLock.
535 virtual EntryKernel* GetEntryByHandle(const ScopedKernelLock& lock,
536 int64 metahandle);
538 virtual EntryKernel* GetEntryById(const ScopedKernelLock& lock, const Id& id);
540 bool InsertEntry(const ScopedKernelLock& lock,
541 BaseWriteTransaction* trans,
542 EntryKernel* entry);
544 // Remove each of |metahandle|'s attachment ids from index_by_attachment_id.
545 void RemoveFromAttachmentIndex(
546 const ScopedKernelLock& lock,
547 const int64 metahandle,
548 const sync_pb::AttachmentMetadata& attachment_metadata);
550 // Add each of |metahandle|'s attachment ids to the index_by_attachment_id.
551 void AddToAttachmentIndex(
552 const ScopedKernelLock& lock,
553 const int64 metahandle,
554 const sync_pb::AttachmentMetadata& attachment_metadata);
556 void ClearDirtyMetahandles(const ScopedKernelLock& lock);
558 DirOpenResult OpenImpl(
559 const std::string& name,
560 DirectoryChangeDelegate* delegate,
561 const WeakHandle<TransactionObserver>& transaction_observer);
563 // A helper that implements the logic of checking tree invariants.
564 bool CheckTreeInvariants(syncable::BaseTransaction* trans,
565 const MetahandleSet& handles);
567 // Helper to prime metahandles_map, ids_map, parent_child_index,
568 // unsynced_metahandles, unapplied_update_metahandles, server_tags_map and
569 // client_tags_map from metahandles_index. The input |handles_map| will be
570 // cleared during the initialization process.
571 void InitializeIndices(MetahandlesMap* handles_map);
573 // Constructs a consistent snapshot of the current Directory state and
574 // indices (by deep copy) under a ReadTransaction for use in |snapshot|.
575 // See SaveChanges() for more information.
576 void TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot);
578 // Purges from memory any unused, safe to remove entries that were
579 // successfully deleted on disk as a result of the SaveChanges that processed
580 // |snapshot|. See SaveChanges() for more information.
581 bool VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot);
583 // Rolls back dirty bits in the event that the SaveChanges that
584 // processed |snapshot| failed, for example, due to no disk space.
585 void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot);
587 // Used by CheckTreeInvariants.
588 void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result);
590 // Used by VacuumAfterSaveChanges.
591 bool SafeToPurgeFromMemory(WriteTransaction* trans,
592 const EntryKernel* const entry) const;
593 // A helper used by GetTotalNodeCount.
594 void GetChildSetForKernel(
595 BaseTransaction*,
596 EntryKernel* kernel_,
597 std::deque<const OrderedChildSet*>* child_sets) const;
599 // Append the handles of the children of |parent_id| to |result|.
600 void AppendChildHandles(const ScopedKernelLock& lock,
601 const Id& parent_id,
602 Directory::Metahandles* result);
604 // Helper methods used by PurgeDisabledTypes.
605 void UnapplyEntry(EntryKernel* entry);
606 void DeleteEntry(const ScopedKernelLock& lock,
607 bool save_to_journal,
608 EntryKernel* entry,
609 EntryKernelSet* entries_to_journal);
611 // A private version of the public GetMetaHandlesOfType for when you already
612 // have a ScopedKernelLock.
613 void GetMetaHandlesOfType(const ScopedKernelLock& lock,
614 BaseTransaction* trans,
615 ModelType type,
616 std::vector<int64>* result);
618 // Invoked by DirectoryBackingStore when a catastrophic database error is
619 // detected.
620 void OnCatastrophicError();
622 // Returns true if the initial sync for |type| has completed.
623 bool InitialSyncEndedForType(BaseTransaction* trans, ModelType type);
625 // Stops sending events to the delegate and the transaction
626 // observer.
627 void Close();
629 // Returns true if the directory had encountered an unrecoverable error.
630 // Note: Any function in |Directory| that can be called without holding a
631 // transaction need to check if the Directory already has an unrecoverable
632 // error on it.
633 bool unrecoverable_error_set(const BaseTransaction* trans) const;
635 Kernel* kernel_;
637 scoped_ptr<DirectoryBackingStore> store_;
639 UnrecoverableErrorHandler* const unrecoverable_error_handler_;
640 base::Closure report_unrecoverable_error_function_;
641 bool unrecoverable_error_set_;
643 // Not owned.
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 base::WeakPtrFactory<Directory> weak_ptr_factory_;
655 DISALLOW_COPY_AND_ASSIGN(Directory);
658 } // namespace syncable
659 } // namespace syncer
661 #endif // SYNC_SYNCABLE_DIRECTORY_H_