| 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_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/engine/verify_updates_command.h" | |
| 27 #include "sync/syncable/mutable_entry.h" | 25 #include "sync/syncable/mutable_entry.h" |
| 28 #include "sync/syncable/syncable-inl.h" | 26 #include "sync/syncable/syncable-inl.h" |
| 29 | 27 |
| 30 using base::Time; | 28 using base::Time; |
| 31 using base::TimeDelta; | 29 using base::TimeDelta; |
| 32 using sync_pb::ClientCommand; | 30 using sync_pb::ClientCommand; |
| 33 | 31 |
| 34 namespace syncer { | 32 namespace syncer { |
| 35 | 33 |
| 36 using sessions::ScopedSessionContextConflictResolver; | 34 using sessions::ScopedSessionContextConflictResolver; |
| 37 using sessions::StatusController; | 35 using sessions::StatusController; |
| 38 using sessions::SyncSession; | 36 using sessions::SyncSession; |
| 39 using sessions::ConflictProgress; | |
| 40 using syncable::IS_UNAPPLIED_UPDATE; | 37 using syncable::IS_UNAPPLIED_UPDATE; |
| 41 using syncable::SERVER_CTIME; | 38 using syncable::SERVER_CTIME; |
| 42 using syncable::SERVER_IS_DEL; | 39 using syncable::SERVER_IS_DEL; |
| 43 using syncable::SERVER_IS_DIR; | 40 using syncable::SERVER_IS_DIR; |
| 44 using syncable::SERVER_MTIME; | 41 using syncable::SERVER_MTIME; |
| 45 using syncable::SERVER_NON_UNIQUE_NAME; | 42 using syncable::SERVER_NON_UNIQUE_NAME; |
| 46 using syncable::SERVER_PARENT_ID; | 43 using syncable::SERVER_PARENT_ID; |
| 47 using syncable::SERVER_POSITION_IN_PARENT; | 44 using syncable::SERVER_POSITION_IN_PARENT; |
| 48 using syncable::SERVER_SPECIFICS; | 45 using syncable::SERVER_SPECIFICS; |
| 49 using syncable::SERVER_VERSION; | 46 using syncable::SERVER_VERSION; |
| 50 | 47 |
| 51 #define ENUM_CASE(x) case x: return #x | 48 #define ENUM_CASE(x) case x: return #x |
| 52 const char* SyncerStepToString(const SyncerStep step) | 49 const char* SyncerStepToString(const SyncerStep step) |
| 53 { | 50 { |
| 54 switch (step) { | 51 switch (step) { |
| 55 ENUM_CASE(SYNCER_BEGIN); | 52 ENUM_CASE(SYNCER_BEGIN); |
| 56 ENUM_CASE(DOWNLOAD_UPDATES); | 53 ENUM_CASE(DOWNLOAD_UPDATES); |
| 57 ENUM_CASE(PROCESS_CLIENT_COMMAND); | 54 ENUM_CASE(PROCESS_CLIENT_COMMAND); |
| 58 ENUM_CASE(VERIFY_UPDATES); | 55 ENUM_CASE(VERIFY_UPDATES); |
| 59 ENUM_CASE(PROCESS_UPDATES); | 56 ENUM_CASE(PROCESS_UPDATES); |
| 60 ENUM_CASE(STORE_TIMESTAMPS); | 57 ENUM_CASE(STORE_TIMESTAMPS); |
| 61 ENUM_CASE(APPLY_UPDATES); | 58 ENUM_CASE(APPLY_UPDATES); |
| 62 ENUM_CASE(COMMIT); | 59 ENUM_CASE(COMMIT); |
| 63 ENUM_CASE(RESOLVE_CONFLICTS); | |
| 64 ENUM_CASE(APPLY_UPDATES_TO_RESOLVE_CONFLICTS); | |
| 65 ENUM_CASE(SYNCER_END); | 60 ENUM_CASE(SYNCER_END); |
| 66 } | 61 } |
| 67 NOTREACHED(); | 62 NOTREACHED(); |
| 68 return ""; | 63 return ""; |
| 69 } | 64 } |
| 70 #undef ENUM_CASE | 65 #undef ENUM_CASE |
| 71 | 66 |
| 72 Syncer::Syncer() | 67 Syncer::Syncer() |
| 73 : early_exit_requested_(false) { | 68 : early_exit_requested_(false) { |
| 74 } | 69 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 const bool kCreateMobileBookmarksFolder = false; | 111 const bool kCreateMobileBookmarksFolder = false; |
| 117 #endif | 112 #endif |
| 118 DownloadUpdatesCommand download_updates(kCreateMobileBookmarksFolder); | 113 DownloadUpdatesCommand download_updates(kCreateMobileBookmarksFolder); |
| 119 session->mutable_status_controller()->set_last_download_updates_result( | 114 session->mutable_status_controller()->set_last_download_updates_result( |
| 120 download_updates.Execute(session)); | 115 download_updates.Execute(session)); |
| 121 next_step = PROCESS_CLIENT_COMMAND; | 116 next_step = PROCESS_CLIENT_COMMAND; |
| 122 break; | 117 break; |
| 123 } | 118 } |
| 124 case PROCESS_CLIENT_COMMAND: { | 119 case PROCESS_CLIENT_COMMAND: { |
| 125 ProcessClientCommand(session); | 120 ProcessClientCommand(session); |
| 126 next_step = VERIFY_UPDATES; | |
| 127 break; | |
| 128 } | |
| 129 case VERIFY_UPDATES: { | |
| 130 VerifyUpdatesCommand verify_updates; | |
| 131 verify_updates.Execute(session); | |
| 132 next_step = PROCESS_UPDATES; | 121 next_step = PROCESS_UPDATES; |
| 133 break; | 122 break; |
| 134 } | 123 } |
| 135 case PROCESS_UPDATES: { | 124 case PROCESS_UPDATES: { |
| 136 ProcessUpdatesCommand process_updates; | 125 ProcessUpdatesCommand process_updates; |
| 137 process_updates.Execute(session); | 126 process_updates.Execute(session); |
| 138 next_step = STORE_TIMESTAMPS; | 127 next_step = STORE_TIMESTAMPS; |
| 139 break; | 128 break; |
| 140 } | 129 } |
| 141 case STORE_TIMESTAMPS: { | 130 case STORE_TIMESTAMPS: { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 171 last_step = SYNCER_END; | 160 last_step = SYNCER_END; |
| 172 next_step = SYNCER_END; | 161 next_step = SYNCER_END; |
| 173 } else { | 162 } else { |
| 174 next_step = COMMIT; | 163 next_step = COMMIT; |
| 175 } | 164 } |
| 176 break; | 165 break; |
| 177 } | 166 } |
| 178 case COMMIT: { | 167 case COMMIT: { |
| 179 session->mutable_status_controller()->set_commit_result( | 168 session->mutable_status_controller()->set_commit_result( |
| 180 BuildAndPostCommits(this, session)); | 169 BuildAndPostCommits(this, session)); |
| 181 next_step = RESOLVE_CONFLICTS; | |
| 182 break; | |
| 183 } | |
| 184 case RESOLVE_CONFLICTS: { | |
| 185 StatusController* status = session->mutable_status_controller(); | |
| 186 status->reset_conflicts_resolved(); | |
| 187 ResolveConflictsCommand resolve_conflicts_command; | |
| 188 resolve_conflicts_command.Execute(session); | |
| 189 | |
| 190 // Has ConflictingUpdates includes both resolvable and unresolvable | |
| 191 // conflicts. If we have either, we want to attempt to reapply. | |
| 192 if (status->HasConflictingUpdates()) | |
| 193 next_step = APPLY_UPDATES_TO_RESOLVE_CONFLICTS; | |
| 194 else | |
| 195 next_step = SYNCER_END; | |
| 196 break; | |
| 197 } | |
| 198 case APPLY_UPDATES_TO_RESOLVE_CONFLICTS: { | |
| 199 StatusController* status = session->mutable_status_controller(); | |
| 200 DVLOG(1) << "Applying updates to resolve conflicts"; | |
| 201 ApplyUpdatesCommand apply_updates; | |
| 202 | |
| 203 // We only care to resolve conflicts again if we made progress on the | |
| 204 // simple conflicts. | |
| 205 int before_blocking_conflicting_updates = | |
| 206 status->TotalNumSimpleConflictingItems(); | |
| 207 apply_updates.Execute(session); | |
| 208 int after_blocking_conflicting_updates = | |
| 209 status->TotalNumSimpleConflictingItems(); | |
| 210 // If the following call sets the conflicts_resolved value to true, | |
| 211 // SyncSession::HasMoreToSync() will send us into another sync cycle | |
| 212 // after this one completes. | |
| 213 // | |
| 214 // TODO(rlarocque, 109072): Make conflict resolution not require | |
| 215 // extra sync cycles/GetUpdates. | |
| 216 status->update_conflicts_resolved(before_blocking_conflicting_updates > | |
| 217 after_blocking_conflicting_updates); | |
| 218 next_step = SYNCER_END; | 170 next_step = SYNCER_END; |
| 219 break; | 171 break; |
| 220 } | 172 } |
| 221 case SYNCER_END: { | 173 case SYNCER_END: { |
| 222 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_ENDED); | 174 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_ENDED); |
| 223 next_step = SYNCER_END; | 175 next_step = SYNCER_END; |
| 224 break; | 176 break; |
| 225 } | 177 } |
| 226 default: | 178 default: |
| 227 LOG(ERROR) << "Unknown command: " << current_step; | 179 LOG(ERROR) << "Unknown command: " << current_step; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 entry->Put(SERVER_CTIME, Time()); | 237 entry->Put(SERVER_CTIME, Time()); |
| 286 entry->Put(SERVER_VERSION, 0); | 238 entry->Put(SERVER_VERSION, 0); |
| 287 entry->Put(SERVER_IS_DIR, false); | 239 entry->Put(SERVER_IS_DIR, false); |
| 288 entry->Put(SERVER_IS_DEL, false); | 240 entry->Put(SERVER_IS_DEL, false); |
| 289 entry->Put(IS_UNAPPLIED_UPDATE, false); | 241 entry->Put(IS_UNAPPLIED_UPDATE, false); |
| 290 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 242 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
| 291 entry->Put(SERVER_POSITION_IN_PARENT, 0); | 243 entry->Put(SERVER_POSITION_IN_PARENT, 0); |
| 292 } | 244 } |
| 293 | 245 |
| 294 } // namespace syncer | 246 } // namespace syncer |
| OLD | NEW |