mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 14:20:14 +02:00
A new function Classifier::AsyncApplyUpdates() is implemented for async update. Besides, all public Classifier interfaces become "worker thread only" and we remove DBServiceWorker::ApplyUpdatesBackground/Foreground. In DBServiceWorker::FinishUpdate, instead of calling Classifier::ApplyUpdates, we call Classifier::AsyncApplyUpdates and install a callback for notifying the update observer when update is finished. The callback will occur on the caller thread (i.e. worker thread.) As for the shutdown issue, when the main thread is notified to shut down, we at first *synchronously* dispatch an event to the worker thread to shut down the update thread. After getting synchronized with all other threads, we send last two events "CancelUpdate" and "CloseDb" to notify dangling update (i.e. BeginUpdate is called but FinishUpdate isn't) and do cleanup work. MozReview-Commit-ID: DXZvA2eFKlc --HG-- extra : rebase_source : cd2e27a6b679d2c96e769854d1582ed2dcda12bb
96 lines
3.1 KiB
JavaScript
96 lines
3.1 KiB
JavaScript
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
|
|
"resource://gre/modules/Promise.jsm");
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
|
"resource://gre/modules/Task.jsm");
|
|
|
|
// This url must sync with the table, url in SafeBrowsing.jsm addMozEntries
|
|
const PHISH_TABLE = "test-phish-simple";
|
|
const PHISH_URL = "https://www.itisatrap.org/firefox/its-a-trap.html";
|
|
|
|
/**
|
|
* Waits for a load (or custom) event to finish in a given tab. If provided
|
|
* load an uri into the tab.
|
|
*
|
|
* @param tab
|
|
* The tab to load into.
|
|
* @param [optional] url
|
|
* The url to load, or the current url.
|
|
* @param [optional] event
|
|
* The load event type to wait for. Defaults to "load".
|
|
* @return {Promise} resolved when the event is handled.
|
|
* @resolves to the received event
|
|
* @rejects if a valid load event is not received within a meaningful interval
|
|
*/
|
|
function promiseTabLoadEvent(tab, url, eventType = "load") {
|
|
info(`Wait tab event: ${eventType}`);
|
|
|
|
function handle(loadedUrl) {
|
|
if (loadedUrl === "about:blank" || (url && loadedUrl !== url)) {
|
|
info(`Skipping spurious load event for ${loadedUrl}`);
|
|
return false;
|
|
}
|
|
|
|
info("Tab event received: load");
|
|
return true;
|
|
}
|
|
|
|
let loaded;
|
|
if (eventType === "load") {
|
|
loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, handle);
|
|
} else {
|
|
// No need to use handle.
|
|
loaded =
|
|
BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, eventType,
|
|
true, undefined, true);
|
|
}
|
|
|
|
if (url)
|
|
BrowserTestUtils.loadURI(tab.linkedBrowser, url);
|
|
|
|
return loaded;
|
|
}
|
|
|
|
// This function is mostly ported from classifierCommon.js
|
|
// under toolkit/components/url-classifier/tests/mochitest.
|
|
function waitForDBInit(callback) {
|
|
// Since there are two cases that may trigger the callback,
|
|
// we have to carefully avoid multiple callbacks and observer
|
|
// leaking.
|
|
let didCallback = false;
|
|
function callbackOnce() {
|
|
if (!didCallback) {
|
|
Services.obs.removeObserver(obsFunc, "mozentries-update-finished");
|
|
callback();
|
|
}
|
|
didCallback = true;
|
|
}
|
|
|
|
// The first part: listen to internal event.
|
|
function obsFunc() {
|
|
ok(true, "Received internal event!");
|
|
callbackOnce();
|
|
}
|
|
Services.obs.addObserver(obsFunc, "mozentries-update-finished", false);
|
|
|
|
// The second part: we might have missed the event. Just do
|
|
// an internal database lookup to confirm if the url has been
|
|
// added.
|
|
let principal = Services.scriptSecurityManager
|
|
.createCodebasePrincipal(Services.io.newURI(PHISH_URL), {});
|
|
|
|
let dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
|
|
.getService(Ci.nsIUrlClassifierDBService);
|
|
dbService.lookup(principal, PHISH_TABLE, value => {
|
|
if (value === PHISH_TABLE) {
|
|
ok(true, "DB lookup success!");
|
|
callbackOnce();
|
|
}
|
|
});
|
|
}
|
|
|
|
Services.prefs.setCharPref("urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple");
|
|
Services.prefs.setCharPref("urlclassifier.phishTable", "test-phish-simple");
|
|
Services.prefs.setCharPref("urlclassifier.blockedTable", "test-block-simple");
|
|
SafeBrowsing.init();
|