[gnome-documents] application: Create the miner proxies asynchronously



commit a70c47b78d22ca52ba684c4d807e5a33c86ed9de
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Feb 18 10:46:11 2015 +0100

    application: Create the miner proxies asynchronously
    
    We deliberately don't chain the creation of the proxies and assign the
    variables (ie. this.gdataMiner, etc.) before leaving the main loop.
    Otherwise, if the window is destroyed while the proxy creation was
    still in flight, then some of the variables would get assigned after
    they were null-ed, which would be a race.
    
    Similarly, be careful about calling _refreshMinerNow with a null miner.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744625

 src/application.js |   43 ++++++++++++++++++++++++++++++++++++-------
 src/miners.js      |   19 +++++++++++--------
 2 files changed, 47 insertions(+), 15 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index c2d63cd..e015f07 100644
--- a/src/application.js
+++ b/src/application.js
@@ -344,11 +344,39 @@ const Application = new Lang.Class({
         this.set_app_menu(menu);
     },
 
+    _createMiners: function(callback) {
+        let count = 3;
+
+        this.gdataMiner = new Miners.GDataMiner(Lang.bind(this,
+            function() {
+                count--;
+                if (count == 0)
+                    callback();
+            }));
+
+        this.owncloudMiner = new Miners.OwncloudMiner(Lang.bind(this,
+            function() {
+                count--;
+                if (count == 0)
+                    callback();
+            }));
+
+        this.zpjMiner = new Miners.ZpjMiner(Lang.bind(this,
+            function() {
+                count--;
+                if (count == 0)
+                    callback();
+            }));
+    },
+
     _refreshMinerNow: function(miner) {
         let env = GLib.getenv('DOCUMENTS_DISABLE_MINERS');
         if (env)
             return false;
 
+        if (!miner)
+            return false;
+
         this.minersRunning.push(miner);
         this.emitJS('miners-changed', this.minersRunning);
 
@@ -407,14 +435,15 @@ const Application = new Lang.Class({
     },
 
     _startMiners: function() {
-        this.gdataMiner = new Miners.GDataMiner();
-        this.owncloudMiner = new Miners.OwncloudMiner();
-        this.zpjMiner = new Miners.ZpjMiner();
-
-        this._refreshMiners();
+        this._createMiners(Lang.bind(this,
+            function() {
+                this._refreshMiners();
 
-        this._sourceAddedId = sourceManager.connect('item-added', Lang.bind(this, this._refreshMiners));
-        this._sourceRemovedId = sourceManager.connect('item-removed', Lang.bind(this, this._refreshMiners));
+                this._sourceAddedId = sourceManager.connect('item-added',
+                                                            Lang.bind(this, this._refreshMiners));
+                this._sourceRemovedId = sourceManager.connect('item-removed',
+                                                              Lang.bind(this, this._refreshMiners));
+            }));
     },
 
     _stopMiners: function() {
diff --git a/src/miners.js b/src/miners.js
index f3cd49c..323d3ab 100644
--- a/src/miners.js
+++ b/src/miners.js
@@ -34,23 +34,26 @@ const MinerIface = '<node> \
 
 var MinerProxy = Gio.DBusProxy.makeProxyWrapper(MinerIface);
 
-function _makeMinerProxy(iface, path) {
-    let miner = new MinerProxy(Gio.DBus.session, iface, path);
+function _makeMinerProxy(iface, path, callback) {
+    let miner = new MinerProxy(Gio.DBus.session, iface, path, callback);
     miner.set_default_timeout(GLib.MAXINT32);
     return miner;
 }
 
-function GDataMiner() {
+function GDataMiner(callback) {
     return _makeMinerProxy('org.gnome.OnlineMiners.GData',
-                           '/org/gnome/OnlineMiners/GData');
+                           '/org/gnome/OnlineMiners/GData',
+                           callback);
 }
 
-function OwncloudMiner() {
+function OwncloudMiner(callback) {
     return _makeMinerProxy('org.gnome.OnlineMiners.Owncloud',
-                           '/org/gnome/OnlineMiners/Owncloud');
+                           '/org/gnome/OnlineMiners/Owncloud',
+                           callback);
 }
 
-function ZpjMiner() {
+function ZpjMiner(callback) {
     return _makeMinerProxy('org.gnome.OnlineMiners.Zpj',
-                           '/org/gnome/OnlineMiners/Zpj');
+                           '/org/gnome/OnlineMiners/Zpj',
+                           callback);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]