Bug 462438 - kill MOZ_PROFILESHARING and MOZ_IPCD; libpref cleanup, v3; r+sr=benjamin
authorArpad Borsos <arpad.borsos@googlemail.com>
Thu, 04 Dec 2008 15:31:53 +0100
changeset 22324 e6091173285a0bf3fccc275e6532226de98c0e3e
parent 22323 dad669d8d557443fc34f6d2df034bad8f30ec666
child 22325 d8759394226c40e59d16d74c82c1279bc80d7d98
push idunknown
push userunknown
push dateunknown
bugs462438
milestone1.9.2a1pre
Bug 462438 - kill MOZ_PROFILESHARING and MOZ_IPCD; libpref cleanup, v3; r+sr=benjamin
modules/libpref/src/nsPrefService.cpp
modules/libpref/src/nsPrefService.h
modules/libpref/src/nsPrefsFactory.cpp
modules/libpref/src/prefapi.cpp
--- a/modules/libpref/src/nsPrefService.cpp
+++ b/modules/libpref/src/nsPrefService.cpp
@@ -57,53 +57,37 @@
 #include "pldhash.h"
 
 #include "prefapi.h"
 #include "prefread.h"
 #include "prefapi_private_data.h"
 
 #include "nsITimelineService.h"
 
-#ifdef MOZ_PROFILESHARING
-#include "nsIProfileSharingSetup.h"
-#include "nsSharedPrefHandler.h"
-#endif
-
 // Definitions
 #define INITIAL_PREF_FILES 10
 
 // Prototypes
-#ifdef MOZ_PROFILESHARING
-static PRBool isSharingEnabled();
-#endif
-
 static nsresult openPrefFile(nsIFile* aFile);
 static nsresult pref_InitInitialObjects(void);
 
 //-----------------------------------------------------------------------------
 
 /*
  * Constructor/Destructor
  */
 
 nsPrefService::nsPrefService()
 : mDontWriteUserPrefs(PR_FALSE)
-#if MOZ_PROFILESHARING
-  , mDontWriteSharedUserPrefs(PR_FALSE)
-#endif
 {
 }
 
 nsPrefService::~nsPrefService()
 {
   PREF_Cleanup();
-
-#ifdef MOZ_PROFILESHARING
-  NS_IF_RELEASE(gSharedPrefHandler);
-#endif
 }
 
 
 /*
  * nsISupports Implementation
  */
 
 NS_IMPL_THREADSAFE_ADDREF(nsPrefService)
@@ -159,51 +143,35 @@ nsresult nsPrefService::Init()
            do_GetService("@mozilla.org/observer-service;1", &rv);
   if (observerService) {
     rv = observerService->AddObserver(this, "profile-before-change", PR_TRUE);
     if (NS_SUCCEEDED(rv)) {
       rv = observerService->AddObserver(this, "profile-do-change", PR_TRUE);
     }
   }
 
-#ifdef MOZ_PROFILESHARING  
-  rv = NS_CreateSharedPrefHandler(this);
-#endif
-
   return(rv);
 }
 
 NS_IMETHODIMP nsPrefService::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
 {
   nsresult rv = NS_OK;
 
   if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
     if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
       if (mCurrentFile) {
         mCurrentFile->Remove(PR_FALSE);
         mCurrentFile = nsnull;
       }
     } else {
       rv = SavePrefFile(nsnull);
-#ifdef MOZ_PROFILESHARING
-      if (isSharingEnabled())
-        rv = gSharedPrefHandler->OnSessionEnd();
-#endif
     }
   } else if (!nsCRT::strcmp(aTopic, "profile-do-change")) {
-  
-#ifdef MOZ_PROFILESHARING
-    if (isSharingEnabled())
-      rv = gSharedPrefHandler->OnSessionBegin();
-    else
-#endif
-    {
-      ResetUserPrefs();
-      rv = ReadUserPrefs(nsnull);
-    }
+    ResetUserPrefs();
+    rv = ReadUserPrefs(nsnull);
   } else if (!nsCRT::strcmp(aTopic, "reload-default-prefs")) {
     // Reload the default prefs from file.
     pref_InitInitialObjects();
   }
   return rv;
 }
 
 
@@ -237,21 +205,16 @@ NS_IMETHODIMP nsPrefService::ResetPrefs(
 NS_IMETHODIMP nsPrefService::ResetUserPrefs()
 {
   PREF_ClearAllUserPrefs();
   return NS_OK;    
 }
 
 NS_IMETHODIMP nsPrefService::SavePrefFile(nsIFile *aFile)
 {
-#ifdef MOZ_PROFILESHARING
-  // sharing only applies to the default prefs file
-  if (aFile == nsnull && isSharingEnabled())
-    return gSharedPrefHandler->OnSavePrefs();
-#endif
   return SavePrefFileInternal(aFile);
 }
 
 NS_IMETHODIMP nsPrefService::GetBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
 {
   nsresult rv;
 
   if ((nsnull != aPrefRoot) && (*aPrefRoot != '\0')) {
@@ -297,34 +260,16 @@ nsresult nsPrefService::NotifyServiceObs
   return NS_OK;
 }
 
 nsresult nsPrefService::UseDefaultPrefFile()
 {
   nsresult rv, rv2;
   nsCOMPtr<nsIFile> aFile;
 
-#ifdef MOZ_PROFILESHARING
-  // First, read the shared file.
-  if (isSharingEnabled()) {
-    rv = NS_GetSpecialDirectory(NS_SHARED NS_APP_PREFS_50_FILE, getter_AddRefs(aFile));
-    if (NS_SUCCEEDED(rv)) {
-      rv = ReadAndOwnSharedUserPrefFile(aFile);
-      // Most likely cause of failure here is that the file didn't
-      // exist, so save a new one. mSharedUserPrefReadFailed will be
-      // used to catch an error in actually reading the file.
-      if (NS_FAILED(rv)) {
-        rv2 = SavePrefFileInternal(aFile);
-        NS_ASSERTION(NS_SUCCEEDED(rv2), "Failed to save new shared pref file");
-      }
-    }
-  }
-  // Continue on to read the nonshared file.
-#endif
-
   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
     // exist, so save a new one. mUserPrefReadFailed will be
     // used to catch an error in actually reading the file.
     if (NS_FAILED(rv)) {
       rv2 = SavePrefFileInternal(aFile);
@@ -334,24 +279,17 @@ nsresult nsPrefService::UseDefaultPrefFi
   
   return rv;
 }
 
 nsresult nsPrefService::UseUserPrefFile()
 {
   nsresult rv = NS_OK;
   nsCOMPtr<nsIFile> aFile;
-
-#ifdef MOZ_PROFILESHARING
-  nsCAutoString prefsDirProp(NS_APP_PREFS_50_DIR);
-  if (isSharingEnabled())
-    prefsDirProp.Insert(NS_SHARED, 0); // Prepend modifier so we get shared file
-#else
   nsDependentCString prefsDirProp(NS_APP_PREFS_50_DIR);
-#endif
 
   rv = NS_GetSpecialDirectory(prefsDirProp.get(), getter_AddRefs(aFile));
   if (NS_SUCCEEDED(rv) && aFile) {
     rv = aFile->AppendNative(NS_LITERAL_CSTRING("user.js"));
     if (NS_SUCCEEDED(rv)) {
       PRBool exists = PR_FALSE;
       aFile->Exists(&exists);
       if (exists) {
@@ -379,88 +317,44 @@ nsresult nsPrefService::MakeBackupPrefFi
 nsresult nsPrefService::ReadAndOwnUserPrefFile(nsIFile *aFile)
 {
   NS_ENSURE_ARG(aFile);
   
   if (mCurrentFile == aFile)
     return NS_OK;
   mCurrentFile = aFile;
 
-#ifdef MOZ_PROFILESHARING
-  // We don't want prefs set here to cause transactions
-  gSharedPrefHandler->ReadingUserPrefs(PR_TRUE);
-#endif
-
   nsresult rv = NS_OK;
   PRBool exists = PR_FALSE;
   mCurrentFile->Exists(&exists);
   if (exists) {
     rv = openPrefFile(mCurrentFile);
     if (NS_FAILED(rv)) {
       mDontWriteUserPrefs = NS_FAILED(MakeBackupPrefFile(mCurrentFile));
     }
   } else {
     rv = NS_ERROR_FILE_NOT_FOUND;
   }
 
-#ifdef MOZ_PROFILESHARING
-  gSharedPrefHandler->ReadingUserPrefs(PR_FALSE);
-#endif
-
   return rv;
 }
 
-#ifdef MOZ_PROFILESHARING
-nsresult nsPrefService::ReadAndOwnSharedUserPrefFile(nsIFile *aFile)
-{
-  NS_ENSURE_ARG(aFile);
-
-  if (mCurrentSharedFile == aFile)
-    return NS_OK;
-  mCurrentSharedFile = aFile;
-
-#ifdef MOZ_PROFILESHARING
-  // We don't want prefs set here to cause transactions
-  gSharedPrefHandler->ReadingUserPrefs(PR_TRUE);
-#endif
-
-  nsresult rv = openPrefFile(mCurrentSharedFile);
-  if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) {
-    mDontWriteSharedUserPrefs = NS_FAILED(MakeBackupPrefFile(mCurrentSharedFile));
-  }
-
-#ifdef MOZ_PROFILESHARING
-  gSharedPrefHandler->ReadingUserPrefs(PR_FALSE);
-#endif
-
-  return rv;
-}
-#endif
-
 nsresult nsPrefService::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.
     nsresult rv = NS_OK;
     if (mCurrentFile)
       rv = WritePrefFile(mCurrentFile);
 
-#ifdef MOZ_PROFILESHARING
-    if (mCurrentSharedFile) {
-      nsresult rv2 = WritePrefFile(mCurrentSharedFile);
-      if (NS_SUCCEEDED(rv))
-        rv = rv2;
-    }
-#endif
-
     return rv;
   } else {
     return WritePrefFile(aFile);
   }
 }
 
 nsresult nsPrefService::WritePrefFile(nsIFile* aFile)
 {
@@ -494,20 +388,16 @@ nsresult nsPrefService::WritePrefFile(ns
   if (!gHashTable.ops)
     return NS_ERROR_NOT_INITIALIZED;
 
   // Don't save user prefs if there was an error reading them and we failed
   // to make a backup copy, since all prefs from the error line to the end of
   // the file would be lost (bug 361102).
   if (mDontWriteUserPrefs && aFile == mCurrentFile)
     return NS_OK;
-#if MOZ_PROFILESHARING
-  if (mDontWriteSharedUserPrefs && aFile == mCurrentSharedFile)
-    return NS_OK;
-#endif
 
   // execute a "safe" save by saving through a tempfile
   rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(outStreamSink),
                                        aFile,
                                        -1,
                                        0600);
   if (NS_FAILED(rv)) 
       return rv;
@@ -518,25 +408,16 @@ nsresult nsPrefService::WritePrefFile(ns
   char** valueArray = (char **)PR_Calloc(sizeof(char *), gHashTable.entryCount);
   if (!valueArray)
     return NS_ERROR_OUT_OF_MEMORY;
   
   pref_saveArgs saveArgs;
   saveArgs.prefArray = valueArray;
   saveArgs.saveTypes = SAVE_ALL;
   
-#if MOZ_PROFILESHARING
-  if (isSharingEnabled()) {
-    if (aFile == mCurrentSharedFile)
-      saveArgs.saveTypes = SAVE_SHARED;
-    else if (aFile == mCurrentFile)
-      saveArgs.saveTypes = SAVE_NONSHARED;
-  }
-#endif
-  
   // get the lines that we're supposed to be writing to the file
   PL_DHashTableEnumerate(&gHashTable, pref_savePref, &saveArgs);
     
   /* Sort the preferences to make a readable file on disk */
   NS_QuickSort(valueArray, gHashTable.entryCount, sizeof(char *), pref_CompareStrings, NULL);
   
   // write out the file header
   outStream->Write(outHeader, sizeof(outHeader) - 1, &writeAmount);
@@ -562,32 +443,16 @@ nsresult nsPrefService::WritePrefFile(ns
       return rv;
     }
   }
 
   gDirty = PR_FALSE;
   return NS_OK;
 }
 
-#ifdef MOZ_PROFILESHARING
-static PRBool isSharingEnabled()
-{
-  static PRBool gSharingEnabled = PR_FALSE;
-  
-  // If FALSE, query again. It may not have been set yet.
-  if (!gSharingEnabled) {
-    nsCOMPtr<nsIProfileSharingSetup> sharingSetup =
-        do_GetService("@mozilla.org/embedcomp/profile-sharing-setup;1");
-    if (sharingSetup)
-      sharingSetup->GetIsSharingEnabled(&gSharingEnabled);
-  }
-  return gSharingEnabled;
-}
-#endif
-
 static nsresult openPrefFile(nsIFile* aFile)
 {
   nsCOMPtr<nsIInputStream> inStr;
 
 #if MOZ_TIMELINE
   {
     nsCAutoString str;
     aFile->GetNativePath(str);
--- a/modules/libpref/src/nsPrefService.h
+++ b/modules/libpref/src/nsPrefService.h
@@ -48,18 +48,16 @@
 
 class nsIFile;
 
 class nsPrefService : public nsIPrefService,
                       public nsIObserver,
                       public nsIPrefBranchInternal,
                       public nsSupportsWeakReference
 {
-  friend class nsSharedPrefHandler; 
-  
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPREFSERVICE
   NS_FORWARD_NSIPREFBRANCH(mRootBranch->)
   NS_FORWARD_NSIPREFBRANCH2(mRootBranch->)
   NS_DECL_NSIOBSERVER
 
   nsPrefService();
@@ -76,15 +74,11 @@ protected:
   nsresult SavePrefFileInternal(nsIFile* aFile);
   nsresult WritePrefFile(nsIFile* aFile);
   nsresult MakeBackupPrefFile(nsIFile *aFile);
 
 private:
   nsCOMPtr<nsIPrefBranch2> mRootBranch;
   nsCOMPtr<nsIFile>       mCurrentFile;
   PRPackedBool            mDontWriteUserPrefs;
-#if MOZ_PROFILESHARING
-  nsCOMPtr<nsIFile>       mCurrentSharedFile;
-  PRPackedBool            mDontWriteSharedUserPrefs;
-#endif
 };
 
 #endif // nsPrefService_h__
--- a/modules/libpref/src/nsPrefsFactory.cpp
+++ b/modules/libpref/src/nsPrefsFactory.cpp
@@ -37,20 +37,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsIGenericFactory.h"
 #include "nsPrefService.h"
 #include "nsPrefBranch.h"
 #include "nsIPref.h"
 #include "prefapi.h"
 
-#ifdef MOZ_PROFILESHARING
-#include "nsSharedPrefHandler.h"
-#endif
-
 // remove this when nsPref goes away
 extern NS_IMETHODIMP nsPrefConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult);
 
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrefService, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrefLocalizedString, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsRelativeFilePref)
  
@@ -85,16 +81,11 @@ static const nsModuleComponentInfo compo
     nsPrefConstructor
   },
 };
 
 static void
 UnloadPrefsModule(nsIModule* unused)
 {
   PREF_Cleanup();
-
-#ifdef MOZ_PROFILESHARING
-  NS_ASSERTION(!gSharedPrefHandler, "Leaking the shared pref handler (and the prefservice, presumably).");
-  gSharedPrefHandler = nsnull;
-#endif
 }
 
 NS_IMPL_NSGETMODULE_WITH_DTOR(nsPrefModule, components, UnloadPrefsModule)
--- a/modules/libpref/src/prefapi.cpp
+++ b/modules/libpref/src/prefapi.cpp
@@ -64,20 +64,16 @@
 #include "prlog.h"
 #include "prmem.h"
 #include "prprf.h"
 #include "nsQuickSort.h"
 #include "nsString.h"
 #include "nsPrintfCString.h"
 #include "prlink.h"
 
-#ifdef MOZ_PROFILESHARING
-#include "nsSharedPrefHandler.h"
-#endif
-
 #ifdef XP_OS2
 #define INCL_DOS
 #include <os2.h>
 #endif
 
 #ifdef XP_BEOS
 #include "Alert.h"
 #endif
@@ -339,24 +335,16 @@ pref_savePref(PLDHashTable *table, PLDHa
                           (PrefType) PREF_TYPE(pref)))
         sourcePref = &pref->userPref;
     else if (PREF_IS_LOCKED(pref))
         sourcePref = &pref->defaultPref;
     else
         // do not save default prefs that haven't changed
         return PL_DHASH_NEXT;
 
-#if MOZ_PROFILESHARING
-  if ((argData->saveTypes == SAVE_SHARED &&
-      !gSharedPrefHandler->IsPrefShared(pref->key)) ||
-      (argData->saveTypes == SAVE_NONSHARED &&
-      gSharedPrefHandler->IsPrefShared(pref->key)))
-    return PL_DHASH_NEXT;
-#endif
-
     // strings are in quotes!
     if (pref->flags & PREF_STRING) {
         prefValue = '\"';
         str_escape(sourcePref->stringVal, prefValue);
         prefValue += '\"';
     }
 
     else if (pref->flags & PREF_INT)
@@ -775,20 +763,16 @@ nsresult pref_HashPref(const char *key, 
     if (valueChanged) {
         gDirty = PR_TRUE;
 
         if (gCallbacksEnabled) {
             nsresult rv2 = pref_DoCallback(key);
             if (NS_FAILED(rv2))
                 rv = rv2;
         }
-#ifdef MOZ_PROFILESHARING
-        if (gSharedPrefHandler)
-            gSharedPrefHandler->OnPrefChanged(set_default, pref, value);
-#endif
     }
     return rv;
 }
 
 PrefType
 PREF_GetPrefType(const char *pref_name)
 {
     if (gHashTable.ops)