diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-29 20:28:07 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-29 20:28:07 +0000 |
commit | 4f3837873020736f69b8c3061cc5295d96c68061 (patch) | |
tree | e72dfb0474129ddc5ae41bdbbe7b076b3fbf143d /sync | |
parent | f26b34f29ec732603e96b73d6f47f27034568e4c (diff) | |
download | chromium_src-4f3837873020736f69b8c3061cc5295d96c68061.zip chromium_src-4f3837873020736f69b8c3061cc5295d96c68061.tar.gz chromium_src-4f3837873020736f69b8c3061cc5295d96c68061.tar.bz2 |
[Sync] Move nigori_util* to sync/syncable
It's already in the syncable namespace, so syncable/ seems like
a better place for it.
Move a function from syncer_util.h. to syncable_util.h.
Remove pseudo-namespace class SyncerUtil.
After this change, everything in sync/engine will be in the syncer
namespace.
Also clean up some whitespace.
BUG=128060
TEST=
Review URL: https://chromiumcodereview.appspot.com/10704034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144977 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
24 files changed, 179 insertions, 201 deletions
diff --git a/sync/engine/apply_updates_command_unittest.cc b/sync/engine/apply_updates_command_unittest.cc index 7f9e475..e185b8e 100644 --- a/sync/engine/apply_updates_command_unittest.cc +++ b/sync/engine/apply_updates_command_unittest.cc @@ -9,16 +9,16 @@ #include "base/memory/scoped_ptr.h" #include "base/stringprintf.h" #include "sync/engine/apply_updates_command.h" -#include "sync/engine/nigori_util.h" #include "sync/engine/syncer.h" -#include "sync/engine/syncer_util.h" #include "sync/internal_api/public/test/test_entry_factory.h" #include "sync/protocol/bookmark_specifics.pb.h" #include "sync/protocol/password_specifics.pb.h" #include "sync/sessions/sync_session.h" #include "sync/syncable/mutable_entry.h" +#include "sync/syncable/nigori_util.h" #include "sync/syncable/read_transaction.h" #include "sync/syncable/syncable_id.h" +#include "sync/syncable/syncable_util.h" #include "sync/syncable/write_transaction.h" #include "sync/test/engine/fake_model_worker.h" #include "sync/test/engine/syncer_command_test.h" @@ -634,7 +634,7 @@ TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); Syncer::UnsyncedMetaHandles handles; - SyncerUtil::GetUnsyncedEntries(&trans, &handles); + GetUnsyncedEntries(&trans, &handles); EXPECT_TRUE(handles.empty()); } @@ -677,7 +677,7 @@ TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); Syncer::UnsyncedMetaHandles handles; - SyncerUtil::GetUnsyncedEntries(&trans, &handles); + GetUnsyncedEntries(&trans, &handles); EXPECT_EQ(2*batch_s+1, handles.size()); } @@ -710,7 +710,7 @@ TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); Syncer::UnsyncedMetaHandles handles; - SyncerUtil::GetUnsyncedEntries(&trans, &handles); + GetUnsyncedEntries(&trans, &handles); EXPECT_EQ(2*batch_s+1, handles.size()); } @@ -750,7 +750,7 @@ TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); Syncer::UnsyncedMetaHandles handles; - SyncerUtil::GetUnsyncedEntries(&trans, &handles); + GetUnsyncedEntries(&trans, &handles); EXPECT_EQ(2*batch_s+1, handles.size()); } } @@ -771,7 +771,7 @@ TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) { EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); Syncer::UnsyncedMetaHandles handles; - SyncerUtil::GetUnsyncedEntries(&trans, &handles); + GetUnsyncedEntries(&trans, &handles); EXPECT_TRUE(handles.empty()); } @@ -816,7 +816,7 @@ TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) { syncable::ReadTransaction trans(FROM_HERE, directory()); EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); Syncer::UnsyncedMetaHandles handles; - SyncerUtil::GetUnsyncedEntries(&trans, &handles); + GetUnsyncedEntries(&trans, &handles); EXPECT_EQ(2*batch_s+1, handles.size()); } @@ -851,7 +851,7 @@ TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) { EXPECT_TRUE(cryptographer->has_pending_keys()); Syncer::UnsyncedMetaHandles handles; - SyncerUtil::GetUnsyncedEntries(&trans, &handles); + GetUnsyncedEntries(&trans, &handles); EXPECT_EQ(2*batch_s+1, handles.size()); } } diff --git a/sync/engine/build_commit_command_unittest.cc b/sync/engine/build_commit_command_unittest.cc index 59e98ea..66ba14b 100644 --- a/sync/engine/build_commit_command_unittest.cc +++ b/sync/engine/build_commit_command_unittest.cc @@ -103,5 +103,3 @@ TEST_F(BuildCommitCommandTest, InterpolatePosition) { } } // namespace syncer - - diff --git a/sync/engine/cleanup_disabled_types_command.cc b/sync/engine/cleanup_disabled_types_command.cc index 233f11c..bba5029 100644 --- a/sync/engine/cleanup_disabled_types_command.cc +++ b/sync/engine/cleanup_disabled_types_command.cc @@ -67,4 +67,3 @@ SyncerError CleanupDisabledTypesCommand::ExecuteImpl( } } // namespace syncer - diff --git a/sync/engine/cleanup_disabled_types_command.h b/sync/engine/cleanup_disabled_types_command.h index 5d2ec38..ee0ab86 100644 --- a/sync/engine/cleanup_disabled_types_command.h +++ b/sync/engine/cleanup_disabled_types_command.h @@ -43,4 +43,3 @@ class CleanupDisabledTypesCommand : public SyncerCommand { } // namespace syncer #endif // SYNC_ENGINE_CLEANUP_DISABLED_TYPES_COMMAND_H_ - diff --git a/sync/engine/conflict_resolver.cc b/sync/engine/conflict_resolver.cc index e708f45..54bcb60 100644 --- a/sync/engine/conflict_resolver.cc +++ b/sync/engine/conflict_resolver.cc @@ -353,7 +353,7 @@ ConflictResolver::ProcessSimpleConflict(WriteTransaction* trans, } else { // Otherwise, we've got to undelete by creating a new locally // uncommitted entry. - SyncerUtil::SplitServerInformationIntoNewEntry(trans, &entry); + SplitServerInformationIntoNewEntry(trans, &entry); MutableEntry server_update(trans, syncable::GET_BY_ID, id); CHECK(server_update.good()); diff --git a/sync/engine/download_updates_command.cc b/sync/engine/download_updates_command.cc index f73c350..cde2c85 100644 --- a/sync/engine/download_updates_command.cc +++ b/sync/engine/download_updates_command.cc @@ -126,5 +126,4 @@ void DownloadUpdatesCommand::AppendClientDebugInfoIfNeeded( } } - } // namespace syncer diff --git a/sync/engine/download_updates_command.h b/sync/engine/download_updates_command.h index 56b73c8..d4b7760 100644 --- a/sync/engine/download_updates_command.h +++ b/sync/engine/download_updates_command.h @@ -62,4 +62,3 @@ class DownloadUpdatesCommand : public SyncerCommand { } // namespace syncer #endif // SYNC_ENGINE_DOWNLOAD_UPDATES_COMMAND_H_ - diff --git a/sync/engine/get_commit_ids_command.cc b/sync/engine/get_commit_ids_command.cc index 4b70d88..34bbe295 100644 --- a/sync/engine/get_commit_ids_command.cc +++ b/sync/engine/get_commit_ids_command.cc @@ -8,11 +8,12 @@ #include <utility> #include <vector> -#include "sync/engine/nigori_util.h" #include "sync/engine/syncer_util.h" #include "sync/engine/throttled_data_type_tracker.h" #include "sync/syncable/entry.h" #include "sync/syncable/mutable_entry.h" +#include "sync/syncable/nigori_util.h" +#include "sync/syncable/syncable_util.h" #include "sync/syncable/write_transaction.h" #include "sync/util/cryptographer.h" @@ -39,8 +40,8 @@ SyncerError GetCommitIdsCommand::ExecuteImpl(SyncSession* session) { // are not in the correct order for commit. std::set<int64> ready_unsynced_set; syncable::Directory::UnsyncedMetaHandles all_unsynced_handles; - SyncerUtil::GetUnsyncedEntries(session->write_transaction(), - &all_unsynced_handles); + GetUnsyncedEntries(session->write_transaction(), + &all_unsynced_handles); syncable::ModelTypeSet encrypted_types; bool passphrase_missing = false; diff --git a/sync/engine/process_commit_response_command.cc b/sync/engine/process_commit_response_command.cc index 51e1697..766a6b3 100644 --- a/sync/engine/process_commit_response_command.cc +++ b/sync/engine/process_commit_response_command.cc @@ -152,7 +152,7 @@ SyncerError ProcessCommitResponseCommand::ProcessCommitResponse( } } - SyncerUtil::MarkDeletedChildrenSynced(dir, &deleted_folders); + MarkDeletedChildrenSynced(dir, &deleted_folders); int commit_count = static_cast<int>(proj.size()); if (commit_count == successes) { diff --git a/sync/engine/process_updates_command.cc b/sync/engine/process_updates_command.cc index 8c2ec75..994fe1c 100644 --- a/sync/engine/process_updates_command.cc +++ b/sync/engine/process_updates_command.cc @@ -79,12 +79,12 @@ bool ReverifyEntry(syncable::WriteTransaction* trans, const SyncEntity& entry, const bool is_directory = entry.IsFolder(); const syncable::ModelType model_type = entry.GetModelType(); - return VERIFY_SUCCESS == SyncerUtil::VerifyUpdateConsistency(trans, - entry, - same_id, - deleted, - is_directory, - model_type); + return VERIFY_SUCCESS == VerifyUpdateConsistency(trans, + entry, + same_id, + deleted, + is_directory, + model_type); } } // namespace @@ -100,14 +100,14 @@ ServerUpdateProcessingResult ProcessUpdatesCommand::ProcessUpdate( // Look to see if there's a local item that should recieve this update, // maybe due to a duplicate client tag or a lost commit response. - syncable::Id local_id = SyncerUtil::FindLocalIdToUpdate(trans, update); + syncable::Id local_id = FindLocalIdToUpdate(trans, update); // FindLocalEntryToUpdate has veto power. if (local_id.IsNull()) { return SUCCESS_PROCESSED; // The entry has become irrelevant. } - SyncerUtil::CreateNewEntry(trans, local_id); + CreateNewEntry(trans, local_id); // We take a two step approach. First we store the entries data in the // server fields of a local entry and then move the data to the local fields @@ -177,7 +177,7 @@ ServerUpdateProcessingResult ProcessUpdatesCommand::ProcessUpdate( sync_pb::EntitySpecifics()); } - SyncerUtil::UpdateServerFieldsFromUpdate(&target_entry, update, name); + UpdateServerFieldsFromUpdate(&target_entry, update, name); return SUCCESS_PROCESSED; } diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc index fe20a65..7cf24c8 100644 --- a/sync/engine/syncer_unittest.cc +++ b/sync/engine/syncer_unittest.cc @@ -25,12 +25,10 @@ #include "build/build_config.h" #include "sync/engine/get_commit_ids_command.h" #include "sync/engine/net/server_connection_manager.h" -#include "sync/engine/nigori_util.h" #include "sync/engine/process_updates_command.h" #include "sync/engine/sync_scheduler.h" #include "sync/engine/syncer.h" #include "sync/engine/syncer_proto_util.h" -#include "sync/engine/syncer_util.h" #include "sync/engine/syncproto.h" #include "sync/engine/throttled_data_type_tracker.h" #include "sync/engine/traffic_recorder.h" @@ -42,7 +40,9 @@ #include "sync/protocol/sync.pb.h" #include "sync/sessions/sync_session_context.h" #include "sync/syncable/mutable_entry.h" +#include "sync/syncable/nigori_util.h" #include "sync/syncable/read_transaction.h" +#include "sync/syncable/syncable_util.h" #include "sync/syncable/write_transaction.h" #include "sync/test/engine/fake_model_worker.h" #include "sync/test/engine/mock_connection_manager.h" @@ -570,7 +570,7 @@ TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { Syncer::UnsyncedMetaHandles handles; { syncable::ReadTransaction trans(FROM_HERE, directory()); - SyncerUtil::GetUnsyncedEntries(&trans, &handles); + GetUnsyncedEntries(&trans, &handles); } ASSERT_EQ(0u, handles.size()); } @@ -621,7 +621,7 @@ TEST_F(SyncerTest, GetCommitIdsCommandTruncates) { vector<syncable::Id> expected_order; { syncable::ReadTransaction rtrans(FROM_HERE, directory()); - SyncerUtil::GetUnsyncedEntries(&rtrans, &unsynced_handle_view); + GetUnsyncedEntries(&rtrans, &unsynced_handle_view); } // The expected order is "x", "b", "c", "d", "e", truncated appropriately. expected_order.push_back(ids_.MakeServer("x")); diff --git a/sync/engine/syncer_util.cc b/sync/engine/syncer_util.cc index 4b95d05..9232f60 100644 --- a/sync/engine/syncer_util.cc +++ b/sync/engine/syncer_util.cc @@ -12,7 +12,6 @@ #include "base/location.h" #include "base/metrics/histogram.h" #include "sync/engine/conflict_resolver.h" -#include "sync/engine/nigori_util.h" #include "sync/engine/syncer_proto_util.h" #include "sync/engine/syncer_types.h" #include "sync/engine/syncproto.h" @@ -24,6 +23,7 @@ #include "sync/syncable/directory.h" #include "sync/syncable/entry.h" #include "sync/syncable/mutable_entry.h" +#include "sync/syncable/nigori_util.h" #include "sync/syncable/read_transaction.h" #include "sync/syncable/syncable_changes_version.h" #include "sync/syncable/syncable_util.h" @@ -70,18 +70,7 @@ using syncable::WriteTransaction; namespace syncer { -// Returns the number of unsynced entries. -// static -int SyncerUtil::GetUnsyncedEntries(syncable::BaseTransaction* trans, - std::vector<int64> *handles) { - trans->directory()->GetUnsyncedMetaHandles(trans, handles); - DVLOG_IF(1, !handles->empty()) << "Have " << handles->size() - << " unsynced items."; - return handles->size(); -} - -// static -syncable::Id SyncerUtil::FindLocalIdToUpdate( +syncable::Id FindLocalIdToUpdate( syncable::BaseTransaction* trans, const SyncEntity& update) { // Expected entry points of this function: @@ -194,8 +183,7 @@ syncable::Id SyncerUtil::FindLocalIdToUpdate( return update.id(); } -// static -UpdateAttemptResponse SyncerUtil::AttemptToUpdateEntry( +UpdateAttemptResponse AttemptToUpdateEntry( syncable::WriteTransaction* const trans, syncable::MutableEntry* const entry, ConflictResolver* resolver, @@ -323,7 +311,7 @@ UpdateAttemptResponse SyncerUtil::AttemptToUpdateEntry( << " update, applying normally."; } - SyncerUtil::UpdateLocalDataFromServerData(trans, entry); + UpdateLocalDataFromServerData(trans, entry); return SUCCESS; } @@ -352,8 +340,7 @@ void UpdateBookmarkSpecifics(const std::string& singleton_tag, } // namespace // Pass in name and checksum because of UTF8 conversion. -// static -void SyncerUtil::UpdateServerFieldsFromUpdate( +void UpdateServerFieldsFromUpdate( MutableEntry* target, const SyncEntity& update, const std::string& name) { @@ -424,9 +411,8 @@ void SyncerUtil::UpdateServerFieldsFromUpdate( } // Creates a new Entry iff no Entry exists with the given id. -// static -void SyncerUtil::CreateNewEntry(syncable::WriteTransaction *trans, - const syncable::Id& id) { +void CreateNewEntry(syncable::WriteTransaction *trans, + const syncable::Id& id) { syncable::MutableEntry entry(trans, GET_BY_ID, id); if (!entry.good()) { syncable::MutableEntry new_entry(trans, syncable::CREATE_NEW_UPDATE_ITEM, @@ -434,8 +420,7 @@ void SyncerUtil::CreateNewEntry(syncable::WriteTransaction *trans, } } -// static -void SyncerUtil::SplitServerInformationIntoNewEntry( +void SplitServerInformationIntoNewEntry( syncable::WriteTransaction* trans, syncable::MutableEntry* entry) { syncable::Id id = entry->Get(ID); @@ -452,8 +437,7 @@ void SyncerUtil::SplitServerInformationIntoNewEntry( // This function is called on an entry when we can update the user-facing data // from the server data. -// static -void SyncerUtil::UpdateLocalDataFromServerData( +void UpdateLocalDataFromServerData( syncable::WriteTransaction* trans, syncable::MutableEntry* entry) { DCHECK(!entry->Get(IS_UNSYNCED)); @@ -487,9 +471,7 @@ void SyncerUtil::UpdateLocalDataFromServerData( entry->Put(IS_UNAPPLIED_UPDATE, false); } -// static -VerifyCommitResult SyncerUtil::ValidateCommitEntry( - syncable::Entry* entry) { +VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry) { syncable::Id id = entry->Get(ID); if (id == entry->Get(PARENT_ID)) { CHECK(id.IsRoot()) << "Non-root item is self parenting." << *entry; @@ -508,8 +490,7 @@ VerifyCommitResult SyncerUtil::ValidateCommitEntry( return VERIFY_OK; } -// static -bool SyncerUtil::AddItemThenPredecessors( +bool AddItemThenPredecessors( syncable::BaseTransaction* trans, syncable::Entry* item, syncable::IndexedBitField inclusion_filter, @@ -536,8 +517,7 @@ bool SyncerUtil::AddItemThenPredecessors( return true; } -// static -void SyncerUtil::AddPredecessorsThenItem( +void AddPredecessorsThenItem( syncable::BaseTransaction* trans, syncable::Entry* item, syncable::IndexedBitField inclusion_filter, @@ -551,8 +531,7 @@ void SyncerUtil::AddPredecessorsThenItem( std::reverse(commit_ids->begin() + initial_size, commit_ids->end()); } -// static -void SyncerUtil::MarkDeletedChildrenSynced( +void MarkDeletedChildrenSynced( syncable::Directory* dir, std::set<syncable::Id>* deleted_folders) { // There's two options here. @@ -593,8 +572,7 @@ void SyncerUtil::MarkDeletedChildrenSynced( } } -// static -VerifyResult SyncerUtil::VerifyNewEntry( +VerifyResult VerifyNewEntry( const SyncEntity& update, syncable::Entry* target, const bool deleted) { @@ -612,8 +590,7 @@ VerifyResult SyncerUtil::VerifyNewEntry( // Assumes we have an existing entry; check here for updates that break // consistency rules. -// static -VerifyResult SyncerUtil::VerifyUpdateConsistency( +VerifyResult VerifyUpdateConsistency( syncable::WriteTransaction* trans, const SyncEntity& update, syncable::MutableEntry* target, @@ -656,8 +633,7 @@ VerifyResult SyncerUtil::VerifyUpdateConsistency( // when the server does not give us an update following the // commit of a delete, before undeleting. // Undeletion is common for items that reuse the client-unique tag. - VerifyResult result = - SyncerUtil::VerifyUndelete(trans, update, target); + VerifyResult result = VerifyUndelete(trans, update, target); if (VERIFY_UNDECIDED != result) return result; } @@ -687,10 +663,9 @@ VerifyResult SyncerUtil::VerifyUpdateConsistency( // Assumes we have an existing entry; verify an update that seems to be // expressing an 'undelete' -// static -VerifyResult SyncerUtil::VerifyUndelete(syncable::WriteTransaction* trans, - const SyncEntity& update, - syncable::MutableEntry* target) { +VerifyResult VerifyUndelete(syncable::WriteTransaction* trans, + const SyncEntity& update, + syncable::MutableEntry* target) { // TODO(nick): We hit this path for items deleted items that the server // tells us to re-create; only deleted items with positive base versions // will hit this path. However, it's not clear how such an undeletion diff --git a/sync/engine/syncer_util.h b/sync/engine/syncer_util.h index 7312ab7..5a455e8 100644 --- a/sync/engine/syncer_util.h +++ b/sync/engine/syncer_util.h @@ -24,104 +24,94 @@ namespace syncer { class Cryptographer; class SyncEntity; -class SyncerUtil { - public: - // Returns the number of unsynced entries. - static int GetUnsyncedEntries(syncable::BaseTransaction* trans, - std::vector<int64> *handles); - - // If the server sent down a client-tagged entry, or an entry whose - // commit response was lost, it is necessary to update a local entry - // with an ID that doesn't match the ID of the update. Here, we - // find the ID of such an entry, if it exists. This function may - // determine that |server_entry| should be dropped; if so, it returns - // the null ID -- callers must handle this case. When update application - // should proceed normally with a new local entry, this function will - // return server_entry.id(); the caller must create an entry with that - // ID. This function does not alter the database. - static syncable::Id FindLocalIdToUpdate( - syncable::BaseTransaction* trans, - const SyncEntity& server_entry); - - static UpdateAttemptResponse AttemptToUpdateEntry( - syncable::WriteTransaction* const trans, - syncable::MutableEntry* const entry, - ConflictResolver* resolver, - Cryptographer* cryptographer); - - // Pass in name to avoid redundant UTF8 conversion. - static void UpdateServerFieldsFromUpdate( - syncable::MutableEntry* local_entry, - const SyncEntity& server_entry, - const std::string& name); - - // Creates a new Entry iff no Entry exists with the given id. - static void CreateNewEntry(syncable::WriteTransaction *trans, - const syncable::Id& id); - - static void SplitServerInformationIntoNewEntry( - syncable::WriteTransaction* trans, - syncable::MutableEntry* entry); - - // This function is called on an entry when we can update the user-facing data - // from the server data. - static void UpdateLocalDataFromServerData(syncable::WriteTransaction* trans, - syncable::MutableEntry* entry); - - static VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry); - - static VerifyResult VerifyNewEntry(const SyncEntity& update, - syncable::Entry* target, - const bool deleted); - - // Assumes we have an existing entry; check here for updates that break - // consistency rules. - static VerifyResult VerifyUpdateConsistency(syncable::WriteTransaction* trans, - const SyncEntity& update, - syncable::MutableEntry* target, - const bool deleted, - const bool is_directory, - syncable::ModelType model_type); - - // Assumes we have an existing entry; verify an update that seems to be - // expressing an 'undelete' - static VerifyResult VerifyUndelete(syncable::WriteTransaction* trans, +// If the server sent down a client-tagged entry, or an entry whose +// commit response was lost, it is necessary to update a local entry +// with an ID that doesn't match the ID of the update. Here, we +// find the ID of such an entry, if it exists. This function may +// determine that |server_entry| should be dropped; if so, it returns +// the null ID -- callers must handle this case. When update application +// should proceed normally with a new local entry, this function will +// return server_entry.id(); the caller must create an entry with that +// ID. This function does not alter the database. +syncable::Id FindLocalIdToUpdate( + syncable::BaseTransaction* trans, + const SyncEntity& server_entry); + +UpdateAttemptResponse AttemptToUpdateEntry( + syncable::WriteTransaction* const trans, + syncable::MutableEntry* const entry, + ConflictResolver* resolver, + Cryptographer* cryptographer); + +// Pass in name to avoid redundant UTF8 conversion. +void UpdateServerFieldsFromUpdate( + syncable::MutableEntry* local_entry, + const SyncEntity& server_entry, + const std::string& name); + +// Creates a new Entry iff no Entry exists with the given id. +void CreateNewEntry(syncable::WriteTransaction *trans, + const syncable::Id& id); + +void SplitServerInformationIntoNewEntry( + syncable::WriteTransaction* trans, + syncable::MutableEntry* entry); + +// This function is called on an entry when we can update the user-facing data +// from the server data. +void UpdateLocalDataFromServerData(syncable::WriteTransaction* trans, + syncable::MutableEntry* entry); + +VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry); + +VerifyResult VerifyNewEntry(const SyncEntity& update, + syncable::Entry* target, + const bool deleted); + +// Assumes we have an existing entry; check here for updates that break +// consistency rules. +VerifyResult VerifyUpdateConsistency(syncable::WriteTransaction* trans, const SyncEntity& update, - syncable::MutableEntry* target); - - // Append |item|, followed by a chain of its predecessors selected by - // |inclusion_filter|, to the |commit_ids| vector and tag them as included by - // storing in the set |inserted_items|. |inclusion_filter| (typically one of - // IS_UNAPPLIED_UPDATE or IS_UNSYNCED) selects which type of predecessors to - // include. Returns true if |item| was added, and false if it was already in - // the list. - // - // Use AddPredecessorsThenItem instead of this method if you want the - // item to be the last, rather than first, item appended. - static bool AddItemThenPredecessors( - syncable::BaseTransaction* trans, - syncable::Entry* item, - syncable::IndexedBitField inclusion_filter, - syncable::MetahandleSet* inserted_items, - std::vector<syncable::Id>* commit_ids); - - // Exactly like AddItemThenPredecessors, except items are appended in the - // reverse (and generally more useful) order: a chain of predecessors from - // far to near, and finally the item. - static void AddPredecessorsThenItem( - syncable::BaseTransaction* trans, - syncable::Entry* item, - syncable::IndexedBitField inclusion_filter, - syncable::MetahandleSet* inserted_items, - std::vector<syncable::Id>* commit_ids); - - static void MarkDeletedChildrenSynced( - syncable::Directory* dir, - std::set<syncable::Id>* deleted_folders); - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(SyncerUtil); -}; + syncable::MutableEntry* target, + const bool deleted, + const bool is_directory, + syncable::ModelType model_type); + +// Assumes we have an existing entry; verify an update that seems to be +// expressing an 'undelete' +VerifyResult VerifyUndelete(syncable::WriteTransaction* trans, + const SyncEntity& update, + syncable::MutableEntry* target); + +// Append |item|, followed by a chain of its predecessors selected by +// |inclusion_filter|, to the |commit_ids| vector and tag them as included by +// storing in the set |inserted_items|. |inclusion_filter| (typically one of +// IS_UNAPPLIED_UPDATE or IS_UNSYNCED) selects which type of predecessors to +// include. Returns true if |item| was added, and false if it was already in +// the list. +// +// Use AddPredecessorsThenItem instead of this method if you want the +// item to be the last, rather than first, item appended. +bool AddItemThenPredecessors( + syncable::BaseTransaction* trans, + syncable::Entry* item, + syncable::IndexedBitField inclusion_filter, + syncable::MetahandleSet* inserted_items, + std::vector<syncable::Id>* commit_ids); + +// Exactly like AddItemThenPredecessors, except items are appended in the +// reverse (and generally more useful) order: a chain of predecessors from +// far to near, and finally the item. +void AddPredecessorsThenItem( + syncable::BaseTransaction* trans, + syncable::Entry* item, + syncable::IndexedBitField inclusion_filter, + syncable::MetahandleSet* inserted_items, + std::vector<syncable::Id>* commit_ids); + +void MarkDeletedChildrenSynced( + syncable::Directory* dir, + std::set<syncable::Id>* deleted_folders); } // namespace syncer diff --git a/sync/engine/update_applicator.cc b/sync/engine/update_applicator.cc index 2756902..72d2dec 100644 --- a/sync/engine/update_applicator.cc +++ b/sync/engine/update_applicator.cc @@ -65,7 +65,7 @@ bool UpdateApplicator::AttemptOneApplication( } syncable::MutableEntry entry(trans, syncable::GET_BY_HANDLE, *pointer_); - UpdateAttemptResponse updateResponse = SyncerUtil::AttemptToUpdateEntry( + UpdateAttemptResponse updateResponse = AttemptToUpdateEntry( trans, &entry, resolver_, cryptographer_); switch (updateResponse) { case SUCCESS: diff --git a/sync/engine/verify_updates_command.cc b/sync/engine/verify_updates_command.cc index 93b6263..abb3db8 100644 --- a/sync/engine/verify_updates_command.cc +++ b/sync/engine/verify_updates_command.cc @@ -47,7 +47,7 @@ namespace { // that both clients will refer to the item using the same ID going forward. In // this case, we're right to assume that the update is not a reflection. // -// For more information, see SyncerUtil::FindLocalIdToUpdate(). +// For more information, see FindLocalIdToUpdate(). bool UpdateContainsNewVersion(syncable::BaseTransaction *trans, const SyncEntity &update) { int64 existing_version = -1; // The server always sends positive versions. @@ -150,7 +150,7 @@ VerifyUpdatesCommand::VerifyUpdateResult VerifyUpdatesCommand::VerifyUpdate( } syncable::MutableEntry same_id(trans, GET_BY_ID, id); - result.value = SyncerUtil::VerifyNewEntry(entry, &same_id, deleted); + result.value = VerifyNewEntry(entry, &same_id, deleted); syncable::ModelType placement_type = !deleted ? entry.GetModelType() : same_id.good() ? same_id.GetModelType() : syncable::UNSPECIFIED; @@ -176,7 +176,7 @@ VerifyUpdatesCommand::VerifyUpdateResult VerifyUpdatesCommand::VerifyUpdate( // If we have an existing entry, we check here for updates that break // consistency rules. if (VERIFY_UNDECIDED == result.value) { - result.value = SyncerUtil::VerifyUpdateConsistency(trans, entry, &same_id, + result.value = VerifyUpdateConsistency(trans, entry, &same_id, deleted, is_directory, model_type); } diff --git a/sync/internal_api/sync_manager.cc b/sync/internal_api/sync_manager.cc index efdd5a5..9ba62a4 100644 --- a/sync/internal_api/sync_manager.cc +++ b/sync/internal_api/sync_manager.cc @@ -20,7 +20,6 @@ #include "net/base/network_change_notifier.h" #include "sync/engine/all_status.h" #include "sync/engine/net/server_connection_manager.h" -#include "sync/engine/nigori_util.h" #include "sync/engine/sync_scheduler.h" #include "sync/engine/syncer_types.h" #include "sync/engine/throttled_data_type_tracker.h" @@ -56,6 +55,7 @@ #include "sync/syncable/directory_change_delegate.h" #include "sync/syncable/entry.h" #include "sync/syncable/in_memory_directory_backing_store.h" +#include "sync/syncable/nigori_util.h" #include "sync/syncable/on_disk_directory_backing_store.h" #include "sync/util/cryptographer.h" #include "sync/util/get_session_name.h" diff --git a/sync/internal_api/syncapi_unittest.cc b/sync/internal_api/syncapi_unittest.cc index 2ee4977a..64e5570 100644 --- a/sync/internal_api/syncapi_unittest.cc +++ b/sync/internal_api/syncapi_unittest.cc @@ -23,7 +23,6 @@ #include "base/test/values_test_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "sync/engine/nigori_util.h" #include "sync/internal_api/public/change_record.h" #include "sync/internal_api/public/engine/model_safe_worker.h" #include "sync/internal_api/public/engine/polling_constants.h" @@ -55,6 +54,7 @@ #include "sync/syncable/directory.h" #include "sync/syncable/entry.h" #include "sync/syncable/mutable_entry.h" +#include "sync/syncable/nigori_util.h" #include "sync/syncable/syncable_id.h" #include "sync/syncable/write_transaction.h" #include "sync/test/fake_encryptor.h" diff --git a/sync/internal_api/write_node.cc b/sync/internal_api/write_node.cc index 17fccd0..ce8ce2e 100644 --- a/sync/internal_api/write_node.cc +++ b/sync/internal_api/write_node.cc @@ -6,7 +6,6 @@ #include "base/utf_string_conversions.h" #include "base/values.h" -#include "sync/engine/nigori_util.h" #include "sync/internal_api/public/base_transaction.h" #include "sync/internal_api/public/write_transaction.h" #include "sync/internal_api/syncapi_internal.h" @@ -19,6 +18,7 @@ #include "sync/protocol/theme_specifics.pb.h" #include "sync/protocol/typed_url_specifics.pb.h" #include "sync/syncable/mutable_entry.h" +#include "sync/syncable/nigori_util.h" #include "sync/util/cryptographer.h" using syncer::Cryptographer; diff --git a/sync/sync.gyp b/sync/sync.gyp index a99a80e..14cb5c3 100644 --- a/sync/sync.gyp +++ b/sync/sync.gyp @@ -83,8 +83,6 @@ 'engine/net/server_connection_manager.h', 'engine/net/url_translator.cc', 'engine/net/url_translator.h', - 'engine/nigori_util.cc', - 'engine/nigori_util.h', 'engine/nudge_source.cc', 'engine/nudge_source.h', 'engine/process_commit_response_command.cc', @@ -165,6 +163,8 @@ 'syncable/model_type.cc', 'syncable/mutable_entry.cc', 'syncable/mutable_entry.h', + 'syncable/nigori_util.cc', + 'syncable/nigori_util.h', 'syncable/on_disk_directory_backing_store.cc', 'syncable/on_disk_directory_backing_store.h', 'syncable/read_transaction.cc', @@ -533,7 +533,6 @@ 'engine/cleanup_disabled_types_command_unittest.cc', 'engine/download_updates_command_unittest.cc', 'engine/model_changing_syncer_command_unittest.cc', - 'engine/nigori_util_unittest.cc', 'engine/process_commit_response_command_unittest.cc', 'engine/process_updates_command_unittest.cc', 'engine/resolve_conflicts_command_unittest.cc', @@ -556,6 +555,7 @@ 'sessions/sync_session_unittest.cc', 'syncable/directory_backing_store_unittest.cc', 'syncable/model_type_unittest.cc', + 'syncable/nigori_util_unittest.cc', 'syncable/syncable_enum_conversions_unittest.cc', 'syncable/syncable_id_unittest.cc', 'syncable/syncable_unittest.cc', diff --git a/sync/engine/nigori_util.cc b/sync/syncable/nigori_util.cc index e7d4e5c..e80a124 100644 --- a/sync/engine/nigori_util.cc +++ b/sync/syncable/nigori_util.cc @@ -2,17 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/nigori_util.h" +#include "sync/syncable/nigori_util.h" #include <queue> #include <string> #include <vector> #include "base/json/json_writer.h" -#include "sync/engine/syncer_util.h" #include "sync/syncable/directory.h" #include "sync/syncable/entry.h" #include "sync/syncable/mutable_entry.h" +#include "sync/syncable/syncable_util.h" #include "sync/syncable/write_transaction.h" #include "sync/util/cryptographer.h" @@ -29,7 +29,7 @@ bool ProcessUnsyncedChangesForEncryption( // changes in this code path are likely due to consistency issues (we have // to be updated to a key we already have, e.g. an old key). std::vector<int64> handles; - syncer::SyncerUtil::GetUnsyncedEntries(trans, &handles); + GetUnsyncedEntries(trans, &handles); for (size_t i = 0; i < handles.size(); ++i) { MutableEntry entry(trans, GET_BY_HANDLE, handles[i]); const sync_pb::EntitySpecifics& specifics = entry.Get(SPECIFICS); @@ -51,7 +51,7 @@ bool VerifyUnsyncedChangesAreEncrypted( BaseTransaction* const trans, ModelTypeSet encrypted_types) { std::vector<int64> handles; - syncer::SyncerUtil::GetUnsyncedEntries(trans, &handles); + GetUnsyncedEntries(trans, &handles); for (size_t i = 0; i < handles.size(); ++i) { Entry entry(trans, GET_BY_HANDLE, handles[i]); if (!entry.good()) { diff --git a/sync/engine/nigori_util.h b/sync/syncable/nigori_util.h index 9d3e2de..940b135 100644 --- a/sync/engine/nigori_util.h +++ b/sync/syncable/nigori_util.h @@ -4,8 +4,8 @@ // Various utility methods for nigori-based multi-type encryption. -#ifndef SYNC_ENGINE_NIGORI_UTIL_H_ -#define SYNC_ENGINE_NIGORI_UTIL_H_ +#ifndef SYNC_SYNCABLE_NIGORI_UTIL_H_ +#define SYNC_SYNCABLE_NIGORI_UTIL_H_ #pragma once #include "base/compiler_specific.h" @@ -72,4 +72,4 @@ bool UpdateEntryWithEncryption( } // namespace syncable -#endif // SYNC_ENGINE_NIGORI_UTIL_H_ +#endif // SYNC_SYNCABLE_NIGORI_UTIL_H_ diff --git a/sync/engine/nigori_util_unittest.cc b/sync/syncable/nigori_util_unittest.cc index 2195c78..0ca239a 100644 --- a/sync/engine/nigori_util_unittest.cc +++ b/sync/syncable/nigori_util_unittest.cc @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/nigori_util.h" #include "sync/protocol/bookmark_specifics.pb.h" #include "sync/protocol/sync.pb.h" +#include "sync/syncable/nigori_util.h" #include "sync/util/cryptographer.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/sync/syncable/syncable_util.cc b/sync/syncable/syncable_util.cc index cf5af08..046c369 100644 --- a/sync/syncable/syncable_util.cc +++ b/sync/syncable/syncable_util.cc @@ -5,6 +5,7 @@ #include "sync/syncable/syncable_util.h" #include "base/location.h" +#include "base/logging.h" #include "sync/syncable/directory.h" #include "sync/syncable/entry.h" #include "sync/syncable/mutable_entry.h" @@ -13,6 +14,15 @@ namespace syncable { +// Returns the number of unsynced entries. +int GetUnsyncedEntries(BaseTransaction* trans, + std::vector<int64> *handles) { + trans->directory()->GetUnsyncedMetaHandles(trans, handles); + DVLOG_IF(1, !handles->empty()) << "Have " << handles->size() + << " unsynced items."; + return handles->size(); +} + bool IsLegalNewParent(BaseTransaction* trans, const Id& entry_id, const Id& new_parent_id) { if (entry_id.IsRoot()) @@ -34,7 +44,7 @@ bool IsLegalNewParent(BaseTransaction* trans, const Id& entry_id, } // This function sets only the flags needed to get this entry to sync. -bool MarkForSyncing(syncable::MutableEntry* e) { +bool MarkForSyncing(MutableEntry* e) { DCHECK_NE(static_cast<MutableEntry*>(NULL), e); DCHECK(!e->IsRoot()) << "We shouldn't mark a permanent object for syncing."; if (!(e->Put(IS_UNSYNCED, true))) @@ -44,10 +54,10 @@ bool MarkForSyncing(syncable::MutableEntry* e) { } void ChangeEntryIDAndUpdateChildren( - syncable::WriteTransaction* trans, - syncable::MutableEntry* entry, - const syncable::Id& new_id) { - syncable::Id old_id = entry->Get(ID); + WriteTransaction* trans, + MutableEntry* entry, + const Id& new_id) { + Id old_id = entry->Get(ID); if (!entry->Put(ID, new_id)) { Entry old_entry(trans, GET_BY_ID, new_id); CHECK(old_entry.good()); @@ -57,7 +67,7 @@ void ChangeEntryIDAndUpdateChildren( } if (entry->Get(IS_DIR)) { // Get all child entries of the old id. - syncable::Directory::ChildHandles children; + Directory::ChildHandles children; trans->directory()->GetChildHandlesById(trans, old_id, &children); Directory::ChildHandles::iterator i = children.begin(); while (i != children.end()) { diff --git a/sync/syncable/syncable_util.h b/sync/syncable/syncable_util.h index 133f5ad..ad951fe 100644 --- a/sync/syncable/syncable_util.h +++ b/sync/syncable/syncable_util.h @@ -5,6 +5,10 @@ #ifndef SYNC_SYNCABLE_SYNCABLE_UTIL_H_ #define SYNC_SYNCABLE_SYNCABLE_UTIL_H_ +#include <vector> + +#include "base/basictypes.h" + namespace tracked_objects { class Location; } @@ -16,9 +20,9 @@ class WriteTransaction; class MutableEntry; class Id; -void ChangeEntryIDAndUpdateChildren(syncable::WriteTransaction* trans, - syncable::MutableEntry* entry, - const syncable::Id& new_id); +void ChangeEntryIDAndUpdateChildren(WriteTransaction* trans, + MutableEntry* entry, + const Id& new_id); bool IsLegalNewParent(BaseTransaction* trans, const Id& id, const Id& parentid); @@ -26,6 +30,10 @@ bool SyncAssert(bool condition, const tracked_objects::Location& location, const char* msg, BaseTransaction* trans); + +int GetUnsyncedEntries(BaseTransaction* trans, + std::vector<int64> *handles); + } // namespace syncable #endif // SYNC_SYNCABLE_SYNCABLE_UTIL_H_ |