Bug 1244259 - wait for SafeBrowsing to have added MozEntries in initial runs of talos perf testing, r=jmaher,gcp

MozReview-Commit-ID: Dvs5RQyhfpy
This commit is contained in:
Gijs Kruitbosch 2016-02-12 08:47:31 +00:00
parent 1c2349b1c0
commit f179b8f8c0
5 changed files with 63 additions and 17 deletions

View File

@ -16,8 +16,7 @@
//JMAHER: this is temporarily commented out because this hangs the fennec browser
// dumpLog('\tBrowser outer width/height: ' + window.outerWidth + '/' + window.outerHeight);
dumpLog('__metrics\n');
goQuitApplication();
window.close();
goQuitApplication(true);
">
</body>
</html>

View File

@ -9,7 +9,7 @@ var { interfaces: Ci } = Components;
* fire the TalosQuitApplication custom event. This will
* attempt to force-quit the browser.
*/
addEventListener("TalosQuitApplication", () => {
addEventListener("TalosQuitApplication", event => {
// If we're loaded in a low-priority background process, like
// the background page thumbnailer, then we shouldn't be allowed
// to quit the whole application. This is a workaround until
@ -19,6 +19,6 @@ addEventListener("TalosQuitApplication", () => {
.QueryInterface(Ci.nsISupportsPriority)
.priority;
if (priority != Ci.nsISupportsPriority.PRIORITY_LOWEST) {
sendAsyncMessage("Talos:ForceQuit");
sendAsyncMessage("Talos:ForceQuit", event.detail);
}
});

View File

@ -53,11 +53,23 @@ TalosPowersService.prototype = {
receiveMessage(message) {
if (message.name == "Talos:ForceQuit") {
this.forceQuit();
this.forceQuit(message.data);
}
},
forceQuit() {
forceQuit(messageData) {
if (messageData && messageData.waitForSafeBrowsing) {
let SafeBrowsing = Cu.import("resource://gre/modules/SafeBrowsing.jsm", {}).SafeBrowsing;
let whenDone = () => {
this.forceQuit();
};
SafeBrowsing.addMozEntriesFinishedPromise.then(whenDone, whenDone);
// Speed things up in case nobody else called this:
SafeBrowsing.init();
return;
}
let enumerator = Services.wm.getEnumerator(null);
while (enumerator.hasMoreElements()) {
let domWindow = enumerator.getNext();

View File

@ -68,7 +68,7 @@ function canQuitApplication()
return true;
}
function goQuitApplication()
function goQuitApplication(waitForSafeBrowsing)
{
const privs = 'UniversalPreferencesRead UniversalPreferencesWrite ' +
'UniversalXPConnect';
@ -82,6 +82,30 @@ function goQuitApplication()
throw('goQuitApplication: privilege failure ' + ex);
}
var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULRuntime);
if (xulRuntime.processType == xulRuntime.PROCESS_TYPE_CONTENT) {
// If we're running in a remote browser, emit an event for a
// frame script to pick up to quit the whole browser.
var event = new CustomEvent("TalosQuitApplication", {bubbles:true, detail: {waitForSafeBrowsing}});
document.dispatchEvent(event);
return;
}
if (waitForSafeBrowsing) {
var SafeBrowsing = Components.utils.
import("resource://gre/modules/SafeBrowsing.jsm", {}).SafeBrowsing;
var whenDone = () => {
goQuitApplication(false);
};
SafeBrowsing.addMozEntriesFinishedPromise.then(whenDone, whenDone);
// Speed things up in case nobody else called this:
SafeBrowsing.init();
return false;
}
if (!canQuitApplication())
{
return false;
@ -90,20 +114,17 @@ function goQuitApplication()
const kAppStartup = '@mozilla.org/toolkit/app-startup;1';
const kAppShell = '@mozilla.org/appshell/appShellService;1';
var appService;
var forceQuit;
if (kAppStartup in Components.classes)
{
appService = Components.classes[kAppStartup].
getService(Components.interfaces.nsIAppStartup);
forceQuit = Components.interfaces.nsIAppStartup.eForceQuit;
}
else if (kAppShell in Components.classes)
{
appService = Components.classes[kAppShell].
getService(Components.interfaces.nsIAppShellService);
forceQuit = Components.interfaces.nsIAppShellService.eForceQuit;
}
else
{
@ -130,11 +151,7 @@ function goQuitApplication()
try
{
appService.quit(forceQuit);
// If we're running in a remote browser, emit an event for a
// frame script to pick up to quit the whole browser.
var event = new CustomEvent("TalosQuitApplication", {bubbles:true});
document.dispatchEvent(event);
appService.quit(appService.eForceQuit);
}
catch(ex)
{

View File

@ -332,8 +332,14 @@ this.SafeBrowsing = {
let dummyListener = {
updateUrlRequested: function() { },
streamFinished: function() { },
updateError: function() { },
updateSuccess: function() { }
// We notify observers when we're done in order to be able to make perf
// test results more consistent
updateError: function() {
Services.obs.notifyObservers(db, "mozentries-update-finished", "error");
},
updateSuccess: function() {
Services.obs.notifyObservers(db, "mozentries-update-finished", "success");
}
};
try {
@ -346,6 +352,18 @@ this.SafeBrowsing = {
} catch(ex) {
// beginUpdate will throw harmlessly if there's an existing update in progress, ignore failures.
log("addMozEntries failed!", ex);
Services.obs.notifyObservers(db, "mozentries-update-finished", "exception");
}
},
addMozEntriesFinishedPromise: new Promise(resolve => {
let finished = (subject, topic, data) => {
Services.obs.removeObserver(finished, "mozentries-update-finished");
if (data == "error") {
Cu.reportError("addMozEntries failed to update the db!");
}
resolve();
};
Services.obs.addObserver(finished, "mozentries-update-finished", false);
}),
};