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

Commit

Permalink
Fix double-load of rulesets on update of update channels (#19275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hainish authored May 14, 2020
1 parent 0fad008 commit f1fffc5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 2 additions & 4 deletions chromium/background-scripts/background.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);

0 comments on commit f1fffc5

Please sign in to comment.