| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/engine/update_applicator.h" | 5 #include "chrome/browser/sync/engine/update_applicator.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/sync/engine/syncer_util.h" | 10 #include "chrome/browser/sync/engine/syncer_util.h" |
| 11 #include "chrome/browser/sync/syncable/syncable.h" | 11 #include "chrome/browser/sync/syncable/syncable.h" |
| 12 #include "chrome/browser/sync/syncable/syncable_id.h" | 12 #include "chrome/browser/sync/syncable/syncable_id.h" |
| 13 | 13 |
| 14 using std::vector; | 14 using std::vector; |
| 15 | 15 |
| 16 namespace browser_sync { | 16 namespace browser_sync { |
| 17 | 17 |
| 18 UpdateApplicator::UpdateApplicator(SyncerSession* session, | 18 UpdateApplicator::UpdateApplicator(ConflictResolver* resolver, |
| 19 const vi64iter& begin, | 19 const UpdateIterator& begin, |
| 20 const vi64iter& end) | 20 const UpdateIterator& end) |
| 21 : session_(session), begin_(begin), end_(end), pointer_(begin), | 21 : resolver_(resolver), |
| 22 begin_(begin), |
| 23 end_(end), |
| 24 pointer_(begin), |
| 22 progress_(false) { | 25 progress_(false) { |
| 23 size_t item_count = end - begin; | 26 size_t item_count = end - begin; |
| 24 LOG(INFO) << "UpdateApplicator created for " << item_count << " items."; | 27 LOG(INFO) << "UpdateApplicator created for " << item_count << " items."; |
| 25 successful_ids_.reserve(item_count); | 28 successful_ids_.reserve(item_count); |
| 26 } | 29 } |
| 27 | 30 |
| 28 // Returns true if there's more to do. | 31 // Returns true if there's more to do. |
| 29 bool UpdateApplicator::AttemptOneApplication( | 32 bool UpdateApplicator::AttemptOneApplication( |
| 30 syncable::WriteTransaction* trans) { | 33 syncable::WriteTransaction* trans) { |
| 31 // If there are no updates left to consider, we're done. | 34 // If there are no updates left to consider, we're done. |
| 32 if (end_ == begin_) | 35 if (end_ == begin_) |
| 33 return false; | 36 return false; |
| 34 if (pointer_ == end_) { | 37 if (pointer_ == end_) { |
| 35 if (!progress_) | 38 if (!progress_) |
| 36 return false; | 39 return false; |
| 37 | 40 |
| 38 LOG(INFO) << "UpdateApplicator doing additional pass."; | 41 LOG(INFO) << "UpdateApplicator doing additional pass."; |
| 39 pointer_ = begin_; | 42 pointer_ = begin_; |
| 40 progress_ = false; | 43 progress_ = false; |
| 41 | 44 |
| 42 // Clear the tracked failures to avoid double-counting. | 45 // Clear the tracked failures to avoid double-counting. |
| 43 conflicting_ids_.clear(); | 46 conflicting_ids_.clear(); |
| 44 blocked_ids_.clear(); | 47 blocked_ids_.clear(); |
| 45 } | 48 } |
| 46 syncable::MutableEntry entry(trans, syncable::GET_BY_HANDLE, *pointer_); | 49 syncable::MutableEntry entry(trans, syncable::GET_BY_HANDLE, *pointer_); |
| 47 UpdateAttemptResponse updateResponse = | 50 UpdateAttemptResponse updateResponse = |
| 48 SyncerUtil::AttemptToUpdateEntry(trans, &entry, session_); | 51 SyncerUtil::AttemptToUpdateEntry(trans, &entry, resolver_); |
| 49 switch (updateResponse) { | 52 switch (updateResponse) { |
| 50 case SUCCESS: | 53 case SUCCESS: |
| 51 --end_; | 54 --end_; |
| 52 *pointer_ = *end_; | 55 *pointer_ = *end_; |
| 53 progress_ = true; | 56 progress_ = true; |
| 54 successful_ids_.push_back(entry.Get(syncable::ID)); | 57 successful_ids_.push_back(entry.Get(syncable::ID)); |
| 55 break; | 58 break; |
| 56 case CONFLICT: | 59 case CONFLICT: |
| 57 pointer_++; | 60 pointer_++; |
| 58 conflicting_ids_.push_back(entry.Get(syncable::ID)); | 61 conflicting_ids_.push_back(entry.Get(syncable::ID)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 << " is " << updateResponse; | 72 << " is " << updateResponse; |
| 70 | 73 |
| 71 return true; | 74 return true; |
| 72 } | 75 } |
| 73 | 76 |
| 74 bool UpdateApplicator::AllUpdatesApplied() const { | 77 bool UpdateApplicator::AllUpdatesApplied() const { |
| 75 return conflicting_ids_.empty() && blocked_ids_.empty() && | 78 return conflicting_ids_.empty() && blocked_ids_.empty() && |
| 76 begin_ == end_; | 79 begin_ == end_; |
| 77 } | 80 } |
| 78 | 81 |
| 79 void UpdateApplicator::SaveProgressIntoSessionState() { | 82 void UpdateApplicator::SaveProgressIntoSessionState(SyncerSession* session) { |
| 80 DCHECK(begin_ == end_ || ((pointer_ == end_) && !progress_)) | 83 DCHECK(begin_ == end_ || ((pointer_ == end_) && !progress_)) |
| 81 << "SaveProgress called before updates exhausted."; | 84 << "SaveProgress called before updates exhausted."; |
| 82 | 85 |
| 83 vector<syncable::Id>::const_iterator i; | 86 vector<syncable::Id>::const_iterator i; |
| 84 for (i = conflicting_ids_.begin(); i != conflicting_ids_.end(); ++i) { | 87 for (i = conflicting_ids_.begin(); i != conflicting_ids_.end(); ++i) { |
| 85 session_->EraseBlockedItem(*i); | 88 session->EraseBlockedItem(*i); |
| 86 session_->AddCommitConflict(*i); | 89 session->AddCommitConflict(*i); |
| 87 session_->AddAppliedUpdate(CONFLICT, *i); | 90 session->AddAppliedUpdate(CONFLICT, *i); |
| 88 } | 91 } |
| 89 for (i = blocked_ids_.begin(); i != blocked_ids_.end(); ++i) { | 92 for (i = blocked_ids_.begin(); i != blocked_ids_.end(); ++i) { |
| 90 session_->AddBlockedItem(*i); | 93 session->AddBlockedItem(*i); |
| 91 session_->EraseCommitConflict(*i); | 94 session->EraseCommitConflict(*i); |
| 92 session_->AddAppliedUpdate(BLOCKED, *i); | 95 session->AddAppliedUpdate(BLOCKED, *i); |
| 93 } | 96 } |
| 94 for (i = successful_ids_.begin(); i != successful_ids_.end(); ++i) { | 97 for (i = successful_ids_.begin(); i != successful_ids_.end(); ++i) { |
| 95 session_->EraseCommitConflict(*i); | 98 session->EraseCommitConflict(*i); |
| 96 session_->EraseBlockedItem(*i); | 99 session->EraseBlockedItem(*i); |
| 97 session_->AddAppliedUpdate(SUCCESS, *i); | 100 session->AddAppliedUpdate(SUCCESS, *i); |
| 98 } | 101 } |
| 99 } | 102 } |
| 100 | 103 |
| 101 } // namespace browser_sync | 104 } // namespace browser_sync |
| OLD | NEW |