OLD | NEW |
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 /** | 121 /** |
122 * The number of subscriptions in the storage. | 122 * The number of subscriptions in the storage. |
123 * @type {number} | 123 * @type {number} |
124 */ | 124 */ |
125 get subscriptionCount() | 125 get subscriptionCount() |
126 { | 126 { |
127 return this.knownSubscriptions.size; | 127 return this.knownSubscriptions.size; |
128 } | 128 } |
129 | 129 |
130 /** | 130 /** |
| 131 * Yields subscriptions in the storage to which the given filter belongs. |
| 132 * @param {Filter} filter |
| 133 * @yields {Subscription} |
| 134 */ |
| 135 *subscriptionsForFilter(filter) |
| 136 { |
| 137 if (!filter.subscriptionsAdded) |
| 138 addSubscriptionsToFilter(filter); |
| 139 |
| 140 yield* filter.subscriptions(); |
| 141 } |
| 142 |
| 143 /** |
| 144 * Returns the number of subscriptions in the storage to which the given |
| 145 * filter belongs. |
| 146 * @param {Filter} filter |
| 147 * @return {number} |
| 148 */ |
| 149 getSubscriptionCountForFilter(filter) |
| 150 { |
| 151 if (!filter.subscriptionsAdded) |
| 152 addSubscriptionsToFilter(filter); |
| 153 |
| 154 return filter.subscriptionCount; |
| 155 } |
| 156 |
| 157 /** |
131 * Finds the filter group that a filter should be added to by default. Will | 158 * Finds the filter group that a filter should be added to by default. Will |
132 * return <code>null</code> if this group doesn't exist yet. | 159 * return <code>null</code> if this group doesn't exist yet. |
133 * @param {Filter} filter | 160 * @param {Filter} filter |
134 * @returns {?SpecialSubscription} | 161 * @returns {?SpecialSubscription} |
135 */ | 162 */ |
136 getGroupForFilter(filter) | 163 getGroupForFilter(filter) |
137 { | 164 { |
138 let generalSubscription = null; | 165 let generalSubscription = null; |
139 for (let subscription of this.knownSubscriptions.values()) | 166 for (let subscription of this.knownSubscriptions.values()) |
140 { | 167 { |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 | 682 |
656 /** | 683 /** |
657 * Reads the user's filters from disk, manages them in memory, and writes them | 684 * Reads the user's filters from disk, manages them in memory, and writes them |
658 * back to disk. | 685 * back to disk. |
659 */ | 686 */ |
660 let filterStorage = new FilterStorage(); | 687 let filterStorage = new FilterStorage(); |
661 | 688 |
662 exports.filterStorage = filterStorage; | 689 exports.filterStorage = filterStorage; |
663 | 690 |
664 /** | 691 /** |
| 692 * Adds to a filter any subscriptions in the storage to which the filter |
| 693 * belongs. |
| 694 * @param {Filter} filter |
| 695 */ |
| 696 function addSubscriptionsToFilter(filter) |
| 697 { |
| 698 for (let subscription of filterStorage.subscriptions()) |
| 699 { |
| 700 if (subscription.hasFilter(filter)) |
| 701 filter.addSubscription(subscription); |
| 702 } |
| 703 |
| 704 filter.subscriptionsAdded = true; |
| 705 } |
| 706 |
| 707 /** |
665 * Connects a subscription to its filters without any notifications. | 708 * Connects a subscription to its filters without any notifications. |
666 * @param {Subscription} subscription The subscription that should be | 709 * @param {Subscription} subscription The subscription that should be |
667 * connected to its filters. | 710 * connected to its filters. |
668 * @param {?Array.<Filter>} [filters] A list of filters to which the | 711 * @param {?Array.<Filter>} [filters] A list of filters to which the |
669 * subscription should be connected. If this is not given, the subscription | 712 * subscription should be connected. If this is not given, the subscription |
670 * is connected to its own filters. | 713 * is connected to its own filters. |
671 */ | 714 */ |
672 function connectSubscriptionFilters(subscription, filters) | 715 function connectSubscriptionFilters(subscription, filters) |
673 { | 716 { |
674 if (!filterStorage.knownSubscriptions.has(subscription.url)) | 717 if (!filterStorage.knownSubscriptions.has(subscription.url)) |
(...skipping 21 matching lines...) Expand all Loading... |
696 } | 739 } |
697 | 740 |
698 /** | 741 /** |
699 * Clears any in-memory caches held by subscriptions in the storage. | 742 * Clears any in-memory caches held by subscriptions in the storage. |
700 */ | 743 */ |
701 function clearSubscriptionCaches() | 744 function clearSubscriptionCaches() |
702 { | 745 { |
703 for (let subscription of filterStorage.subscriptions()) | 746 for (let subscription of filterStorage.subscriptions()) |
704 subscription.clearCaches(); | 747 subscription.clearCaches(); |
705 } | 748 } |
OLD | NEW |