remove server lock wrapper; change local lock to work with service.js local locking api
authorDan Mills <thunder@mozilla.com>
Mon, 03 Nov 2008 14:57:59 -0800
changeset 45017 9b0b80c80c8a614e113cbb32831977bdc35e103c
parent 45016 1399b39e832c9e692a13e8bef3ed89e397b41837
child 45018 b82aafc1aa4bc11500beafe3fcc0cf99a529aaaa
push idunknown
push userunknown
push dateunknown
remove server lock wrapper; change local lock to work with service.js local locking api
services/sync/modules/wrap.js
--- a/services/sync/modules/wrap.js
+++ b/services/sync/modules/wrap.js
@@ -38,17 +38,16 @@ const EXPORTED_SYMBOLS = ['Wrap'];
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://weave/log4moz.js");
-Cu.import("resource://weave/dav.js");
 Cu.import("resource://weave/async.js");
 Cu.import("resource://weave/faultTolerance.js");
 
 Function.prototype.async = Async.sugar;
 
 /*
  * Wrapper utility functions
  *
@@ -105,81 +104,42 @@ let Wrap = {
       }
 
       self.done(ret);
     };
   },
 
   // NOTE: see notify, this works the same way.  they can be
   // chained together as well.
-  lock: function WeaveSync_lock(method /* , arg1, arg2, ..., argN */) {
-    let savedMethod = method;
-    let savedArgs = Array.prototype.slice.call(arguments, 1);
-
-    return function WeaveLockWrapper( /* argN+1, argN+2, ... */) {
-      let self = yield;
-      let ret;
-      let args = Array.prototype.slice.call(arguments);
-
-      if (!this._loggedIn)
-        throw "Could not acquire lock (not logged in)";
-      if (DAV.locked)
-        throw "Could not acquire lock (lock already held)";
-
-      let locked = yield DAV.lock.async(DAV, self.cb);
-      if (!locked)
-        throw "Could not acquire lock";
-
-      this._os.notifyObservers(null, this._osPrefix + "lock:acquired", "");
-
-      try {
-        args = savedArgs.concat(args);
-        args.unshift(this, savedMethod, self.cb);
-        ret = yield Async.run.apply(Async, args);
-
-      } catch (e) {
-        throw e;
-
-      } finally {
-        yield DAV.unlock.async(DAV, self.cb);
-        this._os.notifyObservers(null, this._osPrefix + "lock:released", "");
-      }
-
-      self.done(ret);
-    };
-  },
-
-  // NOTE: see notify, this works the same way.  they can be
-  // chained together as well.
   localLock: function WeaveSync_localLock(method /* , arg1, arg2, ..., argN */) {
     let savedMethod = method;
     let savedArgs = Array.prototype.slice.call(arguments, 1);
 
     return function WeaveLocalLockWrapper(/* argN+1, argN+2, ... */) {
       let self = yield;
       let ret;
       let args = Array.prototype.slice.call(arguments);
 
-      if (DAV.locked)
+      let ret = this.lock();
+      if (!ret)
         throw "Could not acquire lock";
-      DAV.allowLock = false;
 
       this._os.notifyObservers(null,
                                this._osPrefix + "local-lock:acquired", "");
 
       try {
         args = savedArgs.concat(args);
         args.unshift(this, savedMethod, self.cb);
         ret = yield Async.run.apply(Async, args);
 
       } catch (e) {
         throw e;
 
       } finally {
-        DAV.allowLock = true;
+        this.unlock();
         this._os.notifyObservers(null,
                                  this._osPrefix + "local-lock:released", "");
       }
 
       self.done(ret);
     };
   },