Merge backout; a=beta9 CLOSED TREE
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 10 Jan 2011 19:40:56 -0500
changeset 60265 badef0f336d2ae302e7bb17cc025d550a67e2ac4
parent 60263 12c4de7f40575730d82b5950b6cd5e478a43d489 (current diff)
parent 60264 93a8c5ffa86df38493816e1a76cfa8dd7054fef6 (diff)
child 60266 859a97109032ed863a171cfe7361269458873531
child 60269 bcab2d6652cb2db3f5486d03f431271b2e3b4d09
push id17902
push usereakhgari@mozilla.com
push dateTue, 11 Jan 2011 00:41:06 +0000
treeherdermozilla-central@badef0f336d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbeta9
milestone2.0b9pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge backout; a=beta9 CLOSED TREE
modules/libpref/src/nsPrefService.cpp
--- a/modules/libpref/src/nsPrefBranch.cpp
+++ b/modules/libpref/src/nsPrefBranch.cpp
@@ -39,26 +39,24 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifdef MOZ_IPC
 #include "mozilla/dom/ContentChild.h"
 #include "nsXULAppAPI.h"
 #endif
 
 #include "nsPrefBranch.h"
-#include "nsPrefService.h"
 #include "nsILocalFile.h"
 #include "nsIObserverService.h"
 #include "nsXPCOM.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIDirectoryService.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsXPIDLString.h"
-#include "nsThreadUtils.h"
 #include "nsIStringBundle.h"
 #include "prefapi.h"
 #include "prmem.h"
 #include "pldhash.h"
 
 #include "plstr.h"
 #include "nsCRT.h"
 #include "mozilla/Services.h"
@@ -144,132 +142,96 @@ NS_INTERFACE_MAP_END
 
 
 /*
  * nsIPrefBranch Implementation
  */
 
 NS_IMETHODIMP nsPrefBranch::GetRoot(char **aRoot)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   NS_ENSURE_ARG_POINTER(aRoot);
   mPrefRoot.Truncate(mPrefRootLength);
   *aRoot = ToNewCString(mPrefRoot);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPrefBranch::GetPrefType(const char *aPrefName, PRInt32 *_retval)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   NS_ENSURE_ARG(aPrefName);
   const char *pref = getPrefName(aPrefName);
   *_retval = PREF_GetPrefType(pref);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPrefBranch::GetBoolPref(const char *aPrefName, PRBool *_retval)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   NS_ENSURE_ARG(aPrefName);
   const char *pref = getPrefName(aPrefName);
   return PREF_GetBoolPref(pref, _retval, mIsDefault);
 }
 
 NS_IMETHODIMP nsPrefBranch::SetBoolPref(const char *aPrefName, PRInt32 aValue)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (GetContentChild()) {
     NS_ERROR("cannot set pref from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   NS_ENSURE_ARG(aPrefName);
   const char *pref = getPrefName(aPrefName);
   return PREF_SetBoolPref(pref, aValue, mIsDefault);
 }
 
 NS_IMETHODIMP nsPrefBranch::GetCharPref(const char *aPrefName, char **_retval)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   NS_ENSURE_ARG(aPrefName);
   const char *pref = getPrefName(aPrefName);
   return PREF_CopyCharPref(pref, _retval, mIsDefault);
 }
 
 NS_IMETHODIMP nsPrefBranch::SetCharPref(const char *aPrefName, const char *aValue)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (GetContentChild()) {
     NS_ERROR("cannot set pref from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   NS_ENSURE_ARG(aPrefName);
   NS_ENSURE_ARG(aValue);
   const char *pref = getPrefName(aPrefName);
   return PREF_SetCharPref(pref, aValue, mIsDefault);
 }
 
 NS_IMETHODIMP nsPrefBranch::GetIntPref(const char *aPrefName, PRInt32 *_retval)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   NS_ENSURE_ARG(aPrefName);
   const char *pref = getPrefName(aPrefName);
   return PREF_GetIntPref(pref, _retval, mIsDefault);
 }
 
 NS_IMETHODIMP nsPrefBranch::SetIntPref(const char *aPrefName, PRInt32 aValue)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (GetContentChild()) {
     NS_ERROR("cannot set pref from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   NS_ENSURE_ARG(aPrefName);
   const char *pref = getPrefName(aPrefName);
   return PREF_SetIntPref(pref, aValue, mIsDefault);
 }
 
 NS_IMETHODIMP nsPrefBranch::GetComplexValue(const char *aPrefName, const nsIID & aType, void **_retval)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   NS_ENSURE_ARG(aPrefName);
 
   nsresult       rv;
   nsXPIDLCString utf8String;
 
   // we have to do this one first because it's different than all the rest
   if (aType.Equals(NS_GET_IID(nsIPrefLocalizedString))) {
     nsCOMPtr<nsIPrefLocalizedString> theString(do_CreateInstance(NS_PREFLOCALIZEDSTRING_CONTRACTID, &rv));
@@ -421,20 +383,16 @@ NS_IMETHODIMP nsPrefBranch::GetComplexVa
   }
 
   NS_WARNING("nsPrefBranch::GetComplexValue - Unsupported interface type");
   return NS_NOINTERFACE;
 }
 
 NS_IMETHODIMP nsPrefBranch::SetComplexValue(const char *aPrefName, const nsIID & aType, nsISupports *aValue)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (GetContentChild()) {
     NS_ERROR("cannot set pref from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   NS_ENSURE_ARG(aPrefName);
@@ -516,89 +474,69 @@ NS_IMETHODIMP nsPrefBranch::SetComplexVa
   }
 
   NS_WARNING("nsPrefBranch::SetComplexValue - Unsupported interface type");
   return NS_NOINTERFACE;
 }
 
 NS_IMETHODIMP nsPrefBranch::ClearUserPref(const char *aPrefName)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (GetContentChild()) {
     NS_ERROR("cannot set pref from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   NS_ENSURE_ARG(aPrefName);
   const char *pref = getPrefName(aPrefName);
   return PREF_ClearUserPref(pref);
 }
 
 NS_IMETHODIMP nsPrefBranch::PrefHasUserValue(const char *aPrefName, PRBool *_retval)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   NS_ENSURE_ARG_POINTER(_retval);
   NS_ENSURE_ARG(aPrefName);
   const char *pref = getPrefName(aPrefName);
   *_retval = PREF_HasUserPref(pref);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPrefBranch::LockPref(const char *aPrefName)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (GetContentChild()) {
     NS_ERROR("cannot lock pref from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   NS_ENSURE_ARG(aPrefName);
   const char *pref = getPrefName(aPrefName);
   return PREF_LockPref(pref, PR_TRUE);
 }
 
 NS_IMETHODIMP nsPrefBranch::PrefIsLocked(const char *aPrefName, PRBool *_retval)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (GetContentChild()) {
     NS_ERROR("cannot check lock pref from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   NS_ENSURE_ARG_POINTER(_retval);
   NS_ENSURE_ARG(aPrefName);
   const char *pref = getPrefName(aPrefName);
   *_retval = PREF_PrefIsLocked(pref);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPrefBranch::UnlockPref(const char *aPrefName)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (GetContentChild()) {
     NS_ERROR("cannot unlock pref from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   NS_ENSURE_ARG(aPrefName);
@@ -609,38 +547,30 @@ NS_IMETHODIMP nsPrefBranch::UnlockPref(c
 /* void resetBranch (in string startingAt); */
 NS_IMETHODIMP nsPrefBranch::ResetBranch(const char *aStartingAt)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP nsPrefBranch::DeleteBranch(const char *aStartingAt)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (GetContentChild()) {
     NS_ERROR("cannot set pref from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   NS_ENSURE_ARG(aStartingAt);
   const char *pref = getPrefName(aStartingAt);
   return PREF_DeleteBranch(pref);
 }
 
 NS_IMETHODIMP nsPrefBranch::GetChildList(const char *aStartingAt, PRUint32 *aCount, char ***aChildArray)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   char            **outArray;
   PRInt32         numPrefs;
   PRInt32         dwIndex;
   EnumerateData   ed;
   nsAutoTArray<nsCString, 32> prefArray;
 
   NS_ENSURE_ARG(aStartingAt);
   NS_ENSURE_ARG_POINTER(aCount);
@@ -690,20 +620,16 @@ NS_IMETHODIMP nsPrefBranch::GetChildList
 
 
 /*
  *  nsIPrefBranch2 methods
  */
 
 NS_IMETHODIMP nsPrefBranch::AddObserver(const char *aDomain, nsIObserver *aObserver, PRBool aHoldWeak)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   PrefCallback *pCallback;
   const char *pref;
 
   NS_ENSURE_ARG(aDomain);
   NS_ENSURE_ARG(aObserver);
 
   // hold a weak reference to the observer if so requested
   if (aHoldWeak) {
@@ -739,20 +665,16 @@ NS_IMETHODIMP nsPrefBranch::AddObserver(
   // NS_ENSURE_ARG above.
   pref = getPrefName(aDomain);
   PREF_RegisterCallback(pref, NotifyObserver, pCallback);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPrefBranch::RemoveObserver(const char *aDomain, nsIObserver *aObserver)
 {
-  if (NS_UNLIKELY(!nsPrefService::CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   NS_ENSURE_ARG(aDomain);
   NS_ENSURE_ARG(aObserver);
 
   nsresult rv = NS_OK;
 
   // If we're in the middle of a call to freeObserverList, don't process this
   // RemoveObserver call -- the observer in question will be removed soon, if
   // it hasn't been already.
--- a/modules/libpref/src/nsPrefService.cpp
+++ b/modules/libpref/src/nsPrefService.cpp
@@ -41,32 +41,30 @@
 #include "mozilla/dom/ContentChild.h"
 #include "nsXULAppAPI.h"
 #endif
 
 #include "nsPrefService.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsICategoryManager.h"
-#include "nsIConsoleService.h"
 #include "nsCategoryManagerUtils.h"
 #include "nsNetUtil.h"
 #include "nsIFile.h"
 #include "nsIInputStream.h"
 #include "nsILocalFile.h"
 #include "nsIObserverService.h"
 #include "nsIStringEnumerator.h"
 #include "nsIZipReader.h"
 #include "nsPrefBranch.h"
 #include "nsXPIDLString.h"
 #include "nsCRT.h"
 #include "nsCOMArray.h"
 #include "nsXPCOMCID.h"
 #include "nsAutoPtr.h"
-#include "nsThreadUtils.h"
 
 #include "nsQuickSort.h"
 #include "prmem.h"
 #include "pldhash.h"
 
 #include "prefapi.h"
 #include "prefread.h"
 #include "prefapi_private_data.h"
@@ -216,20 +214,16 @@ NS_IMETHODIMP nsPrefService::Observe(nsI
     pref_InitInitialObjects();
   }
   return rv;
 }
 
 
 NS_IMETHODIMP nsPrefService::ReadUserPrefs(nsIFile *aFile)
 {
-  if (NS_UNLIKELY(!CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     NS_ERROR("cannot load prefs from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   nsresult rv;
@@ -243,20 +237,16 @@ NS_IMETHODIMP nsPrefService::ReadUserPre
   } else {
     rv = ReadAndOwnUserPrefFile(aFile);
   }
   return rv;
 }
 
 NS_IMETHODIMP nsPrefService::ResetPrefs()
 {
-  if (NS_UNLIKELY(!CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     NS_ERROR("cannot set prefs from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   NotifyServiceObservers(NS_PREFSERVICE_RESET_TOPIC_ID);
@@ -265,37 +255,29 @@ NS_IMETHODIMP nsPrefService::ResetPrefs(
   nsresult rv = PREF_Init();
   NS_ENSURE_SUCCESS(rv, rv);
 
   return pref_InitInitialObjects();
 }
 
 NS_IMETHODIMP nsPrefService::ResetUserPrefs()
 {
-  if (NS_UNLIKELY(!CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     NS_ERROR("cannot set prefs from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   PREF_ClearAllUserPrefs();
   return NS_OK;    
 }
 
 NS_IMETHODIMP nsPrefService::SavePrefFile(nsIFile *aFile)
 {
-  if (NS_UNLIKELY(!CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
 #ifdef MOZ_IPC
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     NS_ERROR("cannot save prefs from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 #endif
 
   return SavePrefFileInternal(aFile);
@@ -386,20 +368,16 @@ NS_IMETHODIMP nsPrefService::MirrorPrefe
 
   PL_DHashTableEnumerate(&gHashTable, pref_MirrorPrefs, aArray);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPrefService::GetBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
 {
-  if (NS_UNLIKELY(!CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   nsresult rv;
 
   if ((nsnull != aPrefRoot) && (*aPrefRoot != '\0')) {
     // TODO: - cache this stuff and allow consumers to share branches (hold weak references I think)
     nsPrefBranch* prefBranch = new nsPrefBranch(aPrefRoot, PR_FALSE);
     if (!prefBranch)
       return NS_ERROR_OUT_OF_MEMORY;
 
@@ -408,20 +386,16 @@ NS_IMETHODIMP nsPrefService::GetBranch(c
     // special case caching the default root
     rv = CallQueryInterface(mRootBranch, _retval);
   }
   return rv;
 }
 
 NS_IMETHODIMP nsPrefService::GetDefaultBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
 {
-  if (NS_UNLIKELY(!CheckAndLogBackgroundThreadUse())) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   nsresult rv;
 
   // TODO: - cache this stuff and allow consumers to share branches (hold weak references I think)
   nsPrefBranch* prefBranch = new nsPrefBranch(aPrefRoot, PR_TRUE);
   if (!prefBranch)
     return NS_ERROR_OUT_OF_MEMORY;
 
   rv = CallQueryInterface(prefBranch, _retval);
@@ -966,27 +940,8 @@ static nsresult pref_InitInitialObjects(
     mozilla::services::GetObserverService();
   if (!observerService)
     return NS_ERROR_FAILURE;
 
   observerService->NotifyObservers(nsnull, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID, nsnull);
 
   return pref_LoadPrefsInDirList(NS_EXT_PREFS_DEFAULTS_DIR_LIST);
 }
-
-// static
-bool
-nsPrefService::CheckAndLogBackgroundThreadUse()
-{
-  if (NS_IsMainThread()) {
-    return true;
-  }
-
-  NS_WARNING("Cannot be used on a background thread!");
-  nsCOMPtr<nsIConsoleService> cs =
-    do_GetService("@mozilla.org/consoleservice;1");
-  if (cs) {
-    (void)cs->LogStringMessage(NS_LITERAL_STRING(
-      "Invalid use of the preferences on a background thread!"
-    ).get());
-  }
-  return false;
-}
--- a/modules/libpref/src/nsPrefService.h
+++ b/modules/libpref/src/nsPrefService.h
@@ -62,23 +62,17 @@ public:
   NS_FORWARD_NSIPREFBRANCH(mRootBranch->)
   NS_FORWARD_NSIPREFBRANCH2(mRootBranch->)
   NS_DECL_NSIOBSERVER
 
   nsPrefService();
   virtual ~nsPrefService();
 
   nsresult Init();
-
-  /**
-   * Checks to make sure we are on the main thread and log if we are not.
-   *
-   * @returns true if on the main thread, and false otherwise.
-   */
-  static bool CheckAndLogBackgroundThreadUse();
+                           
 protected:
   nsresult NotifyServiceObservers(const char *aSubject);
   nsresult UseDefaultPrefFile();
   nsresult UseUserPrefFile();
   nsresult ReadAndOwnUserPrefFile(nsIFile *aFile);
   nsresult ReadAndOwnSharedUserPrefFile(nsIFile *aFile);
   nsresult SavePrefFileInternal(nsIFile* aFile);
   nsresult WritePrefFile(nsIFile* aFile);