Bug 827237 - Wifi: ap list in settings is empty. r=bent. a=blocking-basecamp
authorGregor Wagner <anygregor@gmail.com>
Mon, 07 Jan 2013 16:06:51 +0100
changeset 117979 f3e812fe7621717b436cf12ade04c38db318e341
parent 117978 1339d655c55401990cbf2b3a26d9ed2021986564
child 117980 3360b3e31b283c306427b9b215cba3e9900a7b87
push id136
push usergwagner@mozilla.com
push dateMon, 07 Jan 2013 15:07:52 +0000
reviewersbent, blocking-basecamp
bugs827237
milestone18.0
Bug 827237 - Wifi: ap list in settings is empty. r=bent. a=blocking-basecamp
dom/settings/SettingsManager.js
dom/settings/SettingsService.js
--- a/dom/settings/SettingsManager.js
+++ b/dom/settings/SettingsManager.js
@@ -106,16 +106,21 @@ SettingsLock.prototype = {
               };
 
               setReq.onerror = function() {
                 if (!request.error) {
                   Services.DOMRequest.fireError(request, setReq.error.name)
                 }
               };
             }
+            checkKeyRequest.onerror = function(event) {
+              if (!request.error) {
+                Services.DOMRequest.fireError(request, checkKeyRequest.error.name)
+              }
+            };
           }
           break;
         case "get":
           let getReq = (info.name === "*") ? store.mozGetAll()
                                            : store.mozGetAll(info.name);
 
           getReq.onsuccess = function(event) {
             if (DEBUG) debug("Request for '" + info.name + "' successful. " + 
--- a/dom/settings/SettingsService.js
+++ b/dom/settings/SettingsService.js
@@ -50,45 +50,63 @@ SettingsServiceLock.prototype = {
       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 });
+          let checkKeyRequest = store.get(name);
+
+          checkKeyRequest.onsuccess = function (event) {
+            let defaultValue;
+            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");
+            }
+
+            req = store.put({ settingName: name, defaultValue: defaultValue, userValue: 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,
-              message: message
-            }));
-            lock._open = false;
-          };
+            req.onsuccess = function() {
+              if (DEBUG) 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,
+                message: message
+              }));
+              lock._open = false;
+            };
 
-          req.onerror = function(event) { callback ? callback.handleError(event.target.errorMessage) : null; };
+            req.onerror = function(event) { callback ? callback.handleError(event.target.errorMessage) : null; };
+          }
+
+          checkKeyRequest.onerror = function(event) { callback ? callback.handleError(event.target.errorMessage) : null; };
           break;
         case "get":
           req = store.mozGetAll(name);
           req.onsuccess = function(event) {
             debug("Request successful. Record count:" + event.target.result.length);
             debug("result: " + JSON.stringify(event.target.result));
             this._open = true;
             if (callback) {
               if (event.target.result[0]) {
                 if (event.target.result.length > 1) {
                   debug("Warning: overloaded setting:" + name);
                 }
-                callback.handle(name, event.target.result[0].settingValue);
+                let result = event.target.result[0];
+                let value = result.userValue !== undefined
+                            ? result.userValue
+                            : result.defaultValue;
+                callback.handle(name, value);
               } else
                 callback.handle(name, null);
             } else {
               debug("no callback defined!");
             }
             this._open = false;
           }.bind(lock);
           req.onerror = function error(event) { callback ? callback.handleError(event.target.errorMessage) : null; };