diff --git a/xpfe/components/download-manager/resources/content/downloadmanager.js b/xpfe/components/download-manager/resources/content/downloadmanager.js index 6f0f6d728e31..65c3bb6891ca 100644 --- a/xpfe/components/download-manager/resources/content/downloadmanager.js +++ b/xpfe/components/download-manager/resources/content/downloadmanager.js @@ -87,9 +87,9 @@ function Test() var ds = dlmgr.QueryInterface(Components.interfaces.nsIRDFDataSource); gDownloadView.database.AddDataSource(ds); gDownloadView.builder.rebuild(); - dlmgr.addItem("Some File", uri, lf, null, null); - gDownloadView.builder.rebuild(); - dump("*** goat\n"); +// dlmgr.addItem("Some File", uri, lf, null, null); +// gDownloadView.builder.rebuild(); +// dump("*** goat\n"); } function Shutdown() diff --git a/xpfe/components/download-manager/src/nsDownloadManager.cpp b/xpfe/components/download-manager/src/nsDownloadManager.cpp index 334eac8a88a6..ae498a47527a 100644 --- a/xpfe/components/download-manager/src/nsDownloadManager.cpp +++ b/xpfe/components/download-manager/src/nsDownloadManager.cpp @@ -55,6 +55,7 @@ #include "nsFileStream.h" static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); +static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID); #define PROFILE_DOWNLOAD_FILE "downloads.rdf" #define NSDOWNLOADMANAGER_PROPERTIES_URI "chrome://communicator/locale/downloadmanager/downloadmanager.properties" @@ -67,7 +68,7 @@ nsIRDFResource* gNC_Progress; nsIRDFService* gRDFService; -NS_IMPL_ISUPPORTS3(nsDownloadManager, nsIDownloadManager, nsIRDFDataSource, nsIRDFRemoteDataSource) +NS_IMPL_ISUPPORTS2(nsDownloadManager, nsIDownloadManager, nsIRDFDataSource) nsDownloadManager::nsDownloadManager() { @@ -105,8 +106,24 @@ nsDownloadManager::Init() gRDFService->GetResource(NC_NAMESPACE_URI "Name", &gNC_Name); gRDFService->GetResource(NC_NAMESPACE_URI "Progress", &gNC_Progress); +#if 0 mInner = do_GetService(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "in-memory-datasource", &rv); if (NS_FAILED(rv)) return rv; +#else + mInner = do_GetService(kRDFXMLDataSourceCID, &rv); + if (NS_FAILED(rv)) return rv; + + // This should move elsewhere + nsXPIDLCString downloadsDB; + GetProfileDownloadsFileURL(getter_Copies(downloadsDB)); + + nsCOMPtr remote(do_QueryInterface(mInner)); + rv = remote->Init(downloadsDB); + if (NS_FAILED(rv)) return rv; + + rv = remote->Refresh(PR_TRUE); + if (NS_FAILED(rv)) return rv; +#endif return gRDFService->RegisterDataSource(this, PR_FALSE); } @@ -171,7 +188,8 @@ nsDownloadManager::AddItem(const PRUnichar* aDisplayName, nsIURI* aSourceURI, gRDFService->GetResource(filePath, getter_AddRefs(fileResource)); Assert(downloadItem, gNC_File, fileResource, PR_TRUE); - return Flush(); + nsCOMPtr remote(do_QueryInterface(mInner)); + return remote->Flush(); } nsresult @@ -357,34 +375,11 @@ nsDownloadManager::DoCommand(nsISupportsArray* aSources, return mInner->DoCommand(aSources, aCommand, aArguments); } -//////////////////////////////////////////////////////////////////////// -// nsIRDFRemoteDataSource - -NS_IMETHODIMP -nsDownloadManager::GetLoaded(PRBool* aResult) -{ - *aResult = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -nsDownloadManager::Init(const char* aURI) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsDownloadManager::Refresh(PRBool aBlocking) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsDownloadManager::Flush() +nsresult +nsDownloadManager::GetProfileDownloadsFileURL(char** aDownloadsFileURL) { nsresult rv; - // Locate datasource file nsCOMPtr fileLocator(do_GetService("@mozilla.org/file/directory_service;1")); nsCOMPtr profileDir; rv = fileLocator->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(profileDir)); @@ -393,27 +388,7 @@ nsDownloadManager::Flush() rv = profileDir->Append(PROFILE_DOWNLOAD_FILE); if (NS_FAILED(rv)) return rv; - nsXPIDLCString fileURL; - profileDir->GetURL(getter_Copies(fileURL)); - nsAutoString fileAS; fileAS.AssignWithConversion(fileURL); - - nsFileURL url(fileURL, PR_TRUE); - nsFileSpec path(url); - - nsOutputFileStream out(path); - if (!out.is_open()) - return NS_ERROR_FAILURE; - - nsCOMPtr serializer(do_CreateInstance("@mozilla.org/rdf/xml-serializer;1", &rv)); - if (NS_FAILED(rv)) return rv; - - rv = serializer->Init(mInner); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr source(do_QueryInterface(serializer, &rv)); - if (NS_FAILED(rv)) return rv; - - return source->Serialize(out.GetIStream()); + return profileDir->GetURL(aDownloadsFileURL); } /////////////////////////////////////////////////////////////////////////////// diff --git a/xpfe/components/download-manager/src/nsDownloadManager.h b/xpfe/components/download-manager/src/nsDownloadManager.h index c6d534132421..fa628f931d79 100644 --- a/xpfe/components/download-manager/src/nsDownloadManager.h +++ b/xpfe/components/download-manager/src/nsDownloadManager.h @@ -53,12 +53,10 @@ #include "nsILocalFile.h" class nsDownloadManager : public nsIDownloadManager, - public nsIRDFDataSource, - public nsIRDFRemoteDataSource + public nsIRDFDataSource { public: NS_DECL_NSIRDFDATASOURCE - NS_DECL_NSIRDFREMOTEDATASOURCE NS_DECL_ISUPPORTS NS_DECL_NSIDOWNLOADMANAGER @@ -69,11 +67,12 @@ public: protected: nsresult GetDownloadsContainer(nsIRDFContainer** aResult); + nsresult GetProfileDownloadsFileURL(char** aDownloadsFileURL); + protected: nsCOMPtr mInner; nsCOMPtr mObservers; - nsCOMPtr mRDFService; nsCOMPtr mRDFContainerUtils;