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

Delta Between Two Patch Sets: lib/filterStorage.js

Issue 29853574: Issue 6855 - Release all references to Subscription object once removed (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Aug. 11, 2018, 3:21 p.m.
Right Patch Set: Improve tests Created Aug. 16, 2018, 5:33 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | test/filterStorage.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
153 subscription.free();
Manish Jethani 2018/08/11 15:28:17 At this point all the other references to this obj
154 return; 157 return;
155 } 158 }
156 } 159 }
157 }, 160 },
158 161
159 /** 162 /**
160 * Moves a subscription in the list to a new position. 163 * Moves a subscription in the list to a new position.
161 * @param {Subscription} subscription filter subscription to be moved 164 * @param {Subscription} subscription filter subscription to be moved
162 * @param {Subscription} [insertBefore] filter subscription to insert before 165 * @param {Subscription} [insertBefore] filter subscription to insert before
163 * (if omitted the subscription will be put at the end of the list) 166 * (if omitted the subscription will be put at the end of the list)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 * @param {Filter} filter 208 * @param {Filter} filter
206 * @param {SpecialSubscription} [subscription] 209 * @param {SpecialSubscription} [subscription]
207 * particular group that the filter should be added to 210 * particular group that the filter should be added to
208 * @param {number} [position] 211 * @param {number} [position]
209 * position within the subscription at which the filter should be added 212 * position within the subscription at which the filter should be added
210 */ 213 */
211 addFilter(filter, subscription, position) 214 addFilter(filter, subscription, position)
212 { 215 {
213 if (!subscription) 216 if (!subscription)
214 { 217 {
215 if (filter.subscriptions.some(s => s instanceof SpecialSubscription && 218 for (let currentSubscription of filter.subscriptions)
216 !s.disabled)) 219 {
217 { 220 if (currentSubscription instanceof SpecialSubscription &&
218 return; // No need to add 221 !currentSubscription.disabled)
222 {
223 return; // No need to add
224 }
219 } 225 }
220 subscription = FilterStorage.getGroupForFilter(filter); 226 subscription = FilterStorage.getGroupForFilter(filter);
221 } 227 }
222 if (!subscription) 228 if (!subscription)
223 { 229 {
224 // No group for this filter exists, create one 230 // No group for this filter exists, create one
225 subscription = SpecialSubscription.createForFilter(filter); 231 subscription = SpecialSubscription.createForFilter(filter);
226 this.addSubscription(subscription); 232 this.addSubscription(subscription);
227 return; 233 return;
228 } 234 }
229 235
230 if (typeof position == "undefined") 236 if (typeof position == "undefined")
231 position = subscription.filters.length; 237 position = subscription.filters.length;
232 238
233 if (filter.subscriptions.indexOf(subscription) < 0) 239 filter.subscriptions.add(subscription);
234 filter.subscriptions.push(subscription);
235 subscription.filters.splice(position, 0, filter); 240 subscription.filters.splice(position, 0, filter);
236 FilterNotifier.triggerListeners("filter.added", filter, subscription, 241 FilterNotifier.triggerListeners("filter.added", filter, subscription,
237 position); 242 position);
238 }, 243 },
239 244
240 /** 245 /**
241 * Removes a user-defined filter from the list 246 * Removes a user-defined filter from the list
242 * @param {Filter} filter 247 * @param {Filter} filter
243 * @param {SpecialSubscription} [subscription] a particular filter group that 248 * @param {SpecialSubscription} [subscription] a particular filter group that
244 * the filter should be removed from (if ommited will be removed from all 249 * the filter should be removed from (if ommited will be removed from all
245 * subscriptions) 250 * subscriptions)
246 * @param {number} [position] position inside the filter group at which the 251 * @param {number} [position] position inside the filter group at which the
247 * filter should be removed (if ommited all instances will be removed) 252 * filter should be removed (if ommited all instances will be removed)
248 */ 253 */
249 removeFilter(filter, subscription, position) 254 removeFilter(filter, subscription, position)
250 { 255 {
251 let subscriptions = ( 256 let subscriptions = (
252 subscription ? [subscription] : filter.subscriptions.slice() 257 subscription ? [subscription] : filter.subscriptions
253 ); 258 );
254 for (let i = 0; i < subscriptions.length; i++) 259 for (let currentSubscription of subscriptions)
255 { 260 {
256 let currentSubscription = subscriptions[i];
257 if (currentSubscription instanceof SpecialSubscription) 261 if (currentSubscription instanceof SpecialSubscription)
258 { 262 {
259 let positions = []; 263 let positions = [];
260 if (typeof position == "undefined") 264 if (typeof position == "undefined")
261 { 265 {
262 let index = -1; 266 let index = -1;
263 do 267 do
264 { 268 {
265 index = currentSubscription.filters.indexOf(filter, index + 1); 269 index = currentSubscription.filters.indexOf(filter, index + 1);
266 if (index >= 0) 270 if (index >= 0)
267 positions.push(index); 271 positions.push(index);
268 } while (index >= 0); 272 } while (index >= 0);
269 } 273 }
270 else 274 else
271 positions.push(position); 275 positions.push(position);
272 276
273 for (let j = positions.length - 1; j >= 0; j--) 277 for (let j = positions.length - 1; j >= 0; j--)
274 { 278 {
275 let currentPosition = positions[j]; 279 let currentPosition = positions[j];
276 if (currentSubscription.filters[currentPosition] == filter) 280 if (currentSubscription.filters[currentPosition] == filter)
277 { 281 {
278 currentSubscription.filters.splice(currentPosition, 1); 282 currentSubscription.filters.splice(currentPosition, 1);
279 if (currentSubscription.filters.indexOf(filter) < 0) 283 if (currentSubscription.filters.indexOf(filter) < 0)
280 { 284 filter.subscriptions.delete(currentSubscription);
281 let index = filter.subscriptions.indexOf(currentSubscription);
282 if (index >= 0)
283 filter.subscriptions.splice(index, 1);
284 }
285 FilterNotifier.triggerListeners( 285 FilterNotifier.triggerListeners(
286 "filter.removed", filter, currentSubscription, currentPosition 286 "filter.removed", filter, currentSubscription, currentPosition
287 ); 287 );
288 } 288 }
289 } 289 }
290 } 290 }
291 } 291 }
292 }, 292 },
293 293
294 /** 294 /**
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 * Joins subscription's filters to the subscription without any notifications. 657 * Joins subscription's filters to the subscription without any notifications.
658 * @param {Subscription} subscription 658 * @param {Subscription} subscription
659 * filter subscription that should be connected to its filters 659 * filter subscription that should be connected to its filters
660 */ 660 */
661 function addSubscriptionFilters(subscription) 661 function addSubscriptionFilters(subscription)
662 { 662 {
663 if (!FilterStorage.knownSubscriptions.has(subscription.url)) 663 if (!FilterStorage.knownSubscriptions.has(subscription.url))
664 return; 664 return;
665 665
666 for (let filter of subscription.filters) 666 for (let filter of subscription.filters)
667 filter.subscriptions.push(subscription); 667 filter.subscriptions.add(subscription);
668 } 668 }
669 669
670 /** 670 /**
671 * Removes subscription's filters from the subscription without any 671 * Removes subscription's filters from the subscription without any
672 * notifications. 672 * notifications.
673 * @param {Subscription} subscription filter subscription to be removed 673 * @param {Subscription} subscription filter subscription to be removed
674 */ 674 */
675 function removeSubscriptionFilters(subscription) 675 function removeSubscriptionFilters(subscription)
676 { 676 {
677 if (!FilterStorage.knownSubscriptions.has(subscription.url)) 677 if (!FilterStorage.knownSubscriptions.has(subscription.url))
678 return; 678 return;
679 679
680 for (let filter of subscription.filters) 680 for (let filter of subscription.filters)
681 { 681 filter.subscriptions.delete(subscription);
682 let i = filter.subscriptions.indexOf(subscription);
683 if (i >= 0)
684 filter.subscriptions.splice(i, 1);
685 }
686 } 682 }
687 683
688 /** 684 /**
689 * Listener returned by FilterStorage.importData(), parses filter data. 685 * Listener returned by FilterStorage.importData(), parses filter data.
690 * @constructor 686 * @constructor
691 */ 687 */
692 function INIParser() 688 function INIParser()
693 { 689 {
694 this.fileProperties = this.curObj = {}; 690 this.fileProperties = this.curObj = {};
695 this.subscriptions = []; 691 this.subscriptions = [];
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 case "subscription filters": 734 case "subscription filters":
739 if (this.subscriptions.length) 735 if (this.subscriptions.length)
740 { 736 {
741 let subscription = this.subscriptions[ 737 let subscription = this.subscriptions[
742 this.subscriptions.length - 1 738 this.subscriptions.length - 1
743 ]; 739 ];
744 for (let text of this.curObj) 740 for (let text of this.curObj)
745 { 741 {
746 let filter = Filter.fromText(text); 742 let filter = Filter.fromText(text);
747 subscription.filters.push(filter); 743 subscription.filters.push(filter);
748 filter.subscriptions.push(subscription); 744 filter.subscriptions.add(subscription);
749 } 745 }
750 } 746 }
751 break; 747 break;
752 } 748 }
753 } 749 }
754 750
755 if (val === null) 751 if (val === null)
756 return; 752 return;
757 753
758 this.curSection = match[1].toLowerCase(); 754 this.curSection = match[1].toLowerCase();
(...skipping 16 matching lines...) Expand all
775 else if (this.wantObj === false && val) 771 else if (this.wantObj === false && val)
776 this.curObj.push(val.replace(/\\\[/g, "[")); 772 this.curObj.push(val.replace(/\\\[/g, "["));
777 } 773 }
778 finally 774 finally
779 { 775 {
780 Filter.knownFilters = origKnownFilters; 776 Filter.knownFilters = origKnownFilters;
781 Subscription.knownSubscriptions = origKnownSubscriptions; 777 Subscription.knownSubscriptions = origKnownSubscriptions;
782 } 778 }
783 } 779 }
784 }; 780 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld