Skip to content

Commit

Permalink
Back out 3 changesets (bug 1210211) for b2g build bustage
Browse files Browse the repository at this point in the history
CLOSED TREE

Backed out changeset 204a1746f421 (bug 1210211)
Backed out changeset e5d16111e809 (bug 1210211)
Backed out changeset b78d00c9af42 (bug 1210211)
  • Loading branch information
philor committed Nov 17, 2015
1 parent a0dfb7b commit 6edbd4d
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 280 deletions.
18 changes: 0 additions & 18 deletions dom/interfaces/push/nsIPushNotificationService.idl
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,3 @@ interface nsIPushNotificationService : nsISupports
*/
jsval clearForDomain(in string domain);
};

[scriptable, uuid(a2555e70-46f8-4b52-bf02-d978b979d143)]
interface nsIPushQuotaManager : nsISupports
{
/**
* Informs the quota manager that a notification
* for the given origin has been shown. Used to
* determine if push quota should be relaxed.
*/
void notificationForOriginShown(in string origin);

/**
* Informs the quota manager that a notification
* for the given origin has been closed. Used to
* determine if push quota should be relaxed.
*/
void notificationForOriginClosed(in string origin);
};
22 changes: 0 additions & 22 deletions dom/notification/Notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "nsILoadContext.h"
#include "nsINotificationStorage.h"
#include "nsIPermissionManager.h"
#include "nsIPushNotificationService.h"
#include "nsIScriptSecurityManager.h"
#include "nsIServiceWorkerManager.h"
#include "nsIUUIDGenerator.h"
Expand Down Expand Up @@ -1174,27 +1173,6 @@ NotificationObserver::Observe(nsISupports* aSubject, const char* aTopic,
ContentChild::GetSingleton()->SendOpenNotificationSettings(
IPC::Principal(mPrincipal));
return NS_OK;
} else if (!strcmp("alertshow", aTopic) ||
!strcmp("alertfinished", aTopic)) {
nsCOMPtr<nsIPushQuotaManager> pushQuotaManager =
do_GetService("@mozilla.org/push/NotificationService;1");
if (pushQuotaManager) {
nsAutoCString origin;
nsresult rv = mPrincipal->GetOrigin(origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

if (!strcmp("alertshow", aTopic)) {
rv = pushQuotaManager->NotificationForOriginShown(origin.get());
} else {
rv = pushQuotaManager->NotificationForOriginClosed(origin.get());
}

if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
}

return mObserver->Observe(aSubject, aTopic, aData);
Expand Down
23 changes: 1 addition & 22 deletions dom/push/PushNotificationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ PushNotificationService.prototype = {
_xpcom_factory: XPCOMUtils.generateSingletonFactory(PushNotificationService),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference,
Ci.nsIPushNotificationService,
Ci.nsIPushQuotaManager,]),
Ci.nsIPushNotificationService]),

register: function register(scope, originAttributes) {
return PushService.register({
Expand Down Expand Up @@ -75,26 +74,6 @@ PushNotificationService.prototype = {
}
break;
}
},

// nsIPushQuotaManager methods

notificationForOriginShown: function(origin) {
if (!isParent) {
Services.cpmm.sendAsyncMessage("Push:NotificationForOriginShown", origin);
return;
}

PushService._notificationForOriginShown(origin);
},

notificationForOriginClosed: function(origin) {
if (!isParent) {
Services.cpmm.sendAsyncMessage("Push:NotificationForOriginClosed", origin);
return;
}

PushService._notificationForOriginClosed(origin);
}
};

Expand Down
23 changes: 12 additions & 11 deletions dom/push/PushRecord.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,25 @@ PushRecord.prototype = {
this.quota = 0;
return;
}
let currentQuota;
if (lastVisit > this.lastPush) {
// If the user visited the site since the last time we received a
// notification, reset the quota.
let daysElapsed = (Date.now() - lastVisit) / 24 / 60 / 60 / 1000;
this.quota = Math.min(
currentQuota = Math.min(
Math.round(8 * Math.pow(daysElapsed, -0.8)),
prefs.get("maxQuotaPerSubscription")
);
Services.telemetry.getHistogramById("PUSH_API_QUOTA_RESET_TO").add(this.quota);
Services.telemetry.getHistogramById("PUSH_API_QUOTA_RESET_TO").add(currentQuota - 1);
} else {
// The user hasn't visited the site since the last notification.
currentQuota = this.quota;
}
this.quota = Math.max(currentQuota - 1, 0);
// We check for ctime > 0 to skip older records that did not have ctime.
if (this.isExpired() && this.ctime > 0) {
let duration = Date.now() - this.ctime;
Services.telemetry.getHistogramById("PUSH_API_QUOTA_EXPIRATION_TIME").add(duration / 1000);
}
},

Expand All @@ -83,15 +93,6 @@ PushRecord.prototype = {
this.lastPush = Date.now();
},

reduceQuota() {
this.quota = Math.max(this.quota - 1, 0);
// We check for ctime > 0 to skip older records that did not have ctime.
if (this.isExpired() && this.ctime > 0) {
let duration = Date.now() - this.ctime;
Services.telemetry.getHistogramById("PUSH_API_QUOTA_EXPIRATION_TIME").add(duration / 1000);
}
},

/**
* Queries the Places database for the last time a user visited the site
* associated with a push registration.
Expand Down
92 changes: 7 additions & 85 deletions dom/push/PushService.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ const prefs = new Preferences("dom.push.");

const kCHILD_PROCESS_MESSAGES = ["Push:Register", "Push:Unregister",
"Push:Registration", "Push:RegisterEventNotificationListener",
"Push:NotificationForOriginShown",
"Push:NotificationForOriginClosed",
"child-process-shutdown"];

const PUSH_SERVICE_UNINIT = 0;
Expand Down Expand Up @@ -99,11 +97,6 @@ this.PushService = {
_db: null,
_options: null,
_alarmID: null,
_visibleNotifications: new Map(),

// Callback that is called after attempting to
// reduce the quota for a record. Used for testing purposes.
_updateQuotaTestCallback: null,

_childListeners: [],

Expand Down Expand Up @@ -890,77 +883,20 @@ this.PushService = {
if (shouldNotify) {
notified = this._notifyApp(record, message);
}
// Update quota after the delay, at which point
// we check for visible notifications.
setTimeout(() => this._updateQuota(keyID),
prefs.get("quotaUpdateDelay"));
if (record.isExpired()) {
this._recordDidNotNotify(kDROP_NOTIFICATION_REASON_EXPIRED);
// Drop the registration in the background. If the user returns to the
// site, the service worker will be notified on the next `idle-daily`
// event.
this._backgroundUnregister(record);
}
return notified;
});
}).catch(error => {
console.error("receivedPushMessage: Error notifying app", error);
});
},

_updateQuota: function(keyID) {
console.debug("updateQuota()");

this._db.update(keyID, record => {
// Record may have expired from an earlier quota update.
if (record.isExpired()) {
console.debug(
"updateQuota: Trying to update quota for expired record", record);
return null;
}
// If there are visible notifications, don't apply the quota penalty
// for the message.
if (!this._visibleNotifications.has(record.uri.prePath)) {
record.reduceQuota();
}
return record;
}).then(record => {
if (record && record.isExpired()) {
this._recordDidNotNotify(kDROP_NOTIFICATION_REASON_EXPIRED);
// Drop the registration in the background. If the user returns to the
// site, the service worker will be notified on the next `idle-daily`
// event.
this._backgroundUnregister(record);
}
if (this._updateQuotaTestCallback) {
// Callback so that test may be notified when the quota update is complete.
this._updateQuotaTestCallback();
}
}).catch(error => {
console.debug("updateQuota: Error while trying to update quota", error);
});
},

_notificationForOriginShown(origin) {
console.debug("notificationForOriginShown()", origin);
let count;
if (this._visibleNotifications.has(origin)) {
count = this._visibleNotifications.get(origin);
} else {
count = 0;
}
this._visibleNotifications.set(origin, count + 1);
},

_notificationForOriginClosed(origin) {
console.debug("notificationForOriginClosed()", origin);
let count;
if (this._visibleNotifications.has(origin)) {
count = this._visibleNotifications.get(origin);
} else {
console.debug("notificationForOriginClosed: closing notification that has not been shown?");
return;
}
if (count > 1) {
this._visibleNotifications.set(origin, count - 1);
} else {
this._visibleNotifications.delete(origin);
}
},

_notifyApp: function(aPushRecord, message) {
if (!aPushRecord || !aPushRecord.scope ||
aPushRecord.originAttributes === undefined) {
Expand Down Expand Up @@ -1119,20 +1055,6 @@ this.PushService = {
this._childListeners.splice(i, 1);
}
}
console.debug("receiveMessage: Clearing notifications from child");
this._visibleNotifications.clear();
return;
}

if (aMessage.name === "Push:NotificationForOriginShown") {
console.debug("receiveMessage: Notification shown from child");
this._notificationForOriginShown(aMessage.data);
return;
}

if (aMessage.name === "Push:NotificationForOriginClosed") {
console.debug("receiveMessage: Notification closed from child");
this._notificationForOriginClosed(aMessage.data);
return;
}

Expand Down
1 change: 0 additions & 1 deletion dom/push/test/xpcshell/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ function setPrefs(prefs = {}) {
'http2.retryInterval': 500,
'http2.reset_retry_count_after_ms': 60000,
maxQuotaPerSubscription: 16,
quotaUpdateDelay: 3000,
}, prefs);
for (let pref in defaultPrefs) {
servicePrefs.set(pref, defaultPrefs[pref]);
Expand Down
115 changes: 0 additions & 115 deletions dom/push/test/xpcshell/test_quota_with_notification.js

This file was deleted.

1 change: 0 additions & 1 deletion dom/push/test/xpcshell/xpcshell.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ run-sequentially = This will delete all existing push subscriptions.

[test_quota_exceeded.js]
[test_quota_observer.js]
[test_quota_with_notification.js]
[test_register_case.js]
[test_register_flush.js]
[test_register_invalid_channel.js]
Expand Down
Loading

0 comments on commit 6edbd4d

Please sign in to comment.