Bug 827237 - Wifi: ap list in settings is empty. r=bent
authorGregor Wagner <anygregor@gmail.com>
Mon, 07 Jan 2013 15:14:34 +0100
changeset 117873 206ab8775b4004ddd1a42d50d55c5e8cb4259ad2
parent 117872 5701b113339926255c2625ba38f5b2d1c1c30361
child 117874 4f09ab49c47019bc9c943b66424ca0f7df09349b
push id24123
push usergwagner@mozilla.com
push dateMon, 07 Jan 2013 14:15:03 +0000
treeherdermozilla-central@206ab8775b40 [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; };