| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 bool Syncer::ExitRequested() { | 76 bool Syncer::ExitRequested() { |
| 77 base::AutoLock lock(early_exit_requested_lock_); | 77 base::AutoLock lock(early_exit_requested_lock_); |
| 78 return early_exit_requested_; | 78 return early_exit_requested_; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void Syncer::RequestEarlyExit() { | 81 void Syncer::RequestEarlyExit() { |
| 82 base::AutoLock lock(early_exit_requested_lock_); | 82 base::AutoLock lock(early_exit_requested_lock_); |
| 83 early_exit_requested_ = true; | 83 early_exit_requested_ = true; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void Syncer::SyncShare(sessions::SyncSession* session, | 86 bool Syncer::SyncShare(sessions::SyncSession* session, |
| 87 SyncerStep first_step, | 87 SyncerStep first_step, |
| 88 SyncerStep last_step) { | 88 SyncerStep last_step) { |
| 89 ScopedSessionContextConflictResolver scoped(session->context(), | 89 ScopedSessionContextConflictResolver scoped(session->context(), |
| 90 &resolver_); | 90 &resolver_); |
| 91 session->mutable_status_controller()->UpdateStartTime(); | 91 session->mutable_status_controller()->UpdateStartTime(); |
| 92 SyncerStep current_step = first_step; | 92 SyncerStep current_step = first_step; |
| 93 | 93 |
| 94 SyncerStep next_step = current_step; | 94 SyncerStep next_step = current_step; |
| 95 while (!ExitRequested()) { | 95 while (!ExitRequested()) { |
| 96 TRACE_EVENT1("sync", "SyncerStateMachine", | 96 TRACE_EVENT1("sync", "SyncerStateMachine", |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 next_step = SYNCER_END; | 211 next_step = SYNCER_END; |
| 212 break; | 212 break; |
| 213 } | 213 } |
| 214 case SYNCER_END: { | 214 case SYNCER_END: { |
| 215 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_ENDED); | 215 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_ENDED); |
| 216 next_step = SYNCER_END; | 216 next_step = SYNCER_END; |
| 217 break; | 217 break; |
| 218 } | 218 } |
| 219 default: | 219 default: |
| 220 LOG(ERROR) << "Unknown command: " << current_step; | 220 LOG(ERROR) << "Unknown command: " << current_step; |
| 221 } | 221 } // switch |
| 222 DVLOG(2) << "last step: " << SyncerStepToString(last_step) << ", " | 222 DVLOG(2) << "last step: " << SyncerStepToString(last_step) << ", " |
| 223 << "current step: " << SyncerStepToString(current_step) << ", " | 223 << "current step: " << SyncerStepToString(current_step) << ", " |
| 224 << "next step: " << SyncerStepToString(next_step) << ", " | 224 << "next step: " << SyncerStepToString(next_step) << ", " |
| 225 << "snapshot: " << session->TakeSnapshot().ToString(); | 225 << "snapshot: " << session->TakeSnapshot().ToString(); |
| 226 if (last_step == current_step) { | 226 if (last_step == current_step) |
| 227 session->SetFinished(); | 227 return true; |
| 228 break; | |
| 229 } | |
| 230 current_step = next_step; | 228 current_step = next_step; |
| 231 } | 229 } // while |
| 230 return false; |
| 232 } | 231 } |
| 233 | 232 |
| 234 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) { | 233 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) { |
| 235 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME)); | 234 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME)); |
| 236 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID)); | 235 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID)); |
| 237 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME)); | 236 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME)); |
| 238 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME)); | 237 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME)); |
| 239 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION)); | 238 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION)); |
| 240 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR)); | 239 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR)); |
| 241 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL)); | 240 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL)); |
| 242 dest->Put(IS_UNAPPLIED_UPDATE, src->Get(IS_UNAPPLIED_UPDATE)); | 241 dest->Put(IS_UNAPPLIED_UPDATE, src->Get(IS_UNAPPLIED_UPDATE)); |
| 243 dest->Put(SERVER_SPECIFICS, src->Get(SERVER_SPECIFICS)); | 242 dest->Put(SERVER_SPECIFICS, src->Get(SERVER_SPECIFICS)); |
| 244 dest->Put(SERVER_POSITION_IN_PARENT, src->Get(SERVER_POSITION_IN_PARENT)); | 243 dest->Put(SERVER_POSITION_IN_PARENT, src->Get(SERVER_POSITION_IN_PARENT)); |
| 245 } | 244 } |
| 246 | 245 |
| 247 void ClearServerData(syncable::MutableEntry* entry) { | 246 void ClearServerData(syncable::MutableEntry* entry) { |
| 248 entry->Put(SERVER_NON_UNIQUE_NAME, ""); | 247 entry->Put(SERVER_NON_UNIQUE_NAME, ""); |
| 249 entry->Put(SERVER_PARENT_ID, syncable::GetNullId()); | 248 entry->Put(SERVER_PARENT_ID, syncable::GetNullId()); |
| 250 entry->Put(SERVER_MTIME, Time()); | 249 entry->Put(SERVER_MTIME, Time()); |
| 251 entry->Put(SERVER_CTIME, Time()); | 250 entry->Put(SERVER_CTIME, Time()); |
| 252 entry->Put(SERVER_VERSION, 0); | 251 entry->Put(SERVER_VERSION, 0); |
| 253 entry->Put(SERVER_IS_DIR, false); | 252 entry->Put(SERVER_IS_DIR, false); |
| 254 entry->Put(SERVER_IS_DEL, false); | 253 entry->Put(SERVER_IS_DEL, false); |
| 255 entry->Put(IS_UNAPPLIED_UPDATE, false); | 254 entry->Put(IS_UNAPPLIED_UPDATE, false); |
| 256 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 255 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
| 257 entry->Put(SERVER_POSITION_IN_PARENT, 0); | 256 entry->Put(SERVER_POSITION_IN_PARENT, 0); |
| 258 } | 257 } |
| 259 | 258 |
| 260 } // namespace syncer | 259 } // namespace syncer |
| OLD | NEW |