| 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_updates_command.h" | 13 #include "sync/engine/apply_updates_command.h" |
| 14 #include "sync/engine/build_commit_command.h" | 14 #include "sync/engine/build_commit_command.h" |
| 15 #include "sync/engine/cleanup_disabled_types_command.h" | 15 #include "sync/engine/cleanup_disabled_types_command.h" |
| 16 #include "sync/engine/clear_data_command.h" | 16 #include "sync/engine/clear_data_command.h" |
| 17 #include "sync/engine/commit.h" |
| 17 #include "sync/engine/conflict_resolver.h" | 18 #include "sync/engine/conflict_resolver.h" |
| 18 #include "sync/engine/download_updates_command.h" | 19 #include "sync/engine/download_updates_command.h" |
| 19 #include "sync/engine/get_commit_ids_command.h" | |
| 20 #include "sync/engine/net/server_connection_manager.h" | 20 #include "sync/engine/net/server_connection_manager.h" |
| 21 #include "sync/engine/post_commit_message_command.h" | |
| 22 #include "sync/engine/process_commit_response_command.h" | 21 #include "sync/engine/process_commit_response_command.h" |
| 23 #include "sync/engine/process_updates_command.h" | 22 #include "sync/engine/process_updates_command.h" |
| 24 #include "sync/engine/resolve_conflicts_command.h" | 23 #include "sync/engine/resolve_conflicts_command.h" |
| 25 #include "sync/engine/store_timestamps_command.h" | 24 #include "sync/engine/store_timestamps_command.h" |
| 26 #include "sync/engine/syncer_types.h" | 25 #include "sync/engine/syncer_types.h" |
| 27 #include "sync/engine/syncproto.h" | 26 #include "sync/engine/syncproto.h" |
| 28 #include "sync/engine/verify_updates_command.h" | 27 #include "sync/engine/verify_updates_command.h" |
| 29 #include "sync/syncable/syncable-inl.h" | 28 #include "sync/syncable/syncable-inl.h" |
| 30 #include "sync/syncable/syncable.h" | 29 #include "sync/syncable/syncable.h" |
| 31 | 30 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 58 { | 57 { |
| 59 switch (step) { | 58 switch (step) { |
| 60 ENUM_CASE(SYNCER_BEGIN); | 59 ENUM_CASE(SYNCER_BEGIN); |
| 61 ENUM_CASE(CLEANUP_DISABLED_TYPES); | 60 ENUM_CASE(CLEANUP_DISABLED_TYPES); |
| 62 ENUM_CASE(DOWNLOAD_UPDATES); | 61 ENUM_CASE(DOWNLOAD_UPDATES); |
| 63 ENUM_CASE(PROCESS_CLIENT_COMMAND); | 62 ENUM_CASE(PROCESS_CLIENT_COMMAND); |
| 64 ENUM_CASE(VERIFY_UPDATES); | 63 ENUM_CASE(VERIFY_UPDATES); |
| 65 ENUM_CASE(PROCESS_UPDATES); | 64 ENUM_CASE(PROCESS_UPDATES); |
| 66 ENUM_CASE(STORE_TIMESTAMPS); | 65 ENUM_CASE(STORE_TIMESTAMPS); |
| 67 ENUM_CASE(APPLY_UPDATES); | 66 ENUM_CASE(APPLY_UPDATES); |
| 68 ENUM_CASE(BUILD_COMMIT_REQUEST); | 67 ENUM_CASE(COMMIT); |
| 69 ENUM_CASE(POST_COMMIT_MESSAGE); | |
| 70 ENUM_CASE(PROCESS_COMMIT_RESPONSE); | |
| 71 ENUM_CASE(RESOLVE_CONFLICTS); | 68 ENUM_CASE(RESOLVE_CONFLICTS); |
| 72 ENUM_CASE(APPLY_UPDATES_TO_RESOLVE_CONFLICTS); | 69 ENUM_CASE(APPLY_UPDATES_TO_RESOLVE_CONFLICTS); |
| 73 ENUM_CASE(CLEAR_PRIVATE_DATA); | 70 ENUM_CASE(CLEAR_PRIVATE_DATA); |
| 74 ENUM_CASE(SYNCER_END); | 71 ENUM_CASE(SYNCER_END); |
| 75 } | 72 } |
| 76 NOTREACHED(); | 73 NOTREACHED(); |
| 77 return ""; | 74 return ""; |
| 78 } | 75 } |
| 79 #undef ENUM_CASE | 76 #undef ENUM_CASE |
| 80 | 77 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 170 } |
| 174 case APPLY_UPDATES: { | 171 case APPLY_UPDATES: { |
| 175 ApplyUpdatesCommand apply_updates; | 172 ApplyUpdatesCommand apply_updates; |
| 176 apply_updates.Execute(session); | 173 apply_updates.Execute(session); |
| 177 if (last_step == APPLY_UPDATES) { | 174 if (last_step == APPLY_UPDATES) { |
| 178 // We're in configuration mode, but we still need to run the | 175 // We're in configuration mode, but we still need to run the |
| 179 // SYNCER_END step. | 176 // SYNCER_END step. |
| 180 last_step = SYNCER_END; | 177 last_step = SYNCER_END; |
| 181 next_step = SYNCER_END; | 178 next_step = SYNCER_END; |
| 182 } else { | 179 } else { |
| 183 next_step = BUILD_COMMIT_REQUEST; | 180 next_step = COMMIT; |
| 184 } | 181 } |
| 185 break; | 182 break; |
| 186 } | 183 } |
| 187 // These two steps are combined since they are executed within the same | 184 case COMMIT: { |
| 188 // write transaction. | 185 BuildAndPostCommits(this, session); |
| 189 case BUILD_COMMIT_REQUEST: { | |
| 190 syncable::Directory* dir = session->context()->directory(); | |
| 191 WriteTransaction trans(FROM_HERE, SYNCER, dir); | |
| 192 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); | |
| 193 | |
| 194 DVLOG(1) << "Getting the Commit IDs"; | |
| 195 GetCommitIdsCommand get_commit_ids_command( | |
| 196 session->context()->max_commit_batch_size()); | |
| 197 get_commit_ids_command.Execute(session); | |
| 198 | |
| 199 if (!session->status_controller().commit_ids().empty()) { | |
| 200 DVLOG(1) << "Building a commit message"; | |
| 201 | |
| 202 // This isn't perfect, since the set of extensions activity may not | |
| 203 // correlate exactly with the items being committed. That's OK as | |
| 204 // long as we're looking for a rough estimate of extensions activity, | |
| 205 // not an precise mapping of which commits were triggered by which | |
| 206 // extension. | |
| 207 // | |
| 208 // We will push this list of extensions activity back into the | |
| 209 // ExtensionsActivityMonitor if this commit turns out to not contain | |
| 210 // any bookmarks, or if the commit fails. | |
| 211 session->context()->extensions_monitor()->GetAndClearRecords( | |
| 212 session->mutable_extensions_activity()); | |
| 213 | |
| 214 BuildCommitCommand build_commit_command; | |
| 215 build_commit_command.Execute(session); | |
| 216 | |
| 217 next_step = POST_COMMIT_MESSAGE; | |
| 218 } else { | |
| 219 next_step = RESOLVE_CONFLICTS; | |
| 220 } | |
| 221 | |
| 222 break; | |
| 223 } | |
| 224 case POST_COMMIT_MESSAGE: { | |
| 225 PostCommitMessageCommand post_commit_command; | |
| 226 session->mutable_status_controller()->set_last_post_commit_result( | |
| 227 post_commit_command.Execute(session)); | |
| 228 next_step = PROCESS_COMMIT_RESPONSE; | |
| 229 break; | |
| 230 } | |
| 231 case PROCESS_COMMIT_RESPONSE: { | |
| 232 ProcessCommitResponseCommand process_response_command; | |
| 233 session->mutable_status_controller()-> | |
| 234 set_last_process_commit_response_result( | |
| 235 process_response_command.Execute(session)); | |
| 236 next_step = RESOLVE_CONFLICTS; | 186 next_step = RESOLVE_CONFLICTS; |
| 237 break; | 187 break; |
| 238 } | 188 } |
| 239 case RESOLVE_CONFLICTS: { | 189 case RESOLVE_CONFLICTS: { |
| 240 StatusController* status = session->mutable_status_controller(); | 190 StatusController* status = session->mutable_status_controller(); |
| 241 status->reset_conflicts_resolved(); | 191 status->reset_conflicts_resolved(); |
| 242 ResolveConflictsCommand resolve_conflicts_command; | 192 ResolveConflictsCommand resolve_conflicts_command; |
| 243 resolve_conflicts_command.Execute(session); | 193 resolve_conflicts_command.Execute(session); |
| 244 | 194 |
| 245 // Has ConflictingUpdates includes both resolvable and unresolvable | 195 // Has ConflictingUpdates includes both resolvable and unresolvable |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 entry->Put(SERVER_CTIME, Time()); | 294 entry->Put(SERVER_CTIME, Time()); |
| 345 entry->Put(SERVER_VERSION, 0); | 295 entry->Put(SERVER_VERSION, 0); |
| 346 entry->Put(SERVER_IS_DIR, false); | 296 entry->Put(SERVER_IS_DIR, false); |
| 347 entry->Put(SERVER_IS_DEL, false); | 297 entry->Put(SERVER_IS_DEL, false); |
| 348 entry->Put(IS_UNAPPLIED_UPDATE, false); | 298 entry->Put(IS_UNAPPLIED_UPDATE, false); |
| 349 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 299 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
| 350 entry->Put(SERVER_POSITION_IN_PARENT, 0); | 300 entry->Put(SERVER_POSITION_IN_PARENT, 0); |
| 351 } | 301 } |
| 352 | 302 |
| 353 } // namespace browser_sync | 303 } // namespace browser_sync |
| OLD | NEW |