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

Side by Side Diff: lib/prefs.js

Issue 5968535989780480: Issue 2567 - Simplified stats data structure, fixed regression resetting ad counter (Closed)
Patch Set: Created May 22, 2015, 1:07 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 | « no previous file | lib/stats.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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 * @see https://adblockplus.org/en/preferences#notificationdata 97 * @see https://adblockplus.org/en/preferences#notificationdata
98 * @type {object} 98 * @type {object}
99 */ 99 */
100 defaults.notificationdata = {}; 100 defaults.notificationdata = {};
101 /** 101 /**
102 * @see https://adblockplus.org/en/preferences#notificationurl 102 * @see https://adblockplus.org/en/preferences#notificationurl
103 * @type {string} 103 * @type {string}
104 */ 104 */
105 defaults.notificationurl = "https://notification.adblockplus.org/notification.js on"; 105 defaults.notificationurl = "https://notification.adblockplus.org/notification.js on";
106 /** 106 /**
107 * The total number of ads blocked on all pages. 107 * The total number of requests blocked by the extension.
108 * 108 *
109 * @type {object} 109 * @type {number}
110 * @property {number} [blocked]
111 */ 110 */
112 defaults.stats_total = {}; 111 defaults.blocked_total = 0;
113 /** 112 /**
114 * Whether to show a badge in the toolbar icon indicating the number of blocked ads. 113 * Whether to show a badge in the toolbar icon indicating the number of blocked ads.
115 * 114 *
116 * @type {boolean} 115 * @type {boolean}
117 */ 116 */
118 defaults.show_statsinicon = true; 117 defaults.show_statsinicon = true;
119 /** 118 /**
120 * Whether to show the number of blocked ads in the popup. 119 * Whether to show the number of blocked ads in the popup.
121 * 120 *
122 * @type {boolean} 121 * @type {boolean}
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 }); 238 });
240 239
241 Prefs.onLoaded._dispatch(); 240 Prefs.onLoaded._dispatch();
242 }; 241 };
243 242
244 // Migrate preferences for users updating from old versions. 243 // Migrate preferences for users updating from old versions.
245 // TODO: Remove the migration code after a few releases. 244 // TODO: Remove the migration code after a few releases.
246 ext.storage.migratePrefs({ 245 ext.storage.migratePrefs({
247 map: function(key, value) 246 map: function(key, value)
248 { 247 {
249 if (key in defaults) 248 if (key in defaults || key == "stats_total")
250 { 249 {
251 if (key != "currentVersion") 250 if (key != "currentVersion")
252 { 251 {
253 try 252 try
254 { 253 {
255 value = JSON.parse(value); 254 value = JSON.parse(value);
256 } 255 }
257 catch (e) 256 catch (e)
258 { 257 {
259 return null; 258 return null;
260 } 259 }
261 } 260 }
262 261
262 if (key == "stats_total")
263 {
264 key = "blocked_total";
265 value = value.blocked;
266 }
267
263 return {key: prefToKey(key), value: value}; 268 return {key: prefToKey(key), value: value};
264 } 269 }
265 270
266 return null; 271 return null;
267 }, 272 },
268 273
269 done: function() 274 done: function()
270 { 275 {
271 ext.storage.get(prefs.map(prefToKey), function(items) 276 ext.storage.get(prefs.map(prefToKey), function(items)
272 { 277 {
(...skipping 24 matching lines...) Expand all
297 }); 302 });
298 } 303 }
299 else 304 else
300 { 305 {
301 managedLoaded = true; 306 managedLoaded = true;
302 checkLoaded(); 307 checkLoaded();
303 } 308 }
304 } 309 }
305 310
306 init(); 311 init();
OLDNEW
« no previous file with comments | « no previous file | lib/stats.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld