2012-03-27 01:49:38 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-05-25 21:37:45 +04:00
|
|
|
"use strict";
|
2012-03-27 01:49:38 +04:00
|
|
|
|
2013-01-07 19:16:17 +04:00
|
|
|
const DEBUG = false;
|
2014-08-28 20:49:49 +04:00
|
|
|
function debug(s) {
|
|
|
|
if (DEBUG) dump("-*- SettingsManager: " + s + "\n");
|
|
|
|
}
|
2012-03-27 01:49:38 +04:00
|
|
|
|
2012-04-27 02:10:04 +04:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2014-08-28 20:49:49 +04:00
|
|
|
Cu.import("resource://gre/modules/SettingsQueue.jsm");
|
|
|
|
Cu.import("resource://gre/modules/SettingsDB.jsm");
|
2012-03-27 01:49:38 +04:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
|
|
|
"nsIMessageSender");
|
2014-04-09 03:37:09 +04:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "mrm",
|
|
|
|
"@mozilla.org/memory-reporter-manager;1",
|
|
|
|
"nsIMemoryReporterManager");
|
2012-06-05 03:12:24 +04:00
|
|
|
|
2013-07-16 05:17:46 +04:00
|
|
|
function SettingsLock(aSettingsManager) {
|
2012-03-27 01:49:38 +04:00
|
|
|
this._open = true;
|
2014-08-28 20:49:49 +04:00
|
|
|
this._isBusy = false;
|
|
|
|
this._requests = new Queue();
|
2012-03-27 01:49:38 +04:00
|
|
|
this._settingsManager = aSettingsManager;
|
2014-08-28 20:49:49 +04:00
|
|
|
this._transaction = null;
|
2014-05-07 01:14:23 +04:00
|
|
|
|
|
|
|
let closeHelper = function() {
|
2014-08-28 20:49:49 +04:00
|
|
|
if (DEBUG) debug("closing lock");
|
2014-05-07 01:14:23 +04:00
|
|
|
this._open = false;
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
Services.tm.currentThread.dispatch(closeHelper, Ci.nsIThread.DISPATCH_NORMAL);
|
2012-03-27 01:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsLock.prototype = {
|
2013-01-16 07:32:49 +04:00
|
|
|
get closed() {
|
|
|
|
return !this._open;
|
|
|
|
},
|
|
|
|
|
2013-03-12 09:31:19 +04:00
|
|
|
_wrap: function _wrap(obj) {
|
2014-02-01 23:06:59 +04:00
|
|
|
return Cu.cloneInto(obj, this._settingsManager._window);
|
2013-03-12 09:31:19 +04:00
|
|
|
},
|
|
|
|
|
2014-08-28 20:49:49 +04:00
|
|
|
process: function process() {
|
|
|
|
let lock = this;
|
|
|
|
let store = lock._transaction.objectStore(SETTINGSSTORE_NAME);
|
|
|
|
|
|
|
|
while (!lock._requests.isEmpty()) {
|
|
|
|
let info = lock._requests.dequeue();
|
|
|
|
if (DEBUG) debug("info: " + info.intent);
|
|
|
|
let request = info.request;
|
|
|
|
switch (info.intent) {
|
|
|
|
case "clear":
|
|
|
|
let clearReq = store.clear();
|
|
|
|
clearReq.onsuccess = function() {
|
|
|
|
this._open = true;
|
|
|
|
Services.DOMRequest.fireSuccess(request, 0);
|
|
|
|
this._open = false;
|
|
|
|
}.bind(lock);
|
|
|
|
clearReq.onerror = function() {
|
|
|
|
Services.DOMRequest.fireError(request, 0)
|
|
|
|
};
|
2014-08-28 08:01:29 +04:00
|
|
|
break;
|
2014-08-28 20:49:49 +04:00
|
|
|
case "set":
|
|
|
|
let keys = Object.getOwnPropertyNames(info.settings);
|
|
|
|
if (keys.length) {
|
|
|
|
lock._isBusy = true;
|
|
|
|
}
|
|
|
|
for (let i = 0; i < keys.length; i++) {
|
|
|
|
let key = keys[i];
|
|
|
|
let last = i === keys.length - 1;
|
|
|
|
if (DEBUG) debug("key: " + key + ", val: " + JSON.stringify(info.settings[key]) + ", type: " + typeof(info.settings[key]));
|
|
|
|
let checkKeyRequest = store.get(key);
|
|
|
|
|
|
|
|
checkKeyRequest.onsuccess = function (event) {
|
|
|
|
let defaultValue;
|
|
|
|
let userValue = info.settings[key];
|
|
|
|
if (event.target.result) {
|
|
|
|
defaultValue = event.target.result.defaultValue;
|
|
|
|
} else {
|
|
|
|
defaultValue = null;
|
|
|
|
if (DEBUG) debug("MOZSETTINGS-SET-WARNING: " + key + " is not in the database.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
let obj = {settingName: key, defaultValue: defaultValue, userValue: userValue};
|
|
|
|
if (DEBUG) debug("store1: " + JSON.stringify(obj));
|
|
|
|
let setReq = store.put(obj);
|
|
|
|
|
|
|
|
setReq.onsuccess = function() {
|
|
|
|
cpmm.sendAsyncMessage("Settings:Changed", { key: key, value: userValue });
|
|
|
|
if (last && !request.error) {
|
|
|
|
lock._open = true;
|
|
|
|
Services.DOMRequest.fireSuccess(request, 0);
|
|
|
|
lock._open = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
setReq.onerror = function() {
|
|
|
|
if (!request.error) {
|
|
|
|
Services.DOMRequest.fireError(request, setReq.error.name)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (last) {
|
|
|
|
lock._isBusy = false;
|
|
|
|
if (!lock._requests.isEmpty()) {
|
|
|
|
lock.process();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
checkKeyRequest.onerror = function(event) {
|
|
|
|
if (!request.error) {
|
|
|
|
Services.DOMRequest.fireError(request, checkKeyRequest.error.name)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// Don't break here, instead return. Once the previous requests have
|
|
|
|
// finished this loop will start again.
|
|
|
|
return;
|
|
|
|
case "get":
|
|
|
|
let getReq = (info.name === "*") ? store.mozGetAll()
|
|
|
|
: store.mozGetAll(info.name);
|
|
|
|
|
|
|
|
getReq.onsuccess = function(event) {
|
|
|
|
if (DEBUG) debug("Request for '" + info.name + "' successful. " +
|
|
|
|
"Record count: " + event.target.result.length);
|
|
|
|
|
|
|
|
if (event.target.result.length == 0) {
|
|
|
|
if (DEBUG) debug("MOZSETTINGS-GET-WARNING: " + info.name + " is not in the database.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
let results = {};
|
|
|
|
|
|
|
|
for (var i in event.target.result) {
|
|
|
|
let result = event.target.result[i];
|
|
|
|
var name = result.settingName;
|
|
|
|
if (DEBUG) debug("VAL: " + result.userValue +", " + result.defaultValue + "\n");
|
|
|
|
results[name] = result.userValue !== undefined ? result.userValue : result.defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._open = true;
|
|
|
|
Services.DOMRequest.fireSuccess(request, this._wrap(results));
|
|
|
|
this._open = false;
|
|
|
|
}.bind(lock);
|
|
|
|
|
|
|
|
getReq.onerror = function() {
|
|
|
|
Services.DOMRequest.fireError(request, 0)
|
|
|
|
};
|
2014-08-28 08:01:29 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-08-28 20:49:49 +04:00
|
|
|
},
|
2014-05-07 01:14:23 +04:00
|
|
|
|
2014-08-28 20:49:49 +04:00
|
|
|
createTransactionAndProcess: function() {
|
|
|
|
if (DEBUG) debug("database opened, creating transaction");
|
2014-05-07 01:14:23 +04:00
|
|
|
|
2014-08-28 20:49:49 +04:00
|
|
|
let manager = this._settingsManager;
|
|
|
|
let transactionType = manager.hasWritePrivileges ? "readwrite" : "readonly";
|
|
|
|
|
|
|
|
this._transaction =
|
|
|
|
manager._settingsDB._db.transaction(SETTINGSSTORE_NAME, transactionType);
|
|
|
|
|
|
|
|
this.process();
|
|
|
|
},
|
|
|
|
|
|
|
|
maybeProcess: function() {
|
|
|
|
if (this._transaction && !this._isBusy) {
|
|
|
|
this.process();
|
2014-08-28 08:01:29 +04:00
|
|
|
}
|
2012-03-27 01:49:38 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get: function get(aName) {
|
2012-05-23 05:18:56 +04:00
|
|
|
if (!this._open) {
|
|
|
|
dump("Settings lock not open!\n");
|
2012-03-27 01:49:38 +04:00
|
|
|
throw Components.results.NS_ERROR_ABORT;
|
2012-05-23 05:18:56 +04:00
|
|
|
}
|
2014-08-28 20:49:49 +04:00
|
|
|
|
|
|
|
if (this._settingsManager.hasReadPrivileges) {
|
|
|
|
let req = Services.DOMRequest.createRequest(this._settingsManager._window);
|
|
|
|
this._requests.enqueue({ request: req, intent:"get", name: aName });
|
|
|
|
this.maybeProcess();
|
2012-03-27 01:49:38 +04:00
|
|
|
return req;
|
2014-08-28 20:49:49 +04:00
|
|
|
} else {
|
|
|
|
if (DEBUG) debug("get not allowed");
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_serializePreservingBinaries: function _serializePreservingBinaries(aObject) {
|
|
|
|
function needsUUID(aValue) {
|
|
|
|
if (!aValue || !aValue.constructor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (aValue.constructor.name == "Date") || (aValue instanceof Ci.nsIDOMFile) ||
|
|
|
|
(aValue instanceof Ci.nsIDOMBlob);
|
|
|
|
}
|
|
|
|
// We need to serialize settings objects, otherwise they can change between
|
|
|
|
// the set() call and the enqueued request being processed. We can't simply
|
|
|
|
// parse(stringify(obj)) because that breaks things like Blobs, Files and
|
|
|
|
// Dates, so we use stringify's replacer and parse's reviver parameters to
|
|
|
|
// preserve binaries.
|
|
|
|
let manager = this._settingsManager;
|
|
|
|
let binaries = Object.create(null);
|
|
|
|
let stringified = JSON.stringify(aObject, function(key, value) {
|
|
|
|
value = manager._settingsDB.prepareValue(value);
|
|
|
|
if (needsUUID(value)) {
|
|
|
|
let uuid = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator)
|
|
|
|
.generateUUID().toString();
|
|
|
|
binaries[uuid] = value;
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
return JSON.parse(stringified, function(key, value) {
|
|
|
|
if (value in binaries) {
|
|
|
|
return binaries[value];
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
});
|
2012-03-27 01:49:38 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function set(aSettings) {
|
2012-05-23 05:18:56 +04:00
|
|
|
if (!this._open) {
|
2013-07-16 05:17:46 +04:00
|
|
|
throw "Settings lock not open";
|
2012-05-23 05:18:56 +04:00
|
|
|
}
|
2014-08-28 20:49:49 +04:00
|
|
|
|
|
|
|
if (this._settingsManager.hasWritePrivileges) {
|
|
|
|
let req = Services.DOMRequest.createRequest(this._settingsManager._window);
|
|
|
|
if (DEBUG) debug("send: " + JSON.stringify(aSettings));
|
|
|
|
let settings = this._serializePreservingBinaries(aSettings);
|
|
|
|
this._requests.enqueue({request: req, intent: "set", settings: settings});
|
|
|
|
this.maybeProcess();
|
2012-03-27 01:49:38 +04:00
|
|
|
return req;
|
2014-08-28 20:49:49 +04:00
|
|
|
} else {
|
|
|
|
if (DEBUG) debug("set not allowed");
|
|
|
|
throw "No permission to call set";
|
|
|
|
}
|
2012-03-27 01:49:38 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
clear: function clear() {
|
2012-05-23 05:18:56 +04:00
|
|
|
if (!this._open) {
|
2013-07-16 05:17:46 +04:00
|
|
|
throw "Settings lock not open";
|
2012-05-23 05:18:56 +04:00
|
|
|
}
|
2014-08-28 20:49:49 +04:00
|
|
|
|
|
|
|
if (this._settingsManager.hasWritePrivileges) {
|
|
|
|
let req = Services.DOMRequest.createRequest(this._settingsManager._window);
|
|
|
|
this._requests.enqueue({ request: req, intent: "clear"});
|
|
|
|
this.maybeProcess();
|
2012-03-27 01:49:38 +04:00
|
|
|
return req;
|
2014-08-28 20:49:49 +04:00
|
|
|
} else {
|
|
|
|
if (DEBUG) debug("clear not allowed");
|
|
|
|
throw "No permission to call clear";
|
|
|
|
}
|
2012-03-27 01:49:38 +04:00
|
|
|
},
|
|
|
|
|
2013-07-16 05:17:46 +04:00
|
|
|
classID: Components.ID("{60c9357c-3ae0-4222-8f55-da01428470d5}"),
|
|
|
|
contractID: "@mozilla.org/settingsLock;1",
|
2014-08-28 20:49:49 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
|
2012-03-27 01:49:38 +04:00
|
|
|
};
|
|
|
|
|
2013-07-16 05:17:46 +04:00
|
|
|
function SettingsManager() {
|
2014-08-28 20:49:49 +04:00
|
|
|
this._settingsDB = new SettingsDB();
|
|
|
|
this._settingsDB.init();
|
2012-03-27 01:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsManager.prototype = {
|
2012-06-11 03:44:50 +04:00
|
|
|
_callbacks: null,
|
2012-03-27 01:49:38 +04:00
|
|
|
|
2013-03-12 09:31:19 +04:00
|
|
|
_wrap: function _wrap(obj) {
|
2014-02-01 23:06:59 +04:00
|
|
|
return Cu.cloneInto(obj, this._window);
|
2013-03-12 09:31:19 +04:00
|
|
|
},
|
|
|
|
|
2013-07-16 05:17:46 +04:00
|
|
|
set onsettingchange(aHandler) {
|
|
|
|
this.__DOM_IMPL__.setEventHandler("onsettingchange", aHandler);
|
2012-03-27 01:49:38 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get onsettingchange() {
|
2013-07-16 05:17:46 +04:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("onsettingchange");
|
2012-03-27 01:49:38 +04:00
|
|
|
},
|
|
|
|
|
2012-09-06 04:33:03 +04:00
|
|
|
createLock: function() {
|
2014-08-28 20:49:49 +04:00
|
|
|
if (DEBUG) debug("get lock!");
|
|
|
|
var lock = new SettingsLock(this);
|
|
|
|
this._settingsDB.ensureDB(
|
|
|
|
function() { lock.createTransactionAndProcess(); },
|
|
|
|
function() { dump("Cannot open Settings DB. Trying to open an old version?\n"); }
|
|
|
|
);
|
2012-03-27 01:49:38 +04:00
|
|
|
return lock;
|
|
|
|
},
|
|
|
|
|
2012-06-05 03:12:24 +04:00
|
|
|
receiveMessage: function(aMessage) {
|
2012-12-14 22:20:16 +04:00
|
|
|
if (DEBUG) debug("Settings::receiveMessage: " + aMessage.name);
|
2012-06-05 03:12:24 +04:00
|
|
|
let msg = aMessage.json;
|
|
|
|
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Settings:Change:Return:OK":
|
2013-07-16 05:17:46 +04:00
|
|
|
if (DEBUG) debug('data:' + msg.key + ':' + msg.value + '\n');
|
|
|
|
|
|
|
|
let event = new this._window.MozSettingsEvent("settingchange", this._wrap({
|
|
|
|
settingName: msg.key,
|
|
|
|
settingValue: msg.value
|
|
|
|
}));
|
|
|
|
this.__DOM_IMPL__.dispatchEvent(event);
|
|
|
|
|
|
|
|
if (this._callbacks && this._callbacks[msg.key]) {
|
|
|
|
if (DEBUG) debug("observe callback called! " + msg.key + " " + this._callbacks[msg.key].length);
|
|
|
|
this._callbacks[msg.key].forEach(function(cb) {
|
|
|
|
cb(this._wrap({settingName: msg.key, settingValue: msg.value}));
|
|
|
|
}.bind(this));
|
2012-06-11 03:44:50 +04:00
|
|
|
} else {
|
2012-12-14 22:20:16 +04:00
|
|
|
if (DEBUG) debug("no observers stored!");
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
2012-06-05 03:12:24 +04:00
|
|
|
break;
|
2014-08-28 20:49:49 +04:00
|
|
|
case "Settings:Notifier:Init:OK":
|
|
|
|
// If SettingManager receives this message means SettingChangeNotifier
|
|
|
|
// might not receive the Settings:RegisterForMessage message. We should
|
|
|
|
// send it again after SettingChangeNotifier is ready.
|
|
|
|
if (this.hasReadPrivileges) {
|
|
|
|
cpmm.sendAsyncMessage("Settings:RegisterForMessages");
|
|
|
|
}
|
|
|
|
break;
|
2013-03-12 09:31:19 +04:00
|
|
|
default:
|
2012-12-14 22:20:16 +04:00
|
|
|
if (DEBUG) debug("Wrong message: " + aMessage.name);
|
2012-06-05 03:12:24 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
addObserver: function addObserver(aName, aCallback) {
|
2012-12-14 22:20:16 +04:00
|
|
|
if (DEBUG) debug("addObserver " + aName);
|
2012-09-27 01:10:32 +04:00
|
|
|
if (!this._callbacks) {
|
2012-06-11 03:44:50 +04:00
|
|
|
this._callbacks = {};
|
2012-09-27 01:10:32 +04:00
|
|
|
}
|
2012-06-11 03:44:50 +04:00
|
|
|
if (!this._callbacks[aName]) {
|
|
|
|
this._callbacks[aName] = [aCallback];
|
|
|
|
} else {
|
|
|
|
this._callbacks[aName].push(aCallback);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
removeObserver: function removeObserver(aName, aCallback) {
|
2012-12-14 22:20:16 +04:00
|
|
|
if (DEBUG) debug("deleteObserver " + aName);
|
2012-06-11 03:44:50 +04:00
|
|
|
if (this._callbacks && this._callbacks[aName]) {
|
2014-08-28 20:49:49 +04:00
|
|
|
let index = this._callbacks[aName].indexOf(aCallback)
|
2012-06-11 03:44:50 +04:00
|
|
|
if (index != -1) {
|
2014-08-28 20:49:49 +04:00
|
|
|
this._callbacks[aName].splice(index, 1)
|
2012-06-11 03:44:50 +04:00
|
|
|
} else {
|
2012-12-14 22:20:16 +04:00
|
|
|
if (DEBUG) debug("Callback not found for: " + aName);
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
|
|
|
} else {
|
2012-12-14 22:20:16 +04:00
|
|
|
if (DEBUG) debug("No observers stored for " + aName);
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
2014-08-28 08:01:29 +04:00
|
|
|
},
|
|
|
|
|
2012-03-27 01:49:38 +04:00
|
|
|
init: function(aWindow) {
|
2014-04-09 03:37:09 +04:00
|
|
|
mrm.registerStrongReporter(this);
|
2012-06-05 03:12:24 +04:00
|
|
|
cpmm.addMessageListener("Settings:Change:Return:OK", this);
|
2014-08-28 20:49:49 +04:00
|
|
|
cpmm.addMessageListener("Settings:Notifier:Init:OK", this);
|
2012-03-27 01:49:38 +04:00
|
|
|
this._window = aWindow;
|
|
|
|
Services.obs.addObserver(this, "inner-window-destroyed", false);
|
|
|
|
let util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
this.innerWindowID = util.currentInnerWindowID;
|
2014-08-28 20:49:49 +04:00
|
|
|
|
|
|
|
let readPerm = Services.perms.testExactPermissionFromPrincipal(aWindow.document.nodePrincipal, "settings-read");
|
|
|
|
let writePerm = Services.perms.testExactPermissionFromPrincipal(aWindow.document.nodePrincipal, "settings-write");
|
|
|
|
this.hasReadPrivileges = readPerm == Ci.nsIPermissionManager.ALLOW_ACTION;
|
|
|
|
this.hasWritePrivileges = writePerm == Ci.nsIPermissionManager.ALLOW_ACTION;
|
|
|
|
|
|
|
|
if (this.hasReadPrivileges) {
|
|
|
|
cpmm.sendAsyncMessage("Settings:RegisterForMessages");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.hasReadPrivileges && !this.hasWritePrivileges) {
|
|
|
|
dump("No settings permission for: " + aWindow.document.nodePrincipal.origin + "\n");
|
|
|
|
Cu.reportError("No settings permission for: " + aWindow.document.nodePrincipal.origin);
|
|
|
|
}
|
2012-03-27 01:49:38 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
observe: function(aSubject, aTopic, aData) {
|
2012-12-14 22:20:16 +04:00
|
|
|
if (DEBUG) debug("Topic: " + aTopic);
|
2012-03-27 01:49:38 +04:00
|
|
|
if (aTopic == "inner-window-destroyed") {
|
|
|
|
let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
|
|
|
if (wId == this.innerWindowID) {
|
2014-04-09 03:37:09 +04:00
|
|
|
this.cleanup();
|
2012-03-27 01:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-21 10:06:54 +04:00
|
|
|
collectReports: function(aCallback, aData, aAnonymize) {
|
2014-08-28 20:49:49 +04:00
|
|
|
for (var topic in this._callbacks) {
|
2014-04-09 03:37:09 +04:00
|
|
|
let length = this._callbacks[topic].length;
|
|
|
|
if (length == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let path;
|
|
|
|
if (length < 20) {
|
|
|
|
path = "settings-observers";
|
|
|
|
} else {
|
2014-05-21 10:06:54 +04:00
|
|
|
path = "settings-observers-suspect/referent(topic=" +
|
|
|
|
(aAnonymize ? "<anonymized>" : topic) + ")";
|
2014-04-09 03:37:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
aCallback.callback("", path,
|
|
|
|
Ci.nsIMemoryReporter.KIND_OTHER,
|
|
|
|
Ci.nsIMemoryReporter.UNITS_COUNT,
|
|
|
|
this._callbacks[topic].length,
|
|
|
|
"The number of settings observers for this topic.",
|
|
|
|
aData);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cleanup: function() {
|
|
|
|
Services.obs.removeObserver(this, "inner-window-destroyed");
|
|
|
|
cpmm.removeMessageListener("Settings:Change:Return:OK", this);
|
2014-08-28 20:49:49 +04:00
|
|
|
cpmm.removeMessageListener("Settings:Notifier:Init:OK", this);
|
2014-04-09 03:37:09 +04:00
|
|
|
mrm.unregisterStrongReporter(this);
|
|
|
|
this._requests = null;
|
|
|
|
this._window = null;
|
|
|
|
this._innerWindowID = null;
|
2014-08-28 20:49:49 +04:00
|
|
|
this._settingsDB.close();
|
2014-04-09 03:37:09 +04:00
|
|
|
},
|
|
|
|
|
2013-07-16 05:17:46 +04:00
|
|
|
classID: Components.ID("{c40b1c70-00fb-11e2-a21f-0800200c9a66}"),
|
|
|
|
contractID: "@mozilla.org/settingsManager;1",
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
2014-04-09 03:37:09 +04:00
|
|
|
Ci.nsIDOMGlobalPropertyInitializer,
|
|
|
|
Ci.nsIObserver,
|
|
|
|
Ci.nsIMemoryReporter]),
|
2013-07-16 05:17:46 +04:00
|
|
|
};
|
2012-03-27 01:49:38 +04:00
|
|
|
|
2014-08-28 20:49:49 +04:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SettingsManager, SettingsLock])
|