2001-07-31 23:05:34 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla FastLoad code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 2001 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brendan Eich <brendan@mozilla.org> (original author)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "prio.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "pldhash.h"
|
|
|
|
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsAutoLock.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFastLoadFile.h"
|
|
|
|
#include "nsFastLoadPtr.h"
|
|
|
|
#include "nsFastLoadService.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
#include "nsISeekableStream.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
|
2001-08-17 23:45:11 +04:00
|
|
|
// XXXbe we *know* that nsIObject*Stream is implemented by nsFastLoadFile.cpp
|
|
|
|
inline nsFastLoadFileReader* GetReader(nsIObjectInputStream* aStream) {
|
|
|
|
return NS_STATIC_CAST(nsFastLoadFileReader*, aStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsFastLoadFileWriter* GetWriter(nsIObjectOutputStream* aStream) {
|
|
|
|
return NS_STATIC_CAST(nsFastLoadFileWriter*, aStream);
|
|
|
|
}
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
PR_IMPLEMENT_DATA(nsIFastLoadService*) gFastLoadService_ = nsnull;
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsFastLoadService, nsIFastLoadService)
|
|
|
|
|
|
|
|
nsFastLoadService::nsFastLoadService()
|
|
|
|
: mLock(nsnull),
|
|
|
|
mFastLoadPtrMap(nsnull),
|
|
|
|
mDirection(0)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
|
|
|
NS_ASSERTION(gFastLoadService_ == nsnull, "double FastLoadService init?");
|
|
|
|
gFastLoadService_ = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFastLoadService::~nsFastLoadService()
|
|
|
|
{
|
|
|
|
gFastLoadService_ = nsnull;
|
|
|
|
|
|
|
|
if (mInputStream)
|
|
|
|
mInputStream->Close();
|
|
|
|
if (mOutputStream)
|
|
|
|
mOutputStream->Close();
|
|
|
|
|
|
|
|
if (mFastLoadPtrMap)
|
|
|
|
PL_DHashTableDestroy(mFastLoadPtrMap);
|
|
|
|
if (mLock)
|
|
|
|
PR_DestroyLock(mLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFastLoadService::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
nsFastLoadService* fastLoadService = new nsFastLoadService();
|
|
|
|
if (!fastLoadService)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
fastLoadService->mLock = PR_NewLock();
|
|
|
|
if (!fastLoadService->mLock) {
|
|
|
|
delete fastLoadService;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(fastLoadService);
|
|
|
|
nsresult rv = fastLoadService->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(fastLoadService);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined XP_MAC
|
|
|
|
|
|
|
|
// Mac format: "<Basename> FastLoad File" with <basename> capitalized.
|
|
|
|
# include "nsCRT.h"
|
|
|
|
|
|
|
|
# define MASSAGE_BASENAME(bn) (bn.SetCharAt(nsCRT::ToUpper(bn.CharAt(0)), 0))
|
|
|
|
# define PLATFORM_FASL_SUFFIX " FastLoad File"
|
|
|
|
|
2001-08-01 00:34:37 +04:00
|
|
|
#elif defined(XP_UNIX) || defined(XP_BEOS)
|
2001-07-31 23:05:34 +04:00
|
|
|
|
|
|
|
// Unix format: "<basename>.mfasl".
|
|
|
|
# define MASSAGE_BASENAME(bn) /* nothing */
|
|
|
|
# define PLATFORM_FASL_SUFFIX ".mfasl"
|
|
|
|
|
2001-08-01 00:34:37 +04:00
|
|
|
#elif defined(XP_WIN) || defined(XP_OS2)
|
2001-07-31 23:05:34 +04:00
|
|
|
|
|
|
|
// Windows format: "<basename>.mfl".
|
|
|
|
# define MASSAGE_BASENAME(bn) /* nothing */
|
|
|
|
# define PLATFORM_FASL_SUFFIX ".mfl"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFastLoadService::NewFastLoadFile(const char* aBaseName, nsIFile* *aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
|
|
|
|
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
|
|
|
|
getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCAutoString name(aBaseName);
|
|
|
|
MASSAGE_BASENAME(name);
|
|
|
|
name += PLATFORM_FASL_SUFFIX;
|
|
|
|
rv = file->Append(name);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
*aResult = file;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFastLoadService::NewInputStream(nsIInputStream* aSrcStream,
|
2001-08-17 23:45:11 +04:00
|
|
|
PRUint32 *aChecksum,
|
2001-07-31 23:05:34 +04:00
|
|
|
nsIObjectInputStream* *aResult)
|
|
|
|
{
|
2001-08-17 23:45:11 +04:00
|
|
|
nsresult rv;
|
2001-07-31 23:05:34 +04:00
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObjectInputStream> stream;
|
2001-08-17 23:45:11 +04:00
|
|
|
rv = NS_NewFastLoadFileReader(getter_AddRefs(stream), aSrcStream);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsFastLoadFileReader* reader = GetReader(stream);
|
|
|
|
|
|
|
|
rv = reader->GetChecksum(aChecksum);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
|
|
|
*aResult = stream;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFastLoadService::NewOutputStream(nsIOutputStream* aDestStream,
|
|
|
|
nsIObjectOutputStream* *aResult)
|
|
|
|
{
|
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
|
2001-08-17 23:45:11 +04:00
|
|
|
return NS_NewFastLoadFileWriter(aResult, aDestStream);
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-08-17 23:45:11 +04:00
|
|
|
nsFastLoadService::GetCurrentInputStream(nsIObjectInputStream* *aResult)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aResult = mInputStream);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-08-17 23:45:11 +04:00
|
|
|
nsFastLoadService::SetCurrentInputStream(nsIObjectInputStream* aStream)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
mInputStream = aStream;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-08-17 23:45:11 +04:00
|
|
|
nsFastLoadService::GetCurrentOutputStream(nsIObjectOutputStream* *aResult)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aResult = mOutputStream);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-08-17 23:45:11 +04:00
|
|
|
nsFastLoadService::SetCurrentOutputStream(nsIObjectOutputStream* aStream)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
mOutputStream = aStream;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-08-17 23:45:11 +04:00
|
|
|
nsFastLoadService::GetCurrentFileIO(nsIFastLoadFileIO* *aResult)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aResult = mFileIO);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-08-17 23:45:11 +04:00
|
|
|
nsFastLoadService::SetCurrentFileIO(nsIFastLoadFileIO* aFileIO)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
mFileIO = aFileIO;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-08-17 23:45:11 +04:00
|
|
|
nsFastLoadService::GetCurrentDirection(PRInt32 *aResult)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
*aResult = mDirection;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFastLoadService::StartMuxedDocument(nsISupports* aURI, const char* aURISpec,
|
|
|
|
PRInt32 aDirectionFlags)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
|
|
|
|
// Try for an input stream first, in case aURISpec's data is multiplexed
|
|
|
|
// in the current FastLoad file.
|
|
|
|
if ((aDirectionFlags & NS_FASTLOAD_READ) && mInputStream) {
|
2001-08-17 23:45:11 +04:00
|
|
|
nsFastLoadFileReader* reader = GetReader(mInputStream);
|
|
|
|
rv = reader->StartMuxedDocument(aURI, aURISpec);
|
|
|
|
if (NS_SUCCEEDED(rv) || rv != NS_ERROR_NOT_AVAILABLE)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// If aURISpec is not found in the reader, wrap it with an updater
|
|
|
|
// and store the updater at mOutputStream.
|
|
|
|
if (!mOutputStream && mFileIO) {
|
|
|
|
nsCOMPtr<nsIOutputStream> output;
|
|
|
|
rv = mFileIO->GetOutputStream(getter_AddRefs(output));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = NS_NewFastLoadFileUpdater(getter_AddRefs(mOutputStream),
|
|
|
|
output,
|
|
|
|
reader);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
|
2001-08-17 23:45:11 +04:00
|
|
|
if (aDirectionFlags == NS_FASTLOAD_READ) {
|
|
|
|
// Tell our caller to re-start multiplexing, rather than attempt
|
|
|
|
// to select and deserialize now.
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Writer or Updater must close after the Reader,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-17 13:52:55 +04:00
|
|
|
}
|
2001-08-17 23:45:11 +04:00
|
|
|
|
|
|
|
if ((aDirectionFlags & NS_FASTLOAD_WRITE) && mOutputStream)
|
|
|
|
rv = GetWriter(mOutputStream)->StartMuxedDocument(aURI, aURISpec);
|
2001-07-31 23:05:34 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFastLoadService::SelectMuxedDocument(nsISupports* aURI)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
|
|
|
|
// Try to select the reader, if any; then only if the URI was not in the
|
|
|
|
// file already, select the writer/updater.
|
|
|
|
if (mInputStream) {
|
2001-08-17 23:45:11 +04:00
|
|
|
rv = GetReader(mInputStream)->SelectMuxedDocument(aURI);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mDirection = NS_FASTLOAD_READ;
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rv == NS_ERROR_NOT_AVAILABLE && mOutputStream) {
|
2001-08-17 23:45:11 +04:00
|
|
|
rv = GetWriter(mOutputStream)->SelectMuxedDocument(aURI);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mDirection = NS_FASTLOAD_WRITE;
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFastLoadService::EndMuxedDocument(nsISupports* aURI)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
|
|
|
|
// Try to end the document identified by aURI in the reader, if any; then
|
|
|
|
// only if the URI was not in the file already, end the writer/updater.
|
2001-08-17 23:45:11 +04:00
|
|
|
if (mInputStream)
|
|
|
|
rv = GetReader(mInputStream)->EndMuxedDocument(aURI);
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2001-08-17 23:45:11 +04:00
|
|
|
if (rv == NS_ERROR_NOT_AVAILABLE && mOutputStream)
|
|
|
|
rv = GetWriter(mOutputStream)->EndMuxedDocument(aURI);
|
2001-07-31 23:05:34 +04:00
|
|
|
|
|
|
|
mDirection = 0;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-08-17 23:45:11 +04:00
|
|
|
nsFastLoadService::AppendDependency(const char* aFileName)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
nsAutoLock lock(mLock);
|
2001-08-17 23:45:11 +04:00
|
|
|
if (!mOutputStream)
|
|
|
|
return NS_OK;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2001-08-17 23:45:11 +04:00
|
|
|
if (!GetWriter(mOutputStream)->AppendDependency(aFileName))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-08-17 23:45:11 +04:00
|
|
|
nsFastLoadService::MaxDependencyModifiedTime(PRTime *aTime)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
*aTime = LL_ZERO;
|
|
|
|
|
|
|
|
nsAutoLock lock(mLock);
|
2001-08-17 23:45:11 +04:00
|
|
|
if (!mOutputStream)
|
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Writer or Updater must close after the Reader,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-17 13:52:55 +04:00
|
|
|
return NS_OK;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2001-08-17 23:45:11 +04:00
|
|
|
nsFastLoadFileWriter* writer = GetWriter(mOutputStream);
|
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Writer or Updater must close after the Reader,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-17 13:52:55 +04:00
|
|
|
|
2001-08-17 23:45:11 +04:00
|
|
|
for (PRUint32 i = 0, n = writer->GetDependencyCount(); i < n; i++) {
|
|
|
|
PRFileInfo info;
|
|
|
|
if (PR_GetFileInfo(writer->GetDependency(i), &info) == PR_SUCCESS &&
|
|
|
|
LL_CMP(*aTime, <, info.modifyTime)) {
|
|
|
|
*aTime = info.modifyTime;
|
|
|
|
}
|
|
|
|
}
|
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Writer or Updater must close after the Reader,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-17 13:52:55 +04:00
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct nsFastLoadPtrEntry : public PLDHashEntryHdr {
|
|
|
|
nsISupports** mPtrAddr; // key, must come first for PL_DHashGetStubOps
|
|
|
|
PRUint32 mOffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFastLoadService::GetFastLoadReferent(nsISupports* *aPtrAddr)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(*aPtrAddr == nsnull,
|
|
|
|
"aPtrAddr doesn't point to null nsFastLoadPtr<T>::mRawAddr?");
|
|
|
|
|
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
if (!mFastLoadPtrMap || !mInputStream)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsFastLoadPtrEntry* entry =
|
|
|
|
NS_STATIC_CAST(nsFastLoadPtrEntry*,
|
|
|
|
PL_DHashTableOperate(mFastLoadPtrMap, aPtrAddr,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
if (PL_DHASH_ENTRY_IS_FREE(entry))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISeekableStream> seekable(do_QueryInterface(mInputStream));
|
|
|
|
|
|
|
|
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, entry->mOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mInputStream->ReadObject(PR_TRUE, aPtrAddr);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Shrink the table if half the entries are removed sentinels.
|
|
|
|
PRUint32 size = PR_BIT(mFastLoadPtrMap->sizeLog2);
|
|
|
|
if (mFastLoadPtrMap->removedCount >= (size >> 2))
|
|
|
|
PL_DHashTableOperate(mFastLoadPtrMap, entry, PL_DHASH_REMOVE);
|
|
|
|
else
|
|
|
|
PL_DHashTableRawRemove(mFastLoadPtrMap, entry);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFastLoadService::ReadFastLoadPtr(nsIObjectInputStream* aInputStream,
|
|
|
|
nsISupports* *aPtrAddr)
|
|
|
|
{
|
|
|
|
// nsFastLoadPtrs self-construct to null, so if we have a non-null value
|
|
|
|
// in our inout parameter, we must have been read already, alright!
|
|
|
|
if (*aPtrAddr)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
PRUint32 nextOffset;
|
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
|
|
|
|
rv = aInputStream->Read32(&nextOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISeekableStream> seekable(do_QueryInterface(aInputStream));
|
|
|
|
if (!seekable)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRUint32 thisOffset;
|
|
|
|
rv = seekable->Tell(&thisOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, nextOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (!mFastLoadPtrMap) {
|
|
|
|
mFastLoadPtrMap = PL_NewDHashTable(PL_DHashGetStubOps(), this,
|
|
|
|
sizeof(nsFastLoadPtrEntry),
|
|
|
|
PL_DHASH_MIN_SIZE);
|
|
|
|
if (!mFastLoadPtrMap)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFastLoadPtrEntry* entry =
|
|
|
|
NS_STATIC_CAST(nsFastLoadPtrEntry*,
|
|
|
|
PL_DHashTableOperate(mFastLoadPtrMap, aPtrAddr,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
NS_ASSERTION(entry->mPtrAddr == nsnull, "duplicate nsFastLoadPtr?!");
|
|
|
|
|
|
|
|
entry->mPtrAddr = aPtrAddr;
|
|
|
|
entry->mOffset = thisOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFastLoadService::WriteFastLoadPtr(nsIObjectOutputStream* aOutputStream,
|
|
|
|
nsISupports* aObject)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aObject != nsnull, "writing an unread nsFastLoadPtr?!");
|
|
|
|
if (!aObject)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsAutoLock lock(mLock); // serialize writes to aOutputStream
|
|
|
|
|
|
|
|
nsCOMPtr<nsISeekableStream> seekable(do_QueryInterface(aOutputStream));
|
|
|
|
if (!seekable)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRUint32 saveOffset;
|
|
|
|
rv = seekable->Tell(&saveOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = aOutputStream->Write32(0); // nextOffset placeholder
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = aOutputStream->WriteObject(aObject, PR_TRUE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PRUint32 nextOffset;
|
|
|
|
rv = seekable->Tell(&nextOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, saveOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = aOutputStream->Write32(nextOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, nextOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|