Bug 656826 part.1 Rename nsPrefService to mozilla::Prefrences r=roc+bsmedberg
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 23 May 2011 23:54:02 +0900
changeset 69976 3c987837655070cdf3073ebe9da6cc6ab3afc7e6
parent 69975 1027e54104dfb93e843cfe05686a522350bb556f
child 69977 0d754af939ec0c33130e8cc0d37baf903079558f
push id20148
push usermasayuki@d-toybox.com
push dateMon, 23 May 2011 14:55:05 +0000
treeherdermozilla-central@8b60dc275a20 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs656826
milestone6.0a1
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
Bug 656826 part.1 Rename nsPrefService to mozilla::Prefrences r=roc+bsmedberg
modules/libpref/src/nsPrefService.cpp
modules/libpref/src/nsPrefService.h
modules/libpref/src/nsPrefsFactory.cpp
--- a/modules/libpref/src/nsPrefService.cpp
+++ b/modules/libpref/src/nsPrefService.cpp
@@ -68,65 +68,68 @@
 #include "prefapi_private_data.h"
 #include "PrefTuple.h"
 
 #include "nsITimelineService.h"
 
 #include "mozilla/Omnijar.h"
 #include "nsZipArchive.h"
 
+namespace mozilla {
+
 // Definitions
 #define INITIAL_PREF_FILES 10
 static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
 
 // Prototypes
 static nsresult openPrefFile(nsIFile* aFile);
 static nsresult pref_InitInitialObjects(void);
 static nsresult pref_LoadPrefsInDirList(const char *listId);
 
 //-----------------------------------------------------------------------------
 
 /*
  * Constructor/Destructor
  */
 
-nsPrefService::nsPrefService()
+Preferences::Preferences()
 {
 }
 
-nsPrefService::~nsPrefService()
+Preferences::~Preferences()
 {
   PREF_Cleanup();
 }
 
 
 /*
  * nsISupports Implementation
  */
 
-NS_IMPL_THREADSAFE_ADDREF(nsPrefService)
-NS_IMPL_THREADSAFE_RELEASE(nsPrefService)
+NS_IMPL_THREADSAFE_ADDREF(Preferences)
+NS_IMPL_THREADSAFE_RELEASE(Preferences)
 
-NS_INTERFACE_MAP_BEGIN(nsPrefService)
+NS_INTERFACE_MAP_BEGIN(Preferences)
     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrefService)
     NS_INTERFACE_MAP_ENTRY(nsIPrefService)
     NS_INTERFACE_MAP_ENTRY(nsIPrefServiceInternal)
     NS_INTERFACE_MAP_ENTRY(nsIObserver)
     NS_INTERFACE_MAP_ENTRY(nsIPrefBranch)
     NS_INTERFACE_MAP_ENTRY(nsIPrefBranch2)
     NS_INTERFACE_MAP_ENTRY(nsIPrefBranchInternal)
     NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 NS_INTERFACE_MAP_END
 
 
 /*
  * nsIPrefService Implementation
  */
 
-nsresult nsPrefService::Init()
+nsresult
+Preferences::Init()
 {
   nsPrefBranch *rootBranch = new nsPrefBranch("", PR_FALSE); 
   if (!rootBranch)
     return NS_ERROR_OUT_OF_MEMORY;
 
   mRootBranch = (nsIPrefBranch2 *)rootBranch;
 
   nsresult rv;
@@ -175,17 +178,19 @@ nsresult nsPrefService::Init()
   if (NS_SUCCEEDED(rv))
     rv = observerService->AddObserver(this, "profile-do-change", PR_TRUE);
 
   observerService->AddObserver(this, "load-extension-defaults", PR_TRUE);
 
   return(rv);
 }
 
-NS_IMETHODIMP nsPrefService::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
+NS_IMETHODIMP
+Preferences::Observe(nsISupports *aSubject, const char *aTopic,
+                     const PRUnichar *someData)
 {
   if (XRE_GetProcessType() == GeckoProcessType_Content)
     return NS_ERROR_NOT_AVAILABLE;
 
   nsresult rv = NS_OK;
 
   if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
     if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
@@ -204,17 +209,18 @@ NS_IMETHODIMP nsPrefService::Observe(nsI
   } else if (!nsCRT::strcmp(aTopic, "reload-default-prefs")) {
     // Reload the default prefs from file.
     pref_InitInitialObjects();
   }
   return rv;
 }
 
 
-NS_IMETHODIMP nsPrefService::ReadUserPrefs(nsIFile *aFile)
+NS_IMETHODIMP
+Preferences::ReadUserPrefs(nsIFile *aFile)
 {
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     NS_ERROR("cannot load prefs from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   nsresult rv;
 
@@ -225,55 +231,59 @@ NS_IMETHODIMP nsPrefService::ReadUserPre
     NotifyServiceObservers(NS_PREFSERVICE_READ_TOPIC_ID);
 
   } else {
     rv = ReadAndOwnUserPrefFile(aFile);
   }
   return rv;
 }
 
-NS_IMETHODIMP nsPrefService::ResetPrefs()
+NS_IMETHODIMP
+Preferences::ResetPrefs()
 {
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     NS_ERROR("cannot set prefs from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   NotifyServiceObservers(NS_PREFSERVICE_RESET_TOPIC_ID);
   PREF_CleanupPrefs();
 
   nsresult rv = PREF_Init();
   NS_ENSURE_SUCCESS(rv, rv);
 
   return pref_InitInitialObjects();
 }
 
-NS_IMETHODIMP nsPrefService::ResetUserPrefs()
+NS_IMETHODIMP
+Preferences::ResetUserPrefs()
 {
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     NS_ERROR("cannot set prefs from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   PREF_ClearAllUserPrefs();
   return NS_OK;    
 }
 
-NS_IMETHODIMP nsPrefService::SavePrefFile(nsIFile *aFile)
+NS_IMETHODIMP
+Preferences::SavePrefFile(nsIFile *aFile)
 {
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     NS_ERROR("cannot save prefs from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   return SavePrefFileInternal(aFile);
 }
 
 /* part of nsIPrefServiceInternal */
-NS_IMETHODIMP nsPrefService::ReadExtensionPrefs(nsILocalFile *aFile)
+NS_IMETHODIMP
+Preferences::ReadExtensionPrefs(nsILocalFile *aFile)
 {
   nsresult rv;
   nsCOMPtr<nsIZipReader> reader = do_CreateInstance(kZipReaderCID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = reader->Open(aFile);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -311,56 +321,61 @@ NS_IMETHODIMP nsPrefService::ReadExtensi
         break;
       }
     }
     PREF_FinalizeParseState(&ps);
   }
   return rv;
 }
 
-NS_IMETHODIMP nsPrefService::PrefHasUserValue(const nsACString& aPrefName,
-                                              PRBool* aHasValue)
+NS_IMETHODIMP
+Preferences::PrefHasUserValue(const nsACString& aPrefName, PRBool* aHasValue)
 {
   *aHasValue = PREF_HasUserPref(aPrefName.BeginReading());
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrefService::SetPreference(const PrefTuple *aPref)
+NS_IMETHODIMP
+Preferences::SetPreference(const PrefTuple *aPref)
 {
   return pref_SetPrefTuple(*aPref, PR_TRUE);
 }
 
-NS_IMETHODIMP nsPrefService::ClearContentPref(const nsACString& aPrefName)
+NS_IMETHODIMP
+Preferences::ClearContentPref(const nsACString& aPrefName)
 {
   return PREF_ClearUserPref(aPrefName.BeginReading());
 }
 
-NS_IMETHODIMP nsPrefService::MirrorPreference(const nsACString& aPrefName,
-                                              PrefTuple *aPref)
+NS_IMETHODIMP
+Preferences::MirrorPreference(const nsACString& aPrefName, PrefTuple *aPref)
 {
   PrefHashEntry *pref = pref_HashTableLookup(PromiseFlatCString(aPrefName).get());
 
   if (!pref)
     return NS_ERROR_NOT_AVAILABLE;
 
   pref_GetTupleFromEntry(pref, aPref);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrefService::MirrorPreferences(nsTArray<PrefTuple, nsTArrayInfallibleAllocator> *aArray)
+NS_IMETHODIMP
+Preferences::MirrorPreferences(nsTArray<PrefTuple,
+                                        nsTArrayInfallibleAllocator> *aArray)
 {
   aArray->SetCapacity(PL_DHASH_TABLE_SIZE(&gHashTable));
 
   PL_DHashTableEnumerate(&gHashTable, pref_MirrorPrefs, aArray);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrefService::GetBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
+NS_IMETHODIMP
+Preferences::GetBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
 {
   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;
@@ -368,44 +383,47 @@ NS_IMETHODIMP nsPrefService::GetBranch(c
     rv = CallQueryInterface(prefBranch, _retval);
   } else {
     // special case caching the default root
     rv = CallQueryInterface(mRootBranch, _retval);
   }
   return rv;
 }
 
-NS_IMETHODIMP nsPrefService::GetDefaultBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
+NS_IMETHODIMP
+Preferences::GetDefaultBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
 {
   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);
   return rv;
 }
 
 
-nsresult nsPrefService::NotifyServiceObservers(const char *aTopic)
+nsresult
+Preferences::NotifyServiceObservers(const char *aTopic)
 {
   nsCOMPtr<nsIObserverService> observerService = 
     mozilla::services::GetObserverService();  
   if (!observerService)
     return NS_ERROR_FAILURE;
 
   nsISupports *subject = (nsISupports *)((nsIPrefService *)this);
   observerService->NotifyObservers(subject, aTopic, nsnull);
   
   return NS_OK;
 }
 
-nsresult nsPrefService::UseDefaultPrefFile()
+nsresult
+Preferences::UseDefaultPrefFile()
 {
   nsresult rv, rv2;
   nsCOMPtr<nsIFile> aFile;
 
   rv = NS_GetSpecialDirectory(NS_APP_PREFS_50_FILE, getter_AddRefs(aFile));
   if (NS_SUCCEEDED(rv)) {
     rv = ReadAndOwnUserPrefFile(aFile);
     // Most likely cause of failure here is that the file didn't
@@ -415,17 +433,18 @@ nsresult nsPrefService::UseDefaultPrefFi
       rv2 = SavePrefFileInternal(aFile);
       NS_ASSERTION(NS_SUCCEEDED(rv2), "Failed to save new shared pref file");
     }
   }
   
   return rv;
 }
 
-nsresult nsPrefService::UseUserPrefFile()
+nsresult
+Preferences::UseUserPrefFile()
 {
   nsresult rv = NS_OK;
   nsCOMPtr<nsIFile> aFile;
   nsDependentCString prefsDirProp(NS_APP_PREFS_50_DIR);
 
   rv = NS_GetSpecialDirectory(prefsDirProp.get(), getter_AddRefs(aFile));
   if (NS_SUCCEEDED(rv) && aFile) {
     rv = aFile->AppendNative(NS_LITERAL_CSTRING("user.js"));
@@ -437,17 +456,18 @@ nsresult nsPrefService::UseUserPrefFile(
       } else {
         rv = NS_ERROR_FILE_NOT_FOUND;
       }
     }
   }
   return rv;
 }
 
-nsresult nsPrefService::MakeBackupPrefFile(nsIFile *aFile)
+nsresult
+Preferences::MakeBackupPrefFile(nsIFile *aFile)
 {
   // Example: this copies "prefs.js" to "Invalidprefs.js" in the same directory.
   // "Invalidprefs.js" is removed if it exists, prior to making the copy.
   nsAutoString newFilename;
   nsresult rv = aFile->GetLeafName(newFilename);
   NS_ENSURE_SUCCESS(rv, rv);
   newFilename.Insert(NS_LITERAL_STRING("Invalid"), 0);
   nsCOMPtr<nsIFile> newFile;
@@ -461,17 +481,18 @@ nsresult nsPrefService::MakeBackupPrefFi
     rv = newFile->Remove(PR_FALSE);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   rv = aFile->CopyTo(nsnull, newFilename);
   NS_ENSURE_SUCCESS(rv, rv);
   return rv;
 }
 
-nsresult nsPrefService::ReadAndOwnUserPrefFile(nsIFile *aFile)
+nsresult
+Preferences::ReadAndOwnUserPrefFile(nsIFile *aFile)
 {
   NS_ENSURE_ARG(aFile);
   
   if (mCurrentFile == aFile)
     return NS_OK;
   mCurrentFile = aFile;
 
   nsresult rv = NS_OK;
@@ -487,17 +508,18 @@ nsresult nsPrefService::ReadAndOwnUserPr
     }
   } else {
     rv = NS_ERROR_FILE_NOT_FOUND;
   }
 
   return rv;
 }
 
-nsresult nsPrefService::SavePrefFileInternal(nsIFile *aFile)
+nsresult
+Preferences::SavePrefFileInternal(nsIFile *aFile)
 {
   if (nsnull == aFile) {
     // the gDirty flag tells us if we should write to mCurrentFile
     // we only check this flag when the caller wants to write to the default
     if (!gDirty)
       return NS_OK;
     
     // It's possible that we never got a prefs file.
@@ -506,17 +528,18 @@ nsresult nsPrefService::SavePrefFileInte
       rv = WritePrefFile(mCurrentFile);
 
     return rv;
   } else {
     return WritePrefFile(aFile);
   }
 }
 
-nsresult nsPrefService::WritePrefFile(nsIFile* aFile)
+nsresult
+Preferences::WritePrefFile(nsIFile* aFile)
 {
   const char                outHeader[] =
     "# Mozilla User Preferences"
     NS_LINEBREAK
     NS_LINEBREAK
     "/* Do not edit this file."
     NS_LINEBREAK
     " *"
@@ -922,8 +945,10 @@ 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);
 }
+
+} // namespace mozilla
--- a/modules/libpref/src/nsPrefService.h
+++ b/modules/libpref/src/nsPrefService.h
@@ -44,32 +44,34 @@
 #include "nsIPrefBranch.h"
 #include "nsIPrefBranchInternal.h"
 #include "nsIObserver.h"
 #include "nsCOMPtr.h"
 #include "nsWeakReference.h"
 
 class nsIFile;
 
-class nsPrefService : public nsIPrefService,
-                      public nsIPrefServiceInternal,
-                      public nsIObserver,
-                      public nsIPrefBranchInternal,
-                      public nsSupportsWeakReference
+namespace mozilla {
+
+class Preferences : public nsIPrefService,
+                    public nsIPrefServiceInternal,
+                    public nsIObserver,
+                    public nsIPrefBranchInternal,
+                    public nsSupportsWeakReference
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPREFSERVICE
   NS_DECL_NSIPREFSERVICEINTERNAL
   NS_FORWARD_NSIPREFBRANCH(mRootBranch->)
   NS_FORWARD_NSIPREFBRANCH2(mRootBranch->)
   NS_DECL_NSIOBSERVER
 
-  nsPrefService();
-  virtual ~nsPrefService();
+  Preferences();
+  virtual ~Preferences();
 
   nsresult Init();
                            
 protected:
   nsresult NotifyServiceObservers(const char *aSubject);
   nsresult UseDefaultPrefFile();
   nsresult UseUserPrefFile();
   nsresult ReadAndOwnUserPrefFile(nsIFile *aFile);
@@ -78,9 +80,11 @@ protected:
   nsresult WritePrefFile(nsIFile* aFile);
   nsresult MakeBackupPrefFile(nsIFile *aFile);
 
 private:
   nsCOMPtr<nsIPrefBranch2> mRootBranch;
   nsCOMPtr<nsIFile>        mCurrentFile;
 };
 
+} // namespace mozilla
+
 #endif // nsPrefService_h__
--- a/modules/libpref/src/nsPrefsFactory.cpp
+++ b/modules/libpref/src/nsPrefsFactory.cpp
@@ -36,27 +36,28 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/ModuleUtils.h"
 #include "nsPrefService.h"
 #include "nsPrefBranch.h"
 #include "prefapi.h"
 
+using namespace mozilla;
 
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrefService, Init)
+NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(Preferences, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrefLocalizedString, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsRelativeFilePref)
 
 static NS_DEFINE_CID(kPrefServiceCID, NS_PREFSERVICE_CID);
 static NS_DEFINE_CID(kPrefLocalizedStringCID, NS_PREFLOCALIZEDSTRING_CID);
 static NS_DEFINE_CID(kRelativeFilePrefCID, NS_RELATIVEFILEPREF_CID);
  
 static mozilla::Module::CIDEntry kPrefCIDs[] = {
-  { &kPrefServiceCID, true, NULL, nsPrefServiceConstructor },
+  { &kPrefServiceCID, true, NULL, PreferencesConstructor },
   { &kPrefLocalizedStringCID, false, NULL, nsPrefLocalizedStringConstructor },
   { &kRelativeFilePrefCID, false, NULL, nsRelativeFilePrefConstructor },
   { NULL }
 };
 
 static mozilla::Module::ContractIDEntry kPrefContracts[] = {
   { NS_PREFSERVICE_CONTRACTID, &kPrefServiceCID },
   { NS_PREFLOCALIZEDSTRING_CONTRACTID, &kPrefLocalizedStringCID },