| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 29 matching lines...) Expand all Loading... |
| 40 let formatVersion = 4; | 40 let formatVersion = 4; |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * This class reads user's filters from disk, manages them in memory | 43 * This class reads user's filters from disk, manages them in memory |
| 44 * and writes them back. | 44 * and writes them back. |
| 45 * @class | 45 * @class |
| 46 */ | 46 */ |
| 47 let FilterStorage = exports.FilterStorage = | 47 let FilterStorage = exports.FilterStorage = |
| 48 { | 48 { |
| 49 /** | 49 /** |
| 50 * Will be set to true after the initial loadFromDisk() call completes. |
| 51 * @type {boolean} |
| 52 */ |
| 53 initialized: false, |
| 54 |
| 55 /** |
| 50 * Version number of the patterns.ini format used. | 56 * Version number of the patterns.ini format used. |
| 51 * @type {number} | 57 * @type {number} |
| 52 */ | 58 */ |
| 53 get formatVersion() | 59 get formatVersion() |
| 54 { | 60 { |
| 55 return formatVersion; | 61 return formatVersion; |
| 56 }, | 62 }, |
| 57 | 63 |
| 58 /** | 64 /** |
| 59 * File that the filter list has been loaded from and should be saved to | 65 * File that the filter list has been loaded from and should be saved to |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 */ | 462 */ |
| 457 loadFromDisk() | 463 loadFromDisk() |
| 458 { | 464 { |
| 459 let readFile = () => | 465 let readFile = () => |
| 460 { | 466 { |
| 461 let parser = { | 467 let parser = { |
| 462 process: this.importData() | 468 process: this.importData() |
| 463 }; | 469 }; |
| 464 IO.readFromFile(this.sourceFile, parser, readFromFileException => | 470 IO.readFromFile(this.sourceFile, parser, readFromFileException => |
| 465 { | 471 { |
| 472 this.initialized = true; |
| 473 |
| 466 if (!readFromFileException && this.subscriptions.length == 0) | 474 if (!readFromFileException && this.subscriptions.length == 0) |
| 467 { | 475 { |
| 468 // No filter subscriptions in the file, this isn't right. | 476 // No filter subscriptions in the file, this isn't right. |
| 469 readFromFileException = new Error("No data in the file"); | 477 readFromFileException = new Error("No data in the file"); |
| 470 } | 478 } |
| 471 | 479 |
| 472 if (readFromFileException) | 480 if (readFromFileException) |
| 473 Cu.reportError(readFromFileException); | 481 Cu.reportError(readFromFileException); |
| 474 | 482 |
| 475 if (readFromFileException) | 483 if (readFromFileException) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 487 { | 495 { |
| 488 // Give up | 496 // Give up |
| 489 }); | 497 }); |
| 490 }; | 498 }; |
| 491 | 499 |
| 492 IO.statFile(this.sourceFile, (statError, statData) => | 500 IO.statFile(this.sourceFile, (statError, statData) => |
| 493 { | 501 { |
| 494 if (statError || !statData.exists) | 502 if (statError || !statData.exists) |
| 495 { | 503 { |
| 496 this.firstRun = true; | 504 this.firstRun = true; |
| 505 this.initialized = true; |
| 497 FilterNotifier.triggerListeners("load"); | 506 FilterNotifier.triggerListeners("load"); |
| 498 } | 507 } |
| 499 else | 508 else |
| 500 readFile(); | 509 readFile(); |
| 501 }); | 510 }); |
| 502 }, | 511 }, |
| 503 | 512 |
| 504 /** | 513 /** |
| 505 * Restores an automatically created backup. | 514 * Restores an automatically created backup. |
| 506 * @param {number} backupIndex | 515 * @param {number} backupIndex |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 Subscription.knownSubscriptions = origKnownSubscriptions; | 898 Subscription.knownSubscriptions = origKnownSubscriptions; |
| 890 } | 899 } |
| 891 | 900 |
| 892 // Allow events to be processed every now and then. | 901 // Allow events to be processed every now and then. |
| 893 // Note: IO.readFromFile() will deal with the potential reentrance here. | 902 // Note: IO.readFromFile() will deal with the potential reentrance here. |
| 894 this.linesProcessed++; | 903 this.linesProcessed++; |
| 895 if (this.linesProcessed % 1000 == 0) | 904 if (this.linesProcessed % 1000 == 0) |
| 896 return Utils.yield(); | 905 return Utils.yield(); |
| 897 } | 906 } |
| 898 }; | 907 }; |
| OLD | NEW |