diff options
-rw-r--r-- | sync/engine/conflict_resolver.cc | 2 | ||||
-rw-r--r-- | sync/engine/get_commit_ids_command.cc | 8 | ||||
-rw-r--r-- | sync/engine/get_commit_ids_command.h | 2 | ||||
-rw-r--r-- | sync/engine/syncer_unittest.cc | 14 | ||||
-rw-r--r-- | sync/engine/syncer_util.cc | 6 | ||||
-rw-r--r-- | sync/internal_api/sync_manager_impl.cc | 4 | ||||
-rw-r--r-- | sync/sync_core.gypi | 1 | ||||
-rw-r--r-- | sync/sync_tests.gypi | 2 | ||||
-rw-r--r-- | sync/syncable/directory.cc | 21 | ||||
-rw-r--r-- | sync/syncable/directory.h | 188 | ||||
-rw-r--r-- | sync/syncable/scoped_kernel_lock.cc | 19 | ||||
-rw-r--r-- | sync/syncable/scoped_kernel_lock.h | 2 | ||||
-rw-r--r-- | sync/syncable/syncable_mock.cc | 32 | ||||
-rw-r--r-- | sync/syncable/syncable_mock.h | 48 | ||||
-rw-r--r-- | sync/syncable/syncable_unittest.cc | 10 | ||||
-rw-r--r-- | sync/syncable/syncable_util.cc | 4 | ||||
-rw-r--r-- | sync/test/engine/syncer_command_test.cc | 18 | ||||
-rw-r--r-- | sync/test/engine/syncer_command_test.h | 22 | ||||
-rw-r--r-- | sync/test/engine/test_syncable_utils.cc | 8 |
19 files changed, 144 insertions, 267 deletions
diff --git a/sync/engine/conflict_resolver.cc b/sync/engine/conflict_resolver.cc index fafd237..c9d78fc 100644 --- a/sync/engine/conflict_resolver.cc +++ b/sync/engine/conflict_resolver.cc @@ -193,7 +193,7 @@ void ConflictResolver::ProcessSimpleConflict(WriteTransaction* trans, entry.Put(syncable::BASE_SERVER_SPECIFICS, sync_pb::EntitySpecifics()); } else { // SERVER_IS_DEL is true if (entry.Get(syncable::IS_DIR)) { - Directory::ChildHandles children; + Directory::Metahandles children; trans->directory()->GetChildHandlesById(trans, entry.Get(syncable::ID), &children); diff --git a/sync/engine/get_commit_ids_command.cc b/sync/engine/get_commit_ids_command.cc index 6b2325f..7297f51 100644 --- a/sync/engine/get_commit_ids_command.cc +++ b/sync/engine/get_commit_ids_command.cc @@ -41,7 +41,7 @@ SyncerError GetCommitIdsCommand::ExecuteImpl(SyncSession* session) { // Gather the full set of unsynced items and store it in the session. They // are not in the correct order for commit. std::set<int64> ready_unsynced_set; - syncable::Directory::UnsyncedMetaHandles all_unsynced_handles; + syncable::Directory::Metahandles all_unsynced_handles; GetUnsyncedEntries(trans_, &all_unsynced_handles); @@ -165,10 +165,10 @@ void GetCommitIdsCommand::FilterUnreadyEntries( ModelTypeSet throttled_types, ModelTypeSet encrypted_types, bool passphrase_missing, - const syncable::Directory::UnsyncedMetaHandles& unsynced_handles, + const syncable::Directory::Metahandles& unsynced_handles, std::set<int64>* ready_unsynced_set) { - for (syncable::Directory::UnsyncedMetaHandles::const_iterator iter = - unsynced_handles.begin(); iter != unsynced_handles.end(); ++iter) { + for (syncable::Directory::Metahandles::const_iterator iter = + unsynced_handles.begin(); iter != unsynced_handles.end(); ++iter) { syncable::Entry entry(trans, syncable::GET_BY_HANDLE, *iter); if (IsEntryReadyForCommit(throttled_types, encrypted_types, diff --git a/sync/engine/get_commit_ids_command.h b/sync/engine/get_commit_ids_command.h index a41dd00..1bbbecd 100644 --- a/sync/engine/get_commit_ids_command.h +++ b/sync/engine/get_commit_ids_command.h @@ -66,7 +66,7 @@ class SYNC_EXPORT_PRIVATE GetCommitIdsCommand : public SyncerCommand { ModelTypeSet throttled_types, ModelTypeSet encrypted_types, bool passphrase_missing, - const syncable::Directory::UnsyncedMetaHandles& unsynced_handles, + const syncable::Directory::Metahandles& unsynced_handles, std::set<int64>* ready_unsynced_set); private: diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc index c1196ef..c85ab7e 100644 --- a/sync/engine/syncer_unittest.cc +++ b/sync/engine/syncer_unittest.cc @@ -241,7 +241,7 @@ class SyncerTest : public testing::Test, syncer_ = new Syncer(); syncable::ReadTransaction trans(FROM_HERE, directory()); - syncable::Directory::ChildHandles children; + syncable::Directory::Metahandles children; directory()->GetChildHandlesById(&trans, trans.root_id(), &children); ASSERT_EQ(0u, children.size()); saw_syncer_event_ = false; @@ -2350,7 +2350,7 @@ TEST_F(SyncerTest, DoublyChangedWithResolver) { local_cache_guid(), local_id.GetServerId()); mock_server_->set_conflict_all_commits(true); SyncShareNudge(); - syncable::Directory::ChildHandles children; + syncable::Directory::Metahandles children; { syncable::ReadTransaction trans(FROM_HERE, directory()); directory()->GetChildHandlesById(&trans, parent_id_, &children); @@ -2453,7 +2453,7 @@ TEST_F(SyncerTest, ParentAndChildBothMatch) { SyncShareNudge(); { syncable::ReadTransaction trans(FROM_HERE, directory()); - Directory::ChildHandles children; + Directory::Metahandles children; directory()->GetChildHandlesById(&trans, root_id_, &children); EXPECT_EQ(1u, children.size()); directory()->GetChildHandlesById(&trans, parent_id, &children); @@ -2461,7 +2461,7 @@ TEST_F(SyncerTest, ParentAndChildBothMatch) { std::vector<int64> unapplied; directory()->GetUnappliedUpdateMetaHandles(&trans, all_types, &unapplied); EXPECT_EQ(0u, unapplied.size()); - syncable::Directory::UnsyncedMetaHandles unsynced; + syncable::Directory::Metahandles unsynced; directory()->GetUnsyncedMetaHandles(&trans, &unsynced); EXPECT_EQ(0u, unsynced.size()); saw_syncer_event_ = false; @@ -3920,7 +3920,7 @@ TEST_F(SyncerTest, ClientTagUpdateClashesWithLocalEntry) { EXPECT_EQ("tag2", tag2.Get(UNIQUE_CLIENT_TAG)); tag2_metahandle = tag2.Get(META_HANDLE); - syncable::Directory::ChildHandles children; + syncable::Directory::Metahandles children; directory()->GetChildHandlesById(&trans, trans.root_id(), &children); ASSERT_EQ(2U, children.size()); } @@ -3960,7 +3960,7 @@ TEST_F(SyncerTest, ClientTagUpdateClashesWithLocalEntry) { EXPECT_EQ("tag2", tag2.Get(UNIQUE_CLIENT_TAG)); EXPECT_EQ(tag2_metahandle, tag2.Get(META_HANDLE)); - syncable::Directory::ChildHandles children; + syncable::Directory::Metahandles children; directory()->GetChildHandlesById(&trans, trans.root_id(), &children); ASSERT_EQ(2U, children.size()); } @@ -4039,7 +4039,7 @@ TEST_F(SyncerTest, ClientTagClashWithinBatchOfUpdates) { EXPECT_EQ(21, tag_c.Get(BASE_VERSION)); EXPECT_EQ("tag c", tag_c.Get(UNIQUE_CLIENT_TAG)); - syncable::Directory::ChildHandles children; + syncable::Directory::Metahandles children; directory()->GetChildHandlesById(&trans, trans.root_id(), &children); ASSERT_EQ(3U, children.size()); } diff --git a/sync/engine/syncer_util.cc b/sync/engine/syncer_util.cc index e0e566f..93f2bef 100644 --- a/sync/engine/syncer_util.cc +++ b/sync/engine/syncer_util.cc @@ -242,7 +242,7 @@ UpdateAttemptResponse AttemptToUpdateEntry( } } } else if (entry->Get(IS_DIR)) { - Directory::ChildHandles handles; + Directory::Metahandles handles; trans->directory()->GetChildHandlesById(trans, id, &handles); if (!handles.empty()) { // If we have still-existing children, then we need to deal with @@ -492,14 +492,14 @@ void MarkDeletedChildrenSynced( // may be sensible if this code shows up in profiling. if (deleted_folders->empty()) return; - Directory::UnsyncedMetaHandles handles; + Directory::Metahandles handles; { syncable::ReadTransaction trans(FROM_HERE, dir); dir->GetUnsyncedMetaHandles(&trans, &handles); } if (handles.empty()) return; - Directory::UnsyncedMetaHandles::iterator it; + Directory::Metahandles::iterator it; for (it = handles.begin() ; it != handles.end() ; ++it) { // Single transaction / entry we deal with. WriteTransaction trans(FROM_HERE, SYNCER, dir); diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc index b63e54b..62c1605 100644 --- a/sync/internal_api/sync_manager_impl.cc +++ b/sync/internal_api/sync_manager_impl.cc @@ -1223,10 +1223,10 @@ JsArgList SyncManagerImpl::GetChildNodeIds(const JsArgList& args) { int64 id = GetId(args.Get(), 0); if (id != kInvalidId) { ReadTransaction trans(FROM_HERE, GetUserShare()); - syncable::Directory::ChildHandles child_handles; + syncable::Directory::Metahandles child_handles; trans.GetDirectory()->GetChildHandlesByHandle(trans.GetWrappedTrans(), id, &child_handles); - for (syncable::Directory::ChildHandles::const_iterator it = + for (syncable::Directory::Metahandles::const_iterator it = child_handles.begin(); it != child_handles.end(); ++it) { child_ids->Append(new base::StringValue(base::Int64ToString(*it))); } diff --git a/sync/sync_core.gypi b/sync/sync_core.gypi index 0ff7b4b..3191855 100644 --- a/sync/sync_core.gypi +++ b/sync/sync_core.gypi @@ -139,6 +139,7 @@ 'syncable/on_disk_directory_backing_store.h', 'syncable/parent_child_index.cc', 'syncable/parent_child_index.h', + 'syncable/scoped_kernel_lock.cc', 'syncable/scoped_kernel_lock.h', 'syncable/scoped_parent_child_index_updater.cc', 'syncable/scoped_parent_child_index_updater.h', diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi index fc5f317..110c955 100644 --- a/sync/sync_tests.gypi +++ b/sync/sync_tests.gypi @@ -31,8 +31,6 @@ 'js/js_test_util.h', 'sessions/test_util.cc', 'sessions/test_util.h', - 'syncable/syncable_mock.cc', - 'syncable/syncable_mock.h', 'test/callback_counter.h', 'test/engine/fake_model_worker.cc', 'test/engine/fake_model_worker.h', diff --git a/sync/syncable/directory.cc b/sync/syncable/directory.cc index eb15cd6..1cbb445 100644 --- a/sync/syncable/directory.cc +++ b/sync/syncable/directory.cc @@ -14,6 +14,7 @@ #include "sync/syncable/entry_kernel.h" #include "sync/syncable/in_memory_directory_backing_store.h" #include "sync/syncable/on_disk_directory_backing_store.h" +#include "sync/syncable/scoped_kernel_lock.h" #include "sync/syncable/scoped_parent_child_index_updater.h" #include "sync/syncable/syncable-inl.h" #include "sync/syncable/syncable_base_transaction.h" @@ -31,14 +32,6 @@ namespace syncable { const base::FilePath::CharType Directory::kSyncDatabaseFilename[] = FILE_PATH_LITERAL("SyncData.sqlite3"); -void Directory::InitKernelForTest( - const std::string& name, - DirectoryChangeDelegate* delegate, - const WeakHandle<TransactionObserver>& transaction_observer) { - DCHECK(!kernel_); - kernel_ = new Kernel(name, KernelLoadInfo(), delegate, transaction_observer); -} - Directory::PersistedKernelInfo::PersistedKernelInfo() : next_id(0) { ModelTypeSet protocol_types = ProtocolTypes(); @@ -265,7 +258,7 @@ EntryKernel* Directory::GetEntryByHandle(int64 metahandle, bool Directory::GetChildHandlesById( BaseTransaction* trans, const Id& parent_id, - Directory::ChildHandles* result) { + Directory::Metahandles* result) { if (!SyncAssert(this == trans->directory(), FROM_HERE, "Directories don't match", trans)) return false; @@ -278,7 +271,7 @@ bool Directory::GetChildHandlesById( bool Directory::GetChildHandlesByHandle( BaseTransaction* trans, int64 handle, - Directory::ChildHandles* result) { + Directory::Metahandles* result) { if (!SyncAssert(this == trans->directory(), FROM_HERE, "Directories don't match", trans)) return false; @@ -893,7 +886,7 @@ void Directory::GetAllEntryKernels(BaseTransaction* trans, } void Directory::GetUnsyncedMetaHandles(BaseTransaction* trans, - UnsyncedMetaHandles* result) { + Metahandles* result) { result->clear(); ScopedKernelLock lock(this); copy(kernel_->unsynced_metahandles.begin(), @@ -1285,7 +1278,7 @@ void Directory::PutPredecessor(EntryKernel* e, EntryKernel* predecessor) { // TODO(rlarocque): Avoid this indirection. Just return the set. void Directory::AppendChildHandles(const ScopedKernelLock& lock, const Id& parent_id, - Directory::ChildHandles* result) { + Directory::Metahandles* result) { const OrderedChildSet* children = kernel_->parent_child_index.GetChildren(parent_id); if (!children) @@ -1298,9 +1291,5 @@ void Directory::AppendChildHandles(const ScopedKernelLock& lock, } } -ScopedKernelLock::ScopedKernelLock(const Directory* dir) - : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { -} - } // namespace syncable } // namespace syncer diff --git a/sync/syncable/directory.h b/sync/syncable/directory.h index 4bfd274..5f907fb 100644 --- a/sync/syncable/directory.h +++ b/sync/syncable/directory.h @@ -9,6 +9,7 @@ #include <string> #include <vector> +#include "base/basictypes.h" #include "base/file_util.h" #include "base/gtest_prod_util.h" #include "base/hash_tables.h" @@ -19,7 +20,6 @@ #include "sync/syncable/entry_kernel.h" #include "sync/syncable/metahandle_set.h" #include "sync/syncable/parent_child_index.h" -#include "sync/syncable/scoped_kernel_lock.h" #include "sync/syncable/syncable_delete_journal.h" namespace syncer { @@ -62,8 +62,31 @@ class SYNC_EXPORT Directory { TakeSnapshotGetsMetahandlesToPurge); public: + typedef std::vector<int64> Metahandles; + + // Be careful when using these hash_map containers. According to the spec, + // inserting into them may invalidate all iterators. + // + // It gets worse, though. The Anroid STL library has a bug that means it may + // invalidate all iterators when you erase from the map, too. That means that + // you can't iterate while erasing. STLDeleteElements(), std::remove_if(), + // and other similar functions are off-limits too, until this bug is fixed. + // + // See http://sourceforge.net/p/stlport/bugs/239/. + typedef base::hash_map<int64, EntryKernel*> MetahandlesMap; + typedef base::hash_map<std::string, EntryKernel*> IdsMap; + typedef base::hash_map<std::string, EntryKernel*> TagsMap; + static const base::FilePath::CharType kSyncDatabaseFilename[]; + // The dirty/clean state of kernel fields backed by the share_info table. + // This is public so it can be used in SaveChangesSnapshot for persistence. + enum KernelShareInfoStatus { + KERNEL_SHARE_INFO_INVALID, + KERNEL_SHARE_INFO_VALID, + KERNEL_SHARE_INFO_DIRTY + }; + // Various data that the Directory::Kernel we are backing (persisting data // for) needs saved across runs of the application. struct SYNC_EXPORT_PRIVATE PersistedKernelInfo { @@ -105,14 +128,6 @@ class SYNC_EXPORT Directory { } }; - // The dirty/clean state of kernel fields backed by the share_info table. - // This is public so it can be used in SaveChangesSnapshot for persistence. - enum KernelShareInfoStatus { - KERNEL_SHARE_INFO_INVALID, - KERNEL_SHARE_INFO_VALID, - KERNEL_SHARE_INFO_DIRTY - }; - // When the Directory is told to SaveChanges, a SaveChangesSnapshot is // constructed and forms a consistent snapshot of what needs to be sent to // the backing store. @@ -128,21 +143,6 @@ class SYNC_EXPORT Directory { MetahandleSet delete_journals_to_purge; }; - typedef std::vector<int64> ChildHandles; - - // Be careful when using these hash_map containers. According to the spec, - // inserting into them may invalidate all iterators. - // - // It gets worse, though. The Anroid STL library has a bug that means it may - // invalidate all iterators when you erase from the map, too. That means that - // you can't iterate while erasing. STLDeleteElements(), std::remove_if(), - // and other similar functions are off-limits too, until this bug is fixed. - // - // See http://sourceforge.net/p/stlport/bugs/239/. - typedef base::hash_map<int64, EntryKernel*> MetahandlesMap; - typedef base::hash_map<std::string, EntryKernel*> IdsMap; - typedef base::hash_map<std::string, EntryKernel*> TagsMap; - // Does not take ownership of |encryptor|. // |report_unrecoverable_error_function| may be NULL. // Takes ownership of |store|. @@ -241,42 +241,17 @@ class SYNC_EXPORT Directory { DeleteJournal* delete_journal(); - protected: // for friends, mainly used by Entry constructors - virtual EntryKernel* GetEntryByHandle(int64 handle); - virtual EntryKernel* GetEntryByHandle(int64 metahandle, - ScopedKernelLock* lock); - virtual EntryKernel* GetEntryById(const Id& id); - EntryKernel* GetEntryByServerTag(const std::string& tag); - virtual EntryKernel* GetEntryByClientTag(const std::string& tag); - EntryKernel* GetRootEntry(); - bool ReindexId(WriteTransaction* trans, EntryKernel* const entry, - const Id& new_id); - bool ReindexParentId(WriteTransaction* trans, EntryKernel* const entry, - const Id& new_parent_id); - void ClearDirtyMetahandles(); - - DirOpenResult OpenImpl( - const std::string& name, - DirectoryChangeDelegate* delegate, - const WeakHandle<TransactionObserver>& transaction_observer); - - private: - // These private versions expect the kernel lock to already be held - // before calling. - EntryKernel* GetEntryById(const Id& id, ScopedKernelLock* const lock); - - public: // Returns the child meta handles (even those for deleted/unlinked // nodes) for given parent id. Clears |result| if there are no // children. bool GetChildHandlesById(BaseTransaction*, const Id& parent_id, - ChildHandles* result); + Metahandles* result); // Returns the child meta handles (even those for deleted/unlinked // nodes) for given meta handle. Clears |result| if there are no // children. bool GetChildHandlesByHandle(BaseTransaction*, int64 handle, - ChildHandles* result); + Metahandles* result); // Counts all items under the given node, including the node itself. int GetTotalNodeCount(BaseTransaction*, EntryKernel* kernel_) const; @@ -330,9 +305,8 @@ class SYNC_EXPORT Directory { // Get GetUnsyncedMetaHandles should only be called after SaveChanges and // before any new entries have been created. The intention is that the // syncer should call it from its PerformSyncQueries member. - typedef std::vector<int64> UnsyncedMetaHandles; void GetUnsyncedMetaHandles(BaseTransaction* trans, - UnsyncedMetaHandles* result); + Metahandles* result); // Returns all server types with unapplied updates. A subset of // those types can then be passed into @@ -389,53 +363,21 @@ class SYNC_EXPORT Directory { ModelTypeSet types_to_journal, ModelTypeSet types_to_unapply); - private: - // A helper that implements the logic of checking tree invariants. - bool CheckTreeInvariants(syncable::BaseTransaction* trans, - const MetahandleSet& handles); - - // Helper to prime metahandles_map, ids_map, parent_child_index, - // unsynced_metahandles, unapplied_update_metahandles, server_tags_map and - // client_tags_map from metahandles_index. The input |handles_map| will be - // cleared during the initialization process. - void InitializeIndices(MetahandlesMap* handles_map); - - // Constructs a consistent snapshot of the current Directory state and - // indices (by deep copy) under a ReadTransaction for use in |snapshot|. - // See SaveChanges() for more information. - void TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot); - - // Purges from memory any unused, safe to remove entries that were - // successfully deleted on disk as a result of the SaveChanges that processed - // |snapshot|. See SaveChanges() for more information. - bool VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot); - - // Rolls back dirty bits in the event that the SaveChanges that - // processed |snapshot| failed, for example, due to no disk space. - void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot); - - // For new entry creation only - bool InsertEntry(WriteTransaction* trans, - EntryKernel* entry, ScopedKernelLock* lock); - bool InsertEntry(WriteTransaction* trans, EntryKernel* entry); - - // Used by CheckTreeInvariants - void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result); - bool SafeToPurgeFromMemory(WriteTransaction* trans, - const EntryKernel* const entry) const; - - // A helper used by GetTotalNodeCount. - void GetChildSetForKernel( - BaseTransaction*, - EntryKernel* kernel_, - std::deque<const OrderedChildSet*>* child_sets) const; - - Directory& operator = (const Directory&); + protected: // for friends, mainly used by Entry constructors + virtual EntryKernel* GetEntryByHandle(int64 handle); + virtual EntryKernel* GetEntryByHandle(int64 metahandle, + ScopedKernelLock* lock); + virtual EntryKernel* GetEntryById(const Id& id); + EntryKernel* GetEntryByServerTag(const std::string& tag); + virtual EntryKernel* GetEntryByClientTag(const std::string& tag); + EntryKernel* GetRootEntry(); + bool ReindexId(WriteTransaction* trans, EntryKernel* const entry, + const Id& new_id); + bool ReindexParentId(WriteTransaction* trans, EntryKernel* const entry, + const Id& new_parent_id); + void ClearDirtyMetahandles(); - protected: - // Used by tests. |delegate| must not be NULL. - // |transaction_observer| must be initialized. - void InitKernelForTest( + DirOpenResult OpenImpl( const std::string& name, DirectoryChangeDelegate* delegate, const WeakHandle<TransactionObserver>& transaction_observer); @@ -529,10 +471,54 @@ class SYNC_EXPORT Directory { const WeakHandle<TransactionObserver> transaction_observer; }; + // These private versions expect the kernel lock to already be held + // before calling. + EntryKernel* GetEntryById(const Id& id, ScopedKernelLock* const lock); + + // A helper that implements the logic of checking tree invariants. + bool CheckTreeInvariants(syncable::BaseTransaction* trans, + const MetahandleSet& handles); + + // Helper to prime metahandles_map, ids_map, parent_child_index, + // unsynced_metahandles, unapplied_update_metahandles, server_tags_map and + // client_tags_map from metahandles_index. The input |handles_map| will be + // cleared during the initialization process. + void InitializeIndices(MetahandlesMap* handles_map); + + // Constructs a consistent snapshot of the current Directory state and + // indices (by deep copy) under a ReadTransaction for use in |snapshot|. + // See SaveChanges() for more information. + void TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot); + + // Purges from memory any unused, safe to remove entries that were + // successfully deleted on disk as a result of the SaveChanges that processed + // |snapshot|. See SaveChanges() for more information. + bool VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot); + + // Rolls back dirty bits in the event that the SaveChanges that + // processed |snapshot| failed, for example, due to no disk space. + void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot); + + // For new entry creation only + bool InsertEntry(WriteTransaction* trans, + EntryKernel* entry, ScopedKernelLock* lock); + bool InsertEntry(WriteTransaction* trans, EntryKernel* entry); + + // Used by CheckTreeInvariants + void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result); + bool SafeToPurgeFromMemory(WriteTransaction* trans, + const EntryKernel* const entry) const; + + // A helper used by GetTotalNodeCount. + void GetChildSetForKernel( + BaseTransaction*, + EntryKernel* kernel_, + std::deque<const OrderedChildSet*>* child_sets) const; + // Append the handles of the children of |parent_id| to |result|. void AppendChildHandles( const ScopedKernelLock& lock, - const Id& parent_id, Directory::ChildHandles* result); + const Id& parent_id, Directory::Metahandles* result); // Helper methods used by PurgeDisabledTypes. void UnapplyEntry(EntryKernel* entry); @@ -557,6 +543,8 @@ class SYNC_EXPORT Directory { // Maintain deleted entries not in |kernel_| until it's verified that they // are deleted in native models as well. scoped_ptr<DeleteJournal> delete_journal_; + + DISALLOW_COPY_AND_ASSIGN(Directory); }; } // namespace syncable diff --git a/sync/syncable/scoped_kernel_lock.cc b/sync/syncable/scoped_kernel_lock.cc new file mode 100644 index 0000000..4a27420 --- /dev/null +++ b/sync/syncable/scoped_kernel_lock.cc @@ -0,0 +1,19 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/syncable/scoped_kernel_lock.h" + +#include "sync/syncable/directory.h" + +namespace syncer { +namespace syncable { + +ScopedKernelLock::ScopedKernelLock(const Directory* dir) + : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { +} + +ScopedKernelLock::~ScopedKernelLock() {} + +} // namespace syncable +} // namespace syncer diff --git a/sync/syncable/scoped_kernel_lock.h b/sync/syncable/scoped_kernel_lock.h index feb2dfd..affc375 100644 --- a/sync/syncable/scoped_kernel_lock.h +++ b/sync/syncable/scoped_kernel_lock.h @@ -16,7 +16,7 @@ class Directory; class ScopedKernelLock { public: explicit ScopedKernelLock(const Directory* dir); - ~ScopedKernelLock() {} + ~ScopedKernelLock(); base::AutoLock scoped_lock_; Directory* const dir_; diff --git a/sync/syncable/syncable_mock.cc b/sync/syncable/syncable_mock.cc deleted file mode 100644 index 9bc68e4..0000000 --- a/sync/syncable/syncable_mock.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "sync/syncable/syncable_mock.h" - -#include "base/location.h" -#include "sync/syncable/in_memory_directory_backing_store.h" - -#include "sync/test/null_transaction_observer.h" - -namespace syncer { -namespace syncable { - -MockDirectory::MockDirectory(UnrecoverableErrorHandler* handler) - : Directory(new syncable::InMemoryDirectoryBackingStore("store"), - handler, - NULL, - NULL, - NULL) { - InitKernelForTest("myk", &delegate_, syncable::NullTransactionObserver()); -} - -MockDirectory::~MockDirectory() {} - -MockSyncableWriteTransaction::MockSyncableWriteTransaction( - const tracked_objects::Location& from_here, Directory *directory) - : WriteTransaction(from_here, syncable::UNITTEST, directory) { -} - -} // namespace syncable -} // namespace syncer diff --git a/sync/syncable/syncable_mock.h b/sync/syncable/syncable_mock.h deleted file mode 100644 index 8d0e88b..0000000 --- a/sync/syncable/syncable_mock.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef SYNC_SYNCABLE_SYNCABLE_MOCK_H_ -#define SYNC_SYNCABLE_SYNCABLE_MOCK_H_ - -#include <string> - -#include "sync/syncable/directory.h" -#include "sync/syncable/syncable_write_transaction.h" -#include "sync/test/null_directory_change_delegate.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace syncer { -namespace syncable { - -class MockDirectory : public Directory { - public: - explicit MockDirectory(UnrecoverableErrorHandler* handler); - virtual ~MockDirectory(); - - MOCK_METHOD1(GetEntryByHandle, syncable::EntryKernel*(int64)); - - MOCK_METHOD2(set_last_downloadstamp, void(ModelType, int64)); - - MOCK_METHOD1(GetEntryByClientTag, - syncable::EntryKernel*(const std::string&)); - - MOCK_METHOD3(PurgeEntriesWithTypeIn, bool(ModelTypeSet, - ModelTypeSet, - ModelTypeSet)); - - private: - syncable::NullDirectoryChangeDelegate delegate_; -}; - -class MockSyncableWriteTransaction : public syncable::WriteTransaction { - public: - MockSyncableWriteTransaction( - const tracked_objects::Location& from_here, Directory *directory); -}; - -} // namespace syncable -} // namespace syncer - -#endif // SYNC_SYNCABLE_SYNCABLE_MOCK_H_ diff --git a/sync/syncable/syncable_unittest.cc b/sync/syncable/syncable_unittest.cc index 950a6b4..3b4649b 100644 --- a/sync/syncable/syncable_unittest.cc +++ b/sync/syncable/syncable_unittest.cc @@ -134,7 +134,7 @@ TEST_F(SyncableGeneralTest, General) { Entry e(&rtrans, GET_BY_ID, id); ASSERT_FALSE(e.good()); // Hasn't been written yet. - Directory::ChildHandles child_handles; + Directory::Metahandles child_handles; dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); EXPECT_TRUE(child_handles.empty()); @@ -159,11 +159,11 @@ TEST_F(SyncableGeneralTest, General) { Entry e(&rtrans, GET_BY_ID, id); ASSERT_TRUE(e.good()); - Directory::ChildHandles child_handles; + Directory::Metahandles child_handles; dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); EXPECT_EQ(1u, child_handles.size()); - for (Directory::ChildHandles::iterator i = child_handles.begin(); + for (Directory::Metahandles::iterator i = child_handles.begin(); i != child_handles.end(); ++i) { EXPECT_EQ(*i, written_metahandle); } @@ -171,7 +171,7 @@ TEST_F(SyncableGeneralTest, General) { dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles); EXPECT_EQ(1u, child_handles.size()); - for (Directory::ChildHandles::iterator i = child_handles.begin(); + for (Directory::Metahandles::iterator i = child_handles.begin(); i != child_handles.end(); ++i) { EXPECT_EQ(*i, written_metahandle); } @@ -916,7 +916,7 @@ TEST_F(SyncableDirectoryTest, TestDelete) { } TEST_F(SyncableDirectoryTest, TestGetUnsynced) { - Directory::UnsyncedMetaHandles handles; + Directory::Metahandles handles; int64 handle1, handle2; { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); diff --git a/sync/syncable/syncable_util.cc b/sync/syncable/syncable_util.cc index 6d7f126..c08f218 100644 --- a/sync/syncable/syncable_util.cc +++ b/sync/syncable/syncable_util.cc @@ -60,9 +60,9 @@ void ChangeEntryIDAndUpdateChildren( } if (entry->Get(IS_DIR)) { // Get all child entries of the old id. - Directory::ChildHandles children; + Directory::Metahandles children; trans->directory()->GetChildHandlesById(trans, old_id, &children); - Directory::ChildHandles::iterator i = children.begin(); + Directory::Metahandles::iterator i = children.begin(); while (i != children.end()) { MutableEntry child_entry(trans, GET_BY_HANDLE, *i++); CHECK(child_entry.good()); diff --git a/sync/test/engine/syncer_command_test.cc b/sync/test/engine/syncer_command_test.cc index 43d3b54..833ed9a 100644 --- a/sync/test/engine/syncer_command_test.cc +++ b/sync/test/engine/syncer_command_test.cc @@ -45,22 +45,4 @@ MockDebugInfoGetter::MockDebugInfoGetter() { MockDebugInfoGetter::~MockDebugInfoGetter() { } -MockDirectorySyncerCommandTest::MockDirectorySyncerCommandTest() - :mock_directory_(&handler_) { -} - -MockDirectorySyncerCommandTest::~MockDirectorySyncerCommandTest() { -} - -void MockDirectorySyncerCommandTest::SetUp() { - // The session always expects there to be a passive worker. - workers()->push_back( - make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); - ResetContext(); -} - -syncable::Directory* MockDirectorySyncerCommandTest::directory() { - return &mock_directory_; -} - } // namespace syncer diff --git a/sync/test/engine/syncer_command_test.h b/sync/test/engine/syncer_command_test.h index 94d1182..a57663d5 100644 --- a/sync/test/engine/syncer_command_test.h +++ b/sync/test/engine/syncer_command_test.h @@ -19,7 +19,7 @@ #include "sync/sessions/debug_info_getter.h" #include "sync/sessions/sync_session.h" #include "sync/sessions/sync_session_context.h" -#include "sync/syncable/syncable_mock.h" +#include "sync/syncable/directory.h" #include "sync/test/engine/fake_model_worker.h" #include "sync/test/engine/mock_connection_manager.h" #include "sync/test/engine/test_directory_setter_upper.h" @@ -44,10 +44,6 @@ class MockDebugInfoGetter : public sessions::DebugInfoGetter { class SyncerCommandTestBase : public testing::Test, public sessions::SyncSession::Delegate { public: - enum UseMockDirectory { - USE_MOCK_DIRECTORY - }; - // SyncSession::Delegate implementation. virtual void OnSilencedUntil( const base::TimeTicks& silenced_until) OVERRIDE { @@ -227,22 +223,6 @@ class SyncerCommandTest : public SyncerCommandTestBase { TestDirectorySetterUpper dir_maker_; }; -class MockDirectorySyncerCommandTest : public SyncerCommandTestBase { - public: - MockDirectorySyncerCommandTest(); - virtual ~MockDirectorySyncerCommandTest(); - virtual syncable::Directory* directory() OVERRIDE; - - syncable::MockDirectory* mock_directory() { - return static_cast<syncable::MockDirectory*>(directory()); - } - - virtual void SetUp() OVERRIDE; - - TestUnrecoverableErrorHandler handler_; - syncable::MockDirectory mock_directory_; -}; - } // namespace syncer #endif // SYNC_TEST_ENGINE_SYNCER_COMMAND_TEST_H_ diff --git a/sync/test/engine/test_syncable_utils.cc b/sync/test/engine/test_syncable_utils.cc index 389a16a..dd7a5c8 100644 --- a/sync/test/engine/test_syncable_utils.cc +++ b/sync/test/engine/test_syncable_utils.cc @@ -21,14 +21,14 @@ namespace syncable { int CountEntriesWithName(BaseTransaction* rtrans, const syncable::Id& parent_id, const string& name) { - Directory::ChildHandles child_handles; + Directory::Metahandles child_handles; rtrans->directory()->GetChildHandlesById(rtrans, parent_id, &child_handles); if (child_handles.size() <= 0) { return 0; } int number_of_entries_with_name = 0; - for (Directory::ChildHandles::iterator i = child_handles.begin(); + for (Directory::Metahandles::iterator i = child_handles.begin(); i != child_handles.end(); ++i) { Entry e(rtrans, GET_BY_HANDLE, *i); CHECK(e.good()); @@ -42,10 +42,10 @@ int CountEntriesWithName(BaseTransaction* rtrans, Id GetFirstEntryWithName(BaseTransaction* rtrans, const syncable::Id& parent_id, const string& name) { - Directory::ChildHandles child_handles; + Directory::Metahandles child_handles; rtrans->directory()->GetChildHandlesById(rtrans, parent_id, &child_handles); - for (Directory::ChildHandles::iterator i = child_handles.begin(); + for (Directory::Metahandles::iterator i = child_handles.begin(); i != child_handles.end(); ++i) { Entry e(rtrans, GET_BY_HANDLE, *i); CHECK(e.good()); |