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

Unified Diff: lib/subscriptionInit.js

Issue 29760565: Issue 6599 - Detect data corruption of storage.local (Closed)
Patch Set: Added dataCorrupted parameter to uninstall page Created April 25, 2018, 1:16 p.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 | « lib/prefs.js ('k') | lib/uninstall.js » ('j') | lib/uninstall.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/subscriptionInit.js
===================================================================
--- a/lib/subscriptionInit.js
+++ b/lib/subscriptionInit.js
@@ -31,6 +31,7 @@
const {Utils} = require("./utils");
const {initNotifications} = require("./notificationHelper");
const {updatesVersion} = require("../adblockplusui/lib/prefs");
+const {setUninstallURL} = require("./uninstall");
let firstRun;
let subscriptionsCallback = null;
@@ -225,7 +226,7 @@
return subscriptions;
}
-function finishInitialization(subscriptions)
+function addSubscriptionsAndNotifyUser(subscriptions)
{
if (subscriptionsCallback)
subscriptions = subscriptionsCallback(subscriptions);
@@ -238,38 +239,42 @@
Synchronizer.execute(subscription);
}
- if (!Prefs.suppress_first_run_page)
+ // Show first run page or the updates page. The latter is only shown
+ // on Chromium (since the current updates page announces features that
+ // aren't new to Firefox users), and only if this version of the
+ // updates page hasn't been shown yet.
+ if (firstRun || info.platform == "chromium" &&
+ updatesVersion > Prefs.last_updates_page_displayed)
{
- let page = null;
- if (firstRun)
- {
- page = "firstRun.html";
- }
- // For now we're limiting the updates page to users of
- // Chromium-based browsers to gage its impact
- else if (info.platform == "chromium" &&
- updatesVersion > Prefs.last_updates_page_displayed)
+ return Prefs.set("last_updates_page_displayed", updatesVersion).catch(() =>
{
- page = "updates.html";
- }
-
- if (page)
+ exports.dataCorrupted = true;
+ }).then(() =>
{
- browser.tabs.create({url: browser.extension.getURL(page)});
-
- // For new users and users that have already seen this updates page we
- // want to avoid showing it again for subsequent updates.
- Prefs.last_updates_page_displayed = updatesVersion;
- }
+ if (!Prefs.suppress_first_run_page)
+ {
+ // Always show the first run page if a data corruption was detected
+ // (either though failure of reading from or writing to storage.local).
+ // The first run page notifies the user about the data corruption.
+ let url;
+ if (firstRun || exports.dataCorrupted)
+ url = "firstRun.html";
+ else
+ url = "updates.html";
+ browser.tabs.create({url});
+ }
+ });
}
-
- initNotifications();
}
-Promise.all([FilterNotifier.once("load"),
- Prefs.untilLoaded]).then(detectFirstRun)
- .then(getSubscriptions)
- .then(finishInitialization);
+Promise.all([
+ FilterNotifier.once("load"),
+ Prefs.untilLoaded.catch(() => { exports.dataCorrupted = true; })
+]).then(detectFirstRun)
+ .then(getSubscriptions)
+ .then(addSubscriptionsAndNotifyUser)
+ .then(setUninstallURL)
+ .then(initNotifications);
/**
* Indicates whether the default filter subscriptions have been added
@@ -281,6 +286,13 @@
exports.reinitialized = false;
/**
+ * Indicates whether a data corruption was detected.
+ *
+ * @type {boolean}
+ */
+exports.dataCorrupted = false;
kzar 2018/04/25 14:38:12 I just realised that this should probably be a get
Sebastian Noack 2018/04/25 14:46:23 Doesn't strike me as a huge issue. But more import
kzar 2018/04/25 14:57:04 Well I agree about not randomly changing "reinitia
Sebastian Noack 2018/04/25 17:08:56 I disagree about only changing either of them. So
+
+/**
* Sets a callback that is called with an array of subscriptions to be added
* during initialization. The callback must return an array of subscriptions
* that will effectively be added.
« no previous file with comments | « lib/prefs.js ('k') | lib/uninstall.js » ('j') | lib/uninstall.js » ('J')

Powered by Google App Engine
This is Rietveld