| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 * Yields subscriptions containing all filters | 83 * Yields subscriptions containing all filters |
| 84 * @yields {Subscription} | 84 * @yields {Subscription} |
| 85 */ | 85 */ |
| 86 *subscriptions() | 86 *subscriptions() |
| 87 { | 87 { |
| 88 yield* this.knownSubscriptions.values(); | 88 yield* this.knownSubscriptions.values(); |
| 89 }, | 89 }, |
| 90 | 90 |
| 91 /** | 91 /** |
| 92 * Number of known subscriptions. | 92 * Number of known subscriptions. |
| 93 * @returns {number} | 93 * @type {number} |
|
Manish Jethani
2018/09/27 17:42:54
This should be `@type {number}` since it's a prope
Jon Sonesen
2018/10/01 03:02:22
Done.
| |
| 94 */ | 94 */ |
| 95 get subscriptionCount() | 95 get subscriptionCount() |
| 96 { | 96 { |
| 97 return this.knownSubscriptions.size; | 97 return this.knownSubscriptions.size; |
| 98 }, | 98 }, |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * Map of subscriptions already on the list, by their URL/identifier | 101 * Map of subscriptions already on the list, by their URL/identifier |
| 102 * @type {Map.<string,Subscription>} | 102 * @type {Map.<string,Subscription>} |
| 103 */ | 103 */ |
| 104 knownSubscriptions: new Map(), | 104 knownSubscriptions: new Map(), |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * Finds the filter group that a filter should be added to by default. Will | 107 * Finds the filter group that a filter should be added to by default. Will |
| 108 * return null if this group doesn't exist yet. | 108 * return null if this group doesn't exist yet. |
| 109 * @param {Filter} filter | 109 * @param {Filter} filter |
| 110 * @return {?SpecialSubscription} | 110 * @return {?SpecialSubscription} |
| 111 */ | 111 */ |
| 112 getGroupForFilter(filter) | 112 getGroupForFilter(filter) |
| 113 { | 113 { |
| 114 let generalSubscription = null; | 114 let generalSubscription = null; |
| 115 for (let subscription of FilterStorage.subscriptions()) | 115 for (let subscription of FilterStorage.knownSubscriptions.values()) |
| 116 { | 116 { |
| 117 if (subscription instanceof SpecialSubscription && !subscription.disabled) | 117 if (subscription instanceof SpecialSubscription && !subscription.disabled) |
| 118 { | 118 { |
| 119 // Always prefer specialized subscriptions | 119 // Always prefer specialized subscriptions |
| 120 if (subscription.isDefaultFor(filter)) | 120 if (subscription.isDefaultFor(filter)) |
| 121 return subscription; | 121 return subscription; |
| 122 | 122 |
| 123 // If this is a general subscription - store it as fallback | 123 // If this is a general subscription - store it as fallback |
| 124 if (!generalSubscription && | 124 if (!generalSubscription && |
| 125 (!subscription.defaults || !subscription.defaults.length)) | 125 (!subscription.defaults || !subscription.defaults.length)) |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 /** | 363 /** |
| 364 * Loads all subscriptions from the disk. | 364 * Loads all subscriptions from the disk. |
| 365 * @return {Promise} promise resolved or rejected when loading is complete | 365 * @return {Promise} promise resolved or rejected when loading is complete |
| 366 */ | 366 */ |
| 367 loadFromDisk() | 367 loadFromDisk() |
| 368 { | 368 { |
| 369 let tryBackup = backupIndex => | 369 let tryBackup = backupIndex => |
| 370 { | 370 { |
| 371 return this.restoreBackup(backupIndex, true).then(() => | 371 return this.restoreBackup(backupIndex, true).then(() => |
| 372 { | 372 { |
| 373 if (this.subscriptionCount == 0) | 373 if (this.knownSubscriptions.size == 0) |
|
Manish Jethani
2018/10/02 00:41:29
You mean to change this to `this.knownSubscription
| |
| 374 return tryBackup(backupIndex + 1); | 374 return tryBackup(backupIndex + 1); |
| 375 }).catch(error => | 375 }).catch(error => |
| 376 { | 376 { |
| 377 // Give up | 377 // Give up |
| 378 }); | 378 }); |
| 379 }; | 379 }; |
| 380 | 380 |
| 381 return IO.statFile(this.sourceFile).then(statData => | 381 return IO.statFile(this.sourceFile).then(statData => |
| 382 { | 382 { |
| 383 if (!statData.exists) | 383 if (!statData.exists) |
| 384 { | 384 { |
| 385 this.firstRun = true; | 385 this.firstRun = true; |
| 386 return; | 386 return; |
| 387 } | 387 } |
| 388 | 388 |
| 389 let parser = this.importData(true); | 389 let parser = this.importData(true); |
| 390 return IO.readFromFile(this.sourceFile, parser).then(() => | 390 return IO.readFromFile(this.sourceFile, parser).then(() => |
| 391 { | 391 { |
| 392 parser(null); | 392 parser(null); |
| 393 if (this.subscriptionCount == 0) | 393 if (this.knownSubscriptions.size == 0) |
| 394 { | 394 { |
| 395 // No filter subscriptions in the file, this isn't right. | 395 // No filter subscriptions in the file, this isn't right. |
| 396 throw new Error("No data in the file"); | 396 throw new Error("No data in the file"); |
| 397 } | 397 } |
| 398 }); | 398 }); |
| 399 }).catch(error => | 399 }).catch(error => |
| 400 { | 400 { |
| 401 Cu.reportError(error); | 401 Cu.reportError(error); |
| 402 return tryBackup(1); | 402 return tryBackup(1); |
| 403 }).then(() => | 403 }).then(() => |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 return this.saveToDisk(); | 437 return this.saveToDisk(); |
| 438 }); | 438 }); |
| 439 }, | 439 }, |
| 440 | 440 |
| 441 /** | 441 /** |
| 442 * Generator serializing filter data and yielding it line by line. | 442 * Generator serializing filter data and yielding it line by line. |
| 443 */ | 443 */ |
| 444 *exportData() | 444 *exportData() |
| 445 { | 445 { |
| 446 // Do not persist external subscriptions | 446 // Do not persist external subscriptions |
| 447 let subscriptions = [...this.subscriptions()].filter( | 447 let subscriptions = []; |
|
Manish Jethani
2018/09/27 17:42:54
I think we should remove this and just add the fol
Jon Sonesen
2018/09/27 18:46:59
Can the iterations be consolidated as well?
Manish Jethani
2018/09/28 08:15:49
It doesn't look like, because all the subscription
Manish Jethani
2018/09/28 22:33:25
OK, scratch this. Let's leave it as it is (in the
Jon Sonesen
2018/10/01 03:02:23
Acknowledged.
Manish Jethani
2018/10/02 00:41:30
I'm sorry about this once again, but I've done an
| |
| 448 s => !(s instanceof ExternalSubscription) | 448 for (let subscription of this.subscriptions()) |
| 449 ); | 449 { |
| 450 if (!(subscription instanceof ExternalSubscription)) | |
| 451 subscriptions.push(subscription); | |
| 452 } | |
| 450 | 453 |
| 451 yield "# Adblock Plus preferences"; | 454 yield "# Adblock Plus preferences"; |
| 452 yield "version=" + formatVersion; | 455 yield "version=" + formatVersion; |
| 453 | 456 |
| 454 let saved = new Set(); | 457 let saved = new Set(); |
| 455 let buf = []; | 458 let buf = []; |
| 456 | 459 |
| 457 // Save subscriptions | 460 // Save subscriptions |
| 458 for (let subscription of subscriptions) | 461 for (let subscription of subscriptions) |
| 459 { | 462 { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 647 * @param {Subscription} subscription filter subscription to be removed | 650 * @param {Subscription} subscription filter subscription to be removed |
| 648 */ | 651 */ |
| 649 function removeSubscriptionFilters(subscription) | 652 function removeSubscriptionFilters(subscription) |
| 650 { | 653 { |
| 651 if (!FilterStorage.knownSubscriptions.has(subscription.url)) | 654 if (!FilterStorage.knownSubscriptions.has(subscription.url)) |
| 652 return; | 655 return; |
| 653 | 656 |
| 654 for (let filter of subscription.filters) | 657 for (let filter of subscription.filters) |
| 655 filter.removeSubscription(subscription); | 658 filter.removeSubscription(subscription); |
| 656 } | 659 } |
| LEFT | RIGHT |