Back out 3 changesets (bug 1210211) for b2g build bustage

CLOSED TREE

Backed out changeset 204a1746f421 (bug 1210211)
Backed out changeset e5d16111e809 (bug 1210211)
Backed out changeset b78d00c9af42 (bug 1210211)
This commit is contained in:
Phil Ringnalda 2015-11-16 19:34:14 -08:00
parent 32c2d0fc3a
commit 8ebf12fec9
9 changed files with 21 additions and 280 deletions

View File

@ -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);
};

View File

@ -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"
@ -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);

View File

@ -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({
@ -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);
}
};

View File

@ -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);
}
},
@ -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.

View File

@ -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;
@ -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: [],
@ -890,10 +883,13 @@ 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 => {
@ -901,66 +897,6 @@ this.PushService = {
});
},
_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) {
@ -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;
}

View File

@ -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]);

View File

@ -1,115 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
const {PushDB, PushService, PushServiceWebSocket} = serviceExports;
Cu.import("resource://gre/modules/Task.jsm");
const userAgentID = 'aaabf1f8-2f68-44f1-a920-b88e9e7d7559';
const nsIPushQuotaManager = Components.interfaces.nsIPushQuotaManager;
function run_test() {
do_get_profile();
setPrefs({
userAgentID,
});
run_next_test();
}
add_task(function* test_expiration_origin_threshold() {
let db = PushServiceWebSocket.newPushDB();
do_register_cleanup(() => {
db.drop().then(_ => db.close())
PushService._notificationForOriginClosed("https://example.com");
});
// Simulate a notification being shown for the origin,
// this should relax the quota and allow as many push messages
// as we want.
PushService._notificationForOriginShown("https://example.com");
yield db.put({
channelID: 'f56645a9-1f32-4655-92ad-ddc37f6d54fb',
pushEndpoint: 'https://example.org/push/1',
scope: 'https://example.com/quota',
pushCount: 0,
lastPush: 0,
version: null,
originAttributes: '',
quota: 16,
});
// A visit one day ago should provide a quota of 8 messages.
yield addVisit({
uri: 'https://example.com/login',
title: 'Sign in to see your auctions',
visits: [{
visitDate: (Date.now() - 1 * 24 * 60 * 60 * 1000) * 1000,
transitionType: Ci.nsINavHistoryService.TRANSITION_LINK,
}],
});
let numMessages = 10;
let updates = 0;
let notifyPromise = promiseObserverNotification('push-notification', (subject, data) => {
dump(updates++);
return updates == numMessages;
});
let updateQuotaPromise = new Promise((resolve, reject) => {
let quotaUpdateCount = 0;
PushService._updateQuotaTestCallback = function() {
quotaUpdateCount++;
if (quotaUpdateCount == 10) {
resolve();
}
};
});
PushService.init({
serverURI: 'wss://push.example.org/',
networkInfo: new MockDesktopNetworkInfo(),
db,
makeWebSocket(uri) {
return new MockWebSocket(uri, {
onHello(request) {
this.serverSendMsg(JSON.stringify({
messageType: 'hello',
status: 200,
uaid: userAgentID,
}));
// If the origin has visible notifications, the
// message should not affect quota.
for (let version = 1; version <= 10; version++) {
this.serverSendMsg(JSON.stringify({
messageType: 'notification',
updates: [{
channelID: 'f56645a9-1f32-4655-92ad-ddc37f6d54fb',
version,
}],
}));
}
},
onUnregister(request) {
ok(false, "Channel should not be unregistered.");
},
// We expect to receive acks, but don't care about their
// contents.
onACK(request) {},
});
},
});
yield waitForPromise(notifyPromise, DEFAULT_TIMEOUT,
'Timed out waiting for notifications');
yield waitForPromise(updateQuotaPromise, DEFAULT_TIMEOUT,
'Timed out waiting for quota to be updated');
let expiredRecord = yield db.getByKeyID('f56645a9-1f32-4655-92ad-ddc37f6d54fb');
notStrictEqual(expiredRecord.quota, 0, 'Expired record not updated');
});

View File

@ -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]

View File

@ -4501,14 +4501,10 @@ pref("dom.push.loglevel", "off");
pref("dom.push.serverURL", "wss://push.services.mozilla.com/");
pref("dom.push.userAgentID", "");
// The maximum number of push messages that a service worker can receive
// The maximum number of notifications that a service worker can receive
// without user interaction.
pref("dom.push.maxQuotaPerSubscription", 16);
// The delay between receiving a push message and updating the quota for a
// subscription.
pref("dom.push.quotaUpdateDelay", 3000); // 3 seconds
// Is the network connection allowed to be up?
// This preference should be used in UX to enable/disable push.
pref("dom.push.connection.enabled", true);