OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/syncer.h" | 5 #include "sync/engine/syncer.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "sync/engine/apply_control_data_updates.h" | 13 #include "sync/engine/apply_control_data_updates.h" |
14 #include "sync/engine/apply_updates_command.h" | 14 #include "sync/engine/apply_updates_and_resolve_conflicts_command.h" |
15 #include "sync/engine/build_commit_command.h" | 15 #include "sync/engine/build_commit_command.h" |
16 #include "sync/engine/commit.h" | 16 #include "sync/engine/commit.h" |
17 #include "sync/engine/conflict_resolver.h" | 17 #include "sync/engine/conflict_resolver.h" |
18 #include "sync/engine/download_updates_command.h" | 18 #include "sync/engine/download_updates_command.h" |
19 #include "sync/engine/net/server_connection_manager.h" | 19 #include "sync/engine/net/server_connection_manager.h" |
20 #include "sync/engine/process_commit_response_command.h" | 20 #include "sync/engine/process_commit_response_command.h" |
21 #include "sync/engine/process_updates_command.h" | 21 #include "sync/engine/process_updates_command.h" |
22 #include "sync/engine/resolve_conflicts_command.h" | |
23 #include "sync/engine/store_timestamps_command.h" | 22 #include "sync/engine/store_timestamps_command.h" |
24 #include "sync/engine/syncer_types.h" | 23 #include "sync/engine/syncer_types.h" |
25 #include "sync/engine/throttled_data_type_tracker.h" | 24 #include "sync/engine/throttled_data_type_tracker.h" |
26 #include "sync/syncable/mutable_entry.h" | 25 #include "sync/syncable/mutable_entry.h" |
27 #include "sync/syncable/syncable-inl.h" | 26 #include "sync/syncable/syncable-inl.h" |
28 | 27 |
29 // TODO(vishwath): Remove this include after node positions have | 28 // TODO(vishwath): Remove this include after node positions have |
30 // shifted to completely using Ordinals. | 29 // shifted to completely using Ordinals. |
31 // See http://crbug.com/145412 . | 30 // See http://crbug.com/145412 . |
32 #include "sync/internal_api/public/base/node_ordinal.h" | 31 #include "sync/internal_api/public/base/node_ordinal.h" |
(...skipping 21 matching lines...) Expand all Loading... |
54 #define ENUM_CASE(x) case x: return #x | 53 #define ENUM_CASE(x) case x: return #x |
55 const char* SyncerStepToString(const SyncerStep step) | 54 const char* SyncerStepToString(const SyncerStep step) |
56 { | 55 { |
57 switch (step) { | 56 switch (step) { |
58 ENUM_CASE(SYNCER_BEGIN); | 57 ENUM_CASE(SYNCER_BEGIN); |
59 ENUM_CASE(DOWNLOAD_UPDATES); | 58 ENUM_CASE(DOWNLOAD_UPDATES); |
60 ENUM_CASE(PROCESS_UPDATES); | 59 ENUM_CASE(PROCESS_UPDATES); |
61 ENUM_CASE(STORE_TIMESTAMPS); | 60 ENUM_CASE(STORE_TIMESTAMPS); |
62 ENUM_CASE(APPLY_UPDATES); | 61 ENUM_CASE(APPLY_UPDATES); |
63 ENUM_CASE(COMMIT); | 62 ENUM_CASE(COMMIT); |
64 ENUM_CASE(RESOLVE_CONFLICTS); | |
65 ENUM_CASE(APPLY_UPDATES_TO_RESOLVE_CONFLICTS); | |
66 ENUM_CASE(SYNCER_END); | 63 ENUM_CASE(SYNCER_END); |
67 } | 64 } |
68 NOTREACHED(); | 65 NOTREACHED(); |
69 return ""; | 66 return ""; |
70 } | 67 } |
71 #undef ENUM_CASE | 68 #undef ENUM_CASE |
72 | 69 |
73 Syncer::Syncer() | 70 Syncer::Syncer() |
74 : early_exit_requested_(false) { | 71 : early_exit_requested_(false) { |
75 } | 72 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 next_step = DOWNLOAD_UPDATES; | 142 next_step = DOWNLOAD_UPDATES; |
146 } else { | 143 } else { |
147 next_step = APPLY_UPDATES; | 144 next_step = APPLY_UPDATES; |
148 } | 145 } |
149 break; | 146 break; |
150 } | 147 } |
151 case APPLY_UPDATES: { | 148 case APPLY_UPDATES: { |
152 // These include encryption updates that should be applied early. | 149 // These include encryption updates that should be applied early. |
153 ApplyControlDataUpdates(session->context()->directory()); | 150 ApplyControlDataUpdates(session->context()->directory()); |
154 | 151 |
155 ApplyUpdatesCommand apply_updates; | 152 ApplyUpdatesAndResolveConflictsCommand apply_updates; |
156 apply_updates.Execute(session); | 153 apply_updates.Execute(session); |
157 | 154 |
158 session->context()->set_hierarchy_conflict_detected( | 155 session->context()->set_hierarchy_conflict_detected( |
159 session->status_controller().num_hierarchy_conflicts() > 0); | 156 session->status_controller().num_hierarchy_conflicts() > 0); |
160 | 157 |
161 session->SendEventNotification(SyncEngineEvent::STATUS_CHANGED); | 158 session->SendEventNotification(SyncEngineEvent::STATUS_CHANGED); |
162 if (last_step == APPLY_UPDATES) { | 159 if (last_step == APPLY_UPDATES) { |
163 // We're in configuration mode, but we still need to run the | 160 // We're in configuration mode, but we still need to run the |
164 // SYNCER_END step. | 161 // SYNCER_END step. |
165 last_step = SYNCER_END; | 162 last_step = SYNCER_END; |
166 next_step = SYNCER_END; | 163 next_step = SYNCER_END; |
167 } else { | 164 } else { |
168 next_step = COMMIT; | 165 next_step = COMMIT; |
169 } | 166 } |
170 break; | 167 break; |
171 } | 168 } |
172 case COMMIT: { | 169 case COMMIT: { |
173 session->mutable_status_controller()->set_commit_result( | 170 session->mutable_status_controller()->set_commit_result( |
174 BuildAndPostCommits(this, session)); | 171 BuildAndPostCommits(this, session)); |
175 next_step = RESOLVE_CONFLICTS; | |
176 break; | |
177 } | |
178 case RESOLVE_CONFLICTS: { | |
179 StatusController* status = session->mutable_status_controller(); | |
180 status->reset_conflicts_resolved(); | |
181 ResolveConflictsCommand resolve_conflicts_command; | |
182 resolve_conflicts_command.Execute(session); | |
183 | |
184 // Has ConflictingUpdates includes both resolvable and unresolvable | |
185 // conflicts. If we have either, we want to attempt to reapply. | |
186 if (status->HasConflictingUpdates()) | |
187 next_step = APPLY_UPDATES_TO_RESOLVE_CONFLICTS; | |
188 else | |
189 next_step = SYNCER_END; | |
190 break; | |
191 } | |
192 case APPLY_UPDATES_TO_RESOLVE_CONFLICTS: { | |
193 StatusController* status = session->mutable_status_controller(); | |
194 DVLOG(1) << "Applying updates to resolve conflicts"; | |
195 ApplyUpdatesCommand apply_updates; | |
196 | |
197 // We only care to resolve conflicts again if we made progress on the | |
198 // simple conflicts. | |
199 int before_blocking_conflicting_updates = | |
200 status->num_simple_conflicts(); | |
201 apply_updates.Execute(session); | |
202 int after_blocking_conflicting_updates = | |
203 status->num_simple_conflicts(); | |
204 // If the following call sets the conflicts_resolved value to true, | |
205 // SyncSession::HasMoreToSync() will send us into another sync cycle | |
206 // after this one completes. | |
207 // | |
208 // TODO(rlarocque, 109072): Make conflict resolution not require | |
209 // extra sync cycles/GetUpdates. | |
210 status->update_conflicts_resolved(before_blocking_conflicting_updates > | |
211 after_blocking_conflicting_updates); | |
212 next_step = SYNCER_END; | 172 next_step = SYNCER_END; |
213 break; | 173 break; |
214 } | 174 } |
215 case SYNCER_END: { | 175 case SYNCER_END: { |
216 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_ENDED); | 176 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_ENDED); |
217 next_step = SYNCER_END; | 177 next_step = SYNCER_END; |
218 break; | 178 break; |
219 } | 179 } |
220 default: | 180 default: |
221 LOG(ERROR) << "Unknown command: " << current_step; | 181 LOG(ERROR) << "Unknown command: " << current_step; |
(...skipping 30 matching lines...) Expand all Loading... |
252 entry->Put(SERVER_CTIME, Time()); | 212 entry->Put(SERVER_CTIME, Time()); |
253 entry->Put(SERVER_VERSION, 0); | 213 entry->Put(SERVER_VERSION, 0); |
254 entry->Put(SERVER_IS_DIR, false); | 214 entry->Put(SERVER_IS_DIR, false); |
255 entry->Put(SERVER_IS_DEL, false); | 215 entry->Put(SERVER_IS_DEL, false); |
256 entry->Put(IS_UNAPPLIED_UPDATE, false); | 216 entry->Put(IS_UNAPPLIED_UPDATE, false); |
257 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 217 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
258 entry->Put(SERVER_ORDINAL_IN_PARENT, Int64ToNodeOrdinal(0)); | 218 entry->Put(SERVER_ORDINAL_IN_PARENT, Int64ToNodeOrdinal(0)); |
259 } | 219 } |
260 | 220 |
261 } // namespace syncer | 221 } // namespace syncer |
OLD | NEW |