[Pkg-mozext-commits] [adblock-plus] 02/52: Issue 537 - Mark first few downloads

David Prévot taffit at moszumanska.debian.org
Thu Jan 22 21:43:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus.

commit 394ce5b83dbdb42dac80e85b481bf54f23bc3491
Author: Thomas Greiner <thomas at adblockplus.org>
Date:   Wed Nov 12 11:07:53 2014 +0100

    Issue 537 - Mark first few downloads
---
 lib/downloader.js          | 15 ++++++++++++++-
 lib/notification.js        |  3 +++
 lib/subscriptionClasses.js | 24 +++++++++++++++++-------
 lib/synchronizer.js        |  2 ++
 4 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/lib/downloader.js b/lib/downloader.js
index d1ef209..62ceb13 100644
--- a/lib/downloader.js
+++ b/lib/downloader.js
@@ -191,13 +191,18 @@ Downloader.prototype =
       url += "&";
     else
       url += "?";
+    // We limit the download count to 4+ to keep the request anonymized
+    let downloadCount = downloadable.downloadCount;
+    if (downloadCount > 4)
+      downloadCount = "4+";
     url += "addonName=" + encodeURIComponent(addonName) +
         "&addonVersion=" + encodeURIComponent(addonVersion) +
         "&application=" + encodeURIComponent(application) +
         "&applicationVersion=" + encodeURIComponent(applicationVersion) +
         "&platform=" + encodeURIComponent(platform) +
         "&platformVersion=" + encodeURIComponent(platformVersion) +
-        "&lastVersion=" + encodeURIComponent(downloadable.lastVersion);
+        "&lastVersion=" + encodeURIComponent(downloadable.lastVersion) +
+        "&downloadCount=" + encodeURIComponent(downloadCount);
     return url;
   },
 
@@ -291,6 +296,8 @@ Downloader.prototype =
         return;
       }
 
+      downloadable.downloadCount++;
+
       this.onDownloadSuccess(downloadable, request.responseText, errorCallback, function redirectCallback(url)
       {
         if (redirects >= this.maxRedirects)
@@ -378,4 +385,10 @@ Downloadable.prototype =
    * @type Integer
    */
   hardExpiration: 0,
+  
+  /**
+   * Number indicating how often the object was downloaded.
+   * @type Integer
+   */
+  downloadCount: 0,
 };
diff --git a/lib/notification.js b/lib/notification.js
index b00d24c..6dd21e1 100644
--- a/lib/notification.js
+++ b/lib/notification.js
@@ -107,6 +107,8 @@ let Notification = exports.Notification =
       downloadable.softExpiration = Prefs.notificationdata.softExpiration;
     if (typeof Prefs.notificationdata.hardExpiration === "number")
       downloadable.hardExpiration = Prefs.notificationdata.hardExpiration;
+    if (typeof Prefs.notificationdata.downloadCount === "number")
+      downloadable.downloadCount = Prefs.notificationdata.downloadCount;
     yield downloadable;
   },
 
@@ -144,6 +146,7 @@ let Notification = exports.Notification =
     Prefs.notificationdata.lastError = 0;
     Prefs.notificationdata.downloadStatus = "synchronize_ok";
     [Prefs.notificationdata.softExpiration, Prefs.notificationdata.hardExpiration] = downloader.processExpirationInterval(EXPIRATION_INTERVAL);
+    Prefs.notificationdata.downloadCount = downloadable.downloadCount;
     saveNotificationData();
   },
 
diff --git a/lib/subscriptionClasses.js b/lib/subscriptionClasses.js
index c62f87a..be2836a 100644
--- a/lib/subscriptionClasses.js
+++ b/lib/subscriptionClasses.js
@@ -196,17 +196,17 @@ Subscription.fromObject = function(obj)
     if ("downloadStatus" in obj)
       result._downloadStatus = obj.downloadStatus;
     if ("lastSuccess" in obj)
-      result.lastSuccess = parseInt(obj.lastSuccess) || 0;
+      result.lastSuccess = parseInt(obj.lastSuccess, 10) || 0;
     if ("lastCheck" in obj)
-      result._lastCheck = parseInt(obj.lastCheck) || 0;
+      result._lastCheck = parseInt(obj.lastCheck, 10) || 0;
     if ("expires" in obj)
-      result.expires = parseInt(obj.expires) || 0;
+      result.expires = parseInt(obj.expires, 10) || 0;
     if ("softExpiration" in obj)
-      result.softExpiration = parseInt(obj.softExpiration) || 0;
+      result.softExpiration = parseInt(obj.softExpiration, 10) || 0;
     if ("errors" in obj)
-      result._errors = parseInt(obj.errors) || 0;
+      result._errors = parseInt(obj.errors, 10) || 0;
     if ("version" in obj)
-      result.version = parseInt(obj.version) || 0;
+      result.version = parseInt(obj.version, 10) || 0;
     if ("requiredVersion" in obj)
     {
       let {addonVersion} = require("info");
@@ -217,7 +217,9 @@ Subscription.fromObject = function(obj)
     if ("homepage" in obj)
       result._homepage = obj.homepage;
     if ("lastDownload" in obj)
-      result._lastDownload = parseInt(obj.lastDownload) || 0;
+      result._lastDownload = parseInt(obj.lastDownload, 10) || 0;
+    if ("downloadCount" in obj)
+      result.downloadCount = parseInt(obj.downloadCount, 10) || 0;
   }
   catch (e)
   {
@@ -560,6 +562,12 @@ DownloadableSubscription.prototype =
    * @type Boolean
    */
   upgradeRequired: false,
+  
+  /**
+   * Number indicating how often the object was downloaded.
+   * @type Number
+   */
+  downloadCount: 0,
 
   /**
    * See Subscription.serialize()
@@ -583,5 +591,7 @@ DownloadableSubscription.prototype =
       buffer.push("version=" + this.version);
     if (this.requiredVersion)
       buffer.push("requiredVersion=" + this.requiredVersion);
+    if (this.downloadCount)
+      buffer.push("downloadCount=" + this.downloadCount);
   }
 };
diff --git a/lib/synchronizer.js b/lib/synchronizer.js
index 4c822f0..ca19e2d 100644
--- a/lib/synchronizer.js
+++ b/lib/synchronizer.js
@@ -113,6 +113,7 @@ let Synchronizer = exports.Synchronizer =
     result.softExpiration = subscription.softExpiration * MILLIS_IN_SECOND;
     result.hardExpiration = subscription.expires * MILLIS_IN_SECOND;
     result.manual = manual;
+    result.downloadCount = subscription.downloadCount;
     return result;
   },
 
@@ -195,6 +196,7 @@ let Synchronizer = exports.Synchronizer =
     // The download actually succeeded
     subscription.lastSuccess = subscription.lastDownload = Math.round(Date.now() / MILLIS_IN_SECOND);
     subscription.downloadStatus = "synchronize_ok";
+    subscription.downloadCount = downloadable.downloadCount;
     subscription.errors = 0;
 
     // Remove lines containing parameters

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git



More information about the Pkg-mozext-commits mailing list