Bug 785298 - Settings API: set() can carry a customized message to notify "mozsettings-changed" observers. r=gwagner

This commit is contained in:
Gene Lian 2012-08-31 15:37:43 +08:00
parent 02ca3e551c
commit 7163f76e66
5 changed files with 31 additions and 19 deletions

View File

@ -13,10 +13,14 @@ interface nsISettingsServiceCallback : nsISupports
void handleError(in DOMString aErrorMessage);
};
[scriptable, uuid(3ab3cbc0-8513-11e1-b0c4-0800200c9a66)]
[scriptable, uuid(d7a395a0-e292-11e1-834e-1761d57f5f99)]
interface nsISettingsServiceLock : nsISupports
{
void set(in string aName, in jsval aValue, in nsISettingsServiceCallback aCallback);
void set(in string aName,
in jsval aValue,
in nsISettingsServiceCallback aCallback,
[optional] in string aMessage);
void get(in string aName, in nsISettingsServiceCallback aCallback);
};

View File

@ -22,7 +22,7 @@ Cu.import("resource://gre/modules/Services.jsm");
const nsIClassInfo = Ci.nsIClassInfo;
const SETTINGSSERVICELOCK_CONTRACTID = "@mozilla.org/settingsServiceLock;1";
const SETTINGSSERVICELOCK_CID = Components.ID("{3ab3cbc0-8513-11e1-b0c4-0800200c9a66}");
const SETTINGSSERVICELOCK_CID = Components.ID("{d7a395a0-e292-11e1-834e-1761d57f5f99}");
const nsISettingsServiceLock = Ci.nsISettingsServiceLock;
function SettingsServiceLock(aSettingsService)
@ -51,9 +51,10 @@ SettingsServiceLock.prototype = {
switch (info.intent) {
case "set":
let value = info.value;
let message = info.message;
if(typeof(value) == 'object')
debug("object name:" + name + ", val: " + JSON.stringify(value));
req = store.put({settingName: name, settingValue: value});
req = store.put({ settingName: name, settingValue: value });
req.onsuccess = function() {
debug("set on success");
@ -62,7 +63,8 @@ SettingsServiceLock.prototype = {
callback.handle(name, value);
Services.obs.notifyObservers(lock, "mozsettings-changed", JSON.stringify({
key: name,
value: value
value: value,
message: message
}));
lock._open = false;
};
@ -117,20 +119,26 @@ SettingsServiceLock.prototype = {
this.createTransactionAndProcess();
},
set: function set(aName, aValue, aCallback) {
set: function set(aName, aValue, aCallback, aMessage) {
debug("set: " + aName + ": " + JSON.stringify(aValue));
this._requests.enqueue({ callback: aCallback, intent: "set", name: aName, value: aValue});
if (aMessage === undefined)
aMessage = null;
this._requests.enqueue({ callback: aCallback,
intent: "set",
name: aName,
value: aValue,
message: aMessage });
this.createTransactionAndProcess();
},
classID : SETTINGSSERVICELOCK_CID,
QueryInterface : XPCOMUtils.generateQI([nsISettingsServiceLock]),
classInfo : XPCOMUtils.generateCI({classID: SETTINGSSERVICELOCK_CID,
contractID: SETTINGSSERVICELOCK_CONTRACTID,
classDescription: "SettingsServiceLock",
interfaces: [nsISettingsServiceLock],
flags: nsIClassInfo.DOM_OBJECT})
classInfo : XPCOMUtils.generateCI({ classID: SETTINGSSERVICELOCK_CID,
contractID: SETTINGSSERVICELOCK_CONTRACTID,
classDescription: "SettingsServiceLock",
interfaces: [nsISettingsServiceLock],
flags: nsIClassInfo.DOM_OBJECT })
};
const SETTINGSSERVICE_CID = Components.ID("{3458e760-8513-11e1-b0c4-0800200c9a66}");

View File

@ -1,5 +1,5 @@
component {3ab3cbc0-8513-11e1-b0c4-0800200c9a66} SettingsService.js
contract @mozilla.org/settingsServiceLock;1 {3ab3cbc0-8513-11e1-b0c4-0800200c9a66}
component {d7a395a0-e292-11e1-834e-1761d57f5f99} SettingsService.js
contract @mozilla.org/settingsServiceLock;1 {d7a395a0-e292-11e1-834e-1761d57f5f99}
component {3458e760-8513-11e1-b0c4-0800200c9a66} SettingsService.js
contract @mozilla.org/settingsService;1 {3458e760-8513-11e1-b0c4-0800200c9a66}

View File

@ -80,7 +80,7 @@ AutoMounterSetting::AutoMounterSetting()
nsCOMPtr<nsISettingsServiceLock> lock;
settingsService->GetLock(getter_AddRefs(lock));
nsCOMPtr<nsISettingsServiceCallback> callback = new SettingsServiceCallback();
lock->Set(UMS_MODE, INT_TO_JSVAL(AUTOMOUNTER_DISABLE), callback);
lock->Set(UMS_MODE, INT_TO_JSVAL(AUTOMOUNTER_DISABLE), callback, nullptr);
}
AutoMounterSetting::~AutoMounterSetting()

View File

@ -96,14 +96,14 @@ TestSettingsAPI()
nsCOMPtr<nsISettingsServiceLock> lock1;
iss->GetLock(getter_AddRefs(lock1));
lock->Set("asdf", BOOLEAN_TO_JSVAL(true), cb0);
lock->Set("asdf", BOOLEAN_TO_JSVAL(true), cb0, nullptr);
lock1->Get("asdf", cb1);
lock->Get("asdf", cb2);
lock->Set("asdf", BOOLEAN_TO_JSVAL(false), cb3);
lock->Set("asdf", BOOLEAN_TO_JSVAL(false), cb3, nullptr);
lock->Get("asdf", cb4);
lock->Set("int", INT_TO_JSVAL(9), cb5);
lock->Set("int", INT_TO_JSVAL(9), cb5, nullptr);
lock->Get("int", cb6);
lock->Set("doub", DOUBLE_TO_JSVAL(9.4), cb7);
lock->Set("doub", DOUBLE_TO_JSVAL(9.4), cb7, nullptr);
lock->Get("doub", cb8);
lock1->Get("asdfxxx", cb9);