Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Fix double-load of rulesets on update of update channels (fixes #19102) #19275

Merged
merged 1 commit into from May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions chromium/background-scripts/background.js
Expand Up @@ -869,19 +869,17 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {

// Ensure that we check for new rulesets from the update channel immediately.
// If the scope has changed, make sure that the rulesets are re-initialized.
update.removeStorageListener();
store.set({update_channels: item.update_channels}, () => {
// Since loadUpdateChannesKeys is already contained in chrome.storage.onChanged
// within update.js, the below call will make it run twice. This is
// necesssary to avoid a race condition, see #16673
update.loadUpdateChannelsKeys().then(() => {
update.resetTimer();
if(scope_changed) {
initializeAllRules();
}
sendResponse(true);
});
update.addStorageListener();
});

});
return true;
},
Expand Down
18 changes: 15 additions & 3 deletions chromium/background-scripts/update.js
Expand Up @@ -252,7 +252,7 @@ async function performCheck() {
}
};

chrome.storage.onChanged.addListener(async function(changes, areaName) {
async function storageListener(changes, areaName) {
if (areaName === 'sync' || areaName === 'local') {
if ('autoUpdateRulesets' in changes) {
if (changes.autoUpdateRulesets.newValue) {
Expand All @@ -266,7 +266,17 @@ chrome.storage.onChanged.addListener(async function(changes, areaName) {
if ('update_channels' in changes) {
await loadUpdateChannelsKeys();
}
});
};

function addStorageListener() {
chrome.storage.onChanged.addListener(storageListener);
}

function removeStorageListener() {
chrome.storage.onChanged.removeListener(storageListener);
}

addStorageListener();

let initialCheck,
subsequentChecks;
Expand Down Expand Up @@ -326,7 +336,9 @@ Object.assign(exports, {
initialize,
getRulesetTimestamps,
resetTimer,
loadUpdateChannelsKeys
loadUpdateChannelsKeys,
addStorageListener,
removeStorageListener,
});

})(typeof exports == 'undefined' ? require.scopes.update = {} : exports);