Bug 1203161 - remove the browser.search.cache.enabled pref, r=adw.

This commit is contained in:
Florian Quèze 2015-09-11 14:18:15 +02:00
Родитель 8263535ca5
Коммит 02fc488f62
1 изменённых файлов: 52 добавлений и 72 удалений

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

@ -2074,57 +2074,54 @@ Engine.prototype = {
case "https": case "https":
case "ftp": case "ftp":
// No use downloading the icon if the engine file is read-only // No use downloading the icon if the engine file is read-only
if (!this._readOnly || LOG("_setIcon: Downloading icon: \"" + uri.spec +
getBoolPref(BROWSER_SEARCH_PREF + "cache.enabled", true)) { "\" for engine: \"" + this.name + "\"");
LOG("_setIcon: Downloading icon: \"" + uri.spec + var chan = NetUtil.ioService.newChannelFromURI2(uri,
"\" for engine: \"" + this.name + "\""); null, // aLoadingNode
var chan = NetUtil.ioService.newChannelFromURI2(uri, Services.scriptSecurityManager.getSystemPrincipal(),
null, // aLoadingNode null, // aTriggeringPrincipal
Services.scriptSecurityManager.getSystemPrincipal(), Ci.nsILoadInfo.SEC_NORMAL,
null, // aTriggeringPrincipal Ci.nsIContentPolicy.TYPE_IMAGE);
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE);
let iconLoadCallback = function (aByteArray, aEngine) { let iconLoadCallback = function (aByteArray, aEngine) {
// This callback may run after we've already set a preferred icon, // This callback may run after we've already set a preferred icon,
// so check again. // so check again.
if (aEngine._hasPreferredIcon && !aIsPreferred) if (aEngine._hasPreferredIcon && !aIsPreferred)
return; return;
if (!aByteArray || aByteArray.length > MAX_ICON_SIZE) { if (!aByteArray || aByteArray.length > MAX_ICON_SIZE) {
LOG("iconLoadCallback: load failed, or the icon was too large!"); LOG("iconLoadCallback: load failed, or the icon was too large!");
return; return;
}
var str = btoa(String.fromCharCode.apply(null, aByteArray));
let dataURL = ICON_DATAURL_PREFIX + str;
aEngine._iconURI = makeURI(dataURL);
if (aWidth && aHeight) {
aEngine._addIconToMap(aWidth, aHeight, dataURL)
}
// The engine might not have a file yet, if it's being downloaded,
// because the request for the engine file itself (_onLoad) may not
// yet be complete. In that case, this change will be written to
// file when _onLoad is called. For readonly engines, we'll store
// the changes in the cache once notified below.
if (aEngine._file && !aEngine._readOnly)
aEngine._serializeToFile();
notifyAction(aEngine, SEARCH_ENGINE_CHANGED);
aEngine._hasPreferredIcon = aIsPreferred;
} }
// If we're currently acting as an "update engine", then the callback var str = btoa(String.fromCharCode.apply(null, aByteArray));
// should set the icon on the engine we're updating and not us, since let dataURL = ICON_DATAURL_PREFIX + str;
// |this| might be gone by the time the callback runs. aEngine._iconURI = makeURI(dataURL);
var engineToSet = this._engineToUpdate || this;
var listener = new loadListener(chan, engineToSet, iconLoadCallback); if (aWidth && aHeight) {
chan.notificationCallbacks = listener; aEngine._addIconToMap(aWidth, aHeight, dataURL)
chan.asyncOpen(listener, null); }
// The engine might not have a file yet, if it's being downloaded,
// because the request for the engine file itself (_onLoad) may not
// yet be complete. In that case, this change will be written to
// file when _onLoad is called. For readonly engines, we'll store
// the changes in the cache once notified below.
if (aEngine._file && !aEngine._readOnly)
aEngine._serializeToFile();
notifyAction(aEngine, SEARCH_ENGINE_CHANGED);
aEngine._hasPreferredIcon = aIsPreferred;
} }
// If we're currently acting as an "update engine", then the callback
// should set the icon on the engine we're updating and not us, since
// |this| might be gone by the time the callback runs.
var engineToSet = this._engineToUpdate || this;
var listener = new loadListener(chan, engineToSet, iconLoadCallback);
chan.notificationCallbacks = listener;
chan.asyncOpen(listener, null);
break; break;
} }
}, },
@ -3614,9 +3611,6 @@ SearchService.prototype = {
}, },
_buildCache: function SRCH_SVC__buildCache() { _buildCache: function SRCH_SVC__buildCache() {
if (!getBoolPref(BROWSER_SEARCH_PREF + "cache.enabled", true))
return;
TelemetryStopwatch.start("SEARCH_SERVICE_BUILD_CACHE_MS"); TelemetryStopwatch.start("SEARCH_SERVICE_BUILD_CACHE_MS");
let cache = {}; let cache = {};
let locale = getLocale(); let locale = getLocale();
@ -3697,13 +3691,10 @@ SearchService.prototype = {
LOG("_syncLoadEngines: start"); LOG("_syncLoadEngines: start");
// See if we have a cache file so we don't have to parse a bunch of XML. // See if we have a cache file so we don't have to parse a bunch of XML.
let cache = {}; let cache = {};
let cacheEnabled = getBoolPref(BROWSER_SEARCH_PREF + "cache.enabled", true); let cacheFile = getDir(NS_APP_USER_PROFILE_50_DIR);
if (cacheEnabled) { cacheFile.append("search.json");
let cacheFile = getDir(NS_APP_USER_PROFILE_50_DIR); if (cacheFile.exists())
cacheFile.append("search.json"); cache = this._readCacheFile(cacheFile);
if (cacheFile.exists())
cache = this._readCacheFile(cacheFile);
}
let [chromeFiles, chromeURIs] = this._findJAREngines(); let [chromeFiles, chromeURIs] = this._findJAREngines();
@ -3756,7 +3747,7 @@ SearchService.prototype = {
this._visibleDefaultEngines.some(notInCacheVisibleEngines) || this._visibleDefaultEngines.some(notInCacheVisibleEngines) ||
toLoad.some(modifiedDir); toLoad.some(modifiedDir);
if (!cacheEnabled || rebuildCache) { if (rebuildCache) {
LOG("_loadEngines: Absent or outdated cache. Loading engines from disk."); LOG("_loadEngines: Absent or outdated cache. Loading engines from disk.");
distDirs.forEach(this._loadEnginesFromDir, this); distDirs.forEach(this._loadEnginesFromDir, this);
@ -3764,8 +3755,7 @@ SearchService.prototype = {
otherDirs.forEach(this._loadEnginesFromDir, this); otherDirs.forEach(this._loadEnginesFromDir, this);
if (cacheEnabled) this._buildCache();
this._buildCache();
return; return;
} }
@ -3787,11 +3777,8 @@ SearchService.prototype = {
LOG("_asyncLoadEngines: start"); LOG("_asyncLoadEngines: start");
// See if we have a cache file so we don't have to parse a bunch of XML. // See if we have a cache file so we don't have to parse a bunch of XML.
let cache = {}; let cache = {};
let cacheEnabled = getBoolPref(BROWSER_SEARCH_PREF + "cache.enabled", true); let cacheFilePath = OS.Path.join(OS.Constants.Path.profileDir, "search.json");
if (cacheEnabled) { cache = yield checkForSyncCompletion(this._asyncReadCacheFile(cacheFilePath));
let cacheFilePath = OS.Path.join(OS.Constants.Path.profileDir, "search.json");
cache = yield checkForSyncCompletion(this._asyncReadCacheFile(cacheFilePath));
}
Services.obs.notifyObservers(null, SEARCH_SERVICE_TOPIC, "find-jar-engines"); Services.obs.notifyObservers(null, SEARCH_SERVICE_TOPIC, "find-jar-engines");
let [chromeFiles, chromeURIs] = let [chromeFiles, chromeURIs] =
@ -3882,7 +3869,7 @@ SearchService.prototype = {
this._visibleDefaultEngines.some(notInCacheVisibleEngines) || this._visibleDefaultEngines.some(notInCacheVisibleEngines) ||
(yield checkForSyncCompletion(hasModifiedDir(toLoad))); (yield checkForSyncCompletion(hasModifiedDir(toLoad)));
if (!cacheEnabled || rebuildCache) { if (rebuildCache) {
LOG("_asyncLoadEngines: Absent or outdated cache. Loading engines from disk."); LOG("_asyncLoadEngines: Absent or outdated cache. Loading engines from disk.");
let engines = []; let engines = [];
for (let loadDir of distDirs) { for (let loadDir of distDirs) {
@ -3902,8 +3889,7 @@ SearchService.prototype = {
for (let engine of engines) { for (let engine of engines) {
this._addEngineToStore(engine); this._addEngineToStore(engine);
} }
if (cacheEnabled) this._buildCache();
this._buildCache();
return; return;
} }
@ -5545,12 +5531,6 @@ var engineUpdateService = {
if (!getBoolPref(BROWSER_SEARCH_PREF + "update", true) || !engine._hasUpdates) if (!getBoolPref(BROWSER_SEARCH_PREF + "update", true) || !engine._hasUpdates)
return; return;
// We use the cache to store updated app engines, so refuse to update if the
// cache is disabled.
if (engine._readOnly &&
!getBoolPref(BROWSER_SEARCH_PREF + "cache.enabled", true))
return;
let testEngine = null; let testEngine = null;
let updateURL = engine._getURLOfType(URLTYPE_OPENSEARCH); let updateURL = engine._getURLOfType(URLTYPE_OPENSEARCH);
let updateURI = (updateURL && updateURL._hasRelation("self")) ? let updateURI = (updateURL && updateURL._hasRelation("self")) ?