code review: avoid redundant PSL selfie

This commit is contained in:
Raymond Hill 2018-04-06 16:02:35 -04:00
parent 79b4706746
commit 4d8974fe80
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
3 changed files with 32 additions and 44 deletions

View file

@ -132,8 +132,8 @@ var µBlock = (function() { // jshint ignore:line
// read-only // read-only
systemSettings: { systemSettings: {
compiledMagic: 'puuijtkfpspv', compiledMagic: 1,
selfieMagic: 'tuqilngsxkwo' selfieMagic: 1
}, },
restoreBackupSettings: { restoreBackupSettings: {
@ -177,11 +177,7 @@ var µBlock = (function() { // jshint ignore:line
epickerZap: false, epickerZap: false,
epickerEprom: null, epickerEprom: null,
scriptlets: { scriptlets: {},
},
// so that I don't have to care for last comma
dummy: 0
}; };
})(); })();

View file

@ -19,8 +19,6 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global publicSuffixList */
'use strict'; 'use strict';
/******************************************************************************/ /******************************************************************************/
@ -95,7 +93,12 @@ var onAllReady = function() {
// - PSL // - PSL
var onPSLReady = function() { var onPSLReady = function() {
µb.loadFilterLists(onAllReady); µb.selfieManager.load(function(valid) {
if ( valid === true ) {
return onAllReady();
}
µb.loadFilterLists(onAllReady);
});
}; };
/******************************************************************************/ /******************************************************************************/
@ -161,31 +164,6 @@ var onVersionReady = function(lastVersion) {
/******************************************************************************/ /******************************************************************************/
var onSelfieReady = function(selfie) {
if (
selfie instanceof Object === false ||
selfie.magic !== µb.systemSettings.selfieMagic
) {
return false;
}
if ( publicSuffixList.fromSelfie(selfie.publicSuffixList) !== true ) {
return false;
}
if ( selfie.redirectEngine === undefined ) {
return false;
}
µb.availableFilterLists = selfie.availableFilterLists;
µb.staticNetFilteringEngine.fromSelfie(selfie.staticNetFilteringEngine);
µb.redirectEngine.fromSelfie(selfie.redirectEngine);
µb.staticExtFilteringEngine.fromSelfie(selfie.staticExtFilteringEngine);
µb.loadRedirectResources();
return true;
};
/******************************************************************************/
// https://github.com/chrisaljoudi/uBlock/issues/226 // https://github.com/chrisaljoudi/uBlock/issues/226
// Whitelist in memory. // Whitelist in memory.
// Whitelist parser needs PSL to be ready. // Whitelist parser needs PSL to be ready.
@ -243,7 +221,7 @@ var onSystemSettingsReady = function(fetched) {
if ( mustSaveSystemSettings ) { if ( mustSaveSystemSettings ) {
fetched.selfie = null; fetched.selfie = null;
µb.selfieManager.destroy(); µb.selfieManager.destroy();
vAPI.storage.set(µb.systemSettings, µb.noopFunc); vAPI.storage.set(µb.systemSettings);
} }
}; };
@ -261,13 +239,8 @@ var onFirstFetchReady = function(fetched) {
onNetWhitelistReady(fetched.netWhitelist); onNetWhitelistReady(fetched.netWhitelist);
onVersionReady(fetched.version); onVersionReady(fetched.version);
// If we have a selfie, skip loading PSL, filter lists µb.loadPublicSuffixList(onPSLReady);
vAPI.cacheStorage.get('selfie', function(bin) { µb.loadRedirectResources();
if ( bin instanceof Object && onSelfieReady(bin.selfie) ) {
return onAllReady();
}
µb.loadPublicSuffixList(onPSLReady);
});
}; };
/******************************************************************************/ /******************************************************************************/

View file

@ -1001,7 +1001,6 @@
timer = null; timer = null;
var selfie = { var selfie = {
magic: this.systemSettings.selfieMagic, magic: this.systemSettings.selfieMagic,
publicSuffixList: publicSuffixList.toSelfie(),
availableFilterLists: this.availableFilterLists, availableFilterLists: this.availableFilterLists,
staticNetFilteringEngine: this.staticNetFilteringEngine.toSelfie(), staticNetFilteringEngine: this.staticNetFilteringEngine.toSelfie(),
redirectEngine: this.redirectEngine.toSelfie(), redirectEngine: this.redirectEngine.toSelfie(),
@ -1010,6 +1009,25 @@
vAPI.cacheStorage.set({ selfie: selfie }); vAPI.cacheStorage.set({ selfie: selfie });
}.bind(µBlock); }.bind(µBlock);
var load = function(callback) {
vAPI.cacheStorage.get('selfie', function(bin) {
var µb = µBlock;
if (
bin instanceof Object === false ||
bin.selfie instanceof Object === false ||
bin.selfie.magic !== µb.systemSettings.selfieMagic ||
bin.selfie.redirectEngine === undefined
) {
return callback(false);
}
µb.availableFilterLists = bin.selfie.availableFilterLists;
µb.staticNetFilteringEngine.fromSelfie(bin.selfie.staticNetFilteringEngine);
µb.redirectEngine.fromSelfie(bin.selfie.redirectEngine);
µb.staticExtFilteringEngine.fromSelfie(bin.selfie.staticExtFilteringEngine);
callback(true);
});
};
var destroy = function() { var destroy = function() {
if ( timer !== null ) { if ( timer !== null ) {
clearTimeout(timer); clearTimeout(timer);
@ -1020,6 +1038,7 @@
}.bind(µBlock); }.bind(µBlock);
return { return {
load: load,
destroy: destroy destroy: destroy
}; };
})(); })();