Bug 627672 - XPCOM component (libdbusservice.so) is not registered although it should be, r=honzab
authorMartin Stransky <stransky@redhat.com>
Tue, 18 Oct 2011 18:46:59 +0900
changeset 78902 c886f3cef1a95ff160d0c413e5a2dd4f840b7918
parent 78901 6b83e2e33b5a3a15564ec577bd1e727732a3095a
child 78903 387f388bca1f158a869a8220d46eba08ccaefffe
push id21350
push usermak77@bonardo.net
push dateWed, 19 Oct 2011 09:48:37 +0000
treeherdermozilla-central@311fdb9b38b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs627672
milestone10.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 627672 - XPCOM component (libdbusservice.so) is not registered although it should be, r=honzab
netwerk/base/src/nsIOService.cpp
netwerk/base/src/nsIOService.h
--- a/netwerk/base/src/nsIOService.cpp
+++ b/netwerk/base/src/nsIOService.cpp
@@ -159,31 +159,33 @@ PRInt16 gBadPortList[] = {
   2049, // nfs
   4045, // lockd
   6000, // x11        
   0,    // This MUST be zero so that we can populating the array
 };
 
 static const char kProfileChangeNetTeardownTopic[] = "profile-change-net-teardown";
 static const char kProfileChangeNetRestoreTopic[] = "profile-change-net-restore";
+static const char kProfileDoChange[] = "profile-do-change";
 
 // Necko buffer cache
 nsIMemory* nsIOService::gBufferCache = nsnull;
 PRUint32   nsIOService::gDefaultSegmentSize = 4096;
 PRUint32   nsIOService::gDefaultSegmentCount = 24;
 
 ////////////////////////////////////////////////////////////////////////////////
 
 nsIOService::nsIOService()
     : mOffline(true)
     , mOfflineForProfileChange(false)
     , mManageOfflineStatus(true)
     , mSettingOffline(false)
     , mSetOfflineValue(false)
     , mShutdown(false)
+    , mNetworkLinkServiceInitialized(false)
     , mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY)
     , mContentSniffers(NS_CONTENT_SNIFFER_CATEGORY)
     , mAutoDialEnabled(false)
 {
 }
 
 nsresult
 nsIOService::Init()
@@ -229,16 +231,17 @@ nsIOService::Init()
     }
     
     // Register for profile change notifications
     nsCOMPtr<nsIObserverService> observerService =
         mozilla::services::GetObserverService();
     if (observerService) {
         observerService->AddObserver(this, kProfileChangeNetTeardownTopic, true);
         observerService->AddObserver(this, kProfileChangeNetRestoreTopic, true);
+        observerService->AddObserver(this, kProfileDoChange, true);
         observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
         observerService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true);
     }
     else
         NS_WARNING("failed to get observer service");
         
     NS_TIME_FUNCTION_MARK("Registered observers");
 
@@ -257,30 +260,18 @@ nsIOService::Init()
         NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Was unable to allocate.  No gBufferCache.");
         CallQueryInterface(recyclingAllocator, &gBufferCache);
     }
 
     NS_TIME_FUNCTION_MARK("Set up the recycling allocator");
 
     gIOService = this;
 
-    // go into managed mode if we can, and chrome process
-    if (XRE_GetProcessType() == GeckoProcessType_Default)
-        mNetworkLinkService = do_GetService(NS_NETWORK_LINK_SERVICE_CONTRACTID);
-
-    if (!mNetworkLinkService)
-        // We can't really determine if the machine has a usable network connection,
-        // so let's cross our fingers!
-        mManageOfflineStatus = false;
-
-    if (mManageOfflineStatus)
-        TrackNetworkLinkStatusForOffline();
-    else
-        SetOffline(false);
-    
+    InitializeNetworkLinkService();
+ 
     NS_TIME_FUNCTION_MARK("Set up network link service");
 
     return NS_OK;
 }
 
 
 nsIOService::~nsIOService()
 {
@@ -305,16 +296,55 @@ nsIOService::InitializeSocketTransportSe
         rv = mSocketTransportService->Init();
         NS_ASSERTION(NS_SUCCEEDED(rv), "socket transport service init failed");
         mSocketTransportService->SetAutodialEnabled(mAutoDialEnabled);
     }
 
     return rv;
 }
 
+nsresult
+nsIOService::InitializeNetworkLinkService()
+{
+    NS_TIME_FUNCTION;
+
+    nsresult rv = NS_OK;
+
+    if (mNetworkLinkServiceInitialized)
+        return rv;
+
+    if (!NS_IsMainThread()) {
+        NS_WARNING("Network link service should be created on main thread"); 
+        return NS_ERROR_FAILURE; 
+    }
+
+    // go into managed mode if we can, and chrome process
+    if (XRE_GetProcessType() == GeckoProcessType_Default)
+    {
+        mNetworkLinkService = do_GetService(NS_NETWORK_LINK_SERVICE_CONTRACTID, &rv);
+    }
+
+    if (mNetworkLinkService) {
+        mNetworkLinkServiceInitialized = true;
+    }
+    else {
+        // We can't really determine if the machine has a usable network connection,
+        // so let's cross our fingers!
+        mManageOfflineStatus = false;
+    }
+   
+
+    if (mManageOfflineStatus)
+        TrackNetworkLinkStatusForOffline();
+    else
+        SetOffline(false);
+    
+    return rv;
+}
+
 nsIOService*
 nsIOService::GetInstance() {
     if (!gIOService) {
         gIOService = new nsIOService();
         if (!gIOService)
             return nsnull;
         NS_ADDREF(gIOService);
 
@@ -685,16 +715,18 @@ nsIOService::NewChannel(const nsACString
     if (NS_FAILED(rv)) return rv;
 
     return NewChannelFromURI(uri, result);
 }
 
 bool
 nsIOService::IsLinkUp()
 {
+    InitializeNetworkLinkService();
+
     if (!mNetworkLinkService) {
         // We cannot decide, assume the link is up
         return true;
     }
 
     bool isLinkUp;
     nsresult rv;
     rv = mNetworkLinkService->GetIsLinkUp(&isLinkUp);
@@ -963,16 +995,25 @@ nsIOService::Observe(nsISupports *subjec
     else if (!strcmp(topic, kProfileChangeNetRestoreTopic)) {
         if (mOfflineForProfileChange) {
             mOfflineForProfileChange = false;
             if (!mManageOfflineStatus ||
                 NS_FAILED(TrackNetworkLinkStatusForOffline())) {
                 SetOffline(false);
             }
         } 
+    } 
+    else if (!strcmp(topic, kProfileDoChange)) { 
+        if (data && NS_LITERAL_STRING("startup").Equals(data)) {
+            // Lazy initialization of network link service (see bug 620472)
+            InitializeNetworkLinkService();
+            // Set up the initilization flag regardless the actuall result.
+            // If we fail here, we will fail always on.
+            mNetworkLinkServiceInitialized = true;
+        }
     }
     else if (!strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
         // Remember we passed XPCOM shutdown notification to prevent any
         // changes of the offline status from now. We must not allow going
         // online after this point.
         mShutdown = true;
 
         SetOffline(true);
@@ -1079,21 +1120,28 @@ nsIOService::NewSimpleNestedURI(nsIURI* 
     NS_ENSURE_SUCCESS(rv, rv);
 
     NS_IF_ADDREF(*aResult = new nsSimpleNestedURI(safeURI));
     return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
 NS_IMETHODIMP
 nsIOService::SetManageOfflineStatus(bool aManage) {
+    nsresult rv = NS_OK;
+
+    InitializeNetworkLinkService();
     bool wasManaged = mManageOfflineStatus;
     mManageOfflineStatus = aManage;
-    if (mManageOfflineStatus && !wasManaged)
-        return TrackNetworkLinkStatusForOffline();
-    return NS_OK;
+
+    if (mManageOfflineStatus && !wasManaged) {
+        rv = TrackNetworkLinkStatusForOffline();
+        if (NS_FAILED(rv))
+            mManageOfflineStatus = false;
+    }
+    return rv;
 }
 
 NS_IMETHODIMP
 nsIOService::GetManageOfflineStatus(bool* aManage) {
     *aManage = mManageOfflineStatus;
     return NS_OK;
 }
 
--- a/netwerk/base/src/nsIOService.h
+++ b/netwerk/base/src/nsIOService.h
@@ -129,16 +129,17 @@ private:
                                               nsIProtocolHandler* hdlr);
 
     // Prefs wrangling
     NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch *prefs, const char *pref = nsnull);
     NS_HIDDEN_(void) GetPrefBranch(nsIPrefBranch2 **);
     NS_HIDDEN_(void) ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove);
 
     nsresult InitializeSocketTransportService();
+    nsresult InitializeNetworkLinkService();
 
 private:
     bool                                 mOffline;
     bool                                 mOfflineForProfileChange;
     bool                                 mManageOfflineStatus;
 
     // Used to handle SetOffline() reentrancy.  See the comment in
     // SetOffline() for more details.
@@ -146,17 +147,18 @@ private:
     bool                                 mSetOfflineValue;
 
     bool                                 mShutdown;
 
     nsCOMPtr<nsPISocketTransportService> mSocketTransportService;
     nsCOMPtr<nsPIDNSService>             mDNSService;
     nsCOMPtr<nsIProtocolProxyService2>   mProxyService;
     nsCOMPtr<nsINetworkLinkService>      mNetworkLinkService;
-    
+    bool                                 mNetworkLinkServiceInitialized;
+
     // Cached protocol handlers
     nsWeakPtr                            mWeakHandler[NS_N(gScheme)];
 
     // cached categories
     nsCategoryCache<nsIChannelEventSink> mChannelEventSinks;
     nsCategoryCache<nsIContentSniffer>   mContentSniffers;
 
     nsTArray<PRInt32>                    mRestrictedPortList;