| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 next_step = SYNCER_END; | 172 next_step = SYNCER_END; |
| 173 break; | 173 break; |
| 174 } | 174 } |
| 175 case SYNCER_END: { | 175 case SYNCER_END: { |
| 176 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_ENDED); | 176 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_ENDED); |
| 177 next_step = SYNCER_END; | 177 next_step = SYNCER_END; |
| 178 break; | 178 break; |
| 179 } | 179 } |
| 180 default: | 180 default: |
| 181 LOG(ERROR) << "Unknown command: " << current_step; | 181 LOG(ERROR) << "Unknown command: " << current_step; |
| 182 } | 182 } // switch |
| 183 DVLOG(2) << "last step: " << SyncerStepToString(last_step) << ", " | 183 DVLOG(2) << "last step: " << SyncerStepToString(last_step) << ", " |
| 184 << "current step: " << SyncerStepToString(current_step) << ", " | 184 << "current step: " << SyncerStepToString(current_step) << ", " |
| 185 << "next step: " << SyncerStepToString(next_step) << ", " | 185 << "next step: " << SyncerStepToString(next_step) << ", " |
| 186 << "snapshot: " << session->TakeSnapshot().ToString(); | 186 << "snapshot: " << session->TakeSnapshot().ToString(); |
| 187 if (last_step == current_step) { | 187 if (last_step == current_step) |
| 188 session->SetFinished(); | 188 return true; |
| 189 break; | |
| 190 } | |
| 191 current_step = next_step; | 189 current_step = next_step; |
| 192 } | 190 } // while |
| 191 return false; |
| 193 } | 192 } |
| 194 | 193 |
| 195 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) { | 194 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) { |
| 196 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME)); | 195 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME)); |
| 197 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID)); | 196 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID)); |
| 198 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME)); | 197 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME)); |
| 199 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME)); | 198 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME)); |
| 200 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION)); | 199 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION)); |
| 201 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR)); | 200 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR)); |
| 202 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL)); | 201 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL)); |
| 203 dest->Put(IS_UNAPPLIED_UPDATE, src->Get(IS_UNAPPLIED_UPDATE)); | 202 dest->Put(IS_UNAPPLIED_UPDATE, src->Get(IS_UNAPPLIED_UPDATE)); |
| 204 dest->Put(SERVER_SPECIFICS, src->Get(SERVER_SPECIFICS)); | 203 dest->Put(SERVER_SPECIFICS, src->Get(SERVER_SPECIFICS)); |
| 205 dest->Put(SERVER_ORDINAL_IN_PARENT, src->Get(SERVER_ORDINAL_IN_PARENT)); | 204 dest->Put(SERVER_ORDINAL_IN_PARENT, src->Get(SERVER_ORDINAL_IN_PARENT)); |
| 206 } | 205 } |
| 207 | 206 |
| 208 void ClearServerData(syncable::MutableEntry* entry) { | 207 void ClearServerData(syncable::MutableEntry* entry) { |
| 209 entry->Put(SERVER_NON_UNIQUE_NAME, ""); | 208 entry->Put(SERVER_NON_UNIQUE_NAME, ""); |
| 210 entry->Put(SERVER_PARENT_ID, syncable::GetNullId()); | 209 entry->Put(SERVER_PARENT_ID, syncable::GetNullId()); |
| 211 entry->Put(SERVER_MTIME, Time()); | 210 entry->Put(SERVER_MTIME, Time()); |
| 212 entry->Put(SERVER_CTIME, Time()); | 211 entry->Put(SERVER_CTIME, Time()); |
| 213 entry->Put(SERVER_VERSION, 0); | 212 entry->Put(SERVER_VERSION, 0); |
| 214 entry->Put(SERVER_IS_DIR, false); | 213 entry->Put(SERVER_IS_DIR, false); |
| 215 entry->Put(SERVER_IS_DEL, false); | 214 entry->Put(SERVER_IS_DEL, false); |
| 216 entry->Put(IS_UNAPPLIED_UPDATE, false); | 215 entry->Put(IS_UNAPPLIED_UPDATE, false); |
| 217 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 216 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
| 218 entry->Put(SERVER_ORDINAL_IN_PARENT, Int64ToNodeOrdinal(0)); | 217 entry->Put(SERVER_ORDINAL_IN_PARENT, Int64ToNodeOrdinal(0)); |
| 219 } | 218 } |
| 220 | 219 |
| 221 } // namespace syncer | 220 } // namespace syncer |
| OLD | NEW |