Bug 619487: Assert when preferences are used off the main thread. r=dbaron

This commit is contained in:
Kyle Huey 2014-03-05 17:58:01 -08:00
parent 0bbba6bb61
commit ffba529abe
3 changed files with 24 additions and 3 deletions

View File

@ -402,6 +402,10 @@ Preferences::GetInstanceForService()
bool
Preferences::InitStaticMembers()
{
#ifndef MOZ_B2G
MOZ_ASSERT(NS_IsMainThread());
#endif
if (!sShutdown && !sPreferences) {
nsCOMPtr<nsIPrefService> prefService =
do_GetService(NS_PREFSERVICE_CONTRACTID);

View File

@ -182,7 +182,7 @@ class nsPrefBranch : public nsIPrefBranchInternal,
{
friend class mozilla::PreferenceServiceReporter;
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_ISUPPORTS
NS_DECL_NSIPREFBRANCH
NS_DECL_NSIPREFBRANCH2
NS_DECL_NSIOBSERVER
@ -235,7 +235,7 @@ public:
nsPrefLocalizedString();
virtual ~nsPrefLocalizedString();
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_ISUPPORTS
NS_FORWARD_NSISUPPORTSSTRING(mUnicodeString->)
NS_FORWARD_NSISUPPORTSPRIMITIVE(mUnicodeString->)
@ -253,7 +253,7 @@ private:
class nsRelativeFilePref : public nsIRelativeFilePref
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_ISUPPORTS
NS_DECL_NSIRELATIVEFILEPREF
nsRelativeFilePref();

View File

@ -8,6 +8,7 @@
#include "prefapi.h"
#include "prefapi_private_data.h"
#include "prefread.h"
#include "MainThreadUtils.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
@ -575,6 +576,10 @@ pref_DeleteItem(PLDHashTable *table, PLDHashEntryHdr *heh, uint32_t i, void *arg
nsresult
PREF_DeleteBranch(const char *branch_name)
{
#ifndef MOZ_B2G
MOZ_ASSERT(NS_IsMainThread());
#endif
int len = (int)strlen(branch_name);
if (!gHashTable.ops)
@ -642,6 +647,10 @@ pref_ClearUserPref(PLDHashTable *table, PLDHashEntryHdr *he, uint32_t,
nsresult
PREF_ClearAllUserPrefs()
{
#ifndef MOZ_B2G
MOZ_ASSERT(NS_IsMainThread());
#endif
if (!gHashTable.ops)
return NS_ERROR_NOT_INITIALIZED;
@ -716,6 +725,10 @@ static void pref_SetValue(PrefValue* oldValue, PrefValue newValue, PrefType type
PrefHashEntry* pref_HashTableLookup(const void *key)
{
#ifndef MOZ_B2G
MOZ_ASSERT(NS_IsMainThread());
#endif
PrefHashEntry* result =
static_cast<PrefHashEntry*>(PL_DHashTableOperate(&gHashTable, key, PL_DHASH_LOOKUP));
@ -727,6 +740,10 @@ PrefHashEntry* pref_HashTableLookup(const void *key)
nsresult pref_HashPref(const char *key, PrefValue value, PrefType type, uint32_t flags)
{
#ifndef MOZ_B2G
MOZ_ASSERT(NS_IsMainThread());
#endif
if (!gHashTable.ops)
return NS_ERROR_OUT_OF_MEMORY;