From 350796e3381c55a49957bde947784d630611ca8d Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Tue, 1 Mar 2016 10:45:04 +0100 Subject: [PATCH] Bug 1248550 - Part 5: Move AutoProgressHandler from QuotaClient to DatabaseMaintenance; r=khuey --- dom/indexedDB/ActorsParent.cpp | 284 ++++++++++++++++----------------- 1 file changed, 142 insertions(+), 142 deletions(-) diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index b8651222ff9..a836cb57e85 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -8788,8 +8788,6 @@ class QuotaClient final static const int32_t kPercentUnusedThreshold = 20; public: - class AutoProgressHandler; - enum class MaintenanceAction { Nothing = 0, @@ -8946,66 +8944,6 @@ private: ProcessMaintenanceQueue(); }; -class MOZ_STACK_CLASS QuotaClient::AutoProgressHandler final - : public mozIStorageProgressHandler -{ - Maintenance* mMaintenance; - mozIStorageConnection* mConnection; - - NS_DECL_OWNINGTHREAD - - // This class is stack-based so we never actually allow AddRef/Release to do - // anything. But we need to know if any consumer *thinks* that they have a - // reference to this object so we track the reference countin DEBUG builds. - DebugOnly mDEBUGRefCnt; - -public: - explicit AutoProgressHandler(Maintenance* aMaintenance) - : mMaintenance(aMaintenance) - , mConnection(nullptr) - , mDEBUGRefCnt(0) - { - MOZ_ASSERT(!NS_IsMainThread()); - MOZ_ASSERT(!IsOnBackgroundThread()); - NS_ASSERT_OWNINGTHREAD(QuotaClient::AutoProgressHandler); - MOZ_ASSERT(aMaintenance); - } - - ~AutoProgressHandler() - { - NS_ASSERT_OWNINGTHREAD(QuotaClient::AutoProgressHandler); - - if (mConnection) { - Unregister(); - } - - MOZ_ASSERT(!mDEBUGRefCnt); - } - - nsresult - Register(mozIStorageConnection* aConnection); - - // We don't want the mRefCnt member but this class does not "inherit" - // nsISupports. - NS_DECL_ISUPPORTS_INHERITED - -private: - void - Unregister(); - - NS_DECL_MOZISTORAGEPROGRESSHANDLER - - // Not available for the heap! - void* - operator new(size_t) = delete; - void* - operator new[](size_t) = delete; - void - operator delete(void*) = delete; - void - operator delete[](void*) = delete; -}; - class Maintenance final : public nsRunnable , public OpenDirectoryListener @@ -9263,6 +9201,8 @@ struct Maintenance::DirectoryInfo final class DatabaseMaintenance final : public nsRunnable { + class AutoProgressHandler; + nsCOMPtr mOwningThread; RefPtr mMaintenance; const nsCString mGroup; @@ -9338,6 +9278,66 @@ private: NS_DECL_NSIRUNNABLE }; +class MOZ_STACK_CLASS DatabaseMaintenance::AutoProgressHandler final + : public mozIStorageProgressHandler +{ + Maintenance* mMaintenance; + mozIStorageConnection* mConnection; + + NS_DECL_OWNINGTHREAD + + // This class is stack-based so we never actually allow AddRef/Release to do + // anything. But we need to know if any consumer *thinks* that they have a + // reference to this object so we track the reference countin DEBUG builds. + DebugOnly mDEBUGRefCnt; + +public: + explicit AutoProgressHandler(Maintenance* aMaintenance) + : mMaintenance(aMaintenance) + , mConnection(nullptr) + , mDEBUGRefCnt(0) + { + MOZ_ASSERT(!NS_IsMainThread()); + MOZ_ASSERT(!IsOnBackgroundThread()); + NS_ASSERT_OWNINGTHREAD(DatabaseMaintenance::AutoProgressHandler); + MOZ_ASSERT(aMaintenance); + } + + ~AutoProgressHandler() + { + NS_ASSERT_OWNINGTHREAD(DatabaseMaintenance::AutoProgressHandler); + + if (mConnection) { + Unregister(); + } + + MOZ_ASSERT(!mDEBUGRefCnt); + } + + nsresult + Register(mozIStorageConnection* aConnection); + + // We don't want the mRefCnt member but this class does not "inherit" + // nsISupports. + NS_DECL_ISUPPORTS_INHERITED + +private: + void + Unregister(); + + NS_DECL_MOZISTORAGEPROGRESSHANDLER + + // Not available for the heap! + void* + operator new(size_t) = delete; + void* + operator new[](size_t) = delete; + void + operator delete(void*) = delete; + void + operator delete[](void*) = delete; +}; + class IntString : public nsAutoString { public: @@ -17389,7 +17389,7 @@ DatabaseMaintenance::PerformMaintenanceOnDatabase() return; } - QuotaClient::AutoProgressHandler progressHandler(mMaintenance); + AutoProgressHandler progressHandler(mMaintenance); if (NS_WARN_IF(NS_FAILED(progressHandler.Register(connection)))) { return; } @@ -17859,85 +17859,6 @@ QuotaClient::ProcessMaintenanceQueue() mCurrentMaintenance->RunImmediately(); } -nsresult -QuotaClient:: -AutoProgressHandler::Register(mozIStorageConnection* aConnection) -{ - MOZ_ASSERT(!NS_IsMainThread()); - MOZ_ASSERT(!IsOnBackgroundThread()); - MOZ_ASSERT(aConnection); - - // We want to quickly bail out of any operation if the user becomes active, so - // use a small granularity here since database performance isn't critical. - static const int32_t kProgressGranularity = 50; - - nsCOMPtr oldHandler; - nsresult rv = aConnection->SetProgressHandler(kProgressGranularity, - this, - getter_AddRefs(oldHandler)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - MOZ_ASSERT(!oldHandler); - mConnection = aConnection; - - return NS_OK; -} - -void -QuotaClient:: -AutoProgressHandler::Unregister() -{ - MOZ_ASSERT(!NS_IsMainThread()); - MOZ_ASSERT(!IsOnBackgroundThread()); - MOZ_ASSERT(mConnection); - - nsCOMPtr oldHandler; - nsresult rv = mConnection->RemoveProgressHandler(getter_AddRefs(oldHandler)); - Unused << NS_WARN_IF(NS_FAILED(rv)); - - MOZ_ASSERT_IF(NS_SUCCEEDED(rv), oldHandler == this); -} - -NS_IMETHODIMP_(MozExternalRefCountType) -QuotaClient:: -AutoProgressHandler::AddRef() -{ - NS_ASSERT_OWNINGTHREAD(QuotaClient::AutoProgressHandler); - - mDEBUGRefCnt++; - return 2; -} - -NS_IMETHODIMP_(MozExternalRefCountType) -QuotaClient:: -AutoProgressHandler::Release() -{ - NS_ASSERT_OWNINGTHREAD(QuotaClient::AutoProgressHandler); - - mDEBUGRefCnt--; - return 1; -} - -NS_IMPL_QUERY_INTERFACE(QuotaClient::AutoProgressHandler, - mozIStorageProgressHandler) - -NS_IMETHODIMP -QuotaClient:: -AutoProgressHandler::OnProgress(mozIStorageConnection* aConnection, - bool* _retval) -{ - NS_ASSERT_OWNINGTHREAD(QuotaClient::AutoProgressHandler); - MOZ_ASSERT(aConnection); - MOZ_ASSERT(mConnection == aConnection); - MOZ_ASSERT(_retval); - - *_retval = mMaintenance->IsAbortedOnAnyThread(); - - return NS_OK; -} - void Maintenance::RegisterDatabaseMaintenance( DatabaseMaintenance* aDatabaseMaintenance) @@ -18275,6 +18196,85 @@ DatabaseMaintenance::Run() return NS_OK; } +nsresult +DatabaseMaintenance:: +AutoProgressHandler::Register(mozIStorageConnection* aConnection) +{ + MOZ_ASSERT(!NS_IsMainThread()); + MOZ_ASSERT(!IsOnBackgroundThread()); + MOZ_ASSERT(aConnection); + + // We want to quickly bail out of any operation if the user becomes active, so + // use a small granularity here since database performance isn't critical. + static const int32_t kProgressGranularity = 50; + + nsCOMPtr oldHandler; + nsresult rv = aConnection->SetProgressHandler(kProgressGranularity, + this, + getter_AddRefs(oldHandler)); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + MOZ_ASSERT(!oldHandler); + mConnection = aConnection; + + return NS_OK; +} + +void +DatabaseMaintenance:: +AutoProgressHandler::Unregister() +{ + MOZ_ASSERT(!NS_IsMainThread()); + MOZ_ASSERT(!IsOnBackgroundThread()); + MOZ_ASSERT(mConnection); + + nsCOMPtr oldHandler; + nsresult rv = mConnection->RemoveProgressHandler(getter_AddRefs(oldHandler)); + Unused << NS_WARN_IF(NS_FAILED(rv)); + + MOZ_ASSERT_IF(NS_SUCCEEDED(rv), oldHandler == this); +} + +NS_IMETHODIMP_(MozExternalRefCountType) +DatabaseMaintenance:: +AutoProgressHandler::AddRef() +{ + NS_ASSERT_OWNINGTHREAD(DatabaseMaintenance::AutoProgressHandler); + + mDEBUGRefCnt++; + return 2; +} + +NS_IMETHODIMP_(MozExternalRefCountType) +DatabaseMaintenance:: +AutoProgressHandler::Release() +{ + NS_ASSERT_OWNINGTHREAD(DatabaseMaintenance::AutoProgressHandler); + + mDEBUGRefCnt--; + return 1; +} + +NS_IMPL_QUERY_INTERFACE(DatabaseMaintenance::AutoProgressHandler, + mozIStorageProgressHandler) + +NS_IMETHODIMP +DatabaseMaintenance:: +AutoProgressHandler::OnProgress(mozIStorageConnection* aConnection, + bool* _retval) +{ + NS_ASSERT_OWNINGTHREAD(DatabaseMaintenance::AutoProgressHandler); + MOZ_ASSERT(aConnection); + MOZ_ASSERT(mConnection == aConnection); + MOZ_ASSERT(_retval); + + *_retval = mMaintenance->IsAbortedOnAnyThread(); + + return NS_OK; +} + /******************************************************************************* * Local class implementations ******************************************************************************/