Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: sync/engine/syncer.cc

Issue 10917234: sync: make scheduling logic and job ownership more obvious. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test + comment + rebase Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 bool Syncer::ExitRequested() { 77 bool Syncer::ExitRequested() {
78 base::AutoLock lock(early_exit_requested_lock_); 78 base::AutoLock lock(early_exit_requested_lock_);
79 return early_exit_requested_; 79 return early_exit_requested_;
80 } 80 }
81 81
82 void Syncer::RequestEarlyExit() { 82 void Syncer::RequestEarlyExit() {
83 base::AutoLock lock(early_exit_requested_lock_); 83 base::AutoLock lock(early_exit_requested_lock_);
84 early_exit_requested_ = true; 84 early_exit_requested_ = true;
85 } 85 }
86 86
87 void Syncer::SyncShare(sessions::SyncSession* session, 87 bool Syncer::SyncShare(sessions::SyncSession* session,
88 SyncerStep first_step, 88 SyncerStep first_step,
89 SyncerStep last_step) { 89 SyncerStep last_step) {
90 ScopedSessionContextConflictResolver scoped(session->context(), 90 ScopedSessionContextConflictResolver scoped(session->context(),
91 &resolver_); 91 &resolver_);
92 session->mutable_status_controller()->UpdateStartTime(); 92 session->mutable_status_controller()->UpdateStartTime();
93 SyncerStep current_step = first_step; 93 SyncerStep current_step = first_step;
94 94
95 SyncerStep next_step = current_step; 95 SyncerStep next_step = current_step;
96 while (!ExitRequested()) { 96 while (!ExitRequested()) {
97 TRACE_EVENT1("sync", "SyncerStateMachine", 97 TRACE_EVENT1("sync", "SyncerStateMachine",
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 next_step = SYNCER_END; 212 next_step = SYNCER_END;
213 break; 213 break;
214 } 214 }
215 case SYNCER_END: { 215 case SYNCER_END: {
216 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_ENDED); 216 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_ENDED);
217 next_step = SYNCER_END; 217 next_step = SYNCER_END;
218 break; 218 break;
219 } 219 }
220 default: 220 default:
221 LOG(ERROR) << "Unknown command: " << current_step; 221 LOG(ERROR) << "Unknown command: " << current_step;
222 } 222 } // switch
223 DVLOG(2) << "last step: " << SyncerStepToString(last_step) << ", " 223 DVLOG(2) << "last step: " << SyncerStepToString(last_step) << ", "
224 << "current step: " << SyncerStepToString(current_step) << ", " 224 << "current step: " << SyncerStepToString(current_step) << ", "
225 << "next step: " << SyncerStepToString(next_step) << ", " 225 << "next step: " << SyncerStepToString(next_step) << ", "
226 << "snapshot: " << session->TakeSnapshot().ToString(); 226 << "snapshot: " << session->TakeSnapshot().ToString();
227 if (last_step == current_step) { 227 if (last_step == current_step)
228 session->SetFinished(); 228 return true;
229 break;
230 }
231 current_step = next_step; 229 current_step = next_step;
232 } 230 } // while
231 return false;
233 } 232 }
234 233
235 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) { 234 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) {
236 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME)); 235 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME));
237 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID)); 236 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID));
238 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME)); 237 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME));
239 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME)); 238 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME));
240 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION)); 239 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION));
241 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR)); 240 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR));
242 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL)); 241 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL));
243 dest->Put(IS_UNAPPLIED_UPDATE, src->Get(IS_UNAPPLIED_UPDATE)); 242 dest->Put(IS_UNAPPLIED_UPDATE, src->Get(IS_UNAPPLIED_UPDATE));
244 dest->Put(SERVER_SPECIFICS, src->Get(SERVER_SPECIFICS)); 243 dest->Put(SERVER_SPECIFICS, src->Get(SERVER_SPECIFICS));
245 dest->Put(SERVER_POSITION_IN_PARENT, src->Get(SERVER_POSITION_IN_PARENT)); 244 dest->Put(SERVER_POSITION_IN_PARENT, src->Get(SERVER_POSITION_IN_PARENT));
246 } 245 }
247 246
248 void ClearServerData(syncable::MutableEntry* entry) { 247 void ClearServerData(syncable::MutableEntry* entry) {
249 entry->Put(SERVER_NON_UNIQUE_NAME, ""); 248 entry->Put(SERVER_NON_UNIQUE_NAME, "");
250 entry->Put(SERVER_PARENT_ID, syncable::GetNullId()); 249 entry->Put(SERVER_PARENT_ID, syncable::GetNullId());
251 entry->Put(SERVER_MTIME, Time()); 250 entry->Put(SERVER_MTIME, Time());
252 entry->Put(SERVER_CTIME, Time()); 251 entry->Put(SERVER_CTIME, Time());
253 entry->Put(SERVER_VERSION, 0); 252 entry->Put(SERVER_VERSION, 0);
254 entry->Put(SERVER_IS_DIR, false); 253 entry->Put(SERVER_IS_DIR, false);
255 entry->Put(SERVER_IS_DEL, false); 254 entry->Put(SERVER_IS_DEL, false);
256 entry->Put(IS_UNAPPLIED_UPDATE, false); 255 entry->Put(IS_UNAPPLIED_UPDATE, false);
257 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); 256 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance());
258 entry->Put(SERVER_POSITION_IN_PARENT, 0); 257 entry->Put(SERVER_POSITION_IN_PARENT, 0);
259 } 258 }
260 259
261 } // namespace syncer 260 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698