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

Delta Between Two Patch Sets: lib/prefs.js

Issue 29508671: Testing new options page with the extension (Closed)
Left Patch Set: Fixed pfaa link Created Sept. 27, 2017, 3:44 p.m.
Right Patch Set: Created Oct. 5, 2017, 8:40 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') | metadata.chrome » ('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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 * 144 *
145 * @type {boolean} 145 * @type {boolean}
146 */ 146 */
147 defaults.hidePlaceholders = true; 147 defaults.hidePlaceholders = true;
148 148
149 /** 149 /**
150 * Whether notification opt-out UI should be shown. 150 * Whether notification opt-out UI should be shown.
151 * @type {boolean} 151 * @type {boolean}
152 */ 152 */
153 defaults.notifications_showui = false; 153 defaults.notifications_showui = false;
154 /** 154
155 * Whether notification about privacy conflict should be shown.
156 * @type {boolean}
157 */
158 defaults.ui_warn_tracking = true;
159 /** 155 /**
160 * Determines whether data has been cleaned up after upgrading from the legacy 156 * Determines whether data has been cleaned up after upgrading from the legacy
161 * extension on Firefox. 157 * extension on Firefox.
162 * 158 *
163 * @type {boolean} 159 * @type {boolean}
164 */ 160 */
165 defaults.data_cleanup_done = false; 161 defaults.data_cleanup_done = false;
166 162
167 /** 163 /**
168 * Notification categories to be ignored. 164 * Notification categories to be ignored.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 return null; 236 return null;
241 237
242 return key.substr(keyPrefix.length); 238 return key.substr(keyPrefix.length);
243 } 239 }
244 240
245 function prefToKey(pref) 241 function prefToKey(pref)
246 { 242 {
247 return keyPrefix + pref; 243 return keyPrefix + pref;
248 } 244 }
249 245
246 function savePref(pref)
247 {
248 ext.storage.set(prefToKey(pref), overrides[pref]);
249 }
250
251 let customSave = new Map();
252 if (require("info").platform == "gecko")
253 {
254 // Saving one storage value causes all others to be saved as well on Gecko.
255 // Make sure that updating ad counter doesn't cause the filters data to be
256 // saved frequently as a side-effect.
257 const MIN_UPDATE_INTERVAL = 60 * 1000;
258 let lastUpdate = -MIN_UPDATE_INTERVAL;
259 let updateScheduled = false;
260 customSave.set("blocked_total", pref =>
261 {
262 if (updateScheduled)
263 return;
264
265 let callback = () =>
266 {
267 lastUpdate = performance.now();
268 updateScheduled = false;
269 savePref(pref);
270 };
271
272 let timeElapsed = performance.now() - lastUpdate;
273 if (timeElapsed < MIN_UPDATE_INTERVAL)
274 {
275 setTimeout(callback, MIN_UPDATE_INTERVAL - timeElapsed);
276 updateScheduled = true;
277 }
278 else
279 callback();
280 });
281 }
282
250 function addPreference(pref) 283 function addPreference(pref)
251 { 284 {
252 Object.defineProperty(Prefs, pref, { 285 Object.defineProperty(Prefs, pref, {
253 get() { return (pref in overrides ? overrides : defaults)[pref]; }, 286 get() { return (pref in overrides ? overrides : defaults)[pref]; },
254 set(value) 287 set(value)
255 { 288 {
256 let defaultValue = defaults[pref]; 289 let defaultValue = defaults[pref];
257 290
258 if (typeof value != typeof defaultValue) 291 if (typeof value != typeof defaultValue)
259 throw new Error("Attempt to change preference type"); 292 throw new Error("Attempt to change preference type");
260 293
261 if (value == defaultValue) 294 if (value == defaultValue)
262 { 295 {
263 delete overrides[pref]; 296 delete overrides[pref];
264 ext.storage.remove(prefToKey(pref)); 297 ext.storage.remove(prefToKey(pref));
265 } 298 }
266 else 299 else
267 { 300 {
268 overrides[pref] = value; 301 overrides[pref] = value;
269 ext.storage.set(prefToKey(pref), value); 302 (customSave.get(pref) || savePref)(pref);
270 } 303 }
271 }, 304 },
272 enumerable: true 305 enumerable: true
273 }); 306 });
274 } 307 }
275 308
276 function init() 309 function init()
277 { 310 {
278 let prefs = Object.keys(defaults); 311 let prefs = Object.keys(defaults);
279 prefs.forEach(addPreference); 312 prefs.forEach(addPreference);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 eventEmitter.emit(pref); 364 eventEmitter.emit(pref);
332 } 365 }
333 } 366 }
334 }); 367 });
335 } 368 }
336 369
337 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded); 370 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded);
338 } 371 }
339 372
340 init(); 373 init();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld