Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/filterStorage.js

Issue 29853574: Issue 6855 - Release all references to Subscription object once removed (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Remove Subscription object before emitting "subscription.removed" event Created Aug. 12, 2018, 7:12 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/filterStorage.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 removeSubscription(subscription) 141 removeSubscription(subscription)
142 { 142 {
143 for (let i = 0; i < FilterStorage.subscriptions.length; i++) 143 for (let i = 0; i < FilterStorage.subscriptions.length; i++)
144 { 144 {
145 if (FilterStorage.subscriptions[i].url == subscription.url) 145 if (FilterStorage.subscriptions[i].url == subscription.url)
146 { 146 {
147 removeSubscriptionFilters(subscription); 147 removeSubscriptionFilters(subscription);
148 148
149 FilterStorage.subscriptions.splice(i--, 1); 149 FilterStorage.subscriptions.splice(i--, 1);
150 FilterStorage.knownSubscriptions.delete(subscription.url); 150 FilterStorage.knownSubscriptions.delete(subscription.url);
151
152 // This should be the last remaining reference to the Subscription
153 // object.
154 Subscription.knownSubscriptions.delete(subscription.url);
155
151 FilterNotifier.triggerListeners("subscription.removed", subscription); 156 FilterNotifier.triggerListeners("subscription.removed", subscription);
152 return; 157 return;
153 } 158 }
154 } 159 }
155 }, 160 },
156 161
157 /** 162 /**
158 * Moves a subscription in the list to a new position. 163 * Moves a subscription in the list to a new position.
159 * @param {Subscription} subscription filter subscription to be moved 164 * @param {Subscription} subscription filter subscription to be moved
160 * @param {Subscription} [insertBefore] filter subscription to insert before 165 * @param {Subscription} [insertBefore] filter subscription to insert before
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 * notifications. 675 * notifications.
671 * @param {Subscription} subscription filter subscription to be removed 676 * @param {Subscription} subscription filter subscription to be removed
672 */ 677 */
673 function removeSubscriptionFilters(subscription) 678 function removeSubscriptionFilters(subscription)
674 { 679 {
675 if (!FilterStorage.knownSubscriptions.has(subscription.url)) 680 if (!FilterStorage.knownSubscriptions.has(subscription.url))
676 return; 681 return;
677 682
678 for (let filter of subscription.filters) 683 for (let filter of subscription.filters)
679 { 684 {
680 let i = filter.subscriptions.indexOf(subscription); 685 let index = 0;
681 if (i >= 0) 686
682 filter.subscriptions.splice(i, 1); 687 // The same filter can occur more than once in a subscription. We could
688 // avoid making duplicate subscription entries in a Filter object in
689 // INIParser, but we don't do this in order to avoid slowing down the
690 // loading of the initial subscriptions from disk.
691 while ((index = filter.subscriptions.indexOf(subscription), index) != -1)
692 filter.subscriptions.splice(index, 1);
683 } 693 }
684 } 694 }
685 695
686 /** 696 /**
687 * Listener returned by FilterStorage.importData(), parses filter data. 697 * Listener returned by FilterStorage.importData(), parses filter data.
688 * @constructor 698 * @constructor
689 */ 699 */
690 function INIParser() 700 function INIParser()
691 { 701 {
692 this.fileProperties = this.curObj = {}; 702 this.fileProperties = this.curObj = {};
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 else if (this.wantObj === false && val) 783 else if (this.wantObj === false && val)
774 this.curObj.push(val.replace(/\\\[/g, "[")); 784 this.curObj.push(val.replace(/\\\[/g, "["));
775 } 785 }
776 finally 786 finally
777 { 787 {
778 Filter.knownFilters = origKnownFilters; 788 Filter.knownFilters = origKnownFilters;
779 Subscription.knownSubscriptions = origKnownSubscriptions; 789 Subscription.knownSubscriptions = origKnownSubscriptions;
780 } 790 }
781 } 791 }
782 }; 792 };
OLDNEW
« no previous file with comments | « no previous file | test/filterStorage.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld