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

Delta Between Two Patch Sets: lib/subscriptionInit.js

Issue 29760565: Issue 6599 - Detect data corruption of storage.local (Closed)
Left Patch Set: Added dataCorrupted parameter to uninstall page Created April 25, 2018, 1:16 p.m.
Right Patch Set: Fixed blocked_total optimization logic Created April 27, 2018, 4:55 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/prefs.js ('k') | lib/uninstall.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 13 matching lines...) Expand all
24 SpecialSubscription} = 24 SpecialSubscription} =
25 require("../adblockpluscore/lib/subscriptionClasses"); 25 require("../adblockpluscore/lib/subscriptionClasses");
26 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage"); 26 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage");
27 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); 27 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier");
28 const info = require("../buildtools/info"); 28 const info = require("../buildtools/info");
29 const {Prefs} = require("./prefs"); 29 const {Prefs} = require("./prefs");
30 const {Synchronizer} = require("../adblockpluscore/lib/synchronizer"); 30 const {Synchronizer} = require("../adblockpluscore/lib/synchronizer");
31 const {Utils} = require("./utils"); 31 const {Utils} = require("./utils");
32 const {initNotifications} = require("./notificationHelper"); 32 const {initNotifications} = require("./notificationHelper");
33 const {updatesVersion} = require("../adblockplusui/lib/prefs"); 33 const {updatesVersion} = require("../adblockplusui/lib/prefs");
34 const {setUninstallURL} = require("./uninstall");
35 34
36 let firstRun; 35 let firstRun;
37 let subscriptionsCallback = null; 36 let subscriptionsCallback = null;
37 let reinitialized = false;
38 let dataCorrupted = false;
38 39
39 /** 40 /**
40 * If there aren't any filters, the default subscriptions are added. 41 * If there aren't any filters, the default subscriptions are added.
41 * However, if patterns.ini already did exist and/or any preference 42 * However, if patterns.ini already did exist and/or any preference
42 * is set to a non-default value, this indicates that this isn't the 43 * is set to a non-default value, this indicates that this isn't the
43 * first run, but something went wrong. 44 * first run, but something went wrong.
44 * 45 *
45 * This function detects the first run, and makes sure that the user 46 * This function detects the first run, and makes sure that the user
46 * gets notified (on the first run page) if the data appears incomplete 47 * gets notified (on the first run page) if the data appears incomplete
47 * and therefore will be reinitialized. 48 * and therefore will be reinitialized.
48 */ 49 */
49 function detectFirstRun() 50 function detectFirstRun()
50 { 51 {
51 firstRun = FilterStorage.subscriptions.length == 0; 52 firstRun = FilterStorage.subscriptions.length == 0;
52 53
53 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion)) 54 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion))
54 exports.reinitialized = true; 55 reinitialized = true;
55 56
56 Prefs.currentVersion = info.addonVersion; 57 Prefs.currentVersion = info.addonVersion;
57 } 58 }
58 59
59 /** 60 /**
60 * Determines whether to add the default ad blocking subscription. 61 * Determines whether to add the default ad blocking subscription.
61 * Returns true, if there are no filter subscriptions besides those 62 * Returns true, if there are no filter subscriptions besides those
62 * other subscriptions added automatically, and no custom filters. 63 * other subscriptions added automatically, and no custom filters.
63 * 64 *
64 * On first run, this logic should always result in true since there 65 * On first run, this logic should always result in true since there
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 function supportsNotificationsWithButtons() 140 function supportsNotificationsWithButtons()
140 { 141 {
141 // Microsoft Edge (as of EdgeHTML 16) doesn't have the notifications API. 142 // Microsoft Edge (as of EdgeHTML 16) doesn't have the notifications API.
142 // Opera gives an asynchronous error when buttons are provided (we cannot 143 // Opera gives an asynchronous error when buttons are provided (we cannot
143 // detect that behavior without attempting to show a notification). 144 // detect that behavior without attempting to show a notification).
144 if (!("notifications" in browser) || info.application == "opera") 145 if (!("notifications" in browser) || info.application == "opera")
145 return false; 146 return false;
146 147
147 // Firefox throws synchronously if the "buttons" option is provided. 148 // Firefox throws synchronously if the "buttons" option is provided.
148 // If buttons are supported (i.e. on Chrome), this fails with 149 // If buttons are supported (i.e. on Chrome), this fails with
149 // a different error message due to missing required options. 150 // an asynchronous error due to missing required options.
150 // https://bugzilla.mozilla.org/show_bug.cgi?id=1190681 151 // https://bugzilla.mozilla.org/show_bug.cgi?id=1190681
151 try 152 try
152 { 153 {
153 browser.notifications.create({buttons: []}); 154 browser.notifications.create({buttons: []}).catch(() => {});
154 } 155 }
155 catch (e) 156 catch (e)
156 { 157 {
157 if (e.toString().includes('"buttons" is unsupported')) 158 if (e.toString().includes('"buttons" is unsupported'))
158 return false; 159 return false;
159 } 160 }
160 161
161 return true; 162 return true;
162 } 163 }
163 164
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 242
242 // Show first run page or the updates page. The latter is only shown 243 // Show first run page or the updates page. The latter is only shown
243 // on Chromium (since the current updates page announces features that 244 // on Chromium (since the current updates page announces features that
244 // aren't new to Firefox users), and only if this version of the 245 // aren't new to Firefox users), and only if this version of the
245 // updates page hasn't been shown yet. 246 // updates page hasn't been shown yet.
246 if (firstRun || info.platform == "chromium" && 247 if (firstRun || info.platform == "chromium" &&
247 updatesVersion > Prefs.last_updates_page_displayed) 248 updatesVersion > Prefs.last_updates_page_displayed)
248 { 249 {
249 return Prefs.set("last_updates_page_displayed", updatesVersion).catch(() => 250 return Prefs.set("last_updates_page_displayed", updatesVersion).catch(() =>
250 { 251 {
251 exports.dataCorrupted = true; 252 dataCorrupted = true;
252 }).then(() => 253 }).then(() =>
253 { 254 {
254 if (!Prefs.suppress_first_run_page) 255 if (!Prefs.suppress_first_run_page)
255 { 256 {
256 // Always show the first run page if a data corruption was detected 257 // Always show the first run page if a data corruption was detected
257 // (either though failure of reading from or writing to storage.local). 258 // (either through failure of reading from or writing to storage.local).
258 // The first run page notifies the user about the data corruption. 259 // The first run page notifies the user about the data corruption.
259 let url; 260 let url;
260 if (firstRun || exports.dataCorrupted) 261 if (firstRun || dataCorrupted)
261 url = "firstRun.html"; 262 url = "firstRun.html";
262 else 263 else
263 url = "updates.html"; 264 url = "updates.html";
264 browser.tabs.create({url}); 265 browser.tabs.create({url});
265 } 266 }
266 }); 267 });
267 } 268 }
268 } 269 }
269 270
270 Promise.all([ 271 Promise.all([
271 FilterNotifier.once("load"), 272 FilterNotifier.once("load"),
272 Prefs.untilLoaded.catch(() => { exports.dataCorrupted = true; }) 273 Prefs.untilLoaded.catch(() => { dataCorrupted = true; })
273 ]).then(detectFirstRun) 274 ]).then(detectFirstRun)
274 .then(getSubscriptions) 275 .then(getSubscriptions)
275 .then(addSubscriptionsAndNotifyUser) 276 .then(addSubscriptionsAndNotifyUser)
276 .then(setUninstallURL) 277 // We have to require the "uninstall" module on demand,
278 // as the "uninstall" module in turn requires this module.
279 .then(() => { require("./uninstall").setUninstallURL(); })
277 .then(initNotifications); 280 .then(initNotifications);
278 281
279 /** 282 /**
280 * Indicates whether the default filter subscriptions have been added 283 * Gets a value indicating whether the default filter subscriptions have been
281 * again because there weren't any subscriptions even though this wasn't 284 * added again because there weren't any subscriptions even though this wasn't
282 * the first run. 285 * the first run.
283 * 286 *
284 * @type {boolean} 287 * @return {boolean}
285 */ 288 */
286 exports.reinitialized = false; 289 exports.isReinitialized = () => reinitialized;
287 290
288 /** 291 /**
289 * Indicates whether a data corruption was detected. 292 * Gets a value indicating whether a data corruption was detected.
290 * 293 *
291 * @type {boolean} 294 * @return {boolean}
292 */ 295 */
293 exports.dataCorrupted = false; 296 exports.isDataCorrupted = () => dataCorrupted;
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
294 297
295 /** 298 /**
296 * Sets a callback that is called with an array of subscriptions to be added 299 * Sets a callback that is called with an array of subscriptions to be added
297 * during initialization. The callback must return an array of subscriptions 300 * during initialization. The callback must return an array of subscriptions
298 * that will effectively be added. 301 * that will effectively be added.
299 * 302 *
300 * @param {function} callback 303 * @param {function} callback
301 */ 304 */
302 exports.setSubscriptionsCallback = callback => 305 exports.setSubscriptionsCallback = callback =>
303 { 306 {
304 subscriptionsCallback = callback; 307 subscriptionsCallback = callback;
305 }; 308 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld