Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: chrome/browser/sync/engine/update_applicator.cc

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/engine/update_applicator.h"
6
7 #include <vector>
8
9 #include "base/logging.h"
10 #include "chrome/browser/sync/engine/syncer_util.h"
11 #include "chrome/browser/sync/syncable/syncable.h"
12 #include "chrome/browser/sync/syncable/syncable_id.h"
13
14 using std::vector;
15
16 namespace browser_sync {
17
18 UpdateApplicator::UpdateApplicator(SyncerSession* session,
19 const vi64iter& begin,
20 const vi64iter& end)
21 : session_(session), begin_(begin), end_(end), pointer_(begin),
22 progress_(false) {
23 size_t item_count = end - begin;
24 LOG(INFO) << "UpdateApplicator created for " << item_count << " items.";
25 successful_ids_.reserve(item_count);
26 }
27
28 // returns true if there's more to do.
29 bool UpdateApplicator::AttemptOneApplication(
30 syncable::WriteTransaction* trans) {
31 // If there are no updates left to consider, we're done.
32 if (end_ == begin_)
33 return false;
34 if (pointer_ == end_) {
35 if (!progress_)
36 return false;
37
38 LOG(INFO) << "UpdateApplicator doing additional pass.";
39 pointer_ = begin_;
40 progress_ = false;
41
42 // Clear the tracked failures to avoid double-counting.
43 conflicting_ids_.clear();
44 blocked_ids_.clear();
45 }
46 syncable::MutableEntry entry(trans, syncable::GET_BY_HANDLE, *pointer_);
47 UpdateAttemptResponse updateResponse =
48 SyncerUtil::AttemptToUpdateEntry(trans, &entry, session_);
49 switch (updateResponse) {
50 case SUCCESS:
51 --end_;
52 *pointer_ = *end_;
53 progress_ = true;
54 successful_ids_.push_back(entry.Get(syncable::ID));
55 break;
56 case CONFLICT:
57 pointer_++;
58 conflicting_ids_.push_back(entry.Get(syncable::ID));
59 break;
60 case BLOCKED:
61 pointer_++;
62 blocked_ids_.push_back(entry.Get(syncable::ID));
63 break;
64 }
65 LOG(INFO) << "Apply Status for " << entry.Get(syncable::META_HANDLE)
66 << " is " << updateResponse;
67
68 return true;
69 }
70
71 bool UpdateApplicator::AllUpdatesApplied() const {
72 return conflicting_ids_.empty() && blocked_ids_.empty() &&
73 begin_ == end_;
74 }
75
76 void UpdateApplicator::SaveProgressIntoSessionState() {
77 DCHECK(begin_ == end_ || ((pointer_ == end_) && !progress_))
78 << "SaveProgress called before updates exhausted.";
79
80 vector<syncable::Id>::const_iterator i;
81 for (i = conflicting_ids_.begin(); i != conflicting_ids_.end(); ++i) {
82 session_->EraseBlockedItem(*i);
83 session_->AddCommitConflict(*i);
84 session_->AddAppliedUpdate(CONFLICT, *i);
85 }
86 for (i = blocked_ids_.begin(); i != blocked_ids_.end(); ++i) {
87 session_->AddBlockedItem(*i);
88 session_->EraseCommitConflict(*i);
89 session_->AddAppliedUpdate(BLOCKED, *i);
90 }
91 for (i = successful_ids_.begin(); i != successful_ids_.end(); ++i) {
92 session_->EraseCommitConflict(*i);
93 session_->EraseBlockedItem(*i);
94 session_->AddAppliedUpdate(SUCCESS, *i);
95 }
96 }
97
98 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698