Skip to content

Commit

Permalink
Tidy up removal from suspension queue
Browse files Browse the repository at this point in the history
  • Loading branch information
deanoemcke committed Oct 11, 2018
1 parent 2378f89 commit 1cb3842
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ var tgs = (function() {
.then(function() {
let discardOnLoad = getTabFlagForTabId(tab.id, DISCARD_ON_LOAD);
clearTabFlagsForTabId(tab.id);
gsSuspendManager.markTabAsSuspended(tab);
gsSuspendManager.unqueueTabForSuspension(tab);

if (isCurrentFocusedTab(tab)) {
setIconStatus(gsUtils.STATUS_SUSPENDED, tab.id);
Expand Down
36 changes: 10 additions & 26 deletions src/js/gsSuspendManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ var gsSuspendManager = (function() {
if (!suspensionDetails) {
return;
}
removeTabFromSuspensionQueue(tab, 'Tab unqueue requested externally.');
gsUtils.log(tab.id, 'Tab suspension cancelled externally for tab.');
removeTabFromSuspensionQueue(tab);
}

function executeTabSuspension(tab) {
var suspensionDetails = suspensionQueueDetailsByTabId[tab.id];
delete suspensionQueueDetailsByTabId[tab.id];
if (suspensionDetails && suspensionDetails.cancelled) {
// If suspensionDetails doesn't exist, then assume this tab suspension has been cancelled
if (!suspensionDetails) {
gsUtils.log(tab.id, 'Tab missing from suspensionQueue. Assuming suspension cancelled for this tab.');
return;
}
removeTabFromSuspensionQueue(tab);

var suspendedUrl = suspensionDetails
? suspensionDetails.suspendedUrl
: gsUtils.generateSuspendedUrl(tab.url, tab.title, 0);
Expand Down Expand Up @@ -152,24 +156,7 @@ var gsSuspendManager = (function() {
await forceTabSuspension(tab, suspendedUrl);
}

function removeTabFromSuspensionQueue(tab, reason) {
const suspensionDetails = suspensionQueueDetailsByTabId[tab.id];
if (!suspensionDetails) {
return;
}
if (!suspensionDetails.startDateTime) {
delete suspensionQueueDetailsByTabId[tab.id];
} else {
// Tab already being suspended. Mark to cancel instead
suspensionDetails.cancelled = true;
}
gsUtils.log(
'gsSuspendManager',
`Tab suspension cancelled for tab: ${tab.id}. Reason: ${reason}`
);
}

function markTabAsSuspended(tab) {
function removeTabFromSuspensionQueue(tab) {
delete suspensionQueueDetailsByTabId[tab.id];
}

Expand Down Expand Up @@ -241,10 +228,8 @@ var gsSuspendManager = (function() {
if (
!checkContentScriptEligibilityForSuspension(tabInfo.status, forceLevel)
) {
removeTabFromSuspensionQueue(
tab,
'Content script not eligible for suspension'
);
gsUtils.log(tab.id, `Content script status of ${tabInfo.status} not eligible for suspension. Removing tab from suspensionQueue.`);
removeTabFromSuspensionQueue(tab);
return;
}

Expand Down Expand Up @@ -480,7 +465,6 @@ var gsSuspendManager = (function() {
initAsPromised,
queueTabForSuspension,
unqueueTabForSuspension,
markTabAsSuspended,
executeTabSuspension,
checkTabEligibilityForSuspension,
forceTabSuspension,
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "__MSG_ext_extension_name__",
"description": "__MSG_ext_extension_description__",
"version": "7.0.129",
"version": "7.0.130",
"default_locale": "en",
"permissions": [
"tabs",
Expand Down

0 comments on commit 1cb3842

Please sign in to comment.