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

Side by Side Diff: lib/filterStorage.js

Issue 6305806509146112: Issue 427 - Remove non-standard function and getter syntax (Closed)
Patch Set: Wow sorry for those wrong braces, I am so used to a different style that I didn't even realize what… Created May 18, 2014, 10:51 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/filterClasses.js ('k') | lib/io.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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()
51 {
52 return formatVersion;
53 },
51 54
52 /** 55 /**
53 * File that the filter list has been loaded from and should be saved to 56 * File that the filter list has been loaded from and should be saved to
54 * @type nsIFile 57 * @type nsIFile
55 */ 58 */
56 get sourceFile() 59 get sourceFile()
57 { 60 {
58 let file = null; 61 let file = null;
59 if (Prefs.patternsfile) 62 if (Prefs.patternsfile)
60 { 63 {
(...skipping 14 matching lines...) Expand all
75 { 78 {
76 file = IO.resolveFilePath(Services.prefs.getDefaultBranch("extensions.ad blockplus.").getCharPref("data_directory")); 79 file = IO.resolveFilePath(Services.prefs.getDefaultBranch("extensions.ad blockplus.").getCharPref("data_directory"));
77 if (file) 80 if (file)
78 file.append("patterns.ini"); 81 file.append("patterns.ini");
79 } catch(e) {} 82 } catch(e) {}
80 } 83 }
81 84
82 if (!file) 85 if (!file)
83 Cu.reportError("Adblock Plus: Failed to resolve filter file location from extensions.adblockplus.patternsfile preference"); 86 Cu.reportError("Adblock Plus: Failed to resolve filter file location from extensions.adblockplus.patternsfile preference");
84 87
85 this.__defineGetter__("sourceFile", function() file); 88 this.__defineGetter__("sourceFile", () => file);
86 return this.sourceFile; 89 return this.sourceFile;
87 }, 90 },
88 91
89 /** 92 /**
90 * Will be set to true if no patterns.ini file exists. 93 * Will be set to true if no patterns.ini file exists.
91 * @type Boolean 94 * @type Boolean
92 */ 95 */
93 firstRun: false, 96 firstRun: false,
94 97
95 /** 98 /**
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 * Adds a user-defined filter to the list 221 * Adds a user-defined filter to the list
219 * @param {Filter} filter 222 * @param {Filter} filter
220 * @param {SpecialSubscription} [subscription] particular group that the filte r should be added to 223 * @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 224 * @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) 225 * @param {Boolean} silent if true, no listeners will be triggered (to be use d when filter list is reloaded)
223 */ 226 */
224 addFilter: function(filter, subscription, position, silent) 227 addFilter: function(filter, subscription, position, silent)
225 { 228 {
226 if (!subscription) 229 if (!subscription)
227 { 230 {
228 if (filter.subscriptions.some(function(s) s instanceof SpecialSubscription && !s.disabled)) 231 if (filter.subscriptions.some(s => s instanceof SpecialSubscription && !s. disabled))
229 return; // No need to add 232 return; // No need to add
230 subscription = FilterStorage.getGroupForFilter(filter); 233 subscription = FilterStorage.getGroupForFilter(filter);
231 } 234 }
232 if (!subscription) 235 if (!subscription)
233 { 236 {
234 // No group for this filter exists, create one 237 // No group for this filter exists, create one
235 subscription = SpecialSubscription.createForFilter(filter); 238 subscription = SpecialSubscription.createForFilter(filter);
236 this.addSubscription(subscription); 239 this.addSubscription(subscription);
237 return; 240 return;
238 } 241 }
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 } 624 }
622 }); 625 });
623 } 626 }
624 }.bind(this); 627 }.bind(this);
625 628
626 let removeLastBackup = function(part1, part2) 629 let removeLastBackup = function(part1, part2)
627 { 630 {
628 TimeLine.enter("FilterStorage.saveToDisk() -> removeLastBackup()"); 631 TimeLine.enter("FilterStorage.saveToDisk() -> removeLastBackup()");
629 let file = targetFile.clone(); 632 let file = targetFile.clone();
630 file.leafName = part1 + "-backup" + Prefs.patternsbackups + part2; 633 file.leafName = part1 + "-backup" + Prefs.patternsbackups + part2;
631 IO.removeFile(file, function(e) renameBackup(part1, part2, Prefs.patternsb ackups - 1)); 634 IO.removeFile(file, (e) => renameBackup(part1, part2, Prefs.patternsbackup s - 1));
632 TimeLine.leave("FilterStorage.saveToDisk() <- removeLastBackup()"); 635 TimeLine.leave("FilterStorage.saveToDisk() <- removeLastBackup()");
633 }.bind(this); 636 }.bind(this);
634 637
635 let renameBackup = function(part1, part2, index) 638 let renameBackup = function(part1, part2, index)
636 { 639 {
637 TimeLine.enter("FilterStorage.saveToDisk() -> renameBackup()"); 640 TimeLine.enter("FilterStorage.saveToDisk() -> renameBackup()");
638 if (index > 0) 641 if (index > 0)
639 { 642 {
640 let fromFile = targetFile.clone(); 643 let fromFile = targetFile.clone();
641 fromFile.leafName = part1 + "-backup" + index + part2; 644 fromFile.leafName = part1 + "-backup" + index + part2;
642 645
643 let toName = part1 + "-backup" + (index + 1) + part2; 646 let toName = part1 + "-backup" + (index + 1) + part2;
644 647
645 IO.renameFile(fromFile, toName, function(e) renameBackup(part1, part2, i ndex - 1)); 648 IO.renameFile(fromFile, toName, (e) => renameBackup(part1, part2, index - 1));
646 } 649 }
647 else 650 else
648 { 651 {
649 let toFile = targetFile.clone(); 652 let toFile = targetFile.clone();
650 toFile.leafName = part1 + "-backup" + (index + 1) + part2; 653 toFile.leafName = part1 + "-backup" + (index + 1) + part2;
651 654
652 IO.copyFile(targetFile, toFile, writeFilters); 655 IO.copyFile(targetFile, toFile, writeFilters);
653 } 656 }
654 TimeLine.leave("FilterStorage.saveToDisk() <- renameBackup()"); 657 TimeLine.leave("FilterStorage.saveToDisk() <- renameBackup()");
655 }.bind(this); 658 }.bind(this);
656 659
657 // Do not persist external subscriptions 660 // Do not persist external subscriptions
658 let subscriptions = this.subscriptions.filter(function(s) !(s instanceof Ext ernalSubscription)); 661 let subscriptions = this.subscriptions.filter((s) => !(s instanceof External Subscription));
659 if (!explicitFile) 662 if (!explicitFile)
660 this._saving = true; 663 this._saving = true;
661 664
662 checkBackupRequired(writeFilters, removeLastBackup); 665 checkBackupRequired(writeFilters, removeLastBackup);
663 666
664 TimeLine.leave("FilterStorage.saveToDisk() done"); 667 TimeLine.leave("FilterStorage.saveToDisk() done");
665 }, 668 },
666 669
667 /** 670 /**
668 * Returns the list of existing backup files. 671 * Returns the list of existing backup files.
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 Subscription.knownSubscriptions = origKnownSubscriptions; 888 Subscription.knownSubscriptions = origKnownSubscriptions;
886 } 889 }
887 890
888 // Allow events to be processed every now and then. 891 // Allow events to be processed every now and then.
889 // Note: IO.readFromFile() will deal with the potential reentrance here. 892 // Note: IO.readFromFile() will deal with the potential reentrance here.
890 this.linesProcessed++; 893 this.linesProcessed++;
891 if (this.linesProcessed % 1000 == 0) 894 if (this.linesProcessed % 1000 == 0)
892 Utils.yield(); 895 Utils.yield();
893 } 896 }
894 }; 897 };
OLDNEW
« no previous file with comments | « lib/filterClasses.js ('k') | lib/io.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld