Bug 721603 - We should spin the loop after calling asyncClose in Database.cpp. r=mak.

--HG--
extra : rebase_source : 3defc8d4da90de3f1c4738ec7e56faff6afec521
This commit is contained in:
Rafael Ávila de Espíndola 2012-02-16 07:03:53 -05:00
Родитель 8f4c1c22db
Коммит f738baa87b
3 изменённых файлов: 47 добавлений и 13 удалений

Просмотреть файл

@ -251,6 +251,49 @@ SetJournalMode(nsCOMPtr<mozIStorageConnection>& aDBConn,
return JOURNAL_DELETE; return JOURNAL_DELETE;
} }
class BlockingConnectionCloseCallback : public mozIStorageCompletionCallback {
bool mDone;
public:
NS_DECL_ISUPPORTS
NS_DECL_MOZISTORAGECOMPLETIONCALLBACK
BlockingConnectionCloseCallback();
void Spin();
};
NS_IMETHODIMP
BlockingConnectionCloseCallback::Complete()
{
mDone = true;
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
MOZ_ASSERT(os);
if (!os)
return NS_OK;
DebugOnly<nsresult> rv = os->NotifyObservers(nsnull,
TOPIC_PLACES_CONNECTION_CLOSED,
nsnull);
MOZ_ASSERT(NS_SUCCEEDED(rv));
return NS_OK;
}
BlockingConnectionCloseCallback::BlockingConnectionCloseCallback()
: mDone(false)
{
MOZ_ASSERT(NS_IsMainThread());
}
void BlockingConnectionCloseCallback::Spin() {
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
while (!mDone) {
NS_ProcessNextEvent(thread);
}
}
NS_IMPL_THREADSAFE_ISUPPORTS1(
BlockingConnectionCloseCallback
, mozIStorageCompletionCallback
)
nsresult nsresult
CreateRoot(nsCOMPtr<mozIStorageConnection>& aDBConn, CreateRoot(nsCOMPtr<mozIStorageConnection>& aDBConn,
const nsCString& aRootName, const nsCString& aRootName,
@ -1672,9 +1715,10 @@ Database::Shutdown()
); );
DispatchToAsyncThread(event); DispatchToAsyncThread(event);
nsRefPtr<PlacesEvent> closeListener = nsRefPtr<BlockingConnectionCloseCallback> closeListener =
new PlacesEvent(TOPIC_PLACES_CONNECTION_CLOSED); new BlockingConnectionCloseCallback();
(void)mMainConn->AsyncClose(closeListener); (void)mMainConn->AsyncClose(closeListener);
closeListener->Spin();
// Don't set this earlier, otherwise some internal helper used on shutdown // Don't set this earlier, otherwise some internal helper used on shutdown
// may bail out. // may bail out.

Просмотреть файл

@ -400,13 +400,6 @@ PlacesEvent::Run()
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
PlacesEvent::Complete()
{
Notify();
return NS_OK;
}
void void
PlacesEvent::Notify() PlacesEvent::Notify()
{ {
@ -417,9 +410,8 @@ PlacesEvent::Notify()
} }
} }
NS_IMPL_THREADSAFE_ISUPPORTS2( NS_IMPL_THREADSAFE_ISUPPORTS1(
PlacesEvent PlacesEvent
, mozIStorageCompletionCallback
, nsIRunnable , nsIRunnable
) )

Просмотреть файл

@ -247,12 +247,10 @@ bool GetHiddenState(bool aIsRedirect,
* Notifies a specified topic via the observer service. * Notifies a specified topic via the observer service.
*/ */
class PlacesEvent : public nsRunnable class PlacesEvent : public nsRunnable
, public mozIStorageCompletionCallback
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIRUNNABLE NS_DECL_NSIRUNNABLE
NS_DECL_MOZISTORAGECOMPLETIONCALLBACK
PlacesEvent(const char* aTopic); PlacesEvent(const char* aTopic);
protected: protected: