Bug 753175 - Race condition in Sync Migration / Preference:Get. r=gcp

This commit is contained in:
Margaret Leibovic 2012-05-09 10:20:10 -07:00
parent 46b7d48326
commit 4f91da8e6a

View File

@ -518,7 +518,12 @@ public class ProfileMigrator {
// This includes personal info, so don't log.
// Log.d(LOGTAG, "Message: " + message.toString());
JSONArray jsonPrefs = message.getJSONArray("preferences");
parsePrefs(jsonPrefs);
// Check that the batch of preferences we got notified of are in
// the ones we requested and not those requested by other java code.
if (!parsePrefs(jsonPrefs))
return;
GeckoAppShell.unregisterGeckoEventListener("Preferences:Data",
(GeckoEventListener)this);
@ -576,12 +581,18 @@ public class ProfileMigrator {
return result;
}
protected void parsePrefs(JSONArray jsonPrefs) {
// Returns true if we sucessfully got the preferences we requested.
protected boolean parsePrefs(JSONArray jsonPrefs) {
try {
final int length = jsonPrefs.length();
for (int i = 0; i < length; i++) {
JSONObject jPref = jsonPrefs.getJSONObject(i);
final String prefName = jPref.getString("name");
// Check to make sure we're working with preferences we requested.
if (!mSyncSettingsList.contains(prefName))
return false;
final String prefType = jPref.getString("type");
if ("bool".equals(prefType)) {
final boolean value = jPref.getBoolean("value");
@ -599,7 +610,10 @@ public class ProfileMigrator {
} catch (JSONException e) {
Log.e(LOGTAG, "Exception handling preferences answer: "
+ e.getMessage());
return false;
}
return true;
}
protected void configureSync() {