OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "sync/engine/update_applicator.h" | 5 #include "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 "sync/engine/syncer_util.h" | 10 #include "sync/engine/syncer_util.h" |
11 #include "sync/syncable/entry.h" | 11 #include "sync/syncable/entry.h" |
12 #include "sync/syncable/mutable_entry.h" | 12 #include "sync/syncable/mutable_entry.h" |
13 #include "sync/syncable/syncable_id.h" | 13 #include "sync/syncable/syncable_id.h" |
14 #include "sync/syncable/syncable_write_transaction.h" | 14 #include "sync/syncable/syncable_write_transaction.h" |
15 | 15 |
16 using std::vector; | 16 using std::vector; |
17 | 17 |
18 namespace syncer { | 18 namespace syncer { |
19 | 19 |
20 using syncable::ID; | 20 using syncable::ID; |
21 | 21 |
22 UpdateApplicator::UpdateApplicator(Cryptographer* cryptographer, | 22 UpdateApplicator::UpdateApplicator(Cryptographer* cryptographer) |
23 const ModelSafeRoutingInfo& routes, | |
24 ModelSafeGroup group_filter) | |
25 : cryptographer_(cryptographer), | 23 : cryptographer_(cryptographer), |
26 group_filter_(group_filter), | |
27 routing_info_(routes), | |
28 updates_applied_(0), | 24 updates_applied_(0), |
29 encryption_conflicts_(0), | 25 encryption_conflicts_(0), |
30 hierarchy_conflicts_(0) { | 26 hierarchy_conflicts_(0) { |
31 } | 27 } |
32 | 28 |
33 UpdateApplicator::~UpdateApplicator() { | 29 UpdateApplicator::~UpdateApplicator() { |
34 } | 30 } |
35 | 31 |
36 // Attempt to apply all updates, using multiple passes if necessary. | 32 // Attempt to apply all updates, using multiple passes if necessary. |
37 // | 33 // |
(...skipping 13 matching lines...) Expand all Loading... |
51 syncable::WriteTransaction* trans, | 47 syncable::WriteTransaction* trans, |
52 const std::vector<int64>& handles) { | 48 const std::vector<int64>& handles) { |
53 std::vector<int64> to_apply = handles; | 49 std::vector<int64> to_apply = handles; |
54 | 50 |
55 DVLOG(1) << "UpdateApplicator running over " << to_apply.size() << " items."; | 51 DVLOG(1) << "UpdateApplicator running over " << to_apply.size() << " items."; |
56 while (!to_apply.empty()) { | 52 while (!to_apply.empty()) { |
57 std::vector<int64> to_reapply; | 53 std::vector<int64> to_reapply; |
58 | 54 |
59 for (std::vector<int64>::iterator i = to_apply.begin(); | 55 for (std::vector<int64>::iterator i = to_apply.begin(); |
60 i != to_apply.end(); ++i) { | 56 i != to_apply.end(); ++i) { |
61 syncable::Entry read_entry(trans, syncable::GET_BY_HANDLE, *i); | |
62 if (SkipUpdate(read_entry)) { | |
63 continue; | |
64 } | |
65 | |
66 syncable::MutableEntry entry(trans, syncable::GET_BY_HANDLE, *i); | 57 syncable::MutableEntry entry(trans, syncable::GET_BY_HANDLE, *i); |
67 UpdateAttemptResponse result = AttemptToUpdateEntry( | 58 UpdateAttemptResponse result = AttemptToUpdateEntry( |
68 trans, &entry, cryptographer_); | 59 trans, &entry, cryptographer_); |
69 | 60 |
70 switch (result) { | 61 switch (result) { |
71 case SUCCESS: | 62 case SUCCESS: |
72 updates_applied_++; | 63 updates_applied_++; |
73 break; | 64 break; |
74 case CONFLICT_SIMPLE: | 65 case CONFLICT_SIMPLE: |
75 simple_conflict_ids_.insert(entry.GetId()); | 66 simple_conflict_ids_.insert(entry.GetId()); |
(...skipping 20 matching lines...) Expand all Loading... |
96 } | 87 } |
97 | 88 |
98 // We made some progress, so prepare for what might be another iteration. | 89 // We made some progress, so prepare for what might be another iteration. |
99 // If everything went well, to_reapply will be empty and we'll break out on | 90 // If everything went well, to_reapply will be empty and we'll break out on |
100 // the while condition. | 91 // the while condition. |
101 to_apply.swap(to_reapply); | 92 to_apply.swap(to_reapply); |
102 to_reapply.clear(); | 93 to_reapply.clear(); |
103 } | 94 } |
104 } | 95 } |
105 | 96 |
106 bool UpdateApplicator::SkipUpdate(const syncable::Entry& entry) { | |
107 ModelType type = entry.GetServerModelType(); | |
108 ModelSafeGroup g = GetGroupForModelType(type, routing_info_); | |
109 // The set of updates passed to the UpdateApplicator should already | |
110 // be group-filtered. | |
111 if (g != group_filter_) { | |
112 NOTREACHED(); | |
113 return true; | |
114 } | |
115 if (g == GROUP_PASSIVE && | |
116 !routing_info_.count(type) && | |
117 type != UNSPECIFIED && | |
118 type != TOP_LEVEL_FOLDER) { | |
119 DVLOG(1) << "Skipping update application, type not permitted."; | |
120 return true; | |
121 } | |
122 return false; | |
123 } | |
124 | |
125 } // namespace syncer | 97 } // namespace syncer |
OLD | NEW |