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 "MainThreadUtils.h"
#include "mozilla/gfx/Preferences.h"
#include "nsXULAppAPI.h"
using namespace mozilla;
@ -51,6 +52,13 @@ gfxPrefs::SingletonExists()
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();
mMoz2DPrefAccess = new PreferenceAccessImpl;
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");
}
// 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,
const char* aPref,
bool aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::AddBoolVarCache(aVariable, aPref, aDefault);
}
@ -83,6 +101,7 @@ void gfxPrefs::PrefAddVarCache(int32_t* aVariable,
const char* aPref,
int32_t aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::AddIntVarCache(aVariable, aPref, aDefault);
}
@ -90,6 +109,7 @@ void gfxPrefs::PrefAddVarCache(uint32_t* aVariable,
const char* aPref,
uint32_t aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::AddUintVarCache(aVariable, aPref, aDefault);
}
@ -97,46 +117,55 @@ void gfxPrefs::PrefAddVarCache(float* aVariable,
const char* aPref,
float aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::AddFloatVarCache(aVariable, aPref, aDefault);
}
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)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
return Preferences::GetInt(aPref, aDefault);
}
uint32_t gfxPrefs::PrefGet(const char* aPref, uint32_t aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
return Preferences::GetUint(aPref, aDefault);
}
float gfxPrefs::PrefGet(const char* aPref, float aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
return Preferences::GetFloat(aPref, aDefault);
}
void gfxPrefs::PrefSet(const char* aPref, bool aValue)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::SetBool(aPref, aValue);
}
void gfxPrefs::PrefSet(const char* aPref, int32_t aValue)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::SetInt(aPref, aValue);
}
void gfxPrefs::PrefSet(const char* aPref, uint32_t aValue)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::SetUint(aPref, aValue);
}
void gfxPrefs::PrefSet(const char* aPref, float aValue)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::SetFloat(aPref, aValue);
}

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

@ -84,26 +84,30 @@ private:
};
// 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
{
public:
PrefTemplate()
: 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)
{
AssertMainThread();
switch(aUpdate) {
switch (aUpdate) {
case UpdatePolicy::Skip:
break;
case UpdatePolicy::Once:
mValue = PrefGet(aPreference, mValue);
break;
case UpdatePolicy::Live:
PrefAddVarCache(&mValue,aPreference, mValue);
PrefAddVarCache(&mValue, aPreference, mValue);
break;
default:
MOZ_CRASH("Incomplete switch");
@ -493,6 +497,7 @@ private:
static bool sInstanceHasBeenDestroyed;
private:
static bool IsPrefsServiceAvailable();
// 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);

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

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

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

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