Don't initialize gfxPrefs with libpref in the GPU process. (bug 1280822 part 1, r=milan)

This commit is contained in:
David Anderson 2016-06-26 23:33:14 -07:00
Родитель a4ac8392bb
Коммит d1ac63e903
4 изменённых файлов: 50 добавлений и 4 удалений

Просмотреть файл

@ -8,6 +8,7 @@
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "MainThreadUtils.h" #include "MainThreadUtils.h"
#include "mozilla/gfx/Preferences.h" #include "mozilla/gfx/Preferences.h"
#include "nsXULAppAPI.h"
using namespace mozilla; using namespace mozilla;
@ -51,6 +52,13 @@ gfxPrefs::SingletonExists()
gfxPrefs::gfxPrefs() gfxPrefs::gfxPrefs()
{ {
// UI, content, and plugin processes use XPCOM and should have prefs
// ready by the time we initialize gfxPrefs.
MOZ_ASSERT_IF(XRE_IsContentProcess() ||
XRE_IsParentProcess() ||
XRE_GetProcessType() == GeckoProcessType_Plugin,
Preferences::IsServiceAvailable());
gfxPrefs::AssertMainThread(); gfxPrefs::AssertMainThread();
mMoz2DPrefAccess = new PreferenceAccessImpl; mMoz2DPrefAccess = new PreferenceAccessImpl;
mozilla::gfx::PreferenceAccess::SetAccess(mMoz2DPrefAccess); mozilla::gfx::PreferenceAccess::SetAccess(mMoz2DPrefAccess);
@ -72,10 +80,20 @@ void gfxPrefs::AssertMainThread()
MOZ_ASSERT(NS_IsMainThread(), "this code must be run on the main thread"); MOZ_ASSERT(NS_IsMainThread(), "this code must be run on the main thread");
} }
// On lightweight processes such as for GMP and GPU, XPCOM is not initialized,
// and therefore we don't have access to Preferences. When XPCOM is not
// available we rely on manual synchronization of gfxPrefs values over IPC.
/* static */ bool
gfxPrefs::IsPrefsServiceAvailable()
{
return Preferences::IsServiceAvailable();
}
void gfxPrefs::PrefAddVarCache(bool* aVariable, void gfxPrefs::PrefAddVarCache(bool* aVariable,
const char* aPref, const char* aPref,
bool aDefault) bool aDefault)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::AddBoolVarCache(aVariable, aPref, aDefault); Preferences::AddBoolVarCache(aVariable, aPref, aDefault);
} }
@ -83,6 +101,7 @@ void gfxPrefs::PrefAddVarCache(int32_t* aVariable,
const char* aPref, const char* aPref,
int32_t aDefault) int32_t aDefault)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::AddIntVarCache(aVariable, aPref, aDefault); Preferences::AddIntVarCache(aVariable, aPref, aDefault);
} }
@ -90,6 +109,7 @@ void gfxPrefs::PrefAddVarCache(uint32_t* aVariable,
const char* aPref, const char* aPref,
uint32_t aDefault) uint32_t aDefault)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::AddUintVarCache(aVariable, aPref, aDefault); Preferences::AddUintVarCache(aVariable, aPref, aDefault);
} }
@ -97,46 +117,55 @@ void gfxPrefs::PrefAddVarCache(float* aVariable,
const char* aPref, const char* aPref,
float aDefault) float aDefault)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::AddFloatVarCache(aVariable, aPref, aDefault); Preferences::AddFloatVarCache(aVariable, aPref, aDefault);
} }
bool gfxPrefs::PrefGet(const char* aPref, bool aDefault) bool gfxPrefs::PrefGet(const char* aPref, bool aDefault)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
return Preferences::GetBool(aPref, aDefault); return Preferences::GetBool(aPref, aDefault);
} }
int32_t gfxPrefs::PrefGet(const char* aPref, int32_t aDefault) int32_t gfxPrefs::PrefGet(const char* aPref, int32_t aDefault)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
return Preferences::GetInt(aPref, aDefault); return Preferences::GetInt(aPref, aDefault);
} }
uint32_t gfxPrefs::PrefGet(const char* aPref, uint32_t aDefault) uint32_t gfxPrefs::PrefGet(const char* aPref, uint32_t aDefault)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
return Preferences::GetUint(aPref, aDefault); return Preferences::GetUint(aPref, aDefault);
} }
float gfxPrefs::PrefGet(const char* aPref, float aDefault) float gfxPrefs::PrefGet(const char* aPref, float aDefault)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
return Preferences::GetFloat(aPref, aDefault); return Preferences::GetFloat(aPref, aDefault);
} }
void gfxPrefs::PrefSet(const char* aPref, bool aValue) void gfxPrefs::PrefSet(const char* aPref, bool aValue)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::SetBool(aPref, aValue); Preferences::SetBool(aPref, aValue);
} }
void gfxPrefs::PrefSet(const char* aPref, int32_t aValue) void gfxPrefs::PrefSet(const char* aPref, int32_t aValue)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::SetInt(aPref, aValue); Preferences::SetInt(aPref, aValue);
} }
void gfxPrefs::PrefSet(const char* aPref, uint32_t aValue) void gfxPrefs::PrefSet(const char* aPref, uint32_t aValue)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::SetUint(aPref, aValue); Preferences::SetUint(aPref, aValue);
} }
void gfxPrefs::PrefSet(const char* aPref, float aValue) void gfxPrefs::PrefSet(const char* aPref, float aValue)
{ {
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::SetFloat(aPref, aValue); Preferences::SetFloat(aPref, aValue);
} }

Просмотреть файл

@ -84,26 +84,30 @@ private:
}; };
// Since we cannot use const char*, use a function that returns it. // Since we cannot use const char*, use a function that returns it.
template <UpdatePolicy Update, class T, T Default(void), const char* Pref(void)> template <UpdatePolicy Update, class T, T Default(void), const char* Prefname(void)>
class PrefTemplate class PrefTemplate
{ {
public: public:
PrefTemplate() PrefTemplate()
: mValue(Default()) : mValue(Default())
{ {
Register(Update, Pref()); // If not using the Preferences service, values are synced over IPC, so
// there's no need to register us as a Preferences observer.
if (IsPrefsServiceAvailable()) {
Register(Update, Prefname());
}
} }
void Register(UpdatePolicy aUpdate, const char* aPreference) void Register(UpdatePolicy aUpdate, const char* aPreference)
{ {
AssertMainThread(); AssertMainThread();
switch(aUpdate) { switch (aUpdate) {
case UpdatePolicy::Skip: case UpdatePolicy::Skip:
break; break;
case UpdatePolicy::Once: case UpdatePolicy::Once:
mValue = PrefGet(aPreference, mValue); mValue = PrefGet(aPreference, mValue);
break; break;
case UpdatePolicy::Live: case UpdatePolicy::Live:
PrefAddVarCache(&mValue,aPreference, mValue); PrefAddVarCache(&mValue, aPreference, mValue);
break; break;
default: default:
MOZ_CRASH("Incomplete switch"); MOZ_CRASH("Incomplete switch");
@ -493,6 +497,7 @@ private:
static bool sInstanceHasBeenDestroyed; static bool sInstanceHasBeenDestroyed;
private: private:
static bool IsPrefsServiceAvailable();
// Creating these to avoid having to include Preferences.h in the .h // Creating these to avoid having to include Preferences.h in the .h
static void PrefAddVarCache(bool*, const char*, bool); static void PrefAddVarCache(bool*, const char*, bool);
static void PrefAddVarCache(int32_t*, const char*, int32_t); static void PrefAddVarCache(int32_t*, const char*, int32_t);

Просмотреть файл

@ -433,6 +433,13 @@ Preferences::GetInstanceForService()
return sPreferences; return sPreferences;
} }
// static
bool
Preferences::IsServiceAvailable()
{
return !!sPreferences;
}
// static // static
bool bool
Preferences::InitStaticMembers() Preferences::InitStaticMembers()

Просмотреть файл

@ -51,6 +51,11 @@ public:
nsresult Init(); nsresult Init();
/**
* Returns true if the Preferences service is available, false otherwise.
*/
static bool IsServiceAvailable();
/** /**
* Reset loaded user prefs then read them * Reset loaded user prefs then read them
*/ */