[tor-commits] [meek/master] Actually use the "profile-after-change" observer.

dcf at torproject.org dcf at torproject.org
Wed Apr 9 05:56:56 UTC 2014


commit 2c389fafe92afbed16eabcfbd00fd754f7c9b73f
Author: David Fifield <david at bamsoftware.com>
Date:   Sun Mar 23 17:04:33 2014 -0700

    Actually use the "profile-after-change" observer.
    
    Before we were starting the listener as a side effect of the
    constructor. Actually wait until we get the "profile-after-change"
    notification before running.
---
 firefox/components/main.js |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/firefox/components/main.js b/firefox/components/main.js
index a55eb8c..d4b4d35 100644
--- a/firefox/components/main.js
+++ b/firefox/components/main.js
@@ -37,16 +37,7 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 // nsIServerSocketListener.
 function MeekHTTPHelper() {
     this.wrappedJSObject = this;
-
-    const LOCAL_PORT = 7000;
-
     this.handlers = [];
-
-    // https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIServerSocket
-    var serverSocket = Components.classes["@mozilla.org/network/server-socket;1"]
-        .createInstance(Components.interfaces.nsIServerSocket);
-    serverSocket.init(LOCAL_PORT, true, -1);
-    serverSocket.asyncListen(this);
 }
 MeekHTTPHelper.prototype = {
     classDescription: "meek HTTP helper component",
@@ -55,10 +46,22 @@ MeekHTTPHelper.prototype = {
 
     // https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/XPCOMUtils.jsm#generateQI%28%29
     QueryInterface: XPCOMUtils.generateQI([
-        Components.interfaces.nsIServerSocketListener,
         Components.interfaces.nsIObserver,
+        Components.interfaces.nsIServerSocketListener,
     ]),
 
+    // nsIObserver implementation.
+    observe: function(subject, topic, data) {
+        if (topic !== "profile-after-change")
+            return
+
+        // https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIServerSocket
+        var serverSocket = Components.classes["@mozilla.org/network/server-socket;1"]
+            .createInstance(Components.interfaces.nsIServerSocket);
+        serverSocket.init(MeekHTTPHelper.LOCAL_PORT, true, -1);
+        serverSocket.asyncListen(this);
+    },
+
     // nsIServerSocketListener implementation.
     onSocketAccepted: function(server, transport) {
         dump("onSocketAccepted " + transport.host + ":" + transport.port + "\n");
@@ -73,6 +76,7 @@ MeekHTTPHelper.prototype = {
 
 // Global variables and functions.
 
+MeekHTTPHelper.LOCAL_PORT = 7000;
 MeekHTTPHelper.LOCAL_READ_TIMEOUT = 2.0;
 MeekHTTPHelper.LOCAL_WRITE_TIMEOUT = 2.0;
 





More information about the tor-commits mailing list