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

Unified Diff: lib/typedItCollector.js

Issue 8433028: added hook function to appIntegration to handle function-overwrites from other extensions (Closed)
Patch Set: added missing statement Created Sept. 28, 2012, 9:52 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/survey.js ('k') | lib/typoFixer.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/typedItCollector.js
===================================================================
--- a/lib/typedItCollector.js
+++ b/lib/typedItCollector.js
@@ -7,9 +7,12 @@
let {Prefs} = require("prefs");
let {WindowObserver} = require("windowObserver");
+let DOMAIN_TYPED = 1;
+let DOMAIN_TYPO = 2;
+let DOMAIN_CORRECTION = 3;
+let DOMAIN_FALSE_POSITIVE = 4;
+
let domains = null;
-let userCorrections = null;
-let falsePositives = null;
let timer = null;
// Initialize and make sure to react to pref changes
@@ -64,24 +67,36 @@
function processTypedDomain(domain)
{
if (domains && !privateBrowsingEnabled())
- domains.push(domain);
+ domains[domain] = DOMAIN_TYPED;
+}
+
+exports.processDomainCorrection = processDomainCorrection;
+function processDomainCorrection(domainFrom, domainTo)
+{
+ if (domains && !privateBrowsingEnabled())
+ {
+ domains[domainFrom] = DOMAIN_TYPO;
+ domains[domainTo] = DOMAIN_CORRECTION;
+ }
}
exports.processFalsePositive = processFalsePositive;
function processFalsePositive(domainFrom, domainTo)
{
- if (falsePositives && !privateBrowsingEnabled())
+ if (domains && !privateBrowsingEnabled())
{
- falsePositives.push([domainFrom, domainTo]);
+ domains[domainFrom] = DOMAIN_FALSE_POSITIVE;
+ domains[domainTo] = DOMAIN_TYPED;
}
}
exports.processUserCorrection = processUserCorrection;
function processUserCorrection(domainFrom, domainTo)
{
- if (userCorrections && !privateBrowsingEnabled())
+ if (domains && !privateBrowsingEnabled())
{
- userCorrections.push([domainFrom, domainTo]);
+ domains[domainFrom] = DOMAIN_TYPO;
+ domains[domainTo] = DOMAIN_CORRECTION;
}
}
@@ -101,29 +116,25 @@
function startCollection()
{
- if (domains || falsePositives || userCorrections)
+ if (domains)
return;
onShutdown.add(stopCollection);
- domains = [];
- falsePositives = [];
- userCorrections = [];
+ domains = {};
- // Send data every 15 minutes
+ // Send data every 60 minutes
timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
- timer.initWithCallback(sendAnonymousData, 1000 * 60 * 15, Ci.nsITimer.TYPE_REPEATING_SLACK);
+ timer.initWithCallback(sendAnonymousData, 1000 * 60 * 60, Ci.nsITimer.TYPE_REPEATING_SLACK);
}
function stopCollection()
{
- if (!domains || !falsePositives || !userCorrections)
+ if (!domains)
return;
onShutdown.remove(stopCollection);
domains = null;
- falsePositives = null;
- userCorrections = null;
try
{
@@ -146,43 +157,25 @@
function sendAnonymousData()
{
- if (!Prefs.domainOptIn || (domains.length == 0 && falsePositives.length == 0 && userCorrections.length == 0) || privateBrowsingEnabled())
+ if (!Prefs.domainOptIn || privateBrowsingEnabled())
return;
-
- let postData = {};
+
+ let postData = JSON.stringify(domains);
+ if (postData == JSON.stringify({}))
+ return;
+
let savedDomains = domains;
- let savedFalsePositives = falsePositives;
- let savedUserCorrections = userCorrections;
+ domains = {};
- if(domains.length > 0)
- {
- postData.domains = domains;
- domains = [];
- }
- if(falsePositives.length > 0)
- {
- postData.falsePositives = falsePositives;
- falsePositives = [];
- }
- if(userCorrections.length > 0)
- {
- postData.userCorrections = userCorrections;
- userCorrections = [];
- }
-
let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
request.open("POST", "http://typed.it/submitData");
- request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ request.setRequestHeader("Content-Type", "application/json");
request.addEventListener("load", function(event)
{
if (event.target.status != 200)
- {
domains = domains.concat(savedDomains);
- falsePositives = falsePositives.concat(savedFalsePositives);
- userCorrections = userCorrections.concat(savedUserCorrections);
- }
}, false);
- request.send("data=" + JSON.stringify(postData));
+ request.send(postData);
}
function initWebUI(event)
« no previous file with comments | « lib/survey.js ('k') | lib/typoFixer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld