Bug 1037164 - Add an implementation for Preferences::SetFloat. r=bz
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 11 Jul 2014 08:25:12 -0400
changeset 193581 76928ae5c15565e3fdc56030d9f949eb9afeb321
parent 193580 059b364302aff7371bf82aa4f534ad32e6b915e8
child 193582 c109e4bd68acd46d02a33a97f04b2f0ad85dc371
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs1037164
milestone33.0a1
Bug 1037164 - Add an implementation for Preferences::SetFloat. r=bz
modules/libpref/public/Preferences.h
modules/libpref/src/Preferences.cpp
--- a/modules/libpref/public/Preferences.h
+++ b/modules/libpref/public/Preferences.h
@@ -196,16 +196,17 @@ public:
    * Sets various type pref values.
    */
   static nsresult SetBool(const char* aPref, bool aValue);
   static nsresult SetInt(const char* aPref, int32_t aValue);
   static nsresult SetUint(const char* aPref, uint32_t aValue)
   {
     return SetInt(aPref, static_cast<int32_t>(aValue));
   }
+  static nsresult SetFloat(const char* aPref, float aValue);
   static nsresult SetCString(const char* aPref, const char* aValue);
   static nsresult SetCString(const char* aPref, const nsACString &aValue);
   static nsresult SetString(const char* aPref, const char16_t* aValue);
   static nsresult SetString(const char* aPref, const nsAString &aValue);
 
   static nsresult SetComplex(const char* aPref, const nsIID &aType,
                              nsISupports* aValue);
 
@@ -344,17 +345,16 @@ public:
   static int32_t GetDefaultType(const char* aPref);
 
   // Used to synchronise preferences between chrome and content processes.
   static void GetPreferences(InfallibleTArray<PrefSetting>* aPrefs);
   static void GetPreference(PrefSetting* aPref);
   static void SetPreference(const PrefSetting& aPref);
 
   static int64_t SizeOfIncludingThisAndOtherStuff(mozilla::MallocSizeOf aMallocSizeOf);
-  static nsresult SetFloat(const char* aPref, float aValue);
 
 protected:
   virtual ~Preferences();
 
   nsresult NotifyServiceObservers(const char *aSubject);
   /**
    * Reads the default pref file or, if that failed, try to save a new one.
    *
--- a/modules/libpref/src/Preferences.cpp
+++ b/modules/libpref/src/Preferences.cpp
@@ -1564,16 +1564,23 @@ Preferences::SetInt(const char* aPref, i
 {
   ENSURE_MAIN_PROCESS("Cannot SetInt from content process:", aPref);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   return PREF_SetIntPref(aPref, aValue, false);
 }
 
 // static
 nsresult
+Preferences::SetFloat(const char* aPref, float aValue)
+{
+  return SetCString(aPref, nsPrintfCString("%f", aValue).get());
+}
+
+// static
+nsresult
 Preferences::SetComplex(const char* aPref, const nsIID &aType,
                         nsISupports* aValue)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   return sRootBranch->SetComplexValue(aPref, aType, aValue);
 }
 
 // static