Bug 827237 - Wifi: ap list in settings is empty. r=bent
authorGregor Wagner <anygregor@gmail.com>
Mon, 07 Jan 2013 15:03:26 +0100
changeset 117919 d2c5708db6efde4c8113b6ccf56ee6694ad31f61
parent 117918 ac4b105b91373fb25993760a3782d4517531c97d
child 117920 bb2faa4aa72b1b5b55ae66e3980b23058c4d72de
push id20738
push usergwagner@mozilla.com
push dateMon, 07 Jan 2013 14:03:42 +0000
treeherdermozilla-inbound@d2c5708db6ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs827237
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 827237 - Wifi: ap list in settings is empty. r=bent
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; };