Commit c4c75629 authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Deregister notification listeners when packing is done.

Deregistering the handlers avoids them being called once the packing
operation is done, and an unrelated future pack operation is in
progress. It also frees up a bit of memory.

BUG=791895

Change-Id: I52b8382d18b95637c868c1cdb91fed4b0f6fd276
Reviewed-on: https://chromium-review.googlesource.com/c/1317208Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605540}
parent 94d77dfe
...@@ -624,6 +624,28 @@ unpacker.app = { ...@@ -624,6 +624,28 @@ unpacker.app = {
function() {}); function() {});
}, unpacker.app.PACKING_NOTIFICATION_DELAY); }, unpacker.app.PACKING_NOTIFICATION_DELAY);
var progressNotificationCreated = false;
// If notification is closed while packing is in progress, flag to
// create/update is reset.
var onNotificationClosed = function(notificationId) {
if (notificationId === compressorId.toString())
progressNotificationCreated = false;
};
var onNotificationButtonClicked = function(
notificationId, buttonIndex) {
if (notificationId === compressorId.toString())
compressor.sendCancelArchiveRequest();
};
chrome.notifications.onClosed.addListener(onNotificationClosed);
chrome.notifications.onButtonClicked.addListener(
onNotificationButtonClicked);
var clearNotifications = function(compressorId) {
chrome.notifications.clear(compressorId.toString(), function() {});
chrome.notifications.onClosed.removeListener(onNotificationClosed);
chrome.notifications.onButtonClicked.removeListener(
onNotificationButtonClicked);
};
var onError = function(compressorId) { var onError = function(compressorId) {
clearTimeout(deferredNotificationTimer); clearTimeout(deferredNotificationTimer);
chrome.notifications.create( chrome.notifications.create(
...@@ -649,8 +671,7 @@ unpacker.app = { ...@@ -649,8 +671,7 @@ unpacker.app = {
// content of a zip file is small it will flash the notification. // content of a zip file is small it will flash the notification.
// Thus we clear the notification with a delay to avoid flashing. // Thus we clear the notification with a delay to avoid flashing.
setTimeout(function() { setTimeout(function() {
chrome.notifications.clear( clearNotifications(compressorId);
compressorId.toString(), function() {});
}, unpacker.app.PACKING_NOTIFICATION_CLEAR_DELAY); }, unpacker.app.PACKING_NOTIFICATION_CLEAR_DELAY);
unpacker.app.cleanupCompressor( unpacker.app.cleanupCompressor(
compressorId, false /* hasError */, false /* canceled */); compressorId, false /* hasError */, false /* canceled */);
...@@ -658,12 +679,11 @@ unpacker.app = { ...@@ -658,12 +679,11 @@ unpacker.app = {
var onCancel = function(compressorId) { var onCancel = function(compressorId) {
clearTimeout(deferredNotificationTimer); clearTimeout(deferredNotificationTimer);
chrome.notifications.clear(compressorId.toString(), function() {}); clearNotifications(compressorId);
unpacker.app.cleanupCompressor( unpacker.app.cleanupCompressor(
compressorId, false /* hasError */, true /* canceled */); compressorId, false /* hasError */, true /* canceled */);
}; };
var progressNotificationCreated = false;
var progressValue = -1; var progressValue = -1;
var onProgress = function(compressorId, progress) { var onProgress = function(compressorId, progress) {
clearTimeout(deferredNotificationTimer); clearTimeout(deferredNotificationTimer);
...@@ -703,17 +723,6 @@ unpacker.app = { ...@@ -703,17 +723,6 @@ unpacker.app = {
}; };
compressor.compress(onSuccess, onError, onProgress, onCancel); compressor.compress(onSuccess, onError, onProgress, onCancel);
// If notification is closed while packing is in progress, flag to
// create/update is reset.
chrome.notifications.onClosed.addListener(function() {
progressNotificationCreated = false;
});
chrome.notifications.onButtonClicked.addListener(function(
notificationId, buttonIndex) {
if (notificationId === compressorId.toString())
compressor.sendCancelArchiveRequest();
});
}); });
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment