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

Unified Diff: lib/firefoxDataCleanup.js

Issue 29526555: Issue 5554 - [webextensions] Adjust data to account for UI limitations (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome
Patch Set: Return early on fresh installs Created Aug. 24, 2017, 9:57 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/prefs.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/firefoxDataCleanup.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/firefoxDataCleanup.js
@@ -0,0 +1,84 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+"use strict";
+
+let {Filter, ActiveFilter} = require("filterClasses");
Sebastian Noack 2017/08/24 10:19:44 It seems we use const (instead let) for module imp
Wladimir Palant 2017/08/24 10:44:24 Done.
+let {FilterNotifier} = require("filterNotifier");
+let {FilterStorage} = require("filterStorage");
+let {IO} = require("io");
+let {Prefs} = require("prefs");
+let {SpecialSubscription} = require("subscriptionClasses");
+
+Promise.all([FilterNotifier.once("load"), Prefs.untilLoaded]).then(() =>
+{
+ if (Prefs.data_cleanup_done)
+ return;
+
+ if (FilterStorage.firstRun)
+ {
+ Prefs.data_cleanup_done = true;
+ return;
+ }
+
+ let haveHitCounts = [];
+
+ for (let key in Filter.knownFilters)
+ {
+ let filter = Filter.knownFilters[key];
+ if (!(filter instanceof ActiveFilter))
+ continue;
+
+ if (filter.disabled)
+ {
+ // Enable or replace disabled filters
+ filter.disabled = false;
+
+ for (let subscription of filter.subscriptions)
+ {
+ if (subscription instanceof SpecialSubscription)
+ {
+ while (true)
+ {
+ let position = subscription.filters.indexOf(filter);
+ if (position < 0)
Sebastian Noack 2017/08/24 10:19:44 You might want to use includes() instead of indexO
Wladimir Palant 2017/08/24 10:44:24 No, we are using the position later on.
+ break;
+
+ let newFilter = Filter.fromText("! " + filter.text);
+ FilterStorage.removeFilter(filter, subscription, position);
+ FilterStorage.addFilter(newFilter, subscription, position);
+ }
+ }
+ }
+ }
+
+ if (filter.hitCount || filter.lastHit)
+ haveHitCounts.push(filter);
+ }
+
+ // Reset hit statistics on any filters having them
+ FilterStorage.resetHitCounts(haveHitCounts);
+
+ // Remove any existing automatic backups
+ let backups = [];
+ for (let i = 1; i < 100; i++)
+ backups.push(`file:patterns-backup${i}.ini`);
+ browser.storage.local.remove(backups).then(() =>
+ {
+ Prefs.data_cleanup_done = true;
+ });
+});
« no previous file with comments | « no previous file | lib/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld