diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-21 01:28:14 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-21 01:28:14 +0000 |
commit | a8c7c6723f97950f10be1525f3e7d0a5235174af (patch) | |
tree | d10f1100f710f92e45843abfb94dd8d13611f138 /chrome | |
parent | 3705af0831a549671b720ad03a12bf8eb892b981 (diff) | |
download | chromium_src-a8c7c6723f97950f10be1525f3e7d0a5235174af.zip chromium_src-a8c7c6723f97950f10be1525f3e7d0a5235174af.tar.gz chromium_src-a8c7c6723f97950f10be1525f3e7d0a5235174af.tar.bz2 |
sync: Make BaseNode lookup-related Init functions return specific failures.
This will help glue/ code raise separate UnrecoverableErrors (e.g. for encryption issues vs
weird corruption) more easily.
BUG=121587,123223,123647
TEST=unit tests / sync_unit_tests
Review URL: http://codereview.chromium.org/10152003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133320 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
30 files changed, 366 insertions, 233 deletions
diff --git a/chrome/browser/sync/glue/bookmark_change_processor.cc b/chrome/browser/sync/glue/bookmark_change_processor.cc index bc0cd15..ebf6c8d 100644 --- a/chrome/browser/sync/glue/bookmark_change_processor.cc +++ b/chrome/browser/sync/glue/bookmark_change_processor.cc @@ -459,7 +459,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( passed_deletes = true; sync_api::ReadNode src(trans); - if (!src.InitByIdLookup(it->id)) { + if (src.InitByIdLookup(it->id) != sync_api::BaseNode::INIT_OK) { error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, "ApplyModelChanges was passed a bad ID"); return; @@ -474,7 +474,8 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( // fail). Therefore, we add special logic here just to detect the // Synced Bookmarks folder. sync_api::ReadNode synced_bookmarks(trans); - if (synced_bookmarks.InitByTagLookup(kMobileBookmarksTag) && + if (synced_bookmarks.InitByTagLookup(kMobileBookmarksTag) == + sync_api::BaseNode::INIT_OK && synced_bookmarks.GetId() == it->id) { // This is a newly created Synced Bookmarks node. Associate it. model_associator_->Associate(model->mobile_node(), it->id); diff --git a/chrome/browser/sync/glue/bookmark_model_associator.cc b/chrome/browser/sync/glue/bookmark_model_associator.cc index 219f314..795eb58 100644 --- a/chrome/browser/sync/glue/bookmark_model_associator.cc +++ b/chrome/browser/sync/glue/bookmark_model_associator.cc @@ -238,7 +238,7 @@ bool BookmarkModelAssociator::InitSyncNodeFromChromeId( int64 sync_id = GetSyncIdFromChromeId(node_id); if (sync_id == sync_api::kInvalidId) return false; - if (!sync_node->InitByIdLookup(sync_id)) + if (sync_node->InitByIdLookup(sync_id) != sync_api::BaseNode::INIT_OK) return false; DCHECK(sync_node->GetId() == sync_id); return true; @@ -288,18 +288,21 @@ bool BookmarkModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { sync_api::ReadTransaction trans(FROM_HERE, user_share_); sync_api::ReadNode bookmark_bar_node(&trans); - if (!bookmark_bar_node.InitByIdLookup(bookmark_bar_sync_id)) { + if (bookmark_bar_node.InitByIdLookup(bookmark_bar_sync_id) != + sync_api::BaseNode::INIT_OK) { return false; } sync_api::ReadNode other_bookmarks_node(&trans); - if (!other_bookmarks_node.InitByIdLookup(other_bookmarks_sync_id)) { + if (other_bookmarks_node.InitByIdLookup(other_bookmarks_sync_id) != + sync_api::BaseNode::INIT_OK) { return false; } sync_api::ReadNode mobile_bookmarks_node(&trans); if (has_mobile_folder && - !mobile_bookmarks_node.InitByIdLookup(mobile_bookmarks_sync_id)) { + mobile_bookmarks_node.InitByIdLookup(mobile_bookmarks_sync_id) != + sync_api::BaseNode::INIT_OK) { return false; } @@ -348,7 +351,7 @@ bool BookmarkModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { sync_api::ReadTransaction trans(FROM_HERE, user_share_); sync_api::ReadNode sync_node(&trans); - if (!sync_node.InitByTagLookup(tag.c_str())) + if (sync_node.InitByTagLookup(tag.c_str()) != sync_api::BaseNode::INIT_OK) return false; *sync_id = sync_node.GetId(); return true; @@ -437,7 +440,8 @@ SyncError BookmarkModelAssociator::BuildAssociations() { dfs_stack.pop(); sync_api::ReadNode sync_parent(&trans); - if (!sync_parent.InitByIdLookup(sync_parent_id)) { + if (sync_parent.InitByIdLookup(sync_parent_id) != + sync_api::BaseNode::INIT_OK) { return unrecoverable_error_handler_->CreateAndUploadError( FROM_HERE, "Failed to lookup node.", @@ -455,7 +459,8 @@ SyncError BookmarkModelAssociator::BuildAssociations() { int64 sync_child_id = sync_parent.GetFirstChildId(); while (sync_child_id != sync_api::kInvalidId) { sync_api::WriteNode sync_child_node(&trans); - if (!sync_child_node.InitByIdLookup(sync_child_id)) { + if (sync_child_node.InitByIdLookup(sync_child_id) != + sync_api::BaseNode::INIT_OK) { return unrecoverable_error_handler_->CreateAndUploadError( FROM_HERE, "Failed to lookup node.", @@ -547,7 +552,7 @@ void BookmarkModelAssociator::PersistAssociations() { ++iter) { int64 sync_id = *iter; sync_api::WriteNode sync_node(&trans); - if (!sync_node.InitByIdLookup(sync_id)) { + if (sync_node.InitByIdLookup(sync_id) != sync_api::BaseNode::INIT_OK) { unrecoverable_error_handler_->OnUnrecoverableError(FROM_HERE, "Could not lookup bookmark node for ID persistence."); return; @@ -611,7 +616,7 @@ bool BookmarkModelAssociator::LoadAssociations() { dfs_stack.pop(); ++sync_node_count; sync_api::ReadNode sync_parent(&trans); - if (!sync_parent.InitByIdLookup(parent_id)) { + if (sync_parent.InitByIdLookup(parent_id) != sync_api::BaseNode::INIT_OK) { return false; } @@ -638,7 +643,7 @@ bool BookmarkModelAssociator::LoadAssociations() { while (child_id != sync_api::kInvalidId) { dfs_stack.push(child_id); sync_api::ReadNode child_node(&trans); - if (!child_node.InitByIdLookup(child_id)) { + if (child_node.InitByIdLookup(child_id) != sync_api::BaseNode::INIT_OK) { return false; } child_id = child_node.GetSuccessorId(); diff --git a/chrome/browser/sync/glue/bookmark_model_associator.h b/chrome/browser/sync/glue/bookmark_model_associator.h index d2828c7..31ade9e 100644 --- a/chrome/browser/sync/glue/bookmark_model_associator.h +++ b/chrome/browser/sync/glue/bookmark_model_associator.h @@ -78,8 +78,9 @@ class BookmarkModelAssociator // Initializes the given sync node from the given bookmark node id. // Returns false if no sync node was found for the given bookmark node id or // if the initialization of sync node fails. - virtual bool InitSyncNodeFromChromeId(const int64& node_id, - sync_api::BaseNode* sync_node) OVERRIDE; + virtual bool InitSyncNodeFromChromeId( + const int64& node_id, + sync_api::BaseNode* sync_node) OVERRIDE; // Associates the given bookmark node with the given sync id. virtual void Associate(const BookmarkNode* node, int64 sync_id) OVERRIDE; diff --git a/chrome/browser/sync/glue/generic_change_processor.cc b/chrome/browser/sync/glue/generic_change_processor.cc index afa29d4..017b1ed 100644 --- a/chrome/browser/sync/glue/generic_change_processor.cc +++ b/chrome/browser/sync/glue/generic_change_processor.cc @@ -55,7 +55,7 @@ void GenericChangeProcessor::ApplyChangesFromSyncModel( SyncChange::ACTION_ADD : SyncChange::ACTION_UPDATE; // Need to load specifics from node. sync_api::ReadNode read_node(trans); - if (!read_node.InitByIdLookup(it->id)) { + if (read_node.InitByIdLookup(it->id) != sync_api::BaseNode::INIT_OK) { error_handler()->OnUnrecoverableError( FROM_HERE, "Failed to look up data for received change with id " + @@ -97,7 +97,8 @@ SyncError GenericChangeProcessor::GetSyncDataForType( std::string type_name = syncable::ModelTypeToString(type); sync_api::ReadTransaction trans(FROM_HERE, share_handle()); sync_api::ReadNode root(&trans); - if (!root.InitByTagLookup(syncable::ModelTypeToRootTag(type))) { + if (root.InitByTagLookup(syncable::ModelTypeToRootTag(type)) != + sync_api::BaseNode::INIT_OK) { SyncError error(FROM_HERE, "Server did not create the top-level " + type_name + " node. We might be running against an out-of-date server.", @@ -111,7 +112,8 @@ SyncError GenericChangeProcessor::GetSyncDataForType( int64 sync_child_id = root.GetFirstChildId(); while (sync_child_id != sync_api::kInvalidId) { sync_api::ReadNode sync_child_node(&trans); - if (!sync_child_node.InitByIdLookup(sync_child_id)) { + if (sync_child_node.InitByIdLookup(sync_child_id) != + sync_api::BaseNode::INIT_OK) { SyncError error(FROM_HERE, "Failed to fetch child node for type " + type_name + ".", type); @@ -133,12 +135,14 @@ bool AttemptDelete(const SyncChange& change, sync_api::WriteNode* node) { if (tag.empty()) { return false; } - if (!node->InitByClientTagLookup( - change.sync_data().GetDataType(), tag)) { + if (node->InitByClientTagLookup( + change.sync_data().GetDataType(), tag) != + sync_api::BaseNode::INIT_OK) { return false; } } else { - if (!node->InitByIdLookup(change.sync_data().GetRemoteId())) { + if (node->InitByIdLookup(change.sync_data().GetRemoteId()) != + sync_api::BaseNode::INIT_OK) { return false; } } @@ -176,8 +180,9 @@ SyncError GenericChangeProcessor::ProcessSyncChanges( // TODO(sync): Handle other types of creation (custom parents, folders, // etc.). sync_api::ReadNode root_node(&trans); - if (!root_node.InitByTagLookup( - syncable::ModelTypeToRootTag(change.sync_data().GetDataType()))) { + if (root_node.InitByTagLookup( + syncable::ModelTypeToRootTag(change.sync_data().GetDataType())) != + sync_api::BaseNode::INIT_OK) { NOTREACHED(); SyncError error(FROM_HERE, "Failed to look up root node for type " + type_str, @@ -201,8 +206,9 @@ SyncError GenericChangeProcessor::ProcessSyncChanges( sync_node.SetEntitySpecifics(change.sync_data().GetSpecifics()); } else if (change.change_type() == SyncChange::ACTION_UPDATE) { if (change.sync_data().GetTag() == "" || - !sync_node.InitByClientTagLookup(change.sync_data().GetDataType(), - change.sync_data().GetTag())) { + sync_node.InitByClientTagLookup(change.sync_data().GetDataType(), + change.sync_data().GetTag()) != + sync_api::BaseNode::INIT_OK) { NOTREACHED(); SyncError error(FROM_HERE, "Failed to update " + type_str + " node.", @@ -240,7 +246,8 @@ bool GenericChangeProcessor::SyncModelHasUserCreatedNodes( *has_nodes = false; sync_api::ReadTransaction trans(FROM_HERE, share_handle()); sync_api::ReadNode type_root_node(&trans); - if (!type_root_node.InitByTagLookup(syncable::ModelTypeToRootTag(type))) { + if (type_root_node.InitByTagLookup(syncable::ModelTypeToRootTag(type)) != + sync_api::BaseNode::INIT_OK) { LOG(ERROR) << err_str; return false; } diff --git a/chrome/browser/sync/glue/model_associator.h b/chrome/browser/sync/glue/model_associator.h index ae29ebd..0811a79 100644 --- a/chrome/browser/sync/glue/model_associator.h +++ b/chrome/browser/sync/glue/model_associator.h @@ -77,8 +77,9 @@ class PerDataTypeAssociatorInterface : public AssociatorInterface { // Initializes the given sync node from the given chrome node id. // Returns false if no sync node was found for the given chrome node id or // if the initialization of sync node fails. - virtual bool InitSyncNodeFromChromeId(const IDType& node_id, - sync_api::BaseNode* sync_node) = 0; + virtual bool InitSyncNodeFromChromeId( + const IDType& node_id, + sync_api::BaseNode* sync_node) = 0; // Associates the given chrome node with the given sync id. virtual void Associate(const Node* node, int64 sync_id) = 0; diff --git a/chrome/browser/sync/glue/password_change_processor.cc b/chrome/browser/sync/glue/password_change_processor.cc index f182fb1..b453105 100644 --- a/chrome/browser/sync/glue/password_change_processor.cc +++ b/chrome/browser/sync/glue/password_change_processor.cc @@ -66,7 +66,8 @@ void PasswordChangeProcessor::Observe( sync_api::WriteTransaction trans(FROM_HERE, share_handle()); sync_api::ReadNode password_root(&trans); - if (!password_root.InitByTagLookup(kPasswordTag)) { + if (password_root.InitByTagLookup(kPasswordTag) != + sync_api::BaseNode::INIT_OK) { error_handler()->OnUnrecoverableError(FROM_HERE, "Server did not create the top-level password node. " "We might be running against an out-of-date server."); @@ -103,7 +104,8 @@ void PasswordChangeProcessor::Observe( "Unable to create or retrieve password node"); return; } - if (!sync_node.InitByIdLookup(sync_id)) { + if (sync_node.InitByIdLookup(sync_id) != + sync_api::BaseNode::INIT_OK) { error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, "Unable to create or retrieve password node"); return; @@ -120,7 +122,8 @@ void PasswordChangeProcessor::Observe( "Unexpected notification for: "); return; } else { - if (!sync_node.InitByIdLookup(sync_id)) { + if (sync_node.InitByIdLookup(sync_id) != + sync_api::BaseNode::INIT_OK) { error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, "Password node lookup failed."); return; @@ -140,7 +143,8 @@ void PasswordChangeProcessor::Observe( LOG(WARNING) << "Trying to delete nonexistent password sync node!"; return; } else { - if (!sync_node.InitByIdLookup(sync_id)) { + if (sync_node.InitByIdLookup(sync_id) != + sync_api::BaseNode::INIT_OK) { error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, "Password node lookup failed."); return; @@ -162,7 +166,8 @@ void PasswordChangeProcessor::ApplyChangesFromSyncModel( return; sync_api::ReadNode password_root(trans); - if (!password_root.InitByTagLookup(kPasswordTag)) { + if (password_root.InitByTagLookup(kPasswordTag) != + sync_api::BaseNode::INIT_OK) { error_handler()->OnUnrecoverableError(FROM_HERE, "Password root node lookup failed."); return; @@ -189,7 +194,7 @@ void PasswordChangeProcessor::ApplyChangesFromSyncModel( } sync_api::ReadNode sync_node(trans); - if (!sync_node.InitByIdLookup(it->id)) { + if (sync_node.InitByIdLookup(it->id) != sync_api::BaseNode::INIT_OK) { error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, "Password node lookup failed."); return; diff --git a/chrome/browser/sync/glue/password_model_associator.cc b/chrome/browser/sync/glue/password_model_associator.cc index 1e12f7c..74c79be 100644 --- a/chrome/browser/sync/glue/password_model_associator.cc +++ b/chrome/browser/sync/glue/password_model_associator.cc @@ -74,7 +74,8 @@ SyncError PasswordModelAssociator::AssociateModels() { { sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode password_root(&trans); - if (!password_root.InitByTagLookup(kPasswordTag)) { + if (password_root.InitByTagLookup(kPasswordTag) != + sync_api::BaseNode::INIT_OK) { return error_handler_->CreateAndUploadError( FROM_HERE, "Server did not create the top-level password node. We " @@ -91,7 +92,8 @@ SyncError PasswordModelAssociator::AssociateModels() { std::string tag = MakeTag(**ix); sync_api::ReadNode node(&trans); - if (node.InitByClientTagLookup(syncable::PASSWORDS, tag)) { + if (node.InitByClientTagLookup(syncable::PASSWORDS, tag) == + sync_api::BaseNode::INIT_OK) { const sync_pb::PasswordSpecificsData& password = node.GetPasswordSpecifics(); DCHECK_EQ(tag, MakeTag(password)); @@ -100,7 +102,8 @@ SyncError PasswordModelAssociator::AssociateModels() { if (MergePasswords(password, **ix, &new_password)) { sync_api::WriteNode write_node(&trans); - if (!write_node.InitByClientTagLookup(syncable::PASSWORDS, tag)) { + if (write_node.InitByClientTagLookup(syncable::PASSWORDS, tag) != + sync_api::BaseNode::INIT_OK) { STLDeleteElements(&passwords); return error_handler_->CreateAndUploadError( FROM_HERE, @@ -136,7 +139,8 @@ SyncError PasswordModelAssociator::AssociateModels() { int64 sync_child_id = password_root.GetFirstChildId(); while (sync_child_id != sync_api::kInvalidId) { sync_api::ReadNode sync_child_node(&trans); - if (!sync_child_node.InitByIdLookup(sync_child_id)) { + if (sync_child_node.InitByIdLookup(sync_child_id) != + sync_api::BaseNode::INIT_OK) { return error_handler_->CreateAndUploadError( FROM_HERE, "Failed to fetch child node.", @@ -179,7 +183,8 @@ bool PasswordModelAssociator::DeleteAllNodes( for (PasswordToSyncIdMap::iterator node_id = id_map_.begin(); node_id != id_map_.end(); ++node_id) { sync_api::WriteNode sync_node(trans); - if (!sync_node.InitByIdLookup(node_id->second)) { + if (sync_node.InitByIdLookup(node_id->second) != + sync_api::BaseNode::INIT_OK) { LOG(ERROR) << "Typed url node lookup failed."; return false; } @@ -209,7 +214,8 @@ bool PasswordModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode password_node(&trans); - if (!password_node.InitByIdLookup(password_sync_id)) { + if (password_node.InitByIdLookup(password_sync_id) != + sync_api::BaseNode::INIT_OK) { LOG(ERROR) << "Server did not create the top-level password node. We " << "might be running against an out-of-date server."; return false; @@ -279,7 +285,7 @@ bool PasswordModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode sync_node(&trans); - if (!sync_node.InitByTagLookup(tag.c_str())) + if (sync_node.InitByTagLookup(tag.c_str()) != sync_api::BaseNode::INIT_OK) return false; *sync_id = sync_node.GetId(); return true; diff --git a/chrome/browser/sync/glue/session_change_processor.cc b/chrome/browser/sync/glue/session_change_processor.cc index 16dfc28..b4dd8bf 100644 --- a/chrome/browser/sync/glue/session_change_processor.cc +++ b/chrome/browser/sync/glue/session_change_processor.cc @@ -269,7 +269,7 @@ void SessionChangeProcessor::ApplyChangesFromSyncModel( ScopedStopObserving<SessionChangeProcessor> stop_observing(this); sync_api::ReadNode root(trans); - if (!root.InitByTagLookup(kSessionsTag)) { + if (root.InitByTagLookup(kSessionsTag) != sync_api::BaseNode::INIT_OK) { error_handler()->OnUnrecoverableError(FROM_HERE, "Sessions root node lookup failed."); return; @@ -302,7 +302,7 @@ void SessionChangeProcessor::ApplyChangesFromSyncModel( // Handle an update or add. sync_api::ReadNode sync_node(trans); - if (!sync_node.InitByIdLookup(change.id)) { + if (sync_node.InitByIdLookup(change.id) != sync_api::BaseNode::INIT_OK) { error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, "Session node lookup failed."); return; diff --git a/chrome/browser/sync/glue/session_model_associator.cc b/chrome/browser/sync/glue/session_model_associator.cc index d9f0c48..bf5db1b 100644 --- a/chrome/browser/sync/glue/session_model_associator.cc +++ b/chrome/browser/sync/glue/session_model_associator.cc @@ -144,7 +144,7 @@ bool SessionModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { *has_nodes = false; sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode root(&trans); - if (!root.InitByTagLookup(kSessionsTag)) { + if (root.InitByTagLookup(kSessionsTag) != sync_api::BaseNode::INIT_OK) { LOG(ERROR) << kNoSessionsFolderError; return false; } @@ -163,7 +163,7 @@ int64 SessionModelAssociator::GetSyncIdFromSessionTag(const std::string& tag) { DCHECK(CalledOnValidThread()); sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode node(&trans); - if (!node.InitByClientTagLookup(SESSIONS, tag)) + if (node.InitByClientTagLookup(SESSIONS, tag) != sync_api::BaseNode::INIT_OK) return sync_api::kInvalidId; return node.GetId(); } @@ -272,7 +272,8 @@ bool SessionModelAssociator::AssociateWindows(bool reload_tabs, sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::WriteNode header_node(&trans); - if (!header_node.InitByIdLookup(local_session_syncid_)) { + if (header_node.InitByIdLookup(local_session_syncid_) != + sync_api::BaseNode::INIT_OK) { if (error) { *error = error_handler_->CreateAndUploadError( FROM_HERE, @@ -427,7 +428,7 @@ bool SessionModelAssociator::WriteTabContentsToSyncModel(TabLink* tab_link, sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::WriteNode tab_node(&trans); - if (!tab_node.InitByIdLookup(sync_id)) { + if (tab_node.InitByIdLookup(sync_id) != sync_api::BaseNode::INIT_OK) { if (error) { *error = error_handler_->CreateAndUploadError( FROM_HERE, @@ -501,7 +502,8 @@ void SessionModelAssociator::OnFaviconDataAvailable( // Load the sync tab node and update the favicon data. sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::WriteNode tab_node(&trans); - if (!tab_node.InitByIdLookup(tab_link->sync_id())) { + if (tab_node.InitByIdLookup(tab_link->sync_id()) != + sync_api::BaseNode::INIT_OK) { LOG(WARNING) << "Failed to load sync tab node for tab id " << tab_id << " and url " << tab_link->url().spec(); return; @@ -659,7 +661,8 @@ SyncError SessionModelAssociator::AssociateModels() { sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode root(&trans); - if (!root.InitByTagLookup(syncable::ModelTypeToRootTag(model_type()))) { + if (root.InitByTagLookup(syncable::ModelTypeToRootTag(model_type())) != + sync_api::BaseNode::INIT_OK) { return error_handler_->CreateAndUploadError( FROM_HERE, kNoSessionsFolderError, @@ -809,7 +812,7 @@ bool SessionModelAssociator::UpdateAssociationsFromSyncModel( int64 id = root.GetFirstChildId(); while (id != sync_api::kInvalidId) { sync_api::WriteNode sync_node(trans); - if (!sync_node.InitByIdLookup(id)) { + if (sync_node.InitByIdLookup(id) != sync_api::BaseNode::INIT_OK) { if (error) { *error = error_handler_->CreateAndUploadError( FROM_HERE, @@ -1230,7 +1233,7 @@ int64 SessionModelAssociator::TabNodePool::GetFreeTabNode() { // Tab pool has no free nodes, allocate new one. sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode root(&trans); - if (!root.InitByTagLookup(kSessionsTag)) { + if (root.InitByTagLookup(kSessionsTag) != sync_api::BaseNode::INIT_OK) { LOG(ERROR) << kNoSessionsFolderError; return sync_api::kInvalidId; } @@ -1363,14 +1366,14 @@ void SessionModelAssociator::DeleteForeignSession(const std::string& tag) { sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode root(&trans); - if (!root.InitByTagLookup(kSessionsTag)) { + if (root.InitByTagLookup(kSessionsTag) != sync_api::BaseNode::INIT_OK) { LOG(ERROR) << kNoSessionsFolderError; return; } int64 id = root.GetFirstChildId(); while (id != sync_api::kInvalidId) { sync_api::WriteNode sync_node(&trans); - if (!sync_node.InitByIdLookup(id)) { + if (sync_node.InitByIdLookup(id) != sync_api::BaseNode::INIT_OK) { LOG(ERROR) << "Failed to fetch sync node for id " << id; continue; } diff --git a/chrome/browser/sync/glue/theme_change_processor.cc b/chrome/browser/sync/glue/theme_change_processor.cc index 11872eb..af77b5b 100644 --- a/chrome/browser/sync/glue/theme_change_processor.cc +++ b/chrome/browser/sync/glue/theme_change_processor.cc @@ -43,8 +43,9 @@ void ThemeChangeProcessor::Observe( sync_api::WriteTransaction trans(FROM_HERE, share_handle()); sync_api::WriteNode node(&trans); - if (!node.InitByClientTagLookup(syncable::THEMES, - kCurrentThemeClientTag)) { + if (node.InitByClientTagLookup(syncable::THEMES, + kCurrentThemeClientTag) != + sync_api::BaseNode::INIT_OK) { std::string err = "Could not create node with client tag: "; error_handler()->OnUnrecoverableError(FROM_HERE, err + kCurrentThemeClientTag); @@ -99,7 +100,7 @@ void ThemeChangeProcessor::ApplyChangesFromSyncModel( // ThemeSpecifics, which would cause the default theme to be set. if (change.action != sync_api::ChangeRecord::ACTION_DELETE) { sync_api::ReadNode node(trans); - if (!node.InitByIdLookup(change.id)) { + if (node.InitByIdLookup(change.id) != sync_api::BaseNode::INIT_OK) { error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, "Theme node lookup failed."); return; diff --git a/chrome/browser/sync/glue/theme_model_associator.cc b/chrome/browser/sync/glue/theme_model_associator.cc index 5521de4..f48a829 100644 --- a/chrome/browser/sync/glue/theme_model_associator.cc +++ b/chrome/browser/sync/glue/theme_model_associator.cc @@ -44,7 +44,7 @@ ThemeModelAssociator::~ThemeModelAssociator() {} SyncError ThemeModelAssociator::AssociateModels() { sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode root(&trans); - if (!root.InitByTagLookup(kThemesTag)) { + if (root.InitByTagLookup(kThemesTag) != sync_api::BaseNode::INIT_OK) { return error_handler_->CreateAndUploadError(FROM_HERE, kNoThemesFolderError, model_type()); @@ -55,7 +55,8 @@ SyncError ThemeModelAssociator::AssociateModels() { // TODO(akalin): When we have timestamps, we may want to do // something more intelligent than preferring the sync data over our // local data. - if (node.InitByClientTagLookup(syncable::THEMES, kCurrentThemeClientTag)) { + if (node.InitByClientTagLookup(syncable::THEMES, kCurrentThemeClientTag) == + sync_api::BaseNode::INIT_OK) { // Update the current theme from the sync data. // TODO(akalin): If the sync data does not have // use_system_theme_by_default and we do, update that flag on the @@ -93,7 +94,7 @@ bool ThemeModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { *has_nodes = false; sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode root(&trans); - if (!root.InitByTagLookup(kThemesTag)) { + if (root.InitByTagLookup(kThemesTag) != sync_api::BaseNode::INIT_OK) { LOG(ERROR) << kNoThemesFolderError; return false; } diff --git a/chrome/browser/sync/glue/typed_url_change_processor.cc b/chrome/browser/sync/glue/typed_url_change_processor.cc index 9c853f7..05cd86c 100644 --- a/chrome/browser/sync/glue/typed_url_change_processor.cc +++ b/chrome/browser/sync/glue/typed_url_change_processor.cc @@ -108,7 +108,8 @@ bool TypedUrlChangeProcessor::CreateOrUpdateSyncNode( } sync_api::ReadNode typed_url_root(trans); - if (!typed_url_root.InitByTagLookup(kTypedUrlTag)) { + if (typed_url_root.InitByTagLookup(kTypedUrlTag) != + sync_api::BaseNode::INIT_OK) { error_handler()->OnUnrecoverableError(FROM_HERE, "Server did not create the top-level typed_url node. We " "might be running against an out-of-date server."); @@ -123,7 +124,8 @@ bool TypedUrlChangeProcessor::CreateOrUpdateSyncNode( DCHECK(!visit_vector.empty()); sync_api::WriteNode update_node(trans); - if (update_node.InitByClientTagLookup(syncable::TYPED_URLS, tag)) { + if (update_node.InitByClientTagLookup(syncable::TYPED_URLS, tag) == + sync_api::BaseNode::INIT_OK) { model_associator_->WriteToSyncNode(url, visit_vector, &update_node); } else { sync_api::WriteNode create_node(trans); @@ -157,8 +159,10 @@ void TypedUrlChangeProcessor::HandleURLsDeleted( // The deleted URL could have been non-typed, so it might not be found // in the sync DB. if (sync_node.InitByClientTagLookup(syncable::TYPED_URLS, - row->url().spec())) + row->url().spec()) == + sync_api::BaseNode::INIT_OK) { sync_node.Remove(); + } } } } @@ -199,7 +203,8 @@ void TypedUrlChangeProcessor::ApplyChangesFromSyncModel( return; sync_api::ReadNode typed_url_root(trans); - if (!typed_url_root.InitByTagLookup(kTypedUrlTag)) { + if (typed_url_root.InitByTagLookup(kTypedUrlTag) != + sync_api::BaseNode::INIT_OK) { error_handler()->OnUnrecoverableError(FROM_HERE, "TypedUrl root node lookup failed."); return; @@ -221,7 +226,7 @@ void TypedUrlChangeProcessor::ApplyChangesFromSyncModel( } sync_api::ReadNode sync_node(trans); - if (!sync_node.InitByIdLookup(it->id)) { + if (sync_node.InitByIdLookup(it->id) != sync_api::BaseNode::INIT_OK) { error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, "TypedUrl node lookup failed."); return; diff --git a/chrome/browser/sync/glue/typed_url_model_associator.cc b/chrome/browser/sync/glue/typed_url_model_associator.cc index 77cf40c..80031c3 100644 --- a/chrome/browser/sync/glue/typed_url_model_associator.cc +++ b/chrome/browser/sync/glue/typed_url_model_associator.cc @@ -171,7 +171,8 @@ SyncError TypedUrlModelAssociator::AssociateModels() { { sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode typed_url_root(&trans); - if (!typed_url_root.InitByTagLookup(kTypedUrlTag)) { + if (typed_url_root.InitByTagLookup(kTypedUrlTag) != + sync_api::BaseNode::INIT_OK) { return error_handler_->CreateAndUploadError( FROM_HERE, "Server did not create the top-level typed_url node. We " @@ -190,7 +191,8 @@ SyncError TypedUrlModelAssociator::AssociateModels() { history::VisitVector& visits = visit_vectors[ix->id()]; sync_api::ReadNode node(&trans); - if (node.InitByClientTagLookup(syncable::TYPED_URLS, tag)) { + if (node.InitByClientTagLookup(syncable::TYPED_URLS, tag) == + sync_api::BaseNode::INIT_OK) { // Same URL exists in sync data and in history data - compare the // entries to see if there's any difference. sync_pb::TypedUrlSpecifics typed_url( @@ -209,7 +211,8 @@ SyncError TypedUrlModelAssociator::AssociateModels() { MergeUrls(typed_url, *ix, &visits, &new_url, &added_visits); if (difference & DIFF_UPDATE_NODE) { sync_api::WriteNode write_node(&trans); - if (!write_node.InitByClientTagLookup(syncable::TYPED_URLS, tag)) { + if (write_node.InitByClientTagLookup(syncable::TYPED_URLS, tag) != + sync_api::BaseNode::INIT_OK) { return error_handler_->CreateAndUploadError( FROM_HERE, "Failed to edit typed_url sync node.", @@ -268,7 +271,8 @@ SyncError TypedUrlModelAssociator::AssociateModels() { if (IsAbortPending()) return SyncError(); sync_api::ReadNode sync_child_node(&trans); - if (!sync_child_node.InitByIdLookup(sync_child_id)) { + if (sync_child_node.InitByIdLookup(sync_child_id) != + sync_api::BaseNode::INIT_OK) { return error_handler_->CreateAndUploadError( FROM_HERE, "Failed to fetch child node.", @@ -331,7 +335,7 @@ SyncError TypedUrlModelAssociator::AssociateModels() { if (IsAbortPending()) return SyncError(); sync_api::WriteNode sync_node(&trans); - if (!sync_node.InitByIdLookup(*it)) { + if (sync_node.InitByIdLookup(*it) != sync_api::BaseNode::INIT_OK) { return error_handler_->CreateAndUploadError( FROM_HERE, "Failed to fetch obsolete node.", @@ -419,14 +423,16 @@ bool TypedUrlModelAssociator::DeleteAllNodes( // Just walk through all our child nodes and delete them. sync_api::ReadNode typed_url_root(trans); - if (!typed_url_root.InitByTagLookup(kTypedUrlTag)) { + if (typed_url_root.InitByTagLookup(kTypedUrlTag) != + sync_api::BaseNode::INIT_OK) { LOG(ERROR) << "Could not lookup root node"; return false; } int64 sync_child_id = typed_url_root.GetFirstChildId(); while (sync_child_id != sync_api::kInvalidId) { sync_api::WriteNode sync_child_node(trans); - if (!sync_child_node.InitByIdLookup(sync_child_id)) { + if (sync_child_node.InitByIdLookup(sync_child_id) != + sync_api::BaseNode::INIT_OK) { LOG(ERROR) << "Typed url node lookup failed."; return false; } @@ -455,7 +461,7 @@ bool TypedUrlModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { *has_nodes = false; sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode sync_node(&trans); - if (!sync_node.InitByTagLookup(kTypedUrlTag)) { + if (sync_node.InitByTagLookup(kTypedUrlTag) != sync_api::BaseNode::INIT_OK) { LOG(ERROR) << "Server did not create the top-level typed_url node. We " << "might be running against an out-of-date server."; return false; diff --git a/chrome/browser/sync/internal_api/base_node.h b/chrome/browser/sync/internal_api/base_node.h index 9aaeaec..dbf720a 100644 --- a/chrome/browser/sync/internal_api/base_node.h +++ b/chrome/browser/sync/internal_api/base_node.h @@ -56,15 +56,30 @@ static const int64 kInvalidId = 0; // int64 metahandle, which we call an ID here. class BaseNode { public: + // Enumerates the possible outcomes of trying to initialize a sync node. + enum InitByLookupResult { + INIT_OK, + // Could not find an entry matching the lookup criteria. + INIT_FAILED_ENTRY_NOT_GOOD, + // Found an entry, but it is already deleted. + INIT_FAILED_ENTRY_IS_DEL, + // Found an entry, but was unable to decrypt. + INIT_FAILED_DECRYPT_IF_NECESSARY, + // A precondition was not met for calling init, such as legal input + // arguments. + INIT_FAILED_PRECONDITION, + }; + // All subclasses of BaseNode must provide a way to initialize themselves by // doing an ID lookup. Returns false on failure. An invalid or deleted // ID will result in failure. - virtual bool InitByIdLookup(int64 id) = 0; + virtual InitByLookupResult InitByIdLookup(int64 id) = 0; // All subclasses of BaseNode must also provide a way to initialize themselves // by doing a client tag lookup. Returns false on failure. A deleted node // will return FALSE. - virtual bool InitByClientTagLookup(syncable::ModelType model_type, + virtual InitByLookupResult InitByClientTagLookup( + syncable::ModelType model_type, const std::string& tag) = 0; // Each object is identified by a 64-bit id (internally, the syncable diff --git a/chrome/browser/sync/internal_api/change_reorder_buffer.cc b/chrome/browser/sync/internal_api/change_reorder_buffer.cc index 04c0955..f262ff6 100644 --- a/chrome/browser/sync/internal_api/change_reorder_buffer.cc +++ b/chrome/browser/sync/internal_api/change_reorder_buffer.cc @@ -151,7 +151,7 @@ bool ChangeReorderBuffer::GetAllChangesInTreeOrder( if (i->second == OP_ADD || i->second == OP_UPDATE_POSITION_AND_PROPERTIES) { ReadNode node(sync_trans); - CHECK(node.InitByIdLookup(i->first)); + CHECK_EQ(BaseNode::INIT_OK, node.InitByIdLookup(i->first)); // We only care about parents of entry's with position-sensitive models. if (syncable::ShouldMaintainPosition( diff --git a/chrome/browser/sync/internal_api/read_node.cc b/chrome/browser/sync/internal_api/read_node.cc index 73f2389..417fff8 100644 --- a/chrome/browser/sync/internal_api/read_node.cc +++ b/chrome/browser/sync/internal_api/read_node.cc @@ -34,34 +34,38 @@ void ReadNode::InitByRootLookup() { DCHECK(false) << "Could not lookup root node for reading."; } -bool ReadNode::InitByIdLookup(int64 id) { +BaseNode::InitByLookupResult ReadNode::InitByIdLookup(int64 id) { DCHECK(!entry_) << "Init called twice"; DCHECK_NE(id, kInvalidId); syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); entry_ = new syncable::Entry(trans, syncable::GET_BY_HANDLE, id); if (!entry_->good()) - return false; + return INIT_FAILED_ENTRY_NOT_GOOD; if (entry_->Get(syncable::IS_DEL)) - return false; + return INIT_FAILED_ENTRY_IS_DEL; syncable::ModelType model_type = GetModelType(); LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || model_type == syncable::TOP_LEVEL_FOLDER) << "SyncAPI InitByIdLookup referencing unusual object."; - return DecryptIfNecessary(); + return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; } -bool ReadNode::InitByClientTagLookup(syncable::ModelType model_type, - const std::string& tag) { +BaseNode::InitByLookupResult ReadNode::InitByClientTagLookup( + syncable::ModelType model_type, + const std::string& tag) { DCHECK(!entry_) << "Init called twice"; if (tag.empty()) - return false; + return INIT_FAILED_PRECONDITION; const std::string hash = GenerateSyncableHash(model_type, tag); entry_ = new syncable::Entry(transaction_->GetWrappedTrans(), syncable::GET_BY_CLIENT_TAG, hash); - return (entry_->good() && !entry_->Get(syncable::IS_DEL) && - DecryptIfNecessary()); + if (!entry_->good()) + return INIT_FAILED_ENTRY_NOT_GOOD; + if (entry_->Get(syncable::IS_DEL)) + return INIT_FAILED_ENTRY_IS_DEL; + return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; } const syncable::Entry* ReadNode::GetEntry() const { @@ -72,21 +76,22 @@ const BaseTransaction* ReadNode::GetTransaction() const { return transaction_; } -bool ReadNode::InitByTagLookup(const std::string& tag) { +BaseNode::InitByLookupResult ReadNode::InitByTagLookup( + const std::string& tag) { DCHECK(!entry_) << "Init called twice"; if (tag.empty()) - return false; + return INIT_FAILED_PRECONDITION; syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); entry_ = new syncable::Entry(trans, syncable::GET_BY_SERVER_TAG, tag); if (!entry_->good()) - return false; + return INIT_FAILED_ENTRY_NOT_GOOD; if (entry_->Get(syncable::IS_DEL)) - return false; + return INIT_FAILED_ENTRY_IS_DEL; syncable::ModelType model_type = GetModelType(); LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || model_type == syncable::TOP_LEVEL_FOLDER) << "SyncAPI InitByTagLookup referencing unusually typed object."; - return DecryptIfNecessary(); + return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; } } // namespace sync_api diff --git a/chrome/browser/sync/internal_api/read_node.h b/chrome/browser/sync/internal_api/read_node.h index 2dd90a5..74bcd32 100644 --- a/chrome/browser/sync/internal_api/read_node.h +++ b/chrome/browser/sync/internal_api/read_node.h @@ -28,9 +28,10 @@ class ReadNode : public BaseNode { // populate the node. // BaseNode implementation. - virtual bool InitByIdLookup(int64 id) OVERRIDE; - virtual bool InitByClientTagLookup(syncable::ModelType model_type, - const std::string& tag) OVERRIDE; + virtual InitByLookupResult InitByIdLookup(int64 id) OVERRIDE; + virtual InitByLookupResult InitByClientTagLookup( + syncable::ModelType model_type, + const std::string& tag) OVERRIDE; // There is always a root node, so this can't fail. The root node is // never mutable, so root lookup is only possible on a ReadNode. @@ -39,7 +40,7 @@ class ReadNode : public BaseNode { // Each server-created permanent node is tagged with a unique string. // Look up the node with the particular tag. If it does not exist, // return false. - bool InitByTagLookup(const std::string& tag); + InitByLookupResult InitByTagLookup(const std::string& tag); // Implementation of BaseNode's abstract virtual accessors. virtual const syncable::Entry* GetEntry() const OVERRIDE; diff --git a/chrome/browser/sync/internal_api/sync_manager.cc b/chrome/browser/sync/internal_api/sync_manager.cc index ba62edd..6e6f176 100644 --- a/chrome/browser/sync/internal_api/sync_manager.cc +++ b/chrome/browser/sync/internal_api/sync_manager.cc @@ -1080,7 +1080,7 @@ void SyncManager::SyncInternal::UpdateCryptographerAndNigoriCallback( Cryptographer* cryptographer = trans.GetCryptographer(); WriteNode node(&trans); - if (node.InitByTagLookup(kNigoriTag)) { + if (node.InitByTagLookup(kNigoriTag) == sync_api::BaseNode::INIT_OK) { sync_pb::NigoriSpecifics nigori(node.GetNigoriSpecifics()); Cryptographer::UpdateResult result = cryptographer->Update(nigori); if (result == Cryptographer::NEEDS_PASSPHRASE) { @@ -1253,7 +1253,7 @@ void SyncManager::SyncInternal::MaybeSetSyncTabsInNigoriNode( if (initialized_ && enabled_types.Has(syncable::SESSIONS)) { WriteTransaction trans(FROM_HERE, GetUserShare()); WriteNode node(&trans); - if (!node.InitByTagLookup(kNigoriTag)) { + if (node.InitByTagLookup(kNigoriTag) != sync_api::BaseNode::INIT_OK) { LOG(WARNING) << "Unable to set 'sync_tabs' bit because Nigori node not " << "found."; return; @@ -1279,7 +1279,7 @@ void SyncManager::SyncInternal::SetEncryptionPassphrase( Cryptographer* cryptographer = trans.GetCryptographer(); KeyParams key_params = {"localhost", "dummy", passphrase}; WriteNode node(&trans); - if (!node.InitByTagLookup(kNigoriTag)) { + if (node.InitByTagLookup(kNigoriTag) != sync_api::BaseNode::INIT_OK) { // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. NOTREACHED(); return; @@ -1393,7 +1393,7 @@ void SyncManager::SyncInternal::SetDecryptionPassphrase( Cryptographer* cryptographer = trans.GetCryptographer(); KeyParams key_params = {"localhost", "dummy", passphrase}; WriteNode node(&trans); - if (!node.InitByTagLookup(kNigoriTag)) { + if (node.InitByTagLookup(kNigoriTag) != sync_api::BaseNode::INIT_OK) { // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. NOTREACHED(); return; @@ -1582,7 +1582,7 @@ void SyncManager::SyncInternal::FinishSetPassphrase( bool SyncManager::SyncInternal::IsUsingExplicitPassphrase() { ReadTransaction trans(FROM_HERE, &share_); ReadNode node(&trans); - if (!node.InitByTagLookup(kNigoriTag)) { + if (node.InitByTagLookup(kNigoriTag) != sync_api::BaseNode::INIT_OK) { // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. NOTREACHED(); return false; @@ -1596,7 +1596,7 @@ void SyncManager::SyncInternal::RefreshEncryption() { WriteTransaction trans(FROM_HERE, GetUserShare()); WriteNode node(&trans); - if (!node.InitByTagLookup(kNigoriTag)) { + if (node.InitByTagLookup(kNigoriTag) != sync_api::BaseNode::INIT_OK) { NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " << "found."; return; @@ -1643,7 +1643,7 @@ void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { continue; ReadNode type_root(trans); tag = syncable::ModelTypeToRootTag(iter.Get()); - if (!type_root.InitByTagLookup(tag)) { + if (type_root.InitByTagLookup(tag) != sync_api::BaseNode::INIT_OK) { // This can happen when we enable a datatype for the first time on restart // (for example when we upgrade) and therefore haven't done the initial // download for that type at the time we RefreshEncryption. There's @@ -1662,7 +1662,7 @@ void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { continue; WriteNode child(trans); - if (!child.InitByIdLookup(child_id)) { + if (child.InitByIdLookup(child_id) != sync_api::BaseNode::INIT_OK) { NOTREACHED(); continue; } @@ -1685,11 +1685,12 @@ void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { syncable::ModelTypeToRootTag(syncable::PASSWORDS); // It's possible we'll have the password routing info and not the password // root if we attempted to set a passphrase before passwords was enabled. - if (passwords_root.InitByTagLookup(passwords_tag)) { + if (passwords_root.InitByTagLookup(passwords_tag) == + sync_api::BaseNode::INIT_OK) { int64 child_id = passwords_root.GetFirstChildId(); while (child_id != kInvalidId) { WriteNode child(trans); - if (!child.InitByIdLookup(child_id)) { + if (child.InitByIdLookup(child_id) != sync_api::BaseNode::INIT_OK) { NOTREACHED(); return; } @@ -2092,7 +2093,8 @@ void SyncManager::SyncInternal::OnSyncEngineEvent( // that the nigori node is up to date at the end of each cycle. WriteTransaction trans(FROM_HERE, GetUserShare()); WriteNode nigori_node(&trans); - if (nigori_node.InitByTagLookup(kNigoriTag)) { + if (nigori_node.InitByTagLookup(kNigoriTag) == + sync_api::BaseNode::INIT_OK) { Cryptographer* cryptographer = trans.GetCryptographer(); UpdateNigoriEncryptionState(cryptographer, &nigori_node); } @@ -2272,7 +2274,7 @@ JsArgList GetNodeInfoById(const JsArgList& args, continue; } ReadNode node(&trans); - if (!node.InitByIdLookup(id)) { + if (node.InitByIdLookup(id) != sync_api::BaseNode::INIT_OK) { continue; } node_summaries->Append((node.*info_getter)()); @@ -2480,7 +2482,7 @@ bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add) const { ReadTransaction trans(FROM_HERE, GetUserShare()); ReadNode node(&trans); - if (!node.InitByTagLookup(kNigoriTag)) { + if (node.InitByTagLookup(kNigoriTag) != sync_api::BaseNode::INIT_OK) { DVLOG(1) << "Couldn't find Nigori node."; return false; } diff --git a/chrome/browser/sync/internal_api/syncapi_unittest.cc b/chrome/browser/sync/internal_api/syncapi_unittest.cc index 8ebf0b4..2464dcb 100644 --- a/chrome/browser/sync/internal_api/syncapi_unittest.cc +++ b/chrome/browser/sync/internal_api/syncapi_unittest.cc @@ -144,7 +144,7 @@ int64 MakeNodeWithParent(UserShare* share, int64 parent_id) { WriteTransaction trans(FROM_HERE, share); ReadNode parent_node(&trans); - EXPECT_TRUE(parent_node.InitByIdLookup(parent_id)); + EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); WriteNode node(&trans); EXPECT_TRUE(node.InitUniqueByCreation(model_type, parent_node, client_tag)); node.SetIsFolder(false); @@ -159,7 +159,7 @@ int64 MakeFolderWithParent(UserShare* share, BaseNode* predecessor) { WriteTransaction trans(FROM_HERE, share); ReadNode parent_node(&trans); - EXPECT_TRUE(parent_node.InitByIdLookup(parent_id)); + EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); WriteNode node(&trans); EXPECT_TRUE(node.InitByCreation(model_type, parent_node, predecessor)); node.SetIsFolder(true); @@ -256,7 +256,7 @@ TEST_F(SyncApiTest, SanityCheckTest) { ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); ReadNode node(&trans); // Metahandle 1 can be root, sanity check 2 - EXPECT_FALSE(node.InitByIdLookup(2)); + EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, node.InitByIdLookup(2)); } } @@ -274,8 +274,8 @@ TEST_F(SyncApiTest, BasicTagWrite) { { ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, - "testtag")); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, "testtag")); ReadNode root_node(&trans); root_node.InitByRootLookup(); @@ -319,16 +319,19 @@ TEST_F(SyncApiTest, ModelTypesSiloed) { ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); ReadNode bookmarknode(&trans); - EXPECT_TRUE(bookmarknode.InitByClientTagLookup(syncable::BOOKMARKS, - "collideme")); + EXPECT_EQ(BaseNode::INIT_OK, + bookmarknode.InitByClientTagLookup(syncable::BOOKMARKS, + "collideme")); ReadNode prefnode(&trans); - EXPECT_TRUE(prefnode.InitByClientTagLookup(syncable::PREFERENCES, - "collideme")); + EXPECT_EQ(BaseNode::INIT_OK, + prefnode.InitByClientTagLookup(syncable::PREFERENCES, + "collideme")); ReadNode autofillnode(&trans); - EXPECT_TRUE(autofillnode.InitByClientTagLookup(syncable::AUTOFILL, - "collideme")); + EXPECT_EQ(BaseNode::INIT_OK, + autofillnode.InitByClientTagLookup(syncable::AUTOFILL, + "collideme")); EXPECT_NE(bookmarknode.GetId(), prefnode.GetId()); EXPECT_NE(autofillnode.GetId(), prefnode.GetId()); @@ -340,14 +343,16 @@ TEST_F(SyncApiTest, ReadMissingTagsFails) { { ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); ReadNode node(&trans); - EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS, - "testtag")); + EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, + node.InitByClientTagLookup(syncable::BOOKMARKS, + "testtag")); } { WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); WriteNode node(&trans); - EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS, - "testtag")); + EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, + node.InitByClientTagLookup(syncable::BOOKMARKS, + "testtag")); } } @@ -382,8 +387,9 @@ TEST_F(SyncApiTest, TestDeleteBehavior) { { WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); WriteNode wnode(&trans); - EXPECT_TRUE(wnode.InitByClientTagLookup(syncable::BOOKMARKS, - "testtag")); + EXPECT_EQ(BaseNode::INIT_OK, + wnode.InitByClientTagLookup(syncable::BOOKMARKS, + "testtag")); EXPECT_FALSE(wnode.GetIsFolder()); EXPECT_EQ(wnode.GetTitle(), test_title); @@ -395,8 +401,9 @@ TEST_F(SyncApiTest, TestDeleteBehavior) { { ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); ReadNode node(&trans); - EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS, - "testtag")); + EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, + node.InitByClientTagLookup(syncable::BOOKMARKS, + "testtag")); // Note that for proper function of this API this doesn't need to be // filled, we're checking just to make sure the DB worked in this test. EXPECT_EQ(node.GetTitle(), test_title); @@ -405,7 +412,7 @@ TEST_F(SyncApiTest, TestDeleteBehavior) { { WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); ReadNode folder_node(&trans); - EXPECT_TRUE(folder_node.InitByIdLookup(folder_id)); + EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id)); WriteNode wnode(&trans); // This will undelete the tag. @@ -422,8 +429,9 @@ TEST_F(SyncApiTest, TestDeleteBehavior) { { ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, - "testtag")); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, + "testtag")); EXPECT_EQ(node.GetTitle(), test_title); EXPECT_EQ(node.GetModelType(), syncable::BOOKMARKS); } @@ -453,8 +461,9 @@ TEST_F(SyncApiTest, WriteAndReadPassword) { root_node.InitByRootLookup(); ReadNode password_node(&trans); - EXPECT_TRUE(password_node.InitByClientTagLookup(syncable::PASSWORDS, - "foo")); + EXPECT_EQ(BaseNode::INIT_OK, + password_node.InitByClientTagLookup(syncable::PASSWORDS, + "foo")); const sync_pb::PasswordSpecificsData& data = password_node.GetPasswordSpecifics(); EXPECT_EQ("secret", data.password_value()); @@ -489,15 +498,17 @@ TEST_F(SyncApiTest, WriteEncryptedTitle) { root_node.InitByRootLookup(); ReadNode bookmark_node(&trans); - EXPECT_TRUE(bookmark_node.InitByClientTagLookup(syncable::BOOKMARKS, - "foo")); + EXPECT_EQ(BaseNode::INIT_OK, + bookmark_node.InitByClientTagLookup(syncable::BOOKMARKS, + "foo")); EXPECT_EQ("foo", bookmark_node.GetTitle()); EXPECT_EQ(kEncryptedString, bookmark_node.GetEntry()->Get(syncable::NON_UNIQUE_NAME)); ReadNode pref_node(&trans); - EXPECT_TRUE(pref_node.InitByClientTagLookup(syncable::PREFERENCES, - "bar")); + EXPECT_EQ(BaseNode::INIT_OK, + pref_node.InitByClientTagLookup(syncable::PREFERENCES, + "bar")); EXPECT_EQ(kEncryptedString, pref_node.GetTitle()); } } @@ -507,7 +518,7 @@ TEST_F(SyncApiTest, BaseNodeSetSpecifics) { syncable::BOOKMARKS, "testtag"); WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByIdLookup(child_id)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); sync_pb::EntitySpecifics entity_specifics; entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); @@ -524,7 +535,7 @@ TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) { syncable::BOOKMARKS, "testtag"); WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByIdLookup(child_id)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); sync_pb::EntitySpecifics entity_specifics; @@ -618,7 +629,8 @@ TEST_F(SyncApiTest, EmptyTags) { std::string empty_tag; EXPECT_FALSE(node.InitUniqueByCreation( syncable::TYPED_URLS, root_node, empty_tag)); - EXPECT_FALSE(node.InitByTagLookup(empty_tag)); + EXPECT_EQ(BaseNode::INIT_FAILED_PRECONDITION, + node.InitByTagLookup(empty_tag)); } namespace { @@ -841,7 +853,7 @@ class SyncManagerTest : public testing::Test, cryptographer->GetKeys(nigori.mutable_encrypted()); cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); WriteNode node(&trans); - EXPECT_TRUE(node.InitByIdLookup(nigori_id)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(nigori_id)); node.SetNigoriSpecifics(nigori); } return cryptographer->is_ready(); @@ -942,7 +954,8 @@ TEST_F(SyncManagerTest, DoNotSyncTabsInNigoriNode) { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode node(&trans); - ASSERT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); + ASSERT_EQ(BaseNode::INIT_OK, + node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); EXPECT_FALSE(node.GetNigoriSpecifics().sync_tabs()); } @@ -952,7 +965,8 @@ TEST_F(SyncManagerTest, SyncTabsInNigoriNode) { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode node(&trans); - ASSERT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); + ASSERT_EQ(BaseNode::INIT_OK, + node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); EXPECT_TRUE(node.GetNigoriSpecifics().sync_tabs()); } @@ -1014,7 +1028,7 @@ void CheckGetNodesByIdReturnArgs(const SyncManager& sync_manager, ASSERT_TRUE(node_info); ReadTransaction trans(FROM_HERE, sync_manager.GetUserShare()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByIdLookup(id)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); CheckNodeValue(node, *node_info, is_detailed); } @@ -1331,7 +1345,8 @@ TEST_F(SyncManagerTest, RefreshEncryptionReady) { { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); EXPECT_TRUE(nigori.has_encrypted()); Cryptographer* cryptographer = trans.GetCryptographer(); @@ -1370,7 +1385,8 @@ TEST_F(SyncManagerTest, RefreshEncryptionEmptyNigori) { { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); EXPECT_TRUE(nigori.has_encrypted()); Cryptographer* cryptographer = trans.GetCryptographer(); @@ -1515,7 +1531,7 @@ TEST_F(SyncManagerTest, SetInitialGaiaPass) { { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByTagLookup(kNigoriTag)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); Cryptographer* cryptographer = trans.GetCryptographer(); EXPECT_TRUE(cryptographer->is_ready()); @@ -1591,8 +1607,9 @@ TEST_F(SyncManagerTest, SetPassphraseWithPassword) { EXPECT_FALSE(verifier.CanDecrypt(encrypted)); ReadNode password_node(&trans); - EXPECT_TRUE(password_node.InitByClientTagLookup(syncable::PASSWORDS, - "foo")); + EXPECT_EQ(BaseNode::INIT_OK, + password_node.InitByClientTagLookup(syncable::PASSWORDS, + "foo")); const sync_pb::PasswordSpecificsData& data = password_node.GetPasswordSpecifics(); EXPECT_EQ("secret", data.password_value()); @@ -1618,7 +1635,7 @@ TEST_F(SyncManagerTest, SupplyPendingGAIAPass) { KeyParams params = {"localhost", "dummy", "passphrase2"}; other_cryptographer.AddKey(params); WriteNode node(&trans); - EXPECT_TRUE(node.InitByTagLookup(kNigoriTag)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); sync_pb::NigoriSpecifics nigori; other_cryptographer.GetKeys(nigori.mutable_encrypted()); cryptographer->Update(nigori); @@ -1662,7 +1679,7 @@ TEST_F(SyncManagerTest, SupplyPendingOldGAIAPass) { KeyParams params = {"localhost", "dummy", "old_gaia"}; other_cryptographer.AddKey(params); WriteNode node(&trans); - EXPECT_TRUE(node.InitByTagLookup(kNigoriTag)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); sync_pb::NigoriSpecifics nigori; other_cryptographer.GetKeys(nigori.mutable_encrypted()); node.SetNigoriSpecifics(nigori); @@ -1733,7 +1750,7 @@ TEST_F(SyncManagerTest, SupplyPendingExplicitPass) { KeyParams params = {"localhost", "dummy", "explicit"}; other_cryptographer.AddKey(params); WriteNode node(&trans); - EXPECT_TRUE(node.InitByTagLookup(kNigoriTag)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); sync_pb::NigoriSpecifics nigori; other_cryptographer.GetKeys(nigori.mutable_encrypted()); cryptographer->Update(nigori); @@ -1772,7 +1789,7 @@ TEST_F(SyncManagerTest, SupplyPendingGAIAPassUserProvided) { KeyParams params = {"localhost", "dummy", "passphrase"}; other_cryptographer.AddKey(params); WriteNode node(&trans); - EXPECT_TRUE(node.InitByTagLookup(kNigoriTag)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); sync_pb::NigoriSpecifics nigori; other_cryptographer.GetKeys(nigori.mutable_encrypted()); node.SetNigoriSpecifics(nigori); @@ -1813,13 +1830,15 @@ TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode password_node(&trans); - EXPECT_FALSE(password_node.InitByClientTagLookup(syncable::PASSWORDS, - tag)); + EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, + password_node.InitByClientTagLookup(syncable::PASSWORDS, + tag)); } { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode password_node(&trans); - EXPECT_FALSE(password_node.InitByIdLookup(node_id)); + EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, + password_node.InitByIdLookup(node_id)); } } @@ -1858,7 +1877,7 @@ TEST_F(SyncManagerTest, EncryptBookmarksWithLegacyData) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByIdLookup(node_id1)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); sync_pb::EntitySpecifics entity_specifics; entity_specifics.mutable_bookmark()->set_url(url); @@ -1869,7 +1888,7 @@ TEST_F(SyncManagerTest, EncryptBookmarksWithLegacyData) { node_entry->Put(syncable::NON_UNIQUE_NAME, title); WriteNode node2(&trans); - EXPECT_TRUE(node2.InitByIdLookup(node_id2)); + EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2)); sync_pb::EntitySpecifics entity_specifics2; entity_specifics2.mutable_bookmark()->set_url(url2); @@ -1883,14 +1902,14 @@ TEST_F(SyncManagerTest, EncryptBookmarksWithLegacyData) { { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByIdLookup(node_id1)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); EXPECT_EQ(syncable::BOOKMARKS, node.GetModelType()); EXPECT_EQ(title, node.GetTitle()); EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); ReadNode node2(&trans); - EXPECT_TRUE(node2.InitByIdLookup(node_id2)); + EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2)); EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); // We should de-canonicalize the title in GetTitle(), but the title in the // specifics should be stored in the server legal form. @@ -1926,14 +1945,14 @@ TEST_F(SyncManagerTest, EncryptBookmarksWithLegacyData) { true /* is encrypted */)); ReadNode node(&trans); - EXPECT_TRUE(node.InitByIdLookup(node_id1)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); EXPECT_EQ(syncable::BOOKMARKS, node.GetModelType()); EXPECT_EQ(title, node.GetTitle()); EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); ReadNode node2(&trans); - EXPECT_TRUE(node2.InitByIdLookup(node_id2)); + EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2)); EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); // We should de-canonicalize the title in GetTitle(), but the title in the // specifics should be stored in the server legal form. @@ -1966,7 +1985,7 @@ TEST_F(SyncManagerTest, CreateLocalBookmark) { int64 child_id = root_node.GetFirstChildId(); ReadNode node(&trans); - ASSERT_TRUE(node.InitByIdLookup(child_id)); + ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); EXPECT_FALSE(node.GetIsFolder()); EXPECT_EQ(title, node.GetTitle()); EXPECT_EQ(url, node.GetURL()); @@ -1990,7 +2009,8 @@ TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); node.SetEntitySpecifics(entity_specifics); } EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); @@ -2007,7 +2027,8 @@ TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); const syncable::Entry* node_entry = node.GetEntry(); const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); EXPECT_TRUE(specifics.has_encrypted()); @@ -2028,7 +2049,8 @@ TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); const syncable::Entry* node_entry = node.GetEntry(); const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); EXPECT_TRUE(specifics.has_encrypted()); @@ -2050,7 +2072,8 @@ TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); const syncable::Entry* node_entry = node.GetEntry(); const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); EXPECT_TRUE(specifics.has_encrypted()); @@ -2065,7 +2088,8 @@ TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); node.SetEntitySpecifics(entity_specifics); const syncable::Entry* node_entry = node.GetEntry(); const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); @@ -2084,7 +2108,8 @@ TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { entity_specifics.mutable_bookmark()->set_title("title2"); WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); node.SetEntitySpecifics(entity_specifics); const syncable::Entry* node_entry = node.GetEntry(); const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); @@ -2125,7 +2150,8 @@ TEST_F(SyncManagerTest, UpdatePasswordSetEntitySpecificsNoChange) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); node.SetEntitySpecifics(entity_specifics); } EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); @@ -2159,7 +2185,8 @@ TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); node.SetPasswordSpecifics(node.GetPasswordSpecifics()); } EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); @@ -2168,7 +2195,8 @@ TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); Cryptographer* cryptographer = trans.GetCryptographer(); sync_pb::PasswordSpecificsData data; data.set_password_value("secret2"); @@ -2260,7 +2288,8 @@ TEST_F(SyncManagerTest, SetBookmarkTitle) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); node.SetTitle(UTF8ToWide(client_tag)); } EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); @@ -2269,7 +2298,8 @@ TEST_F(SyncManagerTest, SetBookmarkTitle) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); node.SetTitle(UTF8ToWide("title2")); } EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); @@ -2305,7 +2335,8 @@ TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); node.SetTitle(UTF8ToWide(client_tag)); const syncable::Entry* node_entry = node.GetEntry(); const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); @@ -2319,7 +2350,8 @@ TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); node.SetTitle(UTF8ToWide("title2")); const syncable::Entry* node_entry = node.GetEntry(); const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); @@ -2349,7 +2381,8 @@ TEST_F(SyncManagerTest, SetNonBookmarkTitle) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); node.SetTitle(UTF8ToWide(client_tag)); } EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); @@ -2358,7 +2391,8 @@ TEST_F(SyncManagerTest, SetNonBookmarkTitle) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); node.SetTitle(UTF8ToWide("title2")); } EXPECT_TRUE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); @@ -2396,7 +2430,8 @@ TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); node.SetTitle(UTF8ToWide(client_tag)); const syncable::Entry* node_entry = node.GetEntry(); const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); @@ -2410,7 +2445,8 @@ TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); node.SetTitle(UTF8ToWide("title2")); const syncable::Entry* node_entry = node.GetEntry(); const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); @@ -2450,7 +2486,8 @@ TEST_F(SyncManagerTest, SetPreviouslyEncryptedSpecifics) { // Verify the data. ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); EXPECT_EQ(title, node.GetTitle()); EXPECT_EQ(GURL(url), node.GetURL()); } @@ -2459,7 +2496,8 @@ TEST_F(SyncManagerTest, SetPreviouslyEncryptedSpecifics) { // Overwrite the url (which overwrites the specifics). WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); WriteNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); node.SetURL(GURL(url2)); } @@ -2467,7 +2505,8 @@ TEST_F(SyncManagerTest, SetPreviouslyEncryptedSpecifics) { // Verify it's still encrypted and it has the most recent url. ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadNode node(&trans); - EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); + EXPECT_EQ(BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); EXPECT_EQ(title, node.GetTitle()); EXPECT_EQ(GURL(url2), node.GetURL()); const syncable::Entry* node_entry = node.GetEntry(); diff --git a/chrome/browser/sync/internal_api/write_node.cc b/chrome/browser/sync/internal_api/write_node.cc index 84d0f79..ef47f9d 100644 --- a/chrome/browser/sync/internal_api/write_node.cc +++ b/chrome/browser/sync/internal_api/write_node.cc @@ -265,45 +265,53 @@ WriteNode::~WriteNode() { // Find an existing node matching the ID |id|, and bind this WriteNode to it. // Return true on success. -bool WriteNode::InitByIdLookup(int64 id) { +BaseNode::InitByLookupResult WriteNode::InitByIdLookup(int64 id) { DCHECK(!entry_) << "Init called twice"; DCHECK_NE(id, kInvalidId); entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), syncable::GET_BY_HANDLE, id); - return (entry_->good() && !entry_->Get(syncable::IS_DEL) && - DecryptIfNecessary()); + if (!entry_->good()) + return INIT_FAILED_ENTRY_NOT_GOOD; + if (entry_->Get(syncable::IS_DEL)) + return INIT_FAILED_ENTRY_IS_DEL; + return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; } // Find a node by client tag, and bind this WriteNode to it. // Return true if the write node was found, and was not deleted. // Undeleting a deleted node is possible by ClientTag. -bool WriteNode::InitByClientTagLookup(syncable::ModelType model_type, - const std::string& tag) { +BaseNode::InitByLookupResult WriteNode::InitByClientTagLookup( + syncable::ModelType model_type, + const std::string& tag) { DCHECK(!entry_) << "Init called twice"; if (tag.empty()) - return false; + return INIT_FAILED_PRECONDITION; const std::string hash = GenerateSyncableHash(model_type, tag); entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), syncable::GET_BY_CLIENT_TAG, hash); - return (entry_->good() && !entry_->Get(syncable::IS_DEL) && - DecryptIfNecessary()); + if (!entry_->good()) + return INIT_FAILED_ENTRY_NOT_GOOD; + if (entry_->Get(syncable::IS_DEL)) + return INIT_FAILED_ENTRY_IS_DEL; + return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; } -bool WriteNode::InitByTagLookup(const std::string& tag) { +BaseNode::InitByLookupResult WriteNode::InitByTagLookup( + const std::string& tag) { DCHECK(!entry_) << "Init called twice"; if (tag.empty()) - return false; + return INIT_FAILED_PRECONDITION; entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), syncable::GET_BY_SERVER_TAG, tag); if (!entry_->good()) - return false; + return INIT_FAILED_ENTRY_NOT_GOOD; if (entry_->Get(syncable::IS_DEL)) - return false; + return INIT_FAILED_ENTRY_IS_DEL; syncable::ModelType model_type = GetModelType(); DCHECK_EQ(syncable::NIGORI, model_type); - return true; + return INIT_OK; } void WriteNode::PutModelType(syncable::ModelType model_type) { diff --git a/chrome/browser/sync/internal_api/write_node.h b/chrome/browser/sync/internal_api/write_node.h index ddca68c..7c55ddd 100644 --- a/chrome/browser/sync/internal_api/write_node.h +++ b/chrome/browser/sync/internal_api/write_node.h @@ -54,9 +54,10 @@ class WriteNode : public BaseNode { // populate the node. // BaseNode implementation. - virtual bool InitByIdLookup(int64 id) OVERRIDE; - virtual bool InitByClientTagLookup(syncable::ModelType model_type, - const std::string& tag) OVERRIDE; + virtual InitByLookupResult InitByIdLookup(int64 id) OVERRIDE; + virtual InitByLookupResult InitByClientTagLookup( + syncable::ModelType model_type, + const std::string& tag) OVERRIDE; // Create a new node with the specified parent and predecessor. |model_type| // dictates the type of the item, and controls which EntitySpecifics proto @@ -81,7 +82,7 @@ class WriteNode : public BaseNode { // Each server-created permanent node is tagged with a unique string. // Look up the node with the particular tag. If it does not exist, // return false. - bool InitByTagLookup(const std::string& tag); + InitByLookupResult InitByTagLookup(const std::string& tag); // These Set() functions correspond to the Get() functions of BaseNode. void SetIsFolder(bool folder); diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index f680214..b3301fe 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -82,6 +82,7 @@ using syncable::SPECIFICS; using syncable::UNITTEST; using syncable::WriterTag; using syncable::WriteTransaction; +using sync_api::BaseNode; using testing::_; using testing::DoAll; using testing::DoDefault; @@ -436,9 +437,11 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { bool AddAutofillSyncNode(const AutofillEntry& entry) { sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); sync_api::ReadNode autofill_root(&trans); - if (!autofill_root.InitByTagLookup( - syncable::ModelTypeToRootTag(syncable::AUTOFILL))) + if (autofill_root.InitByTagLookup( + syncable::ModelTypeToRootTag(syncable::AUTOFILL)) != + BaseNode::INIT_OK) { return false; + } sync_api::WriteNode node(&trans); std::string tag = AutocompleteSyncableService::KeyToTag( @@ -457,8 +460,10 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { bool AddAutofillSyncNode(const AutofillProfile& profile) { sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); sync_api::ReadNode autofill_root(&trans); - if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) + if (autofill_root.InitByTagLookup(kAutofillProfileTag) != + BaseNode::INIT_OK) { return false; + } sync_api::WriteNode node(&trans); std::string tag = profile.guid(); if (!node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, @@ -476,14 +481,16 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { std::vector<AutofillProfile>* profiles) { sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); sync_api::ReadNode autofill_root(&trans); - if (!autofill_root.InitByTagLookup( - syncable::ModelTypeToRootTag(syncable::AUTOFILL))) + if (autofill_root.InitByTagLookup( + syncable::ModelTypeToRootTag(syncable::AUTOFILL)) != + BaseNode::INIT_OK) { return false; + } int64 child_id = autofill_root.GetFirstChildId(); while (child_id != sync_api::kInvalidId) { sync_api::ReadNode child_node(&trans); - if (!child_node.InitByIdLookup(child_id)) + if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) return false; const sync_pb::AutofillSpecifics& autofill( @@ -514,13 +521,15 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { std::vector<AutofillProfile>* profiles) { sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); sync_api::ReadNode autofill_root(&trans); - if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) + if (autofill_root.InitByTagLookup(kAutofillProfileTag) != + BaseNode::INIT_OK) { return false; + } int64 child_id = autofill_root.GetFirstChildId(); while (child_id != sync_api::kInvalidId) { sync_api::ReadNode child_node(&trans); - if (!child_node.InitByIdLookup(child_id)) + if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) return false; const sync_pb::AutofillProfileSpecifics& autofill( diff --git a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc index 8656d64..7353037 100644 --- a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc @@ -42,11 +42,12 @@ namespace browser_sync { +using content::BrowserThread; +using sync_api::BaseNode; using testing::_; using testing::InvokeWithoutArgs; using testing::Mock; using testing::StrictMock; -using content::BrowserThread; class TestBookmarkModelAssociator : public BookmarkModelAssociator { public: @@ -73,7 +74,8 @@ class TestBookmarkModelAssociator : public BookmarkModelAssociator { sync_api::ReadNode root(&trans); root_exists = root.InitByTagLookup( - ProfileSyncServiceTestHelper::GetTagForType(type)); + ProfileSyncServiceTestHelper::GetTagForType(type)) == + BaseNode::INIT_OK; } if (!root_exists) { @@ -87,7 +89,7 @@ class TestBookmarkModelAssociator : public BookmarkModelAssociator { sync_api::WriteTransaction trans(FROM_HERE, user_share_); sync_api::ReadNode root(&trans); - EXPECT_TRUE(root.InitByTagLookup( + EXPECT_EQ(BaseNode::INIT_OK, root.InitByTagLookup( ProfileSyncServiceTestHelper::GetTagForType(type))); // First, try to find a node with the title among the root's children. @@ -96,7 +98,7 @@ class TestBookmarkModelAssociator : public BookmarkModelAssociator { int64 last_child_id = sync_api::kInvalidId; for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) { sync_api::ReadNode child(&trans); - child.InitByIdLookup(id); + EXPECT_EQ(BaseNode::INIT_OK, child.InitByIdLookup(id)); last_child_id = id; if (tag_str == child.GetTitle()) { *sync_id = id; @@ -108,7 +110,8 @@ class TestBookmarkModelAssociator : public BookmarkModelAssociator { sync_api::ReadNode predecessor_node(&trans); sync_api::ReadNode* predecessor = NULL; if (last_child_id != sync_api::kInvalidId) { - predecessor_node.InitByIdLookup(last_child_id); + EXPECT_EQ(BaseNode::INIT_OK, + predecessor_node.InitByIdLookup(last_child_id)); predecessor = &predecessor_node; } sync_api::WriteNode node(&trans); @@ -147,13 +150,13 @@ class FakeServerChange { int64 parent_id, int64 predecessor_id) { sync_api::ReadNode parent(trans_); - EXPECT_TRUE(parent.InitByIdLookup(parent_id)); + EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); sync_api::WriteNode node(trans_); if (predecessor_id == 0) { EXPECT_TRUE(node.InitByCreation(syncable::BOOKMARKS, parent, NULL)); } else { sync_api::ReadNode predecessor(trans_); - EXPECT_TRUE(predecessor.InitByIdLookup(predecessor_id)); + EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); EXPECT_TRUE(node.InitByCreation(syncable::BOOKMARKS, parent, &predecessor)); @@ -191,14 +194,14 @@ class FakeServerChange { { // Delete the sync node. sync_api::WriteNode node(trans_); - EXPECT_TRUE(node.InitByIdLookup(id)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); EXPECT_FALSE(node.GetFirstChildId()); node.Remove(); } { // Verify the deletion. sync_api::ReadNode node(trans_); - EXPECT_FALSE(node.InitByIdLookup(id)); + EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, node.InitByIdLookup(id)); } sync_api::ChangeRecord record; @@ -215,7 +218,7 @@ class FakeServerChange { // Set a new title value, and return the old value. std::wstring ModifyTitle(int64 id, const std::wstring& new_title) { sync_api::WriteNode node(trans_); - EXPECT_TRUE(node.InitByIdLookup(id)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); std::string old_title = node.GetTitle(); node.SetTitle(new_title); SetModified(id); @@ -227,15 +230,15 @@ class FakeServerChange { // very useful for assertions. int64 ModifyPosition(int64 id, int64 parent_id, int64 predecessor_id) { sync_api::ReadNode parent(trans_); - EXPECT_TRUE(parent.InitByIdLookup(parent_id)); + EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); sync_api::WriteNode node(trans_); - EXPECT_TRUE(node.InitByIdLookup(id)); + EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); int64 old_parent_id = node.GetParentId(); if (predecessor_id == 0) { EXPECT_TRUE(node.SetPosition(parent, NULL)); } else { sync_api::ReadNode predecessor(trans_); - EXPECT_TRUE(predecessor.InitByIdLookup(predecessor_id)); + EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); EXPECT_TRUE(node.SetPosition(parent, &predecessor)); } @@ -512,7 +515,7 @@ class ProfileSyncServiceBookmarkTest : public testing::Test { ExpectBrowserNodeMatching(trans, id); sync_api::ReadNode gnode(trans); - ASSERT_TRUE(gnode.InitByIdLookup(id)); + ASSERT_EQ(BaseNode::INIT_OK, gnode.InitByIdLookup(id)); stack.push(gnode.GetFirstChildId()); stack.push(gnode.GetSuccessorId()); } diff --git a/chrome/browser/sync/profile_sync_service_password_unittest.cc b/chrome/browser/sync/profile_sync_service_password_unittest.cc index b90e644..5577184 100644 --- a/chrome/browser/sync/profile_sync_service_password_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc @@ -141,7 +141,8 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { void AddPasswordSyncNode(const PasswordForm& entry) { sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); sync_api::ReadNode password_root(&trans); - ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag)); + ASSERT_EQ(sync_api::BaseNode::INIT_OK, + password_root.InitByTagLookup(browser_sync::kPasswordTag)); sync_api::WriteNode node(&trans); std::string tag = PasswordModelAssociator::MakeTag(entry); @@ -245,12 +246,14 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { void GetPasswordEntriesFromSyncDB(std::vector<PasswordForm>* entries) { sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); sync_api::ReadNode password_root(&trans); - ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag)); + ASSERT_EQ(sync_api::BaseNode::INIT_OK, + password_root.InitByTagLookup(browser_sync::kPasswordTag)); int64 child_id = password_root.GetFirstChildId(); while (child_id != sync_api::kInvalidId) { sync_api::ReadNode child_node(&trans); - ASSERT_TRUE(child_node.InitByIdLookup(child_id)); + ASSERT_EQ(sync_api::BaseNode::INIT_OK, + child_node.InitByIdLookup(child_id)); const sync_pb::PasswordSpecificsData& password = child_node.GetPasswordSpecifics(); diff --git a/chrome/browser/sync/profile_sync_service_preference_unittest.cc b/chrome/browser/sync/profile_sync_service_preference_unittest.cc index da17a86..4ddd687 100644 --- a/chrome/browser/sync/profile_sync_service_preference_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_preference_unittest.cc @@ -63,16 +63,18 @@ class ProfileSyncServicePreferenceTest int64 SetSyncedValue(const std::string& name, const Value& value) { sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); sync_api::ReadNode root(&trans); - if (!root.InitByTagLookup( - syncable::ModelTypeToRootTag(syncable::PREFERENCES))) { + if (root.InitByTagLookup(syncable::ModelTypeToRootTag( + syncable::PREFERENCES)) != sync_api::BaseNode::INIT_OK) { return sync_api::kInvalidId; } sync_api::WriteNode tag_node(&trans); sync_api::WriteNode node(&trans); - if (tag_node.InitByClientTagLookup(syncable::PREFERENCES, name)) + if (tag_node.InitByClientTagLookup(syncable::PREFERENCES, name) == + sync_api::BaseNode::INIT_OK) { return WriteSyncedValue(name, value, &tag_node); + } if (node.InitUniqueByCreation(syncable::PREFERENCES, root, name)) return WriteSyncedValue(name, value, &node); @@ -158,8 +160,10 @@ class ProfileSyncServicePreferenceTest sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); sync_api::ReadNode node(&trans); - if (!node.InitByClientTagLookup(syncable::PREFERENCES, name)) + if (node.InitByClientTagLookup(syncable::PREFERENCES, name) != + sync_api::BaseNode::INIT_OK) { return NULL; + } const sync_pb::PreferenceSpecifics& specifics( node.GetEntitySpecifics().preference()); diff --git a/chrome/browser/sync/profile_sync_service_session_unittest.cc b/chrome/browser/sync/profile_sync_service_session_unittest.cc index 0b860fc..2a32d8d 100644 --- a/chrome/browser/sync/profile_sync_service_session_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc @@ -315,7 +315,8 @@ TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) { // Check that we can get the correct session specifics back from the node. sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode node(&trans); - ASSERT_TRUE(node.InitByClientTagLookup(syncable::SESSIONS, machine_tag)); + ASSERT_EQ(sync_api::BaseNode::INIT_OK, + node.InitByClientTagLookup(syncable::SESSIONS, machine_tag)); const sync_pb::SessionSpecifics& specifics(node.GetSessionSpecifics()); ASSERT_EQ(machine_tag, specifics.session_tag()); ASSERT_TRUE(specifics.has_header()); diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc index bbcde9e..c4862ea 100644 --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc @@ -145,7 +145,8 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { const history::VisitVector& visits) { sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); sync_api::ReadNode typed_url_root(&trans); - ASSERT_TRUE(typed_url_root.InitByTagLookup(browser_sync::kTypedUrlTag)); + ASSERT_EQ(sync_api::BaseNode::INIT_OK, + typed_url_root.InitByTagLookup(browser_sync::kTypedUrlTag)); sync_api::WriteNode node(&trans); std::string tag = url.url().spec(); @@ -230,13 +231,14 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { urls->clear(); sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); sync_api::ReadNode typed_url_root(&trans); - if (!typed_url_root.InitByTagLookup(browser_sync::kTypedUrlTag)) + if (typed_url_root.InitByTagLookup(browser_sync::kTypedUrlTag) != + sync_api::BaseNode::INIT_OK) return; int64 child_id = typed_url_root.GetFirstChildId(); while (child_id != sync_api::kInvalidId) { sync_api::ReadNode child_node(&trans); - if (!child_node.InitByIdLookup(child_id)) + if (child_node.InitByIdLookup(child_id) != sync_api::BaseNode::INIT_OK) return; const sync_pb::TypedUrlSpecifics& typed_url( diff --git a/chrome/browser/sync/test/integration/enable_disable_test.cc b/chrome/browser/sync/test/integration/enable_disable_test.cc index 100dea7..29b6275 100644 --- a/chrome/browser/sync/test/integration/enable_disable_test.cc +++ b/chrome/browser/sync/test/integration/enable_disable_test.cc @@ -34,7 +34,8 @@ bool DoesTopLevelNodeExist(sync_api::UserShare* user_share, syncable::ModelType type) { sync_api::ReadTransaction trans(FROM_HERE, user_share); sync_api::ReadNode node(&trans); - return node.InitByTagLookup(syncable::ModelTypeToRootTag(type)); + return node.InitByTagLookup(syncable::ModelTypeToRootTag(type)) == + sync_api::BaseNode::INIT_OK; } IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, EnableOneAtATime) { diff --git a/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc b/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc index 5c88795..455340e 100644 --- a/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc +++ b/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc @@ -8,7 +8,6 @@ #include "chrome/browser/autofill/autofill_profile.h" #include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/browser/sync/api/sync_error_factory_mock.h" -#include "chrome/browser/sync/internal_api/read_node_mock.h" #include "chrome/browser/webdata/autofill_change.h" #include "chrome/browser/webdata/autofill_profile_syncable_service.h" #include "content/test/test_browser_thread.h" diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 473bd36..0c94b6f 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1646,8 +1646,6 @@ 'browser/sync/abstract_profile_sync_service_test.cc', 'browser/sync/abstract_profile_sync_service_test.h', 'browser/sync/backend_migrator_unittest.cc', - 'browser/sync/internal_api/read_node_mock.cc', - 'browser/sync/internal_api/read_node_mock.h', 'browser/sync/glue/app_notification_data_type_controller_unittest.cc', 'browser/sync/glue/autofill_data_type_controller_unittest.cc', 'browser/sync/glue/bookmark_data_type_controller_unittest.cc', |