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

Delta Between Two Patch Sets: lib/stats.js

Issue 29996582: Issue 7257 - Throttle badge updates (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Alternative implementation, update all active tabs Created Feb. 4, 2019, 6:47 a.m.
Right Patch Set: Check for undefined Created Feb. 4, 2019, 7:33 a.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 | « no previous file | no next file » | 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** @module stats */ 18 /** @module stats */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {Prefs} = require("./prefs"); 22 const {Prefs} = require("./prefs");
23 const {BlockingFilter} = require("../adblockpluscore/lib/filterClasses"); 23 const {BlockingFilter} = require("../adblockpluscore/lib/filterClasses");
24 const {filterNotifier} = require("../adblockpluscore/lib/filterNotifier"); 24 const {filterNotifier} = require("../adblockpluscore/lib/filterNotifier");
25 const {port} = require("./messaging"); 25 const {port} = require("./messaging");
26 26
27 const badgeColor = "#646464"; 27 const badgeColor = "#646464";
28
29 // 4 fps.
Sebastian Noack 2019/02/04 07:16:41 Nit: This comment seems somewhat redundant. Perhap
Manish Jethani 2019/02/04 07:36:14 I think it's fine to just remove the comment. Don
30 const badgeRefreshRate = 4; 28 const badgeRefreshRate = 4;
31 29
32 let blockedPerPage = new ext.PageMap(); 30 let blockedPerPage = new ext.PageMap();
33 31
34 let getBlockedPerPage = 32 let getBlockedPerPage =
35 /** 33 /**
36 * Gets the number of requests blocked on the given page. 34 * Gets the number of requests blocked on the given page.
37 * 35 *
38 * @param {Page} page 36 * @param {Page} page
39 * @return {Number} 37 * @return {Number}
40 */ 38 */
41 exports.getBlockedPerPage = page => blockedPerPage.get(page) || 0; 39 exports.getBlockedPerPage = page => blockedPerPage.get(page) || 0;
42 40
43 let activeTabIds = new Set(); 41 let activeTabIds = new Set();
44 let activeTabIdByWindowId = new Map(); 42 let activeTabIdByWindowId = new Map();
45 43
46 let badgeUpdateScheduled = false; 44 let badgeUpdateScheduled = false;
47 45
48 function updateBadge(tabId = -1) 46 function updateBadge(tabId)
Sebastian Noack 2019/02/04 07:16:41 Nit: What would you think about not setting a defa
Manish Jethani 2019/02/04 07:36:14 Works for me, done.
49 { 47 {
50 if (!Prefs.show_statsinicon) 48 if (!Prefs.show_statsinicon)
51 return; 49 return;
Sebastian Noack 2019/02/04 07:16:41 The only purpose of the check here seems to be avo
Manish Jethani 2019/02/04 07:36:14 updateBadge is also called directly, not necessari
52 50
53 for (let id of (tabId == -1 ? activeTabIds : [tabId])) 51 for (let id of (typeof tabId == "undefined" ? activeTabIds : [tabId]))
54 { 52 {
55 let page = new ext.Page({id}); 53 let page = new ext.Page({id});
56 let blockedCount = blockedPerPage.get(page); 54 let blockedCount = blockedPerPage.get(page);
57 55
58 page.browserAction.setBadge(blockedCount && { 56 page.browserAction.setBadge(blockedCount && {
59 color: badgeColor, 57 color: badgeColor,
60 number: blockedCount 58 number: blockedCount
61 }); 59 });
62 } 60 }
63 } 61 }
64 62
65 function scheduleBadgeUpdate(tabId = -1) 63 function scheduleBadgeUpdate(tabId)
66 { 64 {
67 if (!badgeUpdateScheduled && Prefs.show_statsinicon && 65 if (!badgeUpdateScheduled && Prefs.show_statsinicon &&
68 (tabId == -1 || activeTabIds.has(tabId))) 66 (typeof tabId == "undefined" || activeTabIds.has(tabId)))
69 { 67 {
70 setTimeout(() => { badgeUpdateScheduled = false; updateBadge(); }, 68 setTimeout(() => { badgeUpdateScheduled = false; updateBadge(); },
71 1000 / badgeRefreshRate); 69 1000 / badgeRefreshRate);
72 badgeUpdateScheduled = true; 70 badgeUpdateScheduled = true;
73 } 71 }
74 } 72 }
75 73
76 // Once nagivation for the tab has been committed to (e.g. it's no longer 74 // Once nagivation for the tab has been committed to (e.g. it's no longer
77 // being prerendered) we clear its badge, or if some requests were already 75 // being prerendered) we clear its badge, or if some requests were already
78 // blocked beforehand we display those on the badge now. 76 // blocked beforehand we display those on the badge now.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 }); 140 });
143 141
144 if ("windows" in browser) 142 if ("windows" in browser)
145 { 143 {
146 browser.windows.onRemoved.addListener(windowId => 144 browser.windows.onRemoved.addListener(windowId =>
147 { 145 {
148 activeTabIds.delete(activeTabIdByWindowId.get(windowId)); 146 activeTabIds.delete(activeTabIdByWindowId.get(windowId));
149 activeTabIdByWindowId.delete(windowId); 147 activeTabIdByWindowId.delete(windowId);
150 }); 148 });
151 } 149 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld