Chromium Code Reviews| 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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 { | 58 { |
| 59 switch (step) { | 59 switch (step) { |
| 60 ENUM_CASE(SYNCER_BEGIN); | 60 ENUM_CASE(SYNCER_BEGIN); |
| 61 ENUM_CASE(CLEANUP_DISABLED_TYPES); | 61 ENUM_CASE(CLEANUP_DISABLED_TYPES); |
| 62 ENUM_CASE(DOWNLOAD_UPDATES); | 62 ENUM_CASE(DOWNLOAD_UPDATES); |
| 63 ENUM_CASE(PROCESS_CLIENT_COMMAND); | 63 ENUM_CASE(PROCESS_CLIENT_COMMAND); |
| 64 ENUM_CASE(VERIFY_UPDATES); | 64 ENUM_CASE(VERIFY_UPDATES); |
| 65 ENUM_CASE(PROCESS_UPDATES); | 65 ENUM_CASE(PROCESS_UPDATES); |
| 66 ENUM_CASE(STORE_TIMESTAMPS); | 66 ENUM_CASE(STORE_TIMESTAMPS); |
| 67 ENUM_CASE(APPLY_UPDATES); | 67 ENUM_CASE(APPLY_UPDATES); |
| 68 ENUM_CASE(BUILD_COMMIT_REQUEST); | 68 ENUM_CASE(COMMIT); |
| 69 ENUM_CASE(POST_COMMIT_MESSAGE); | |
| 70 ENUM_CASE(PROCESS_COMMIT_RESPONSE); | |
| 71 ENUM_CASE(RESOLVE_CONFLICTS); | 69 ENUM_CASE(RESOLVE_CONFLICTS); |
| 72 ENUM_CASE(APPLY_UPDATES_TO_RESOLVE_CONFLICTS); | 70 ENUM_CASE(APPLY_UPDATES_TO_RESOLVE_CONFLICTS); |
| 73 ENUM_CASE(CLEAR_PRIVATE_DATA); | 71 ENUM_CASE(CLEAR_PRIVATE_DATA); |
| 74 ENUM_CASE(SYNCER_END); | 72 ENUM_CASE(SYNCER_END); |
| 75 } | 73 } |
| 76 NOTREACHED(); | 74 NOTREACHED(); |
| 77 return ""; | 75 return ""; |
| 78 } | 76 } |
| 79 #undef ENUM_CASE | 77 #undef ENUM_CASE |
| 80 | 78 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 } | 176 } |
| 179 case APPLY_UPDATES: { | 177 case APPLY_UPDATES: { |
| 180 ApplyUpdatesCommand apply_updates; | 178 ApplyUpdatesCommand apply_updates; |
| 181 apply_updates.Execute(session); | 179 apply_updates.Execute(session); |
| 182 if (last_step == APPLY_UPDATES) { | 180 if (last_step == APPLY_UPDATES) { |
| 183 // We're in configuration mode, but we still need to run the | 181 // We're in configuration mode, but we still need to run the |
| 184 // SYNCER_END step. | 182 // SYNCER_END step. |
| 185 last_step = SYNCER_END; | 183 last_step = SYNCER_END; |
| 186 next_step = SYNCER_END; | 184 next_step = SYNCER_END; |
| 187 } else { | 185 } else { |
| 188 next_step = BUILD_COMMIT_REQUEST; | 186 next_step = COMMIT; |
| 189 } | 187 } |
| 190 break; | 188 break; |
| 191 } | 189 } |
| 192 // These two steps are combined since they are executed within the same | 190 |
| 193 // write transaction. | 191 case COMMIT: { |
|
rlarocque
2012/04/13 02:02:22
I intend to move this block of code into a functio
| |
| 194 case BUILD_COMMIT_REQUEST: { | 192 StatusController* status_controller = |
| 193 session->mutable_status_controller(); | |
| 195 syncable::Directory* dir = session->context()->directory(); | 194 syncable::Directory* dir = session->context()->directory(); |
| 196 WriteTransaction trans(FROM_HERE, SYNCER, dir); | 195 size_t batch_size = session->context()->max_commit_batch_size(); |
|
rlarocque
2012/04/13 02:02:22
Nick warned me about this. He suggested that the
| |
| 197 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); | |
| 198 | 196 |
| 199 DVLOG(1) << "Getting the Commit IDs"; | 197 for ( ; ; ) { |
| 200 GetCommitIdsCommand get_commit_ids_command( | 198 sessions::OrderedCommitSet commit_set(session->routing_info()); |
| 201 session->context()->max_commit_batch_size()); | 199 ClientToServerMessage commit_message; |
| 202 get_commit_ids_command.Execute(session); | 200 ClientToServerResponse commit_response; |
| 203 | 201 |
| 204 if (!session->status_controller().commit_ids().empty()) { | 202 { |
| 205 DVLOG(1) << "Building a commit message"; | 203 WriteTransaction trans(FROM_HERE, SYNCER, dir); |
| 206 BuildCommitCommand build_commit_command; | 204 sessions::ScopedSetSessionWriteTransaction set_trans(session, |
| 207 build_commit_command.Execute(session); | 205 &trans); |
| 208 | 206 |
| 209 next_step = POST_COMMIT_MESSAGE; | 207 DVLOG(1) << "Getting the Commit IDs"; |
| 210 } else { | 208 GetCommitIdsCommand get_commit_ids_command(batch_size, &commit_set); |
| 211 next_step = RESOLVE_CONFLICTS; | 209 get_commit_ids_command.Execute(session); |
| 210 if (commit_set.Empty()) | |
| 211 break; | |
| 212 | |
| 213 BuildCommitCommand build_commit_command(commit_set, | |
| 214 &commit_message); | |
| 215 build_commit_command.Execute(session); | |
| 216 } // Time for some network IO. Release the lock. | |
| 217 | |
| 218 | |
| 219 DVLOG(1) << "Sending a commit message"; | |
| 220 PostCommitMessageCommand post_commit_command(commit_message, | |
| 221 &commit_response); | |
| 222 status_controller->set_last_post_commit_result( | |
| 223 post_commit_command.Execute(session)); | |
| 224 | |
| 225 ProcessCommitResponseCommand process_response_command( | |
| 226 commit_set, commit_message, commit_response); | |
| 227 status_controller->set_last_process_commit_response_result( | |
| 228 process_response_command.Execute(session)); | |
| 229 | |
| 230 if (status_controller->last_post_commit_result() != SYNCER_OK | |
| 231 || (status_controller->last_process_commit_response_result() | |
| 232 != SYNCER_OK)) { | |
| 233 break; // break out of for loop. | |
| 234 } | |
| 212 } | 235 } |
| 213 | 236 |
| 214 break; | |
| 215 } | |
| 216 case POST_COMMIT_MESSAGE: { | |
| 217 PostCommitMessageCommand post_commit_command; | |
| 218 session->mutable_status_controller()->set_last_post_commit_result( | |
| 219 post_commit_command.Execute(session)); | |
| 220 next_step = PROCESS_COMMIT_RESPONSE; | |
| 221 break; | |
| 222 } | |
| 223 case PROCESS_COMMIT_RESPONSE: { | |
| 224 ProcessCommitResponseCommand process_response_command; | |
| 225 session->mutable_status_controller()-> | |
| 226 set_last_process_commit_response_result( | |
| 227 process_response_command.Execute(session)); | |
| 228 next_step = RESOLVE_CONFLICTS; | 237 next_step = RESOLVE_CONFLICTS; |
| 229 break; | 238 break; |
| 230 } | 239 } |
| 231 case RESOLVE_CONFLICTS: { | 240 case RESOLVE_CONFLICTS: { |
| 232 StatusController* status = session->mutable_status_controller(); | 241 StatusController* status = session->mutable_status_controller(); |
| 233 status->reset_conflicts_resolved(); | 242 status->reset_conflicts_resolved(); |
| 234 ResolveConflictsCommand resolve_conflicts_command; | 243 ResolveConflictsCommand resolve_conflicts_command; |
| 235 resolve_conflicts_command.Execute(session); | 244 resolve_conflicts_command.Execute(session); |
| 236 | 245 |
| 237 // Has ConflictingUpdates includes both resolvable and unresolvable | 246 // Has ConflictingUpdates includes both resolvable and unresolvable |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 entry->Put(SERVER_CTIME, Time()); | 345 entry->Put(SERVER_CTIME, Time()); |
| 337 entry->Put(SERVER_VERSION, 0); | 346 entry->Put(SERVER_VERSION, 0); |
| 338 entry->Put(SERVER_IS_DIR, false); | 347 entry->Put(SERVER_IS_DIR, false); |
| 339 entry->Put(SERVER_IS_DEL, false); | 348 entry->Put(SERVER_IS_DEL, false); |
| 340 entry->Put(IS_UNAPPLIED_UPDATE, false); | 349 entry->Put(IS_UNAPPLIED_UPDATE, false); |
| 341 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 350 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
| 342 entry->Put(SERVER_POSITION_IN_PARENT, 0); | 351 entry->Put(SERVER_POSITION_IN_PARENT, 0); |
| 343 } | 352 } |
| 344 | 353 |
| 345 } // namespace browser_sync | 354 } // namespace browser_sync |
| OLD | NEW |