summaryrefslogtreecommitdiffstats
path: root/sync/engine/update_applicator.cc
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-15 09:35:42 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-15 09:35:42 +0000
commitc1c32c85357f14756247b04b8b5ae41b05bf2e16 (patch)
tree58f25f64e1fa592e8daf276ef69901cd2218f929 /sync/engine/update_applicator.cc
parent63ee33bde2ec8471a70f0f0ec6a1962dd07fc8ab (diff)
downloadchromium_src-c1c32c85357f14756247b04b8b5ae41b05bf2e16.zip
chromium_src-c1c32c85357f14756247b04b8b5ae41b05bf2e16.tar.gz
chromium_src-c1c32c85357f14756247b04b8b5ae41b05bf2e16.tar.bz2
[Sync] Move 'sync' target to sync/
Also move related test files. Move WriteNode::UpdateEntryWithEncryption to nigori_util.h. Clean up defines and dependencies. In particular, get rid of SYNC_ENGINE_VERSION_STRING and hard-code the string in the single place it's used. Rename data_encryption.* to data_encryption_win.* and add a pragma for crypt32.lib. Clean up exit-time constructor warnings in sync{able,er}_unittest.cc. Remove some unused files. BUG=117585 TEST= TBR=jhawkins@chromium.org Review URL: https://chromiumcodereview.appspot.com/9699057 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/engine/update_applicator.cc')
-rw-r--r--sync/engine/update_applicator.cc190
1 files changed, 190 insertions, 0 deletions
diff --git a/sync/engine/update_applicator.cc b/sync/engine/update_applicator.cc
new file mode 100644
index 0000000..5f510f3
--- /dev/null
+++ b/sync/engine/update_applicator.cc
@@ -0,0 +1,190 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/engine/update_applicator.h"
+
+#include <vector>
+
+#include "base/logging.h"
+#include "sync/engine/syncer_util.h"
+#include "sync/sessions/session_state.h"
+#include "sync/syncable/syncable.h"
+#include "sync/syncable/syncable_id.h"
+
+using std::vector;
+
+namespace browser_sync {
+
+UpdateApplicator::UpdateApplicator(ConflictResolver* resolver,
+ Cryptographer* cryptographer,
+ const UpdateIterator& begin,
+ const UpdateIterator& end,
+ const ModelSafeRoutingInfo& routes,
+ ModelSafeGroup group_filter)
+ : resolver_(resolver),
+ cryptographer_(cryptographer),
+ begin_(begin),
+ end_(end),
+ pointer_(begin),
+ group_filter_(group_filter),
+ progress_(false),
+ routing_info_(routes),
+ application_results_(end - begin) {
+ size_t item_count = end - begin;
+ DVLOG(1) << "UpdateApplicator created for " << item_count << " items.";
+}
+
+UpdateApplicator::~UpdateApplicator() {
+}
+
+// Returns true if there's more to do.
+bool UpdateApplicator::AttemptOneApplication(
+ syncable::WriteTransaction* trans) {
+ // If there are no updates left to consider, we're done.
+ if (end_ == begin_)
+ return false;
+ if (pointer_ == end_) {
+ if (!progress_)
+ return false;
+
+ DVLOG(1) << "UpdateApplicator doing additional pass.";
+ pointer_ = begin_;
+ progress_ = false;
+
+ // Clear the tracked failures to avoid double-counting.
+ application_results_.ClearConflicts();
+ }
+
+ syncable::Entry read_only(trans, syncable::GET_BY_HANDLE, *pointer_);
+ if (SkipUpdate(read_only)) {
+ Advance();
+ return true;
+ }
+
+ syncable::MutableEntry entry(trans, syncable::GET_BY_HANDLE, *pointer_);
+ UpdateAttemptResponse updateResponse = SyncerUtil::AttemptToUpdateEntry(
+ trans, &entry, resolver_, cryptographer_);
+ switch (updateResponse) {
+ case SUCCESS:
+ Advance();
+ progress_ = true;
+ application_results_.AddSuccess(entry.Get(syncable::ID));
+ break;
+ case CONFLICT_SIMPLE:
+ pointer_++;
+ application_results_.AddSimpleConflict(entry.Get(syncable::ID));
+ break;
+ case CONFLICT_ENCRYPTION:
+ pointer_++;
+ application_results_.AddEncryptionConflict(entry.Get(syncable::ID));
+ break;
+ case CONFLICT_HIERARCHY:
+ pointer_++;
+ application_results_.AddHierarchyConflict(entry.Get(syncable::ID));
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ DVLOG(1) << "Apply Status for " << entry.Get(syncable::META_HANDLE)
+ << " is " << updateResponse;
+
+ return true;
+}
+
+void UpdateApplicator::Advance() {
+ --end_;
+ *pointer_ = *end_;
+}
+
+bool UpdateApplicator::SkipUpdate(const syncable::Entry& entry) {
+ syncable::ModelType type = entry.GetServerModelType();
+ ModelSafeGroup g = GetGroupForModelType(type, routing_info_);
+ // The set of updates passed to the UpdateApplicator should already
+ // be group-filtered.
+ if (g != group_filter_) {
+ NOTREACHED();
+ return true;
+ }
+ if (g == GROUP_PASSIVE &&
+ !routing_info_.count(type) &&
+ type != syncable::UNSPECIFIED &&
+ type != syncable::TOP_LEVEL_FOLDER) {
+ DVLOG(1) << "Skipping update application, type not permitted.";
+ return true;
+ }
+ return false;
+}
+
+bool UpdateApplicator::AllUpdatesApplied() const {
+ return application_results_.no_conflicts() && begin_ == end_;
+}
+
+void UpdateApplicator::SaveProgressIntoSessionState(
+ sessions::ConflictProgress* conflict_progress,
+ sessions::UpdateProgress* update_progress) {
+ DCHECK(begin_ == end_ || ((pointer_ == end_) && !progress_))
+ << "SaveProgress called before updates exhausted.";
+
+ application_results_.SaveProgress(conflict_progress, update_progress);
+}
+
+UpdateApplicator::ResultTracker::ResultTracker(size_t num_results) {
+ successful_ids_.reserve(num_results);
+}
+
+UpdateApplicator::ResultTracker::~ResultTracker() {
+}
+
+void UpdateApplicator::ResultTracker::AddSimpleConflict(syncable::Id id) {
+ conflicting_ids_.push_back(id);
+}
+
+void UpdateApplicator::ResultTracker::AddEncryptionConflict(syncable::Id id) {
+ encryption_conflict_ids_.push_back(id);
+}
+
+void UpdateApplicator::ResultTracker::AddHierarchyConflict(syncable::Id id) {
+ hierarchy_conflict_ids_.push_back(id);
+}
+
+void UpdateApplicator::ResultTracker::AddSuccess(syncable::Id id) {
+ successful_ids_.push_back(id);
+}
+
+void UpdateApplicator::ResultTracker::SaveProgress(
+ sessions::ConflictProgress* conflict_progress,
+ sessions::UpdateProgress* update_progress) {
+ vector<syncable::Id>::const_iterator i;
+ for (i = conflicting_ids_.begin(); i != conflicting_ids_.end(); ++i) {
+ conflict_progress->AddSimpleConflictingItemById(*i);
+ update_progress->AddAppliedUpdate(CONFLICT_SIMPLE, *i);
+ }
+ for (i = encryption_conflict_ids_.begin();
+ i != encryption_conflict_ids_.end(); ++i) {
+ conflict_progress->AddEncryptionConflictingItemById(*i);
+ update_progress->AddAppliedUpdate(CONFLICT_ENCRYPTION, *i);
+ }
+ for (i = hierarchy_conflict_ids_.begin();
+ i != hierarchy_conflict_ids_.end(); ++i) {
+ conflict_progress->AddHierarchyConflictingItemById(*i);
+ update_progress->AddAppliedUpdate(CONFLICT_HIERARCHY, *i);
+ }
+ for (i = successful_ids_.begin(); i != successful_ids_.end(); ++i) {
+ conflict_progress->EraseSimpleConflictingItemById(*i);
+ update_progress->AddAppliedUpdate(SUCCESS, *i);
+ }
+}
+
+void UpdateApplicator::ResultTracker::ClearConflicts() {
+ conflicting_ids_.clear();
+ encryption_conflict_ids_.clear();
+ hierarchy_conflict_ids_.clear();
+}
+
+bool UpdateApplicator::ResultTracker::no_conflicts() const {
+ return conflicting_ids_.empty();
+}
+
+} // namespace browser_sync