mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 836493 - part 2: eliminate now-unnecessary ServiceMainThreadInitializer; r=mak
This commit is contained in:
parent
e729f89a13
commit
54d163bc01
@ -227,86 +227,6 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(
|
||||
nsIMemoryMultiReporter
|
||||
)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Helpers
|
||||
|
||||
class ServiceMainThreadInitializer : public nsRunnable
|
||||
{
|
||||
public:
|
||||
ServiceMainThreadInitializer(Service *aService,
|
||||
nsIObserver *aObserver,
|
||||
nsIXPConnect **aXPConnectPtr,
|
||||
int32_t *aSynchronousPrefValPtr,
|
||||
int32_t *aPageSizePtr)
|
||||
: mService(aService)
|
||||
, mObserver(aObserver)
|
||||
, mXPConnectPtr(aXPConnectPtr)
|
||||
, mSynchronousPrefValPtr(aSynchronousPrefValPtr)
|
||||
, mPageSizePtr(aPageSizePtr)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
NS_PRECONDITION(NS_IsMainThread(), "Must be running on the main thread!");
|
||||
NS_PRECONDITION(*mPageSizePtr == PREF_TS_PAGESIZE_DEFAULT,
|
||||
"Must be set to the default value here!");
|
||||
|
||||
// NOTE: All code that can only run on the main thread and needs to be run
|
||||
// during initialization should be placed here. During the off-
|
||||
// chance that storage is initialized on a background thread, this
|
||||
// will ensure everything that isn't threadsafe is initialized in
|
||||
// the right place.
|
||||
|
||||
// Register for xpcom-shutdown so we can cleanup after ourselves. The
|
||||
// observer service can only be used on the main thread.
|
||||
nsCOMPtr<nsIObserverService> os =
|
||||
mozilla::services::GetObserverService();
|
||||
NS_ENSURE_TRUE(os, NS_ERROR_FAILURE);
|
||||
nsresult rv = os->AddObserver(mObserver, "xpcom-shutdown", false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = os->AddObserver(mObserver, "xpcom-shutdown-threads", false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// We cache XPConnect for our language helpers. XPConnect can only be
|
||||
// used on the main thread.
|
||||
(void)CallGetService(nsIXPConnect::GetCID(), mXPConnectPtr);
|
||||
|
||||
// We need to obtain the toolkit.storage.synchronous preferences on the main
|
||||
// thread because the preference service can only be accessed there. This
|
||||
// is cached in the service for all future Open[Unshared]Database calls.
|
||||
int32_t synchronous =
|
||||
Preferences::GetInt(PREF_TS_SYNCHRONOUS, PREF_TS_SYNCHRONOUS_DEFAULT);
|
||||
::PR_ATOMIC_SET(mSynchronousPrefValPtr, synchronous);
|
||||
|
||||
// We need to obtain the toolkit.storage.pageSize preferences on the main
|
||||
// thread because the preference service can only be accessed there. This
|
||||
// is cached in the service for all future Open[Unshared]Database calls.
|
||||
int32_t pageSize =
|
||||
Preferences::GetInt(PREF_TS_PAGESIZE, PREF_TS_PAGESIZE_DEFAULT);
|
||||
if (Service::pageSizeIsValid(pageSize) &&
|
||||
PREF_TS_PAGESIZE_DEFAULT != pageSize) {
|
||||
::PR_ATOMIC_SET(mPageSizePtr, pageSize);
|
||||
}
|
||||
|
||||
// Create and register our SQLite memory reporters. Registration can only
|
||||
// happen on the main thread (otherwise you'll get cryptic crashes).
|
||||
mService->mStorageSQLiteReporter = new NS_MEMORY_REPORTER_NAME(StorageSQLite);
|
||||
mService->mStorageSQLiteMultiReporter = new StorageSQLiteMultiReporter(mService);
|
||||
(void)::NS_RegisterMemoryReporter(mService->mStorageSQLiteReporter);
|
||||
(void)::NS_RegisterMemoryMultiReporter(mService->mStorageSQLiteMultiReporter);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
Service *mService;
|
||||
nsIObserver *mObserver;
|
||||
nsIXPConnect **mXPConnectPtr;
|
||||
int32_t *mSynchronousPrefValPtr;
|
||||
int32_t *mPageSizePtr;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Service
|
||||
|
||||
@ -578,6 +498,8 @@ const sqlite3_mem_methods memMethods = {
|
||||
nsresult
|
||||
Service::initialize()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Must be initialized on the main thread");
|
||||
|
||||
int rc;
|
||||
|
||||
#ifdef MOZ_STORAGE_MEMORY
|
||||
@ -602,20 +524,37 @@ Service::initialize()
|
||||
NS_WARNING("Failed to register telemetry VFS");
|
||||
}
|
||||
|
||||
// Set the default value for the toolkit.storage.synchronous pref. It will be
|
||||
// updated with the user preference on the main thread.
|
||||
sSynchronousPref = PREF_TS_SYNCHRONOUS_DEFAULT;
|
||||
// Register for xpcom-shutdown so we can cleanup after ourselves. The
|
||||
// observer service can only be used on the main thread.
|
||||
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||
NS_ENSURE_TRUE(os, NS_ERROR_FAILURE);
|
||||
nsresult rv = os->AddObserver(this, "xpcom-shutdown", false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = os->AddObserver(this, "xpcom-shutdown-threads", false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Run the things that need to run on the main thread there.
|
||||
nsCOMPtr<nsIRunnable> event =
|
||||
new ServiceMainThreadInitializer(this, this, &sXPConnect,
|
||||
&sSynchronousPref, &sDefaultPageSize);
|
||||
if (event && ::NS_IsMainThread()) {
|
||||
(void)event->Run();
|
||||
}
|
||||
else {
|
||||
(void)::NS_DispatchToMainThread(event);
|
||||
}
|
||||
// We cache XPConnect for our language helpers. XPConnect can only be
|
||||
// used on the main thread.
|
||||
(void)CallGetService(nsIXPConnect::GetCID(), &sXPConnect);
|
||||
|
||||
// We need to obtain the toolkit.storage.synchronous preferences on the main
|
||||
// thread because the preference service can only be accessed there. This
|
||||
// is cached in the service for all future Open[Unshared]Database calls.
|
||||
sSynchronousPref =
|
||||
Preferences::GetInt(PREF_TS_SYNCHRONOUS, PREF_TS_SYNCHRONOUS_DEFAULT);
|
||||
|
||||
// We need to obtain the toolkit.storage.pageSize preferences on the main
|
||||
// thread because the preference service can only be accessed there. This
|
||||
// is cached in the service for all future Open[Unshared]Database calls.
|
||||
sDefaultPageSize =
|
||||
Preferences::GetInt(PREF_TS_PAGESIZE, PREF_TS_PAGESIZE_DEFAULT);
|
||||
|
||||
// Create and register our SQLite memory reporters. Registration can only
|
||||
// happen on the main thread (otherwise you'll get cryptic crashes).
|
||||
mStorageSQLiteReporter = new NS_MEMORY_REPORTER_NAME(StorageSQLite);
|
||||
mStorageSQLiteMultiReporter = new StorageSQLiteMultiReporter(this);
|
||||
(void)::NS_RegisterMemoryReporter(mStorageSQLiteReporter);
|
||||
(void)::NS_RegisterMemoryMultiReporter(mStorageSQLiteMultiReporter);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -182,8 +182,6 @@ private:
|
||||
|
||||
static int32_t sSynchronousPref;
|
||||
static int32_t sDefaultPageSize;
|
||||
|
||||
friend class ServiceMainThreadInitializer;
|
||||
};
|
||||
|
||||
} // namespace storage
|
||||
|
Loading…
Reference in New Issue
Block a user