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

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: address review Created 8 years, 1 month 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 bool Syncer::ExitRequested() { 79 bool Syncer::ExitRequested() {
80 base::AutoLock lock(early_exit_requested_lock_); 80 base::AutoLock lock(early_exit_requested_lock_);
81 return early_exit_requested_; 81 return early_exit_requested_;
82 } 82 }
83 83
84 void Syncer::RequestEarlyExit() { 84 void Syncer::RequestEarlyExit() {
85 base::AutoLock lock(early_exit_requested_lock_); 85 base::AutoLock lock(early_exit_requested_lock_);
86 early_exit_requested_ = true; 86 early_exit_requested_ = true;
87 } 87 }
88 88
89 void Syncer::SyncShare(sessions::SyncSession* session, 89 bool Syncer::SyncShare(sessions::SyncSession* session,
90 SyncerStep first_step, 90 SyncerStep first_step,
91 SyncerStep last_step) { 91 SyncerStep last_step) {
92 ScopedSessionContextConflictResolver scoped(session->context(), 92 ScopedSessionContextConflictResolver scoped(session->context(),
93 &resolver_); 93 &resolver_);
94 session->mutable_status_controller()->UpdateStartTime(); 94 session->mutable_status_controller()->UpdateStartTime();
95 SyncerStep current_step = first_step; 95 SyncerStep current_step = first_step;
96 96
97 SyncerStep next_step = current_step; 97 SyncerStep next_step = current_step;
98 while (!ExitRequested()) { 98 while (!ExitRequested()) {
99 TRACE_EVENT1("sync", "SyncerStateMachine", 99 TRACE_EVENT1("sync", "SyncerStateMachine",
(...skipping 112 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_ORDINAL_IN_PARENT, src->Get(SERVER_ORDINAL_IN_PARENT)); 244 dest->Put(SERVER_ORDINAL_IN_PARENT, src->Get(SERVER_ORDINAL_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_ORDINAL_IN_PARENT, Int64ToNodeOrdinal(0)); 257 entry->Put(SERVER_ORDINAL_IN_PARENT, Int64ToNodeOrdinal(0));
259 } 258 }
260 259
261 } // namespace syncer 260 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698