Bug 344059: Don't write search prefs. on shutdown unless something has changed, patch by Adam Guthrie <ispiked@gmail.com>, r=me

This commit is contained in:
gavin%gavinsharp.com 2006-07-27 21:54:53 +00:00
Родитель 8ce53c83e5
Коммит 85f0bb938d
1 изменённых файлов: 23 добавлений и 2 удалений

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

@ -2148,6 +2148,9 @@ function SearchService() {
SearchService.prototype = {
_engines: { },
_sortedEngines: null,
// Whether or not we need to write the order of engines on shutdown. This
// needs to happen anytime _sortedEngines is modified after initial startup.
_needToSetOrderPrefs: false,
_init: function() {
engineMetadataService.init();
@ -2217,8 +2220,10 @@ SearchService.prototype = {
// has already been built (i.e. if this._sortedEngines is non-null). If
// it hasn't, we're still loading engines from disk, and will build the
// sorted engine list when that initial loading is done.
if (this._sortedEngines)
if (this._sortedEngines) {
this._sortedEngines.push(aEngine);
this._needToSetOrderPrefs = true;
}
notifyAction(aEngine, SEARCH_ENGINE_ADDED);
}
@ -2306,6 +2311,10 @@ SearchService.prototype = {
},
_saveSortedEngineList: function SRCH_SVC_saveSortedEngineList() {
// We only need to write the prefs. if something has changed.
if (!this._needToSetOrderPrefs)
return;
var engines = this._getSortedEngines(true);
var values = [];
var names = [];
@ -2334,11 +2343,17 @@ SearchService.prototype = {
if (orderNumber && !this._sortedEngines[orderNumber-1]) {
this._sortedEngines[orderNumber-1] = engine;
addedEngines[engine.name] = engine;
} else {
// We need to call _saveSortedEngines so this gets sorted out.
this._needToSetOrderPrefs = true;
}
}
// Filter out any nulls for engines that may have been removed
this._sortedEngines = this._sortedEngines.filter(function(a) { return !!a; });
var filteredEngines = this._sortedEngines.filter(function(a) { return !!a; });
if (this._sortedEngines.length != filteredEngines.length)
this._needToSetOrderPrefs = true;
this._sortedEngines = filteredEngines;
// Array for the remaining engines, alphabetically sorted
var alphaEngines = [];
@ -2611,6 +2626,9 @@ SearchService.prototype = {
delete this._engines[engineToRemove.name];
notifyAction(engineToRemove, SEARCH_ENGINE_REMOVED);
// Since we removed an engine, we need to update the preferences.
this._needToSetOrderPrefs = true;
}
},
@ -2631,6 +2649,9 @@ SearchService.prototype = {
this._sortedEngines.splice(aNewIndex, 0, movedEngine);
notifyAction(engine, SEARCH_ENGINE_CHANGED);
// Since we moved an engine, we need to update the preferences.
this._needToSetOrderPrefs = true;
},
restoreDefaultEngines: function SRCH_SVC_resetDefaultEngines() {