Bug 785298 - Settings API: set() can carry a customized message to notify "mozsettings-changed" observers. r=gwagner
authorGene Lian <clian@mozilla.com>
Fri, 31 Aug 2012 15:37:43 +0800
changeset 104096 dff1055c2f505ee9428b8809daf78648fdf7b95b
parent 104095 978761f9b84ec03c0a651e6033058bbae4a11f01
child 104097 304f86e12b60dce2aecd388fc736a0cfc1ca468d
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-esr52@2704e441363f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwagner
bugs785298
milestone18.0a1
Bug 785298 - Settings API: set() can carry a customized message to notify "mozsettings-changed" observers. r=gwagner
dom/interfaces/settings/nsISettingsService.idl
dom/settings/SettingsService.js
dom/settings/SettingsService.manifest
dom/system/gonk/AutoMounterSetting.cpp
xpcom/tests/TestSettingsAPI.cpp
--- a/dom/interfaces/settings/nsISettingsService.idl
+++ b/dom/interfaces/settings/nsISettingsService.idl
@@ -8,20 +8,24 @@
 interface nsISettingsServiceCallback : nsISupports
 {
   [implicit_jscontext]
   void handle(in DOMString aName, in jsval aResult);
   [implicit_jscontext]
   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);
 };
 
 [scriptable, uuid(3458e760-8513-11e1-b0c4-0800200c9a66)]
 interface nsISettingsService : nsISupports
 {
   nsISettingsServiceLock getLock();
 };
--- a/dom/settings/SettingsService.js
+++ b/dom/settings/SettingsService.js
@@ -17,17 +17,17 @@ const Cu = Components.utils;
 Cu.import("resource://gre/modules/SettingsQueue.jsm");
 Cu.import("resource://gre/modules/SettingsDB.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 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)
 {
   debug("settingsServiceLock constr!");
   this._open = true;
   this._requests = new Queue();
   this._settingsService = aSettingsService;
@@ -46,28 +46,30 @@ SettingsServiceLock.prototype = {
       let info = lock._requests.dequeue();
       debug("info:" + info.intent);
       let callback = info.callback;
       let req;
       let name = info.name;
       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");
             lock._open = true;
             if (callback)
               callback.handle(name, value);
             Services.obs.notifyObservers(lock, "mozsettings-changed", JSON.stringify({
               key: name,
-              value: value
+              value: value,
+              message: message
             }));
             lock._open = false;
           };
 
           req.onerror = function(event) { callback ? callback.handleError(event.target.errorMessage) : null; };
           break;
         case "get":
           req = store.mozGetAll(name);
@@ -112,30 +114,36 @@ SettingsServiceLock.prototype = {
   },
 
   get: function get(aName, aCallback) {
     debug("get: " + aName + ", " + aCallback);
     this._requests.enqueue({ callback: aCallback, intent:"get", name: aName });
     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}");
 
 let myGlobal = this;
 
 function SettingsService()
 {
--- a/dom/settings/SettingsService.manifest
+++ b/dom/settings/SettingsService.manifest
@@ -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}
--- a/dom/system/gonk/AutoMounterSetting.cpp
+++ b/dom/system/gonk/AutoMounterSetting.cpp
@@ -75,17 +75,17 @@ AutoMounterSetting::AutoMounterSetting()
     do_GetService("@mozilla.org/settingsService;1");
   if (!settingsService) {
     ERR("Failed to get settingsLock service!");
     return;
   }
   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()
 {
   nsCOMPtr<nsIObserverService> observerService =
     mozilla::services::GetObserverService();
   if (observerService) {
     observerService->RemoveObserver(this, MOZSETTINGS_CHANGED);
--- a/xpcom/tests/TestSettingsAPI.cpp
+++ b/xpcom/tests/TestSettingsAPI.cpp
@@ -91,24 +91,24 @@ TestSettingsAPI()
 
   nsCOMPtr<nsISettingsService> iss = do_GetService("@mozilla.org/settingsService;1");
   nsCOMPtr<nsISettingsServiceLock> lock;
   iss->GetLock(getter_AddRefs(lock));
 
   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);
 
   return NS_OK;
 }
 
 int main(int argc, char** argv)
 {