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

Side by Side Diff: lib/filterStorage.js

Issue 5689385303408640: Issue 216 - First run page opens on every update (Closed)
Patch Set: Created March 26, 2014, 12:35 p.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 | « no previous file | no next file » | 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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 /** 359 /**
360 * Loads all subscriptions from the disk 360 * Loads all subscriptions from the disk
361 * @param {nsIFile} [sourceFile] File to read from 361 * @param {nsIFile} [sourceFile] File to read from
362 */ 362 */
363 loadFromDisk: function(sourceFile) 363 loadFromDisk: function(sourceFile)
364 { 364 {
365 if (this._loading) 365 if (this._loading)
366 return; 366 return;
367 367
368 TimeLine.enter("Entered FilterStorage.loadFromDisk()"); 368 TimeLine.enter("Entered FilterStorage.loadFromDisk()");
369 this._loading = true;
369 370
370 let readFile = function(sourceFile, backupIndex) 371 let readFile = function(sourceFile, backupIndex)
371 { 372 {
372 TimeLine.enter("FilterStorage.loadFromDisk() -> readFile()"); 373 TimeLine.enter("FilterStorage.loadFromDisk() -> readFile()");
373 374
374 let parser = new INIParser(); 375 let parser = new INIParser();
375 IO.readFromFile(sourceFile, true, parser, function(e) 376 IO.readFromFile(sourceFile, true, parser, function(e)
376 { 377 {
377 TimeLine.enter("FilterStorage.loadFromDisk() read callback"); 378 TimeLine.enter("FilterStorage.loadFromDisk() read callback");
378 if (!e && parser.subscriptions.length == 0) 379 if (!e && parser.subscriptions.length == 0)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 445
445 this._loading = false; 446 this._loading = false;
446 FilterNotifier.triggerListeners("load"); 447 FilterNotifier.triggerListeners("load");
447 448
448 if (sourceFile != this.sourceFile) 449 if (sourceFile != this.sourceFile)
449 this.saveToDisk(); 450 this.saveToDisk();
450 451
451 TimeLine.leave("FilterStorage.loadFromDisk() read callback done"); 452 TimeLine.leave("FilterStorage.loadFromDisk() read callback done");
452 }.bind(this); 453 }.bind(this);
453 454
454 let startRead = function(file)
455 {
456 this._loading = true;
457 readFile(file, 0);
458 }.bind(this);
459
460 let explicitFile; 455 let explicitFile;
461 if (sourceFile) 456 if (sourceFile)
462 { 457 {
463 explicitFile = true; 458 explicitFile = true;
464 startRead(sourceFile); 459 readFile(sourceFile, 0);
465 } 460 }
466 else 461 else
467 { 462 {
468 explicitFile = false; 463 explicitFile = false;
469 sourceFile = FilterStorage.sourceFile; 464 sourceFile = FilterStorage.sourceFile;
470 465
471 let callback = function(e, statData) 466 let callback = function(e, statData)
472 { 467 {
473 if (e || !statData.exists) 468 if (e || !statData.exists)
474 { 469 {
475 this.firstRun = true; 470 this.firstRun = true;
476 this._loading = false; 471 this._loading = false;
477 FilterNotifier.triggerListeners("load"); 472 FilterNotifier.triggerListeners("load");
478 473
479 TimeLine.leave("FilterStorage.loadFromDisk() read callback done"); 474 TimeLine.leave("FilterStorage.loadFromDisk() read callback done");
480 } 475 }
481 startRead(sourceFile); 476 readFile(sourceFile, 0);
482 } 477 }
483 478
484 if (sourceFile) 479 if (sourceFile)
485 IO.statFile(sourceFile, callback); 480 IO.statFile(sourceFile, callback);
486 else 481 else
487 callback(true); 482 callback(true);
488 } 483 }
489 484
490 TimeLine.leave("FilterStorage.loadFromDisk() done"); 485 TimeLine.leave("FilterStorage.loadFromDisk() done");
491 }, 486 },
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 Subscription.knownSubscriptions = origKnownSubscriptions; 884 Subscription.knownSubscriptions = origKnownSubscriptions;
890 } 885 }
891 886
892 // Allow events to be processed every now and then. 887 // Allow events to be processed every now and then.
893 // Note: IO.readFromFile() will deal with the potential reentrance here. 888 // Note: IO.readFromFile() will deal with the potential reentrance here.
894 this.linesProcessed++; 889 this.linesProcessed++;
895 if (this.linesProcessed % 1000 == 0) 890 if (this.linesProcessed % 1000 == 0)
896 Utils.yield(); 891 Utils.yield();
897 } 892 }
898 }; 893 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld