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: Fixed typos in comment Created April 25, 2018, 2:46 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') | no next file with comments »
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;
+
+/**
* 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld