Bug 1415799 - Inline and remove Preferences::Init(). r=glandium
It has a single call site. MozReview-Commit-ID: A96MRRa3W5N
This commit is contained in:
@@ -3540,6 +3540,8 @@ public:
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
static InfallibleTArray<Preferences::PrefSetting>* gInitPrefs;
|
||||||
|
|
||||||
/* static */ already_AddRefed<Preferences>
|
/* static */ already_AddRefed<Preferences>
|
||||||
Preferences::GetInstanceForService()
|
Preferences::GetInstanceForService()
|
||||||
{
|
{
|
||||||
@@ -3553,13 +3555,62 @@ Preferences::GetInstanceForService()
|
|||||||
}
|
}
|
||||||
|
|
||||||
sPreferences = new Preferences();
|
sPreferences = new Preferences();
|
||||||
Result<Ok, const char*> res = sPreferences->Init();
|
|
||||||
|
MOZ_ASSERT(!gHashTable);
|
||||||
|
gHashTable = new PLDHashTable(
|
||||||
|
&pref_HashTableOps, sizeof(PrefHashEntry), PREF_HASHTABLE_INITIAL_LENGTH);
|
||||||
|
|
||||||
|
Result<Ok, const char*> res = pref_InitInitialObjects();
|
||||||
if (res.isErr()) {
|
if (res.isErr()) {
|
||||||
sPreferences = nullptr;
|
sPreferences = nullptr;
|
||||||
gCacheDataDesc = res.unwrapErr();
|
gCacheDataDesc = res.unwrapErr();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (XRE_IsContentProcess()) {
|
||||||
|
MOZ_ASSERT(gInitPrefs);
|
||||||
|
for (unsigned int i = 0; i < gInitPrefs->Length(); i++) {
|
||||||
|
Preferences::SetPreference(gInitPrefs->ElementAt(i));
|
||||||
|
}
|
||||||
|
delete gInitPrefs;
|
||||||
|
gInitPrefs = nullptr;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Check if there is a deployment configuration file. If so, set up the
|
||||||
|
// pref config machinery, which will actually read the file.
|
||||||
|
nsAutoCString lockFileName;
|
||||||
|
nsresult rv =
|
||||||
|
PREF_GetCStringPref("general.config.filename", lockFileName, false);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
NS_CreateServicesFromCategory(
|
||||||
|
"pref-config-startup",
|
||||||
|
static_cast<nsISupports*>(static_cast<void*>(sPreferences)),
|
||||||
|
"pref-config-startup");
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIObserverService> observerService =
|
||||||
|
mozilla::services::GetObserverService();
|
||||||
|
if (!observerService) {
|
||||||
|
sPreferences = nullptr;
|
||||||
|
gCacheDataDesc = "GetObserverService() failed (1)";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
observerService->AddObserver(
|
||||||
|
sPreferences, "profile-before-change-telemetry", true);
|
||||||
|
rv =
|
||||||
|
observerService->AddObserver(sPreferences, "profile-before-change", true);
|
||||||
|
|
||||||
|
observerService->AddObserver(
|
||||||
|
sPreferences, "suspend_process_notification", true);
|
||||||
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
sPreferences = nullptr;
|
||||||
|
gCacheDataDesc = "AddObserver(\"profile-before-change\") failed";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gCacheData = new nsTArray<nsAutoPtr<CacheData>>();
|
gCacheData = new nsTArray<nsAutoPtr<CacheData>>();
|
||||||
gCacheDataDesc = "set by GetInstanceForService()";
|
gCacheDataDesc = "set by GetInstanceForService()";
|
||||||
|
|
||||||
@@ -3658,68 +3709,12 @@ NS_INTERFACE_MAP_END
|
|||||||
// nsIPrefService Implementation
|
// nsIPrefService Implementation
|
||||||
//
|
//
|
||||||
|
|
||||||
static InfallibleTArray<Preferences::PrefSetting>* gInitPrefs;
|
|
||||||
|
|
||||||
/* static */ void
|
/* static */ void
|
||||||
Preferences::SetInitPreferences(nsTArray<PrefSetting>* aPrefs)
|
Preferences::SetInitPreferences(nsTArray<PrefSetting>* aPrefs)
|
||||||
{
|
{
|
||||||
gInitPrefs = new InfallibleTArray<PrefSetting>(mozilla::Move(*aPrefs));
|
gInitPrefs = new InfallibleTArray<PrefSetting>(mozilla::Move(*aPrefs));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Ok, const char*>
|
|
||||||
Preferences::Init()
|
|
||||||
{
|
|
||||||
MOZ_ASSERT(!gHashTable);
|
|
||||||
gHashTable = new PLDHashTable(
|
|
||||||
&pref_HashTableOps, sizeof(PrefHashEntry), PREF_HASHTABLE_INITIAL_LENGTH);
|
|
||||||
|
|
||||||
MOZ_TRY(pref_InitInitialObjects());
|
|
||||||
|
|
||||||
if (XRE_IsContentProcess()) {
|
|
||||||
MOZ_ASSERT(gInitPrefs);
|
|
||||||
for (unsigned int i = 0; i < gInitPrefs->Length(); i++) {
|
|
||||||
Preferences::SetPreference(gInitPrefs->ElementAt(i));
|
|
||||||
}
|
|
||||||
delete gInitPrefs;
|
|
||||||
gInitPrefs = nullptr;
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
nsAutoCString lockFileName;
|
|
||||||
|
|
||||||
// The following is a small hack which will allow us to only load the library
|
|
||||||
// which supports the netscape.cfg file if the preference is defined. We
|
|
||||||
// test for the existence of the pref, set in the all.js (mozilla) or
|
|
||||||
// all-ns.js (netscape 6), and if it exists we startup the pref config
|
|
||||||
// category which will do the rest.
|
|
||||||
|
|
||||||
nsresult rv =
|
|
||||||
PREF_GetCStringPref("general.config.filename", lockFileName, false);
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
NS_CreateServicesFromCategory(
|
|
||||||
"pref-config-startup",
|
|
||||||
static_cast<nsISupports*>(static_cast<void*>(this)),
|
|
||||||
"pref-config-startup");
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIObserverService> observerService =
|
|
||||||
mozilla::services::GetObserverService();
|
|
||||||
if (!observerService) {
|
|
||||||
return Err("GetObserverService() failed (1)");
|
|
||||||
}
|
|
||||||
|
|
||||||
observerService->AddObserver(this, "profile-before-change-telemetry", true);
|
|
||||||
rv = observerService->AddObserver(this, "profile-before-change", true);
|
|
||||||
|
|
||||||
observerService->AddObserver(this, "suspend_process_notification", true);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
return Err("AddObserver(\"profile-before-change\") failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static */ void
|
/* static */ void
|
||||||
Preferences::InitializeUserPrefs()
|
Preferences::InitializeUserPrefs()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,11 +45,6 @@ enum pref_initPhase
|
|||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
struct Ok;
|
|
||||||
|
|
||||||
template<typename V, typename E>
|
|
||||||
class Result;
|
|
||||||
|
|
||||||
namespace dom {
|
namespace dom {
|
||||||
class PrefSetting;
|
class PrefSetting;
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
@@ -70,8 +65,6 @@ public:
|
|||||||
|
|
||||||
Preferences();
|
Preferences();
|
||||||
|
|
||||||
mozilla::Result<Ok, const char*> Init();
|
|
||||||
|
|
||||||
// Returns true if the Preferences service is available, false otherwise.
|
// Returns true if the Preferences service is available, false otherwise.
|
||||||
static bool IsServiceAvailable();
|
static bool IsServiceAvailable();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user