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

Side by Side Diff: lib/stats.js

Issue 11627039: Added ad counting functionality (Closed)
Patch Set: Created Sept. 11, 2013, 3:10 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
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 /**
19 * @fileOverview Provides usage stats
20 */
21
22 let {Prefs} = require("prefs");
23 let {BlockingFilter} = require("filterClasses");
24 let {FilterNotifier} = require("filterNotifier");
25
26 /**
27 * Base class for individual stats
28 * @param {Object} stats simple object representation of stats
29 */
30 let StatsObject = exports.StatsObject = function(stats)
31 {
32 if (typeof stats == "undefined")
33 return;
34
35 this.blocked = stats.blocked || this.blocked;
36 }
37 StatsObject.prototype = {
38 /**
39 * Number of blocked resources
40 * @type Number
41 */
42 blocked: 0
43 };
44
45 let total = new StatsObject(Prefs["stats_total"]);
46
47 let Stats = exports.Stats = {
48 /**
49 * Total counts
50 */
51 get total()
52 {
53 return total;
54 }
55 }
Wladimir Palant 2013/09/18 09:44:41 The exported API here seems overly complicated for
56
57 FilterNotifier.addListener(function(action, item, tabId)
58 {
59 if (action != "document.stats")
60 return;
61
62 var blocked = item instanceof BlockingFilter;
63
64 // increment counts
65 if (blocked)
66 total.blocked++;
Wladimir Palant 2013/09/18 09:44:41 Prefs.stats_total++; will do here, no point cachin
67
68 ChromeCompat.tabs.sendMessage(tabId, {
69 reqtype: "update-stats",
70 blocked: blocked
71 }, null);
Wladimir Palant 2013/09/18 09:44:41 Simpler: let frameData = getFrameData(tabId, 0);
72
73 Prefs["stats_total"] = total;
74 });
OLDNEW

Powered by Google App Engine
This is Rietveld