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

Delta Between Two Patch Sets: lib/prefs.js

Issue 29760565: Issue 6599 - Detect data corruption of storage.local (Closed)
Left Patch Set: Added missing semicolon, made customSave logic respond asynchrnously Created April 27, 2018, 4:13 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 | « dependencies ('k') | lib/subscriptionInit.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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // saved frequently as a side-effect. 297 // saved frequently as a side-effect.
298 const MIN_UPDATE_INTERVAL = 60 * 1000; 298 const MIN_UPDATE_INTERVAL = 60 * 1000;
299 let lastUpdate = -MIN_UPDATE_INTERVAL; 299 let lastUpdate = -MIN_UPDATE_INTERVAL;
300 let promise = null; 300 let promise = null;
301 customSave.set("blocked_total", pref => 301 customSave.set("blocked_total", pref =>
302 { 302 {
303 if (!promise) 303 if (!promise)
304 { 304 {
305 promise = new Promise((resolve, reject) => 305 promise = new Promise((resolve, reject) =>
306 { 306 {
307 let callback = () => 307 setTimeout(
308 { 308 () =>
309 lastUpdate = performance.now(); 309 {
310 promise = null; 310 lastUpdate = performance.now();
Sebastian Noack 2018/04/27 16:58:58 Since callback() were potentially called synchrono
Thomas Greiner 2018/04/27 17:03:32 Acknowledged.
311 savePref(pref).then(resolve, reject); 311 promise = null;
312 }; 312 savePref(pref).then(resolve, reject);
313 313 },
314 let timeElapsed = performance.now() - lastUpdate; 314 lastUpdate + MIN_UPDATE_INTERVAL - performance.now()
315 if (timeElapsed < MIN_UPDATE_INTERVAL) 315 );
316 setTimeout(callback, MIN_UPDATE_INTERVAL - timeElapsed);
317 else
318 callback();
319 }); 316 });
320 } 317 }
321 return promise; 318 return promise;
322 }); 319 });
323 } 320 }
324 321
325 function addPreference(pref) 322 function addPreference(pref)
326 { 323 {
327 Object.defineProperty(Prefs, pref, { 324 Object.defineProperty(Prefs, pref, {
328 get() { return (pref in overrides ? overrides : defaults)[pref]; }, 325 get() { return (pref in overrides ? overrides : defaults)[pref]; },
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 eventEmitter.emit(pref); 382 eventEmitter.emit(pref);
386 } 383 }
387 } 384 }
388 }); 385 });
389 } 386 }
390 387
391 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded); 388 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded);
392 } 389 }
393 390
394 init(); 391 init();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld