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

Side by Side Diff: sync/engine/syncer.cc

Issue 11192071: sync: Merge apply updates and resolve conflicts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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
OLDNEW
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_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
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);
tim (not reviewing) 2012/10/24 20:29:08 It's great to move this to after applying updates,
rlarocque 2012/10/24 21:21:22 Although I do think this looks nicer, that's not m
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698