From f029b114a4fa8b7350a4b30e4b3e1329c7c9815f Mon Sep 17 00:00:00 2001 From: "nick@chromium.org" Date: Mon, 22 Mar 2010 21:16:52 +0000 Subject: Eliminate a race between the syncerthread delivering PAUSED notifications and the syncmanager subscribing to them. Review URL: http://codereview.chromium.org/1096006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42257 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/sync/engine/syncapi.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/engine/syncapi.cc index e807d3d..64b7e41 100644 --- a/chrome/browser/sync/engine/syncapi.cc +++ b/chrome/browser/sync/engine/syncapi.cc @@ -1379,6 +1379,11 @@ bool SyncManager::SyncInternal::Init( syncer_thread()->WatchTalkMediator(talk_mediator()); allstatus()->WatchSyncerThread(syncer_thread()); + // Subscribe to the syncer thread's channel. + syncer_event_.reset( + NewEventListenerHookup(syncer_thread()->relay_channel(), this, + &SyncInternal::HandleSyncerEvent)); + syncer_thread()->Start(); // Start the syncer thread. This won't actually // result in any syncing until at least the // DirectoryManager broadcasts the OPENED event, @@ -1718,10 +1723,8 @@ SyncManager::Status SyncManager::SyncInternal::ComputeAggregatedStatus() { void SyncManager::SyncInternal::HandleSyncerEvent(const SyncerEvent& event) { if (!initialized()) { - // We get here if A) We have successfully authenticated at least once - // (because we attach HandleSyncerEvent only once we receive notification - // of successful authentication [locally or otherwise]), but B) the initial - // sync had not completed at that time. + // This could be the first time that the syncer has completed a full + // download; if so, we should signal that initialization is complete. if (event.snapshot->is_share_usable) MarkAndNotifyInitializationComplete(); return; @@ -1825,13 +1828,10 @@ void SyncManager::SyncInternal::HandleAuthWatcherEvent( if (lookup->initial_sync_ended()) MarkAndNotifyInitializationComplete(); - } - { - // Start watching the syncer channel directly here. - DCHECK(syncer_thread() != NULL); - syncer_event_.reset( - NewEventListenerHookup(syncer_thread()->relay_channel(), this, - &SyncInternal::HandleSyncerEvent)); + + // If we are transitioning from having bad to good credentials, that + // could mean that the syncer can now make forward progress. Wake it. + syncer_thread_->NudgeSyncer(0, SyncerThread::kLocal); } return; // Authentication failures translate to GoogleServiceAuthError events. -- cgit v1.1