зеркало из https://github.com/mozilla/gecko-dev.git
bug 859715 protect against migration failures of social providers, r=markh
This commit is contained in:
Родитель
5d442bca12
Коммит
9593d34cce
|
@ -126,20 +126,38 @@ let ActiveProviders = {
|
|||
function migrateSettings() {
|
||||
let activeProviders;
|
||||
try {
|
||||
// we don't care what the value is, if it is set, we've already migrated
|
||||
activeProviders = Services.prefs.getCharPref("social.activeProviders");
|
||||
} catch(e) {
|
||||
// do nothing
|
||||
// not set, we'll check if we need to migrate older prefs
|
||||
}
|
||||
if (activeProviders) {
|
||||
// migration from fx21 to fx22 or later
|
||||
// ensure any *builtin* provider in activeproviders is in user level prefs
|
||||
for (let origin in ActiveProviders._providers) {
|
||||
let prefname = getPrefnameFromOrigin(origin);
|
||||
let prefname;
|
||||
try {
|
||||
prefname = getPrefnameFromOrigin(origin);
|
||||
} catch(e) {
|
||||
// Our preference is missing or bad, remove from ActiveProviders and
|
||||
// continue. This is primarily an error-case and should only be
|
||||
// reached by either messing with preferences or hitting the one or
|
||||
// two days of nightly that ran into it, so we'll flush right away.
|
||||
ActiveProviders.delete(origin);
|
||||
ActiveProviders.flush();
|
||||
continue;
|
||||
}
|
||||
if (!Services.prefs.prefHasUserValue(prefname)) {
|
||||
// if we've got an active *builtin* provider, ensure that the pref
|
||||
// is set at a user-level as that will signify *installed* status.
|
||||
let manifest = JSON.parse(Services.prefs.getComplexValue(prefname, Ci.nsISupportsString).data);
|
||||
let manifest;
|
||||
try {
|
||||
manifest = JSON.parse(Services.prefs.getComplexValue(prefname, Ci.nsISupportsString).data);
|
||||
} catch(e) {
|
||||
// see comment in the delete/flush code above.
|
||||
ActiveProviders.delete(origin);
|
||||
ActiveProviders.flush();
|
||||
continue;
|
||||
}
|
||||
// our default manifests have been updated with the builtin flags as of
|
||||
// fx22, delete it so we can set the user-pref
|
||||
delete manifest.builtin;
|
||||
|
@ -167,7 +185,13 @@ function migrateSettings() {
|
|||
let prefs = manifestPrefs.getChildList("", []);
|
||||
for (let pref of prefs) {
|
||||
try {
|
||||
let manifest = JSON.parse(manifestPrefs.getComplexValue(pref, Ci.nsISupportsString).data);
|
||||
let manifest;
|
||||
try {
|
||||
manifest = JSON.parse(manifestPrefs.getComplexValue(pref, Ci.nsISupportsString).data);
|
||||
} catch(e) {
|
||||
// bad or missing preference, we wont update this one.
|
||||
continue;
|
||||
}
|
||||
if (manifest && typeof(manifest) == "object" && manifest.origin) {
|
||||
// our default manifests have been updated with the builtin flags as of
|
||||
// fx22, delete it so we can set the user-pref
|
||||
|
@ -196,7 +220,14 @@ function initService() {
|
|||
Services.obs.removeObserver(xpcomShutdown, "xpcom-shutdown");
|
||||
}, "xpcom-shutdown", false);
|
||||
|
||||
migrateSettings();
|
||||
try {
|
||||
migrateSettings();
|
||||
} catch(e) {
|
||||
// no matter what, if migration fails we do not want to render social
|
||||
// unusable. Worst case scenario is that, when upgrading Firefox, previously
|
||||
// enabled providers are not migrated.
|
||||
Cu.reportError("Error migrating social settings: " + e);
|
||||
}
|
||||
// Initialize the MozSocialAPI
|
||||
if (SocialServiceInternal.enabled)
|
||||
MozSocialAPI.enabled = true;
|
||||
|
|
|
@ -26,6 +26,8 @@ function run_test() {
|
|||
createInstance(Ci.nsISupportsString);
|
||||
let active = {};
|
||||
active[manifest.origin] = 1;
|
||||
// bad.origin tests that a missing manifest does not break migration, bug 859715
|
||||
active["bad.origin"] = 1;
|
||||
activeVal.data = JSON.stringify(active);
|
||||
Services.prefs.setComplexValue("social.activeProviders",
|
||||
Ci.nsISupportsString, activeVal);
|
||||
|
@ -57,4 +59,7 @@ function testMigration(manifest, next) {
|
|||
do_check_true(activeProviders[manifest.origin]);
|
||||
do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
|
||||
do_check_true(JSON.parse(DEFAULT_PREFS.getCharPref(manifest.origin)).builtin);
|
||||
|
||||
// bug 859715, this should have been removed during migration
|
||||
do_check_false(!!activeProviders["bad.origin"]);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче