Bug 1318618 - Support nsCString data type in gfxPrefs; r?dvander draft
authorDaosheng Mu <daoshengmu@gmail.com>
Wed, 23 Nov 2016 09:38:02 +0800
changeset 442699 b88ad06ea819d5ec3c0dd7f6d4f9b46599cb31a9
parent 440454 05e5b12f41df270b31955ff7e6d09245c1f83a7a
child 537868 04a8fb5a04e39a293ea2e9834f59024a98cf4b95
push id36787
push userbmo:dmu@mozilla.com
push dateWed, 23 Nov 2016 02:22:39 +0000
reviewersdvander
bugs1318618
milestone53.0a1
Bug 1318618 - Support nsCString data type in gfxPrefs; r?dvander MozReview-Commit-ID: w5051nuVR5
gfx/ipc/PGPU.ipdl
gfx/thebes/gfxPrefs.cpp
gfx/thebes/gfxPrefs.h
--- a/gfx/ipc/PGPU.ipdl
+++ b/gfx/ipc/PGPU.ipdl
@@ -20,16 +20,17 @@ using mozilla::Telemetry::KeyedAccumulat
 namespace mozilla {
 namespace gfx {
 
 union GfxPrefValue {
   bool;
   int32_t;
   uint32_t;
   float;
+  nsCString;
 };
 
 struct GfxPrefSetting {
   int32_t index;
   GfxPrefValue value;
 };
 
 struct LayerTreeIdMapping {
--- a/gfx/thebes/gfxPrefs.cpp
+++ b/gfx/thebes/gfxPrefs.cpp
@@ -153,16 +153,24 @@ void gfxPrefs::PrefAddVarCache(uint32_t*
 void gfxPrefs::PrefAddVarCache(float* aVariable,
                                const char* aPref,
                                float aDefault)
 {
   MOZ_ASSERT(IsPrefsServiceAvailable());
   Preferences::AddFloatVarCache(aVariable, aPref, aDefault);
 }
 
+void gfxPrefs::PrefAddVarCache(std::string* aVariable,
+                               const char* aPref,
+                               std::string aDefault)
+{
+  MOZ_ASSERT(IsPrefsServiceAvailable());
+  Preferences::SetCString(aPref, aVariable->c_str());
+}
+
 bool gfxPrefs::PrefGet(const char* aPref, bool aDefault)
 {
   MOZ_ASSERT(IsPrefsServiceAvailable());
   return Preferences::GetBool(aPref, aDefault);
 }
 
 int32_t gfxPrefs::PrefGet(const char* aPref, int32_t aDefault)
 {
@@ -177,16 +185,26 @@ uint32_t gfxPrefs::PrefGet(const char* a
 }
 
 float gfxPrefs::PrefGet(const char* aPref, float aDefault)
 {
   MOZ_ASSERT(IsPrefsServiceAvailable());
   return Preferences::GetFloat(aPref, aDefault);
 }
 
+
+std::string gfxPrefs::PrefGet(const char* aPref, std::string aDefault)
+{
+  MOZ_ASSERT(IsPrefsServiceAvailable());
+
+  nsAdoptingCString result;
+  Preferences::GetCString(aPref, &result);
+  return result.get();
+}
+
 void gfxPrefs::PrefSet(const char* aPref, bool aValue)
 {
   MOZ_ASSERT(IsPrefsServiceAvailable());
   Preferences::SetBool(aPref, aValue);
 }
 
 void gfxPrefs::PrefSet(const char* aPref, int32_t aValue)
 {
@@ -201,16 +219,22 @@ void gfxPrefs::PrefSet(const char* aPref
 }
 
 void gfxPrefs::PrefSet(const char* aPref, float aValue)
 {
   MOZ_ASSERT(IsPrefsServiceAvailable());
   Preferences::SetFloat(aPref, aValue);
 }
 
+void gfxPrefs::PrefSet(const char* aPref, std::string aValue)
+{
+  MOZ_ASSERT(IsPrefsServiceAvailable());
+  Preferences::SetCString(aPref, aValue.c_str());
+}
+
 static void
 OnGfxPrefChanged(const char* aPrefname, void* aClosure)
 {
   reinterpret_cast<gfxPrefs::Pref*>(aClosure)->OnChange();
 }
 
 void gfxPrefs::WatchChanges(const char* aPrefname, Pref* aPref)
 {
@@ -241,16 +265,21 @@ void gfxPrefs::CopyPrefValue(const uint3
   *aOutValue = *aValue;
 }
 
 void gfxPrefs::CopyPrefValue(const float* aValue, GfxPrefValue* aOutValue)
 {
   *aOutValue = *aValue;
 }
 
+void gfxPrefs::CopyPrefValue(const std::string* aValue, GfxPrefValue* aOutValue)
+{
+  *aOutValue = nsCString(aValue->c_str());
+}
+
 void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, bool* aOutValue)
 {
   *aOutValue = aValue->get_bool();
 }
 
 void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, int32_t* aOutValue)
 {
   *aOutValue = aValue->get_int32_t();
@@ -260,8 +289,13 @@ void gfxPrefs::CopyPrefValue(const GfxPr
 {
   *aOutValue = aValue->get_uint32_t();
 }
 
 void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, float* aOutValue)
 {
   *aOutValue = aValue->get_float();
 }
+
+void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, std::string* aOutValue)
+{
+  *aOutValue = aValue->get_nsCString().get();
+}
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_PREFS_H
 #define GFX_PREFS_H
 
 #include <cmath>                 // for M_PI
 #include <stdint.h>
+#include <string>
 #include "mozilla/Assertions.h"
 #include "mozilla/Function.h"
 #include "mozilla/gfx/LoggingConstants.h"
 #include "nsTArray.h"
 
 // First time gfxPrefs::GetSingleton() needs to be called on the main thread,
 // before any of the methods accessing the values are used, but after
 // the Preferences system has been initialized.
@@ -637,35 +638,40 @@ private:
 
   static bool IsPrefsServiceAvailable();
   static bool IsParentProcess();
   // Creating these to avoid having to include Preferences.h in the .h
   static void PrefAddVarCache(bool*, const char*, bool);
   static void PrefAddVarCache(int32_t*, const char*, int32_t);
   static void PrefAddVarCache(uint32_t*, const char*, uint32_t);
   static void PrefAddVarCache(float*, const char*, float);
+  static void PrefAddVarCache(std::string*, const char*, std::string);
   static bool PrefGet(const char*, bool);
   static int32_t PrefGet(const char*, int32_t);
   static uint32_t PrefGet(const char*, uint32_t);
   static float PrefGet(const char*, float);
+  static std::string PrefGet(const char*, std::string);
   static void PrefSet(const char* aPref, bool aValue);
   static void PrefSet(const char* aPref, int32_t aValue);
   static void PrefSet(const char* aPref, uint32_t aValue);
   static void PrefSet(const char* aPref, float aValue);
+  static void PrefSet(const char* aPref, std::string aValue);
   static void WatchChanges(const char* aPrefname, Pref* aPref);
   static void UnwatchChanges(const char* aPrefname, Pref* aPref);
   // Creating these to avoid having to include PGPU.h in the .h
   static void CopyPrefValue(const bool* aValue, GfxPrefValue* aOutValue);
   static void CopyPrefValue(const int32_t* aValue, GfxPrefValue* aOutValue);
   static void CopyPrefValue(const uint32_t* aValue, GfxPrefValue* aOutValue);
   static void CopyPrefValue(const float* aValue, GfxPrefValue* aOutValue);
+  static void CopyPrefValue(const std::string* aValue, GfxPrefValue* aOutValue);
   static void CopyPrefValue(const GfxPrefValue* aValue, bool* aOutValue);
   static void CopyPrefValue(const GfxPrefValue* aValue, int32_t* aOutValue);
   static void CopyPrefValue(const GfxPrefValue* aValue, uint32_t* aOutValue);
   static void CopyPrefValue(const GfxPrefValue* aValue, float* aOutValue);
+  static void CopyPrefValue(const GfxPrefValue* aValue, std::string* aOutValue);
 
   static void AssertMainThread();
 
   gfxPrefs();
   ~gfxPrefs();
   gfxPrefs(const gfxPrefs&) = delete;
   gfxPrefs& operator=(const gfxPrefs&) = delete;
 };