Fix in-memory datasource aggregation.
git-svn-id: svn://10.0.0.236/trunk@44249 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
ca6d411ae7
commit
82da269fe3
@ -91,6 +91,7 @@ nsMsgNotificationManager::~nsMsgNotificationManager()
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsMsgNotificationManager)
|
||||
NS_IMPL_RELEASE(nsMsgNotificationManager);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgNotificationManager::QueryInterface(REFNSIID iid, void** result)
|
||||
@ -109,7 +110,8 @@ nsMsgNotificationManager::QueryInterface(REFNSIID iid, void** result)
|
||||
}
|
||||
else if(iid.Equals(nsCOMTypeInfo<nsIRDFDataSource>::GetIID()))
|
||||
{
|
||||
*result = mInMemoryDataSource;
|
||||
// Support nsIRDFDataSource by aggregation.
|
||||
return mInMemoryDataSourceISupports->QueryInterface(iid, result);
|
||||
}
|
||||
|
||||
if(*result)
|
||||
@ -120,28 +122,14 @@ nsMsgNotificationManager::QueryInterface(REFNSIID iid, void** result)
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) nsMsgNotificationManager::Release()
|
||||
{
|
||||
|
||||
--mRefCnt;
|
||||
if (mRefCnt == 1 && mInMemoryDataSource) {
|
||||
mInMemoryDataSource = nsnull; /* nsCOMPtr triggers Release() */
|
||||
}
|
||||
else if (mRefCnt == 0) {
|
||||
delete this;
|
||||
}
|
||||
return mRefCnt;
|
||||
|
||||
}
|
||||
|
||||
nsresult nsMsgNotificationManager::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
|
||||
this,
|
||||
nsCOMTypeInfo<nsIRDFDataSource>::GetIID(),
|
||||
getter_AddRefs(mInMemoryDataSource));
|
||||
nsCOMTypeInfo<nsISupports>::GetIID(),
|
||||
getter_AddRefs(mInMemoryDataSourceISupports));
|
||||
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
@ -253,7 +241,9 @@ nsresult nsMsgNotificationManager::AddNewMailNotification(nsIMsgFolder *folder)
|
||||
timeStampString = "3:33pm";
|
||||
urlString = "test";
|
||||
|
||||
mInMemoryDataSource->Assert(notificationResource, kNC_Type, kNC_NewMessages, PR_TRUE);
|
||||
nsCOMPtr<nsIRDFDataSource> ds = do_QueryInterface(mInMemoryDataSourceISupports);
|
||||
|
||||
ds->Assert(notificationResource, kNC_Type, kNC_NewMessages, PR_TRUE);
|
||||
|
||||
PRUnichar* folderDescription;
|
||||
rv = folder->GetNewMessagesNotificationDescription(&folderDescription);
|
||||
@ -265,7 +255,7 @@ nsresult nsMsgNotificationManager::AddNewMailNotification(nsIMsgFolder *folder)
|
||||
rv = rdfService->GetLiteral(sourceString.GetUnicode(), getter_AddRefs(source));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
mInMemoryDataSource->Assert(notificationResource, kNC_Source, source, PR_TRUE);
|
||||
ds->Assert(notificationResource, kNC_Source, source, PR_TRUE);
|
||||
}
|
||||
|
||||
PRInt32 newMessages;
|
||||
@ -279,7 +269,7 @@ nsresult nsMsgNotificationManager::AddNewMailNotification(nsIMsgFolder *folder)
|
||||
rv = rdfService->GetLiteral(descriptionString.GetUnicode(), getter_AddRefs(description));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
mInMemoryDataSource->Assert(notificationResource, kNC_Description, description, PR_TRUE);
|
||||
ds->Assert(notificationResource, kNC_Description, description, PR_TRUE);
|
||||
}
|
||||
|
||||
//Supposedly rdf will convert this into a localized time string.
|
||||
@ -292,16 +282,16 @@ nsresult nsMsgNotificationManager::AddNewMailNotification(nsIMsgFolder *folder)
|
||||
rv = rdfService->GetLiteral(timeStampString.GetUnicode(), getter_AddRefs(timeStamp));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
mInMemoryDataSource->Assert(notificationResource, kNC_TimeStamp, timeStamp, PR_TRUE);
|
||||
ds->Assert(notificationResource, kNC_TimeStamp, timeStamp, PR_TRUE);
|
||||
}
|
||||
|
||||
rv = rdfService->GetLiteral(urlString.GetUnicode(), getter_AddRefs(url));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
mInMemoryDataSource->Assert(notificationResource, kNC_URL, url, PR_TRUE);
|
||||
ds->Assert(notificationResource, kNC_URL, url, PR_TRUE);
|
||||
}
|
||||
|
||||
mInMemoryDataSource->Assert(kNC_FlashRoot, kNC_Child, notificationResource, PR_TRUE);
|
||||
ds->Assert(kNC_FlashRoot, kNC_Child, notificationResource, PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -323,7 +313,9 @@ nsresult nsMsgNotificationManager::RemoveNewMailNotification(nsIMsgFolder *folde
|
||||
return rv;
|
||||
RemoveOldValues(notificationResource);
|
||||
|
||||
mInMemoryDataSource->Unassert(kNC_FlashRoot, kNC_Child, notificationResource);
|
||||
nsCOMPtr<nsIRDFDataSource> ds = do_QueryInterface(mInMemoryDataSourceISupports);
|
||||
|
||||
ds->Unassert(kNC_FlashRoot, kNC_Child, notificationResource);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -333,25 +325,27 @@ nsresult nsMsgNotificationManager::RemoveOldValues(nsIRDFResource *notificationR
|
||||
nsCOMPtr<nsIRDFNode> target;
|
||||
nsresult rv;
|
||||
|
||||
rv = mInMemoryDataSource->GetTarget(notificationResource, kNC_Description, PR_TRUE, getter_AddRefs(target));
|
||||
if(NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))
|
||||
mInMemoryDataSource->Unassert(notificationResource, kNC_Description, target);
|
||||
nsCOMPtr<nsIRDFDataSource> ds = do_QueryInterface(mInMemoryDataSourceISupports);
|
||||
|
||||
rv = mInMemoryDataSource->GetTarget(notificationResource, kNC_Type, PR_TRUE, getter_AddRefs(target));
|
||||
rv = ds->GetTarget(notificationResource, kNC_Description, PR_TRUE, getter_AddRefs(target));
|
||||
if(NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))
|
||||
mInMemoryDataSource->Unassert(notificationResource, kNC_Type, target);
|
||||
ds->Unassert(notificationResource, kNC_Description, target);
|
||||
|
||||
rv = mInMemoryDataSource->GetTarget(notificationResource, kNC_Source, PR_TRUE, getter_AddRefs(target));
|
||||
rv = ds->GetTarget(notificationResource, kNC_Type, PR_TRUE, getter_AddRefs(target));
|
||||
if(NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))
|
||||
mInMemoryDataSource->Unassert(notificationResource, kNC_Source, target);
|
||||
ds->Unassert(notificationResource, kNC_Type, target);
|
||||
|
||||
rv = mInMemoryDataSource->GetTarget(notificationResource, kNC_TimeStamp, PR_TRUE, getter_AddRefs(target));
|
||||
rv = ds->GetTarget(notificationResource, kNC_Source, PR_TRUE, getter_AddRefs(target));
|
||||
if(NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))
|
||||
mInMemoryDataSource->Unassert(notificationResource, kNC_TimeStamp, target);
|
||||
ds->Unassert(notificationResource, kNC_Source, target);
|
||||
|
||||
rv = mInMemoryDataSource->GetTarget(notificationResource, kNC_URL, PR_TRUE, getter_AddRefs(target));
|
||||
rv = ds->GetTarget(notificationResource, kNC_TimeStamp, PR_TRUE, getter_AddRefs(target));
|
||||
if(NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))
|
||||
mInMemoryDataSource->Unassert(notificationResource, kNC_URL, target);
|
||||
ds->Unassert(notificationResource, kNC_TimeStamp, target);
|
||||
|
||||
rv = ds->GetTarget(notificationResource, kNC_URL, PR_TRUE, getter_AddRefs(target));
|
||||
if(NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))
|
||||
ds->Unassert(notificationResource, kNC_URL, target);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ protected:
|
||||
nsresult BuildNewMailURI(nsIMsgFolder *folder, nsCAutoString &newMailURI);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIRDFDataSource> mInMemoryDataSource;
|
||||
nsCOMPtr<nsISupports> mInMemoryDataSourceISupports;
|
||||
|
||||
static nsIRDFResource* kNC_FlashRoot;
|
||||
static nsIRDFResource* kNC_Type;
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
|
||||
*/
|
||||
|
||||
#include "nsAgg.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIOutputStream.h"
|
||||
@ -178,12 +179,9 @@ protected:
|
||||
friend NS_IMETHODIMP
|
||||
NS_NewRDFInMemoryDataSource(nsISupports* aOuter, const nsIID& aIID, void** aResult);
|
||||
|
||||
nsISupports* mOuter;
|
||||
|
||||
public:
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_AGGREGATED
|
||||
|
||||
// nsIRDFDataSource methods
|
||||
NS_IMETHOD GetURI(char* *uri);
|
||||
@ -578,6 +576,13 @@ NS_IMETHODIMP
|
||||
NS_NewRDFInMemoryDataSource(nsISupports* aOuter, const nsIID& aIID, void** aResult)
|
||||
{
|
||||
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aOuter && !aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
NS_ERROR("aggregation requires nsISupports");
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
InMemoryDataSource* datasource = new InMemoryDataSource(aOuter);
|
||||
if (! datasource)
|
||||
@ -587,7 +592,9 @@ NS_NewRDFInMemoryDataSource(nsISupports* aOuter, const nsIID& aIID, void** aResu
|
||||
|
||||
rv = datasource->Init();
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = datasource->QueryInterface(aIID, aResult); // This'll AddRef()
|
||||
datasource->fAggregated.AddRef();
|
||||
rv = datasource->AggregatedQueryInterface(aIID, aResult); // This'll AddRef()
|
||||
datasource->fAggregated.Release();
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
@ -603,10 +610,9 @@ NS_NewRDFInMemoryDataSource(nsISupports* aOuter, const nsIID& aIID, void** aResu
|
||||
InMemoryDataSource::InMemoryDataSource(nsISupports* aOuter)
|
||||
: mForwardArcs(nsnull),
|
||||
mReverseArcs(nsnull),
|
||||
mOuter(aOuter),
|
||||
mLock(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_INIT_AGGREGATED(aOuter);
|
||||
}
|
||||
|
||||
|
||||
@ -684,60 +690,30 @@ InMemoryDataSource::DeleteForwardArcsEntry(PLHashEntry* he, PRIntn i, void* arg)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
InMemoryDataSource::AddRef()
|
||||
{
|
||||
if (mOuter) {
|
||||
return mOuter->AddRef();
|
||||
}
|
||||
else {
|
||||
return ++mRefCnt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
InMemoryDataSource::Release()
|
||||
{
|
||||
nsrefcnt refcnt;
|
||||
if (mOuter) {
|
||||
refcnt = mOuter->Release();
|
||||
}
|
||||
else {
|
||||
refcnt = --mRefCnt;
|
||||
}
|
||||
if (refcnt == 0) {
|
||||
delete this;
|
||||
}
|
||||
return refcnt;
|
||||
}
|
||||
|
||||
NS_IMPL_AGGREGATED(InMemoryDataSource)
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::QueryInterface(REFNSIID aIID, void** aResult)
|
||||
InMemoryDataSource::AggregatedQueryInterface(REFNSIID aIID, void** aResult)
|
||||
{
|
||||
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
if (aIID.Equals(nsIRDFDataSource::GetIID()) ||
|
||||
((!mOuter && aIID.Equals(kISupportsIID)))) {
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
*aResult = NS_STATIC_CAST(nsISupports*, &fAggregated);
|
||||
}
|
||||
else if (aIID.Equals(nsCOMTypeInfo<nsIRDFDataSource>::GetIID())) {
|
||||
*aResult = NS_STATIC_CAST(nsIRDFDataSource*, this);
|
||||
}
|
||||
else if (aIID.Equals(nsIRDFPurgeableDataSource::GetIID())) {
|
||||
else if (aIID.Equals(nsCOMTypeInfo<nsIRDFPurgeableDataSource>::GetIID())) {
|
||||
*aResult = NS_STATIC_CAST(nsIRDFPurgeableDataSource*, this);
|
||||
}
|
||||
else if (mOuter) {
|
||||
return mOuter->QueryInterface(aIID, aResult);
|
||||
}
|
||||
else {
|
||||
*aResult = nsnull;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF(this);
|
||||
NS_ADDREF(NS_STATIC_CAST(nsISupports*, *aResult));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ private:
|
||||
PRInt32 CompareVersions(VERSION *oldversion, VERSION *newVersion);
|
||||
void StringToVersionNumbers(const nsString& version, int32 *aMajor, int32 *aMinor, int32 *aRelease, int32 *aBuild);
|
||||
|
||||
nsCOMPtr<nsIRDFDataSource> mInner;
|
||||
nsCOMPtr<nsISupports> mInner;
|
||||
nsIRDFService* mRDF;
|
||||
|
||||
|
||||
@ -163,7 +163,7 @@ nsXPINotifierImpl::Init()
|
||||
|
||||
rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
|
||||
this, /* the "outer" */
|
||||
nsIRDFDataSource::GetIID(),
|
||||
nsCOMTypeInfo<nsISupports>::GetIID(),
|
||||
getter_AddRefs(mInner));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
@ -328,11 +328,12 @@ nsXPINotifierImpl::AddNewSoftwareFromDistributor(nsIRDFResource *inDistributor)
|
||||
nsCOMPtr<nsIRDFLiteral> title(do_QueryInterface(titleNode, &rv));
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
mInner->Assert(aPackage, kNC_Type, kXPI_Notifier_Type, PR_TRUE);
|
||||
mInner->Assert(aPackage, kNC_Description, title, PR_TRUE);
|
||||
mInner->Assert(aPackage, kNC_URL, url, PR_TRUE);
|
||||
nsCOMPtr<nsIRDFDataSource> ds = do_QueryInterface(mInner);
|
||||
ds->Assert(aPackage, kNC_Type, kXPI_Notifier_Type, PR_TRUE);
|
||||
ds->Assert(aPackage, kNC_Description, title, PR_TRUE);
|
||||
ds->Assert(aPackage, kNC_URL, url, PR_TRUE);
|
||||
|
||||
mInner->Assert(kNC_FlashRoot, kNC_Child, aPackage, PR_TRUE);
|
||||
ds->Assert(kNC_FlashRoot, kNC_Child, aPackage, PR_TRUE);
|
||||
break;
|
||||
|
||||
}
|
||||
@ -533,19 +534,7 @@ nsXPINotifierImpl::New(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
||||
// nsISupports
|
||||
|
||||
NS_IMPL_ADDREF(nsXPINotifierImpl);
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
nsXPINotifierImpl::Release()
|
||||
{
|
||||
--mRefCnt;
|
||||
if (mRefCnt == 1 && mInner) {
|
||||
mInner = nsnull; /* nsCOMPtr triggers Release() */
|
||||
}
|
||||
else if (mRefCnt == 0) {
|
||||
delete this;
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
NS_IMPL_RELEASE(nsXPINotifierImpl);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPINotifierImpl::QueryInterface(REFNSIID aIID, void** aResult)
|
||||
@ -560,7 +549,7 @@ nsXPINotifierImpl::QueryInterface(REFNSIID aIID, void** aResult)
|
||||
*aResult = NS_STATIC_CAST(nsISupports*, this);
|
||||
}
|
||||
else if (aIID.Equals(nsIRDFDataSource::GetIID())) {
|
||||
*aResult = mInner;
|
||||
return mInner->QueryInterface(aIID, aResult);
|
||||
}
|
||||
else {
|
||||
*aResult = nsnull;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user