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

Side by Side Diff: lib/subscriptionInit.js

Issue 29760565: Issue 6599 - Detect data corruption of storage.local (Closed)
Patch Set: Added comments, show uninstall page also when data corruption occurred Created April 24, 2018, 5:51 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 | « lib/prefs.js ('k') | lib/uninstall.js » ('j') | 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 <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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 subscriptions = subscriptionsCallback(subscriptions); 231 subscriptions = subscriptionsCallback(subscriptions);
232 232
233 for (let subscription of subscriptions) 233 for (let subscription of subscriptions)
234 { 234 {
235 FilterStorage.addSubscription(subscription); 235 FilterStorage.addSubscription(subscription);
236 if (subscription instanceof DownloadableSubscription && 236 if (subscription instanceof DownloadableSubscription &&
237 !subscription.lastDownload) 237 !subscription.lastDownload)
238 Synchronizer.execute(subscription); 238 Synchronizer.execute(subscription);
239 } 239 }
240 240
241 if (!Prefs.suppress_first_run_page) 241 // Show first run page or the updates page. The latter is only shown
242 // on Chromium (since the current updates page announces features that
243 // aren't new to Firefox users), and only if this version of the
244 // updates page hasn't been shown yet.
245 if (firstRun || info.platform == "chromium" &&
246 updatesVersion > Prefs.last_updates_page_displayed)
242 { 247 {
243 let page = null; 248 Prefs.set("last_updates_page_displayed", updatesVersion).catch(() =>
244 if (firstRun)
245 { 249 {
246 page = "firstRun.html"; 250 exports.dataCorrupted = true;
247 } 251 }).then(() =>
248 // For now we're limiting the updates page to users of
249 // Chromium-based browsers to gage its impact
250 else if (info.platform == "chromium" &&
251 updatesVersion > Prefs.last_updates_page_displayed)
252 { 252 {
253 page = "updates.html"; 253 if (!Prefs.suppress_first_run_page)
254 } 254 {
255 255 // Always show the first run page if a data corruption was detected
256 if (page) 256 // (either though failure of reading from or writing to storage.local).
257 { 257 // The first run page notifies the user about the data corruption.
258 browser.tabs.create({url: browser.extension.getURL(page)}); 258 let url;
259 259 if (firstRun || exports.dataCorrupted)
260 // For new users and users that have already seen this updates page we 260 url = "firstRun.html";
261 // want to avoid showing it again for subsequent updates. 261 else
262 Prefs.last_updates_page_displayed = updatesVersion; 262 url = "updates.html";
263 } 263 browser.tabs.create({url});
264 }
265 });
264 } 266 }
265 267
266 initNotifications(); 268 initNotifications();
267 } 269 }
268 270
269 Promise.all([FilterNotifier.once("load"), 271 Promise.all([
270 Prefs.untilLoaded]).then(detectFirstRun) 272 FilterNotifier.once("load"),
271 .then(getSubscriptions) 273 Prefs.untilLoaded.catch(() => { exports.dataCorrupted = true; })
272 .then(finishInitialization); 274 ]).then(detectFirstRun)
275 .then(getSubscriptions)
276 .then(finishInitialization);
273 277
274 /** 278 /**
275 * Indicates whether the default filter subscriptions have been added 279 * Indicates whether the default filter subscriptions have been added
276 * again because there weren't any subscriptions even though this wasn't 280 * again because there weren't any subscriptions even though this wasn't
277 * the first run. 281 * the first run.
278 * 282 *
279 * @type {boolean} 283 * @type {boolean}
280 */ 284 */
281 exports.reinitialized = false; 285 exports.reinitialized = false;
282 286
283 /** 287 /**
288 * Indicates whether a data corruption was detected.
289 *
290 * @type {boolean}
291 */
292 exports.dataCorrupted = false;
293
294 /**
284 * Sets a callback that is called with an array of subscriptions to be added 295 * Sets a callback that is called with an array of subscriptions to be added
285 * during initialization. The callback must return an array of subscriptions 296 * during initialization. The callback must return an array of subscriptions
286 * that will effectively be added. 297 * that will effectively be added.
287 * 298 *
288 * @param {function} callback 299 * @param {function} callback
289 */ 300 */
290 exports.setSubscriptionsCallback = callback => 301 exports.setSubscriptionsCallback = callback =>
291 { 302 {
292 subscriptionsCallback = callback; 303 subscriptionsCallback = callback;
293 }; 304 };
OLDNEW
« 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