From 64d18d9d92e0cff7e3d11645ace58ebb90f63a76 Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Wed, 25 Aug 1999 23:03:15 +0000 Subject: [PATCH] don't actually create account manager until we need it (fixes service/object timing problems on code I'm about to check in) --- mailnews/base/src/nsMsgMailSession.cpp | 45 ++++++++++++++------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/mailnews/base/src/nsMsgMailSession.cpp b/mailnews/base/src/nsMsgMailSession.cpp index db66e2d6acf..123a0474d45 100644 --- a/mailnews/base/src/nsMsgMailSession.cpp +++ b/mailnews/base/src/nsMsgMailSession.cpp @@ -67,19 +67,8 @@ nsMsgMailSession::~nsMsgMailSession() } -nsresult nsMsgMailSession:: Init() +nsresult nsMsgMailSession::Init() { - nsresult rv; - - rv = nsComponentManager::CreateInstance(kMsgAccountManagerCID, - NULL, - nsCOMTypeInfo::GetIID(), - (void **)&m_accountManager); - if (NS_FAILED(rv)) - return rv; - - m_accountManager->LoadAccounts(); - mListeners = new nsVoidArray(); if(!mListeners) return NS_ERROR_OUT_OF_MEMORY; @@ -91,11 +80,14 @@ nsresult nsMsgMailSession:: Init() // nsIMsgMailSession nsresult nsMsgMailSession::GetCurrentIdentity(nsIMsgIdentity ** aIdentity) { - nsresult rv=NS_ERROR_UNEXPECTED; - nsCOMPtr defaultAccount; + nsresult rv; - if (m_accountManager) - rv = m_accountManager->GetDefaultAccount(getter_AddRefs(defaultAccount)); + nsCOMPtr accountManager; + rv = GetAccountManager(getter_AddRefs(accountManager)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr defaultAccount; + rv = accountManager->GetDefaultAccount(getter_AddRefs(defaultAccount)); if (NS_FAILED(rv)) return rv; rv = defaultAccount->GetDefaultIdentity(aIdentity); @@ -108,10 +100,13 @@ nsresult nsMsgMailSession::GetCurrentIdentity(nsIMsgIdentity ** aIdentity) nsresult nsMsgMailSession::GetCurrentServer(nsIMsgIncomingServer ** aServer) { nsresult rv=NS_ERROR_UNEXPECTED; - nsCOMPtr defaultAccount; - if (m_accountManager) - rv = m_accountManager->GetDefaultAccount(getter_AddRefs(defaultAccount)); + nsCOMPtr accountManager; + rv = GetAccountManager(getter_AddRefs(accountManager)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr defaultAccount; + rv = accountManager->GetDefaultAccount(getter_AddRefs(defaultAccount)); if (NS_FAILED(rv)) return rv; //if successful aServer will be addref'd by GetIncomingServer @@ -123,7 +118,17 @@ nsresult nsMsgMailSession::GetCurrentServer(nsIMsgIncomingServer ** aServer) nsresult nsMsgMailSession::GetAccountManager(nsIMsgAccountManager* *aAM) { if (!aAM) return NS_ERROR_NULL_POINTER; - + + if (!m_accountManager) { + nsresult rv; + rv = nsComponentManager::CreateInstance(kMsgAccountManagerCID, + NULL, + NS_GET_IID(nsIMsgAccountManager), + (void **)&m_accountManager); + if (NS_FAILED(rv)) return rv; + m_accountManager->LoadAccounts(); + } + *aAM = m_accountManager; NS_IF_ADDREF(*aAM); return NS_OK;