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

Delta Between Two Patch Sets: lib/filterStorage.js

Issue 29886685: Issue 6856 - Remove FilterStorage.moveSubscription (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Address PS1 Comments Created Sept. 27, 2018, 3:06 p.m.
Right Patch Set: Address PS7 comments Created Oct. 2, 2018, 4:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/filterListener.js ('k') | lib/synchronizer.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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}
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
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)
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
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 = [];
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
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 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld