| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * This file is part of Adblock Plus <http://adblockplus.org/>, | 2  * This file is part of Adblock Plus <http://adblockplus.org/>, | 
| 3  * Copyright (C) 2006-2014 Eyeo GmbH | 3  * Copyright (C) 2006-2014 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 /** | 40 /** | 
| 41  * This class reads user's filters from disk, manages them in memory and writes 
     them back. | 41  * This class reads user's filters from disk, manages them in memory and writes 
     them back. | 
| 42  * @class | 42  * @class | 
| 43  */ | 43  */ | 
| 44 let FilterStorage = exports.FilterStorage = | 44 let FilterStorage = exports.FilterStorage = | 
| 45 { | 45 { | 
| 46   /** | 46   /** | 
| 47    * Version number of the patterns.ini format used. | 47    * Version number of the patterns.ini format used. | 
| 48    * @type Integer | 48    * @type Integer | 
| 49    */ | 49    */ | 
| 50   get formatVersion() formatVersion, | 50   get formatVersion() { return formatVersion }, | 
| 51 | 51 | 
| 52   /** | 52   /** | 
| 53    * File that the filter list has been loaded from and should be saved to | 53    * File that the filter list has been loaded from and should be saved to | 
| 54    * @type nsIFile | 54    * @type nsIFile | 
| 55    */ | 55    */ | 
| 56   get sourceFile() | 56   get sourceFile() | 
| 57   { | 57   { | 
| 58     let file = null; | 58     let file = null; | 
| 59     if (Prefs.patternsfile) | 59     if (Prefs.patternsfile) | 
| 60     { | 60     { | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 75       { | 75       { | 
| 76         file = IO.resolveFilePath(Services.prefs.getDefaultBranch("extensions.ad
     blockplus.").getCharPref("data_directory")); | 76         file = IO.resolveFilePath(Services.prefs.getDefaultBranch("extensions.ad
     blockplus.").getCharPref("data_directory")); | 
| 77         if (file) | 77         if (file) | 
| 78           file.append("patterns.ini"); | 78           file.append("patterns.ini"); | 
| 79       } catch(e) {} | 79       } catch(e) {} | 
| 80     } | 80     } | 
| 81 | 81 | 
| 82     if (!file) | 82     if (!file) | 
| 83       Cu.reportError("Adblock Plus: Failed to resolve filter file location from 
     extensions.adblockplus.patternsfile preference"); | 83       Cu.reportError("Adblock Plus: Failed to resolve filter file location from 
     extensions.adblockplus.patternsfile preference"); | 
| 84 | 84 | 
| 85     this.__defineGetter__("sourceFile", function() file); | 85     this.__defineGetter__("sourceFile", function() { return file; }); | 
| 86     return this.sourceFile; | 86     return this.sourceFile; | 
| 87   }, | 87   }, | 
| 88 | 88 | 
| 89   /** | 89   /** | 
| 90    * Will be set to true if no patterns.ini file exists. | 90    * Will be set to true if no patterns.ini file exists. | 
| 91    * @type Boolean | 91    * @type Boolean | 
| 92    */ | 92    */ | 
| 93   firstRun: false, | 93   firstRun: false, | 
| 94 | 94 | 
| 95   /** | 95   /** | 
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 218    * Adds a user-defined filter to the list | 218    * Adds a user-defined filter to the list | 
| 219    * @param {Filter} filter | 219    * @param {Filter} filter | 
| 220    * @param {SpecialSubscription} [subscription] particular group that the filte
     r should be added to | 220    * @param {SpecialSubscription} [subscription] particular group that the filte
     r should be added to | 
| 221    * @param {Integer} [position] position within the subscription at which the f
     ilter should be added | 221    * @param {Integer} [position] position within the subscription at which the f
     ilter should be added | 
| 222    * @param {Boolean} silent  if true, no listeners will be triggered (to be use
     d when filter list is reloaded) | 222    * @param {Boolean} silent  if true, no listeners will be triggered (to be use
     d when filter list is reloaded) | 
| 223    */ | 223    */ | 
| 224   addFilter: function(filter, subscription, position, silent) | 224   addFilter: function(filter, subscription, position, silent) | 
| 225   { | 225   { | 
| 226     if (!subscription) | 226     if (!subscription) | 
| 227     { | 227     { | 
| 228       if (filter.subscriptions.some(function(s) s instanceof SpecialSubscription
      && !s.disabled)) | 228       if (filter.subscriptions.some(function(s) { return (s instanceof SpecialSu
     bscription && !s.disabled); })) | 
| 229         return;   // No need to add | 229         return;   // No need to add | 
| 230       subscription = FilterStorage.getGroupForFilter(filter); | 230       subscription = FilterStorage.getGroupForFilter(filter); | 
| 231     } | 231     } | 
| 232     if (!subscription) | 232     if (!subscription) | 
| 233     { | 233     { | 
| 234       // No group for this filter exists, create one | 234       // No group for this filter exists, create one | 
| 235       subscription = SpecialSubscription.createForFilter(filter); | 235       subscription = SpecialSubscription.createForFilter(filter); | 
| 236       this.addSubscription(subscription); | 236       this.addSubscription(subscription); | 
| 237       return; | 237       return; | 
| 238     } | 238     } | 
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 621           } | 621           } | 
| 622         }); | 622         }); | 
| 623       } | 623       } | 
| 624     }.bind(this); | 624     }.bind(this); | 
| 625 | 625 | 
| 626     let removeLastBackup = function(part1, part2) | 626     let removeLastBackup = function(part1, part2) | 
| 627     { | 627     { | 
| 628       TimeLine.enter("FilterStorage.saveToDisk() -> removeLastBackup()"); | 628       TimeLine.enter("FilterStorage.saveToDisk() -> removeLastBackup()"); | 
| 629       let file = targetFile.clone(); | 629       let file = targetFile.clone(); | 
| 630       file.leafName = part1 + "-backup" + Prefs.patternsbackups + part2; | 630       file.leafName = part1 + "-backup" + Prefs.patternsbackups + part2; | 
| 631       IO.removeFile(file, function(e) renameBackup(part1, part2, Prefs.patternsb
     ackups - 1)); | 631       IO.removeFile(file, function(e) { renameBackup(part1, part2, Prefs.pattern
     sbackups - 1) }); | 
| 632       TimeLine.leave("FilterStorage.saveToDisk() <- removeLastBackup()"); | 632       TimeLine.leave("FilterStorage.saveToDisk() <- removeLastBackup()"); | 
| 633     }.bind(this); | 633     }.bind(this); | 
| 634 | 634 | 
| 635     let renameBackup = function(part1, part2, index) | 635     let renameBackup = function(part1, part2, index) | 
| 636     { | 636     { | 
| 637       TimeLine.enter("FilterStorage.saveToDisk() -> renameBackup()"); | 637       TimeLine.enter("FilterStorage.saveToDisk() -> renameBackup()"); | 
| 638       if (index > 0) | 638       if (index > 0) | 
| 639       { | 639       { | 
| 640         let fromFile = targetFile.clone(); | 640         let fromFile = targetFile.clone(); | 
| 641         fromFile.leafName = part1 + "-backup" + index + part2; | 641         fromFile.leafName = part1 + "-backup" + index + part2; | 
| 642 | 642 | 
| 643         let toName = part1 + "-backup" + (index + 1) + part2; | 643         let toName = part1 + "-backup" + (index + 1) + part2; | 
| 644 | 644 | 
| 645         IO.renameFile(fromFile, toName, function(e) renameBackup(part1, part2, i
     ndex - 1)); | 645         IO.renameFile(fromFile, toName, function(e) { renameBackup(part1, part2,
      index - 1) }); | 
| 646       } | 646       } | 
| 647       else | 647       else | 
| 648       { | 648       { | 
| 649         let toFile = targetFile.clone(); | 649         let toFile = targetFile.clone(); | 
| 650         toFile.leafName = part1 + "-backup" + (index + 1) + part2; | 650         toFile.leafName = part1 + "-backup" + (index + 1) + part2; | 
| 651 | 651 | 
| 652         IO.copyFile(targetFile, toFile, writeFilters); | 652         IO.copyFile(targetFile, toFile, writeFilters); | 
| 653       } | 653       } | 
| 654       TimeLine.leave("FilterStorage.saveToDisk() <- renameBackup()"); | 654       TimeLine.leave("FilterStorage.saveToDisk() <- renameBackup()"); | 
| 655     }.bind(this); | 655     }.bind(this); | 
| 656 | 656 | 
| 657     // Do not persist external subscriptions | 657     // Do not persist external subscriptions | 
| 658     let subscriptions = this.subscriptions.filter(function(s) !(s instanceof Ext
     ernalSubscription)); | 658     let subscriptions = this.subscriptions.filter(function(s) { return !(s insta
     nceof ExternalSubscription); }); | 
| 659     if (!explicitFile) | 659     if (!explicitFile) | 
| 660       this._saving = true; | 660       this._saving = true; | 
| 661 | 661 | 
| 662     checkBackupRequired(writeFilters, removeLastBackup); | 662     checkBackupRequired(writeFilters, removeLastBackup); | 
| 663 | 663 | 
| 664     TimeLine.leave("FilterStorage.saveToDisk() done"); | 664     TimeLine.leave("FilterStorage.saveToDisk() done"); | 
| 665   }, | 665   }, | 
| 666 | 666 | 
| 667   /** | 667   /** | 
| 668    * Returns the list of existing backup files. | 668    * Returns the list of existing backup files. | 
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 885       Subscription.knownSubscriptions = origKnownSubscriptions; | 885       Subscription.knownSubscriptions = origKnownSubscriptions; | 
| 886     } | 886     } | 
| 887 | 887 | 
| 888     // Allow events to be processed every now and then. | 888     // Allow events to be processed every now and then. | 
| 889     // Note: IO.readFromFile() will deal with the potential reentrance here. | 889     // Note: IO.readFromFile() will deal with the potential reentrance here. | 
| 890     this.linesProcessed++; | 890     this.linesProcessed++; | 
| 891     if (this.linesProcessed % 1000 == 0) | 891     if (this.linesProcessed % 1000 == 0) | 
| 892       Utils.yield(); | 892       Utils.yield(); | 
| 893   } | 893   } | 
| 894 }; | 894 }; | 
| OLD | NEW | 
|---|