Bug 735573. (Av1) Document UseDefaultPrefFile() and fix its nsresult value. r=bsmedberg.
authorSerge Gautherie <sgautherie.bz@free.fr>
Fri, 23 Mar 2012 02:13:20 +0100
changeset 90119 2cec1f79a141fc6098fae474c67b6eb03c8d819c
parent 90118 901727f56830ce30e37996e0746b45a574e091fb
child 90120 996b89200406b4abae2ab874be1ed412aa14017c
push id7485
push usermak77@bonardo.net
push dateFri, 23 Mar 2012 11:52:16 +0000
treeherdermozilla-inbound@b3e429486693 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs735573
milestone14.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 735573. (Av1) Document UseDefaultPrefFile() and fix its nsresult value. r=bsmedberg.
modules/libpref/public/Preferences.h
modules/libpref/src/Preferences.cpp
--- a/modules/libpref/public/Preferences.h
+++ b/modules/libpref/public/Preferences.h
@@ -347,16 +347,22 @@ public:
   static void MirrorPreferences(nsTArray<PrefTuple,
                                 nsTArrayInfallibleAllocator> *aArray);
   static bool MirrorPreference(const char *aPref, PrefTuple *aTuple);
   static void ClearContentPref(const char *aPref);
   static void SetPreference(const PrefTuple *aTuple);
 
 protected:
   nsresult NotifyServiceObservers(const char *aSubject);
+  /**
+   * Reads the default pref file or, if that failed, try to save a new one.
+   *
+   * @return NS_OK if either action succeeded,
+   *         or the error code related to the read attempt.
+   */
   nsresult UseDefaultPrefFile();
   nsresult UseUserPrefFile();
   nsresult ReadAndOwnUserPrefFile(nsIFile *aFile);
   nsresult ReadAndOwnSharedUserPrefFile(nsIFile *aFile);
   nsresult SavePrefFileInternal(nsIFile* aFile);
   nsresult WritePrefFile(nsIFile* aFile);
   nsresult MakeBackupPrefFile(nsIFile *aFile);
 
--- a/modules/libpref/src/Preferences.cpp
+++ b/modules/libpref/src/Preferences.cpp
@@ -399,24 +399,26 @@ Preferences::ReadUserPrefs(nsIFile *aFil
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     NS_ERROR("cannot load prefs from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   nsresult rv;
 
   if (nsnull == aFile) {
-
     NotifyServiceObservers(NS_PREFSERVICE_READ_TOPIC_ID);
 
     rv = UseDefaultPrefFile();
-    UseUserPrefFile();
+    // A user pref file is optional.
+    // Ignore all errors related to it, so we retain 'rv' value :-|
+    (void) UseUserPrefFile();
   } else {
     rv = ReadAndOwnUserPrefFile(aFile);
   }
+
   return rv;
 }
 
 NS_IMETHODIMP
 Preferences::ResetPrefs()
 {
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     NS_ERROR("cannot set prefs from content process");
@@ -582,28 +584,30 @@ Preferences::NotifyServiceObservers(cons
   observerService->NotifyObservers(subject, aTopic, nsnull);
   
   return NS_OK;
 }
 
 nsresult
 Preferences::UseDefaultPrefFile()
 {
-  nsresult rv, rv2;
+  nsresult rv;
   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
     // 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);
-      NS_ASSERTION(NS_SUCCEEDED(rv2), "Failed to save new shared pref file");
+      if (NS_FAILED(SavePrefFileInternal(aFile)))
+        NS_ERROR("Failed to save new shared pref file");
+      else
+        rv = NS_OK;
     }
   }
   
   return rv;
 }
 
 nsresult
 Preferences::UseUserPrefFile()