[tracker] firefox: Use asynchronous connection opening



commit 438456340655f3b447227ca9952888b862f960e5
Author: Adrien Bustany <adrien bustany nokia com>
Date:   Thu Aug 4 19:13:18 2011 +0300

    firefox: Use asynchronous connection opening

 src/plugins/firefox/chrome/content/plugin.js |   39 ++++++++++++++++++-------
 1 files changed, 28 insertions(+), 11 deletions(-)
---
diff --git a/src/plugins/firefox/chrome/content/plugin.js b/src/plugins/firefox/chrome/content/plugin.js
index 7e40e00..9601bf3 100644
--- a/src/plugins/firefox/chrome/content/plugin.js
+++ b/src/plugins/firefox/chrome/content/plugin.js
@@ -21,14 +21,7 @@ org.bustany.TrackerFox.Plugin={
 			return;
 		}
 
-		this._bookmarks = org.bustany.TrackerFox.Bookmarks;
-
-		if (!this._bookmarks.init (this._connection)) {
-			dump ("Couldn't initialize bookmarks service!\n");
-			return;
-		}
-
-		this._bookmarks.syncBookmarks();
+		// The rest of the init is done in onTrackerReady()
 	},
 
 	onUnload: function () {
@@ -47,16 +40,40 @@ org.bustany.TrackerFox.Plugin={
 			return false;
 		}
 
+		var plugin = this;
+		var callback_closure = function(source_object, result, user_data) {
+			plugin.onTrackerReady(source_object, result, user_data);
+		}
+
+		tracker.connection_open_async(null,
+		                              tracker.AsyncReadyCallback.ptr(callback_closure),
+		                              null);
+
+		return true;
+	},
+
+	onTrackerReady: function(source_object, result, user_data) {
+		var tracker = this._tracker;
+
 		var error = new tracker.Error.ptr;
-		this._connection = tracker.connection_open (null, error.address());
+		this._connection = tracker.connection_open_finish (result, error.address());
 
 		if (!error.isNull ()) {
 			dump ("Could not initialize Tracker: " + error.contents.message.readString() + "\n");
 			tracker.error_free(error);
-			return false;
+			return;
 		}
 
-		return true;
+		// Tracker is OK, let's continue with the initialization
+
+		this._bookmarks = org.bustany.TrackerFox.Bookmarks;
+
+		if (!this._bookmarks.init (this._connection)) {
+			dump ("Couldn't initialize bookmarks service!\n");
+			return;
+		}
+
+		this._bookmarks.syncBookmarks();
 	}
 };
 



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