Bug 793239 - SettingsLock should have a state property to indicate if it is still valid. r=gwagner
☠☠ backed out by 9ca4e8812ed1 ☠ ☠
authorReuben Morais <reuben.morais@gmail.com>
Tue, 15 Jan 2013 16:32:15 -0800
changeset 118968 89942aa8ae6ad9c67bbbaf3b0e3d8d1088b97642
parent 118967 2b9b4a3a835fe6e5f44bcc59896faf69fdf7f964
child 118969 05e097a707148936571cb441e84278d1bf1a63a7
push id21385
push usergwagner@mozilla.com
push dateWed, 16 Jan 2013 00:33:02 +0000
treeherdermozilla-inbound@89942aa8ae6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwagner
bugs793239
milestone21.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 793239 - SettingsLock should have a state property to indicate if it is still valid. r=gwagner
dom/settings/SettingsManager.js
dom/settings/SettingsManager.manifest
dom/settings/tests/test_settings_basics.html
--- a/dom/settings/SettingsManager.js
+++ b/dom/settings/SettingsManager.js
@@ -19,30 +19,34 @@ Cu.import("resource://gre/modules/XPCOMU
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsIMessageSender");
 
 const nsIClassInfo            = Ci.nsIClassInfo;
 const SETTINGSLOCK_CONTRACTID = "@mozilla.org/settingsLock;1";
-const SETTINGSLOCK_CID        = Components.ID("{ef95ddd0-6308-11e1-b86c-0800200c9a66}");
+const SETTINGSLOCK_CID        = Components.ID("{60c9357c-3ae0-4222-8f55-da01428470d5}");
 const nsIDOMSettingsLock      = Ci.nsIDOMSettingsLock;
 
 function SettingsLock(aSettingsManager)
 {
   this._open = true;
   this._isBusy = false;
   this._requests = new Queue();
   this._settingsManager = aSettingsManager;
   this._transaction = null;
 }
 
 SettingsLock.prototype = {
 
+  get closed() {
+    return !this._open;
+  },
+
   process: function process() {
     let lock = this;
     lock._open = false;
     let store = lock._transaction.objectStore(SETTINGSSTORE_NAME);
 
     while (!lock._requests.isEmpty()) {
       let info = lock._requests.dequeue();
       if (DEBUG) debug("info: " + info.intent);
--- a/dom/settings/SettingsManager.manifest
+++ b/dom/settings/SettingsManager.manifest
@@ -1,6 +1,6 @@
 component {c40b1c70-00fb-11e2-a21f-0800200c9a66} SettingsManager.js
 contract @mozilla.org/settingsManager;1 {c40b1c70-00fb-11e2-a21f-0800200c9a66}
 category JavaScript-navigator-property mozSettings @mozilla.org/settingsManager;1
 
-component {ef95ddd0-6308-11e1-b86c-0800200c9a66} SettingsManager.js
-contract @mozilla.org/settingsLock;1 {ef95ddd0-6308-11e1-b86c-0800200c9a66}
+component {60c9357c-3ae0-4222-8f55-da01428470d5} SettingsManager.js
+contract @mozilla.org/settingsLock;1 {60c9357c-3ae0-4222-8f55-da01428470d5}
--- a/dom/settings/tests/test_settings_basics.html
+++ b/dom/settings/tests/test_settings_basics.html
@@ -693,16 +693,43 @@ var steps = [
     req = lock.get("screen.brightness");
     req.onsuccess = function () {
       check(req.result["screen.brightness"], 0.7, "get done");
       next();
     }
     req.onerror = onFailure;
   },
   function() {
+    ok(true, "Test closed attribute on a valid lock");
+    var lock = mozSettings.createLock();
+    is(lock.closed, false, "closed attribute is false on creation");
+    req = lock.get("screen.brightness");
+    req.onsuccess = function () {
+      is(lock.closed, false, "closed attribute is false on success callback");
+      next();
+    }
+    req.onerror = onFailure;
+  },
+  function () {
+    ok(true, "Test closed attribute on invalid lock");
+    var lockx = mozSettings.createLock();
+    var cb = function() {
+      var reqx = null;
+      try {
+        reqx = lockx.set(wifiNetworks0);
+        ok(false, "should have thrown");
+      } catch (ex) {
+        is(lockx.closed, true, "closed attribute is true");
+        ok(true, "Caught Exception");
+        next();
+      }
+    }
+    SimpleTest.executeSoon(cb);
+  },
+  function() {
     ok(true, "Clear DB");
     var lock = mozSettings.createLock();
     req = lock.clear();
     req.onsuccess = function () {
       ok(true, "Deleted the database");
       next();
     };
     req.onerror = onFailure;