зеркало из https://github.com/mozilla/pjs.git
Bug 654489 - Remove fastload, r=bsmedberg
This commit is contained in:
Родитель
1826fbc6a9
Коммит
9740ca25a1
|
@ -52,7 +52,6 @@
|
|||
#include "nsIChannel.h"
|
||||
#include "nsIChromeRegistry.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIFastLoadService.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsIFileChannel.h"
|
||||
|
|
|
@ -151,7 +151,6 @@ MOZ_URL_CLASSIFIER = @MOZ_URL_CLASSIFIER@
|
|||
MOZ_ZIPWRITER = @MOZ_ZIPWRITER@
|
||||
MOZ_MORK = @MOZ_MORK@
|
||||
MOZ_MORKREADER = @MOZ_MORKREADER@
|
||||
MOZ_NO_FAST_LOAD = @MOZ_NO_FAST_LOAD@
|
||||
MOZ_OGG = @MOZ_OGG@
|
||||
MOZ_RAW = @MOZ_RAW@
|
||||
MOZ_SYDNEYAUDIO = @MOZ_SYDNEYAUDIO@
|
||||
|
|
16
configure.in
16
configure.in
|
@ -4768,7 +4768,6 @@ MOZ_MORK=
|
|||
MOZ_MORKREADER=1
|
||||
MOZ_AUTH_EXTENSION=1
|
||||
MOZ_NO_ACTIVEX_SUPPORT=1
|
||||
MOZ_NO_FAST_LOAD=
|
||||
MOZ_OGG=1
|
||||
MOZ_RAW=
|
||||
MOZ_SYDNEYAUDIO=
|
||||
|
@ -5723,21 +5722,6 @@ if test "$NS_PRINTING"; then
|
|||
AC_DEFINE(NS_PRINT_PREVIEW)
|
||||
fi
|
||||
|
||||
dnl ========================================================
|
||||
dnl = Disable Fast Load
|
||||
dnl ========================================================
|
||||
MOZ_ARG_DISABLE_BOOL(xpcom-fastload,
|
||||
[ --disable-xpcom-fastload
|
||||
Disable XPCOM fastload support],
|
||||
MOZ_NO_FAST_LOAD=1,
|
||||
MOZ_NO_FAST_LOAD=)
|
||||
|
||||
AC_SUBST(MOZ_NO_FAST_LOAD)
|
||||
|
||||
if test -n "$MOZ_NO_FAST_LOAD"; then
|
||||
AC_DEFINE(MOZ_NO_FAST_LOAD)
|
||||
fi
|
||||
|
||||
dnl ========================================================
|
||||
dnl = Enable Raw Codecs
|
||||
dnl ========================================================
|
||||
|
|
|
@ -50,8 +50,6 @@
|
|||
#include "nsIURI.h"
|
||||
|
||||
#include "nsIChromeRegistry.h"
|
||||
#include "nsIFastLoadService.h"
|
||||
#include "nsIFastLoadFileControl.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIObjectInputStream.h"
|
||||
#include "nsIObjectOutputStream.h"
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
#include "nsIXPConnect.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIFastLoadService.h"
|
||||
#include "nsIObjectInputStream.h"
|
||||
#include "nsIObjectOutputStream.h"
|
||||
#include "nsITimer.h"
|
||||
|
@ -68,28 +67,6 @@ using namespace mozilla::scache;
|
|||
{ 0xbb, 0xef, 0xf0, 0xcc, 0xb5, 0xfa, 0x64, 0xb6 }}
|
||||
#define MOZJSCOMPONENTLOADER_CONTRACTID "@mozilla.org/moz/jsloader;1"
|
||||
|
||||
// nsIFastLoadFileIO implementation for component fastload
|
||||
class nsXPCFastLoadIO : public nsIFastLoadFileIO
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIFASTLOADFILEIO
|
||||
|
||||
nsXPCFastLoadIO(nsIFile *file) : mFile(file), mTruncateOutputFile(true) {}
|
||||
|
||||
void SetInputStream(nsIInputStream *stream) { mInputStream = stream; }
|
||||
void SetOutputStream(nsIOutputStream *stream) { mOutputStream = stream; }
|
||||
|
||||
private:
|
||||
~nsXPCFastLoadIO() {}
|
||||
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
nsCOMPtr<nsIOutputStream> mOutputStream;
|
||||
bool mTruncateOutputFile;
|
||||
};
|
||||
|
||||
|
||||
class mozJSComponentLoader : public mozilla::ModuleLoader,
|
||||
public xpcIJSModuleLoader,
|
||||
public nsIObserver
|
||||
|
|
|
@ -93,7 +93,6 @@ using mozilla::dom::ContentParent;
|
|||
#include "nsIContentHandler.h"
|
||||
#include "nsIDialogParamBlock.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIFastLoadService.h" // for PLATFORM_FASL_SUFFIX
|
||||
#include "mozilla/ModuleUtils.h"
|
||||
#include "nsIIOService2.h"
|
||||
#include "nsIObserverService.h"
|
||||
|
@ -2289,6 +2288,12 @@ static void RemoveComponentRegistries(nsIFile* aProfileDir, nsIFile* aLocalProfi
|
|||
if (!file)
|
||||
return;
|
||||
|
||||
#if defined(XP_UNIX) || defined(XP_BEOS)
|
||||
#define PLATFORM_FASL_SUFFIX ".mfasl"
|
||||
#elif defined(XP_WIN) || defined(XP_OS2)
|
||||
#define PLATFORM_FASL_SUFFIX ".mfl"
|
||||
#endif
|
||||
|
||||
file->AppendNative(NS_LITERAL_CSTRING("XUL" PLATFORM_FASL_SUFFIX));
|
||||
file->Remove(PR_FALSE);
|
||||
|
||||
|
|
|
@ -74,8 +74,6 @@
|
|||
#include "nsIException.h"
|
||||
#include "nsIExceptionService.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIFastLoadFileControl.h"
|
||||
#include "nsIFastLoadService.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIHashable.h"
|
||||
#include "nsIINIParser.h"
|
||||
|
|
|
@ -64,10 +64,6 @@
|
|||
COMPONENT(STRINGINPUTSTREAM, nsStringInputStreamConstructor)
|
||||
COMPONENT(MULTIPLEXINPUTSTREAM, nsMultiplexInputStreamConstructor)
|
||||
|
||||
#ifndef MOZ_NO_FAST_LOAD
|
||||
COMPONENT(FASTLOADSERVICE, nsFastLoadService::Create)
|
||||
#endif
|
||||
|
||||
COMPONENT(VARIANT, nsVariantConstructor)
|
||||
COMPONENT(INTERFACEINFOMANAGER_SERVICE, nsXPTIInterfaceInfoManagerGetSingleton)
|
||||
|
||||
|
|
|
@ -107,8 +107,6 @@
|
|||
#include "nsStringStream.h"
|
||||
extern nsresult nsStringInputStreamConstructor(nsISupports *, REFNSIID, void **);
|
||||
|
||||
#include "nsFastLoadService.h"
|
||||
|
||||
#include "nsAtomService.h"
|
||||
#include "nsAtomTable.h"
|
||||
#include "nsTraceRefcnt.h"
|
||||
|
|
|
@ -85,13 +85,6 @@ CMMSRCS += \
|
|||
$(NULL)
|
||||
endif
|
||||
|
||||
ifndef MOZ_NO_FAST_LOAD
|
||||
CPPSRCS += \
|
||||
nsFastLoadFile.cpp \
|
||||
nsFastLoadService.cpp \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
CPPSRCS += nsLocalFileOS2.cpp
|
||||
else
|
||||
|
@ -107,7 +100,6 @@ EXPORTS = \
|
|||
nsDirectoryService.h \
|
||||
nsDirectoryServiceAtomList.h \
|
||||
nsEscape.h \
|
||||
nsFastLoadService.h \
|
||||
nsLinebreakConverter.h \
|
||||
nsLocalFile.h \
|
||||
nsMultiplexInputStream.h \
|
||||
|
@ -138,8 +130,6 @@ XPIDLSRCS = \
|
|||
nsIBinaryInputStream.idl \
|
||||
nsIBinaryOutputStream.idl \
|
||||
nsIDirectoryEnumerator.idl \
|
||||
nsIFastLoadFileControl.idl \
|
||||
nsIFastLoadService.idl \
|
||||
nsIInputStreamTee.idl \
|
||||
nsILocalFileWin.idl \
|
||||
nsILineInputStream.idl \
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,582 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla 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/MPL/
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brendan Eich <brendan@mozilla.org> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsFastLoadFile_h___
|
||||
#define nsFastLoadFile_h___
|
||||
|
||||
/**
|
||||
* Mozilla FastLoad file format and helper types.
|
||||
*/
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "pldhash.h"
|
||||
#include "nsAlgorithm.h"
|
||||
|
||||
#include "nsBinaryStream.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsID.h"
|
||||
#include "nsMemory.h"
|
||||
|
||||
#include "nsIFastLoadFileControl.h"
|
||||
#include "nsIFastLoadService.h"
|
||||
#include "nsISeekableStream.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
/**
|
||||
* FastLoad file Object ID (OID) is an identifier for multiply and cyclicly
|
||||
* connected objects in the serialized graph of all reachable objects.
|
||||
*
|
||||
* Holy Mixed Metaphors: JS, after Common Lisp, uses #n= to define a "sharp
|
||||
* variable" naming an object that's multiply or cyclicly connected, and #n#
|
||||
* to stand for a connection to an already-defined object. We too call any
|
||||
* object with multiple references "sharp", and (here it comes) any object
|
||||
* with only one reference "dull".
|
||||
*
|
||||
* Note that only sharp objects require a mapping from OID to FastLoad file
|
||||
* offset and other information. Dull objects can be serialized _in situ_
|
||||
* (where they are referenced) and deserialized when their (singular, shared)
|
||||
* OID is scanned.
|
||||
*
|
||||
* We also compress 16-byte XPCOM IDs into 32-bit dense identifiers to save
|
||||
* space. See nsFastLoadFooter, below, for the mapping data structure used to
|
||||
* compute an nsID given an NSFastLoadID.
|
||||
*/
|
||||
typedef PRUint32 NSFastLoadID; // nsFastLoadFooter::mIDMap index
|
||||
typedef PRUint32 NSFastLoadOID; // nsFastLoadFooter::mObjectMap index
|
||||
|
||||
/**
|
||||
* A Mozilla FastLoad file is an untagged (in general) stream of objects and
|
||||
* primitive-type data. Small integers are fairly common, and could easily be
|
||||
* confused for NSFastLoadIDs and NSFastLoadOIDs. To help catch bugs where
|
||||
* reader and writer code fail to match, we XOR unlikely 32-bit numbers with
|
||||
* NSFastLoad*IDs when storing and fetching. The following unlikely values are
|
||||
* irrational numbers ((sqrt(5)-1)/2, sqrt(2)-1) represented in fixed point.
|
||||
*
|
||||
* The reader XORs, converts the ID to an index, and bounds-checks all array
|
||||
* accesses that use the index. Array access code asserts that the index is in
|
||||
* bounds, and returns a dummy array element if it isn't.
|
||||
*/
|
||||
#define MFL_ID_XOR_KEY 0x9E3779B9 // key XOR'd with ID when serialized
|
||||
#define MFL_OID_XOR_KEY 0x6A09E667 // key XOR'd with OID when serialized
|
||||
|
||||
/**
|
||||
* An OID can be tagged to introduce the serialized definition of the object,
|
||||
* or to stand for a strong or weak reference to that object. Thus the high
|
||||
* 29 bits actually identify the object, and the low three bits tell whether
|
||||
* the object is being defined or just referenced -- and via what inheritance
|
||||
* chain or inner object, if necessary.
|
||||
*
|
||||
* The MFL_QUERY_INTERFACE_TAG bit helps us cope with aggregation and multiple
|
||||
* inheritance: object identity follows the XPCOM rule, but a deserializer may
|
||||
* need to query for an interface not on the primary inheritance chain ending
|
||||
* in the nsISupports whose address uniquely identifies the XPCOM object being
|
||||
* referenced or defined.
|
||||
*/
|
||||
#define MFL_OBJECT_TAG_BITS 3
|
||||
#define MFL_OBJECT_TAG_MASK PR_BITMASK(MFL_OBJECT_TAG_BITS)
|
||||
|
||||
#define MFL_OBJECT_DEF_TAG 1U // object definition follows this OID
|
||||
#define MFL_WEAK_REF_TAG 2U // OID weakly refers to a prior object
|
||||
// NB: do not confuse with nsWeakPtr!
|
||||
#define MFL_QUERY_INTERFACE_TAG 4U // QI object to the ID follows this OID
|
||||
// NB: an NSFastLoadID, not an nsIID!
|
||||
|
||||
/**
|
||||
* The dull object identifier introduces the definition of all objects that
|
||||
* have only one (necessarily strong) ref in the serialization. The definition
|
||||
* appears at the point of reference.
|
||||
*/
|
||||
#define MFL_DULL_OBJECT_OID MFL_OBJECT_DEF_TAG
|
||||
|
||||
/**
|
||||
* Convert an OID to an index into nsFastLoadFooter::mObjectMap.
|
||||
*/
|
||||
#define MFL_OID_TO_SHARP_INDEX(oid) (((oid) >> MFL_OBJECT_TAG_BITS) - 1)
|
||||
#define MFL_SHARP_INDEX_TO_OID(index) (((index) + 1) << MFL_OBJECT_TAG_BITS)
|
||||
|
||||
/**
|
||||
* Magic "number" at start of a FastLoad file. Inspired by the PNG "magic"
|
||||
* string, which inspired XPCOM's typelib (.xpt) file magic. Guaranteed to be
|
||||
* corrupted by FTP-as-ASCII and other likely errors, meaningful to clued-in
|
||||
* humans, and ending in ^Z to terminate erroneous text input on Windows.
|
||||
*/
|
||||
#define MFL_FILE_MAGIC "XPCOM\nMozFASL\r\n\032"
|
||||
#define MFL_FILE_MAGIC_SIZE 16
|
||||
|
||||
#define MFL_FILE_VERSION_0 0
|
||||
#define MFL_FILE_VERSION_1 1000
|
||||
#define MFL_FILE_VERSION 5 // rev'ed to defend against unversioned
|
||||
// XPCOM JS component fastload files
|
||||
|
||||
/**
|
||||
* Compute Fletcher's 16-bit checksum over aLength bytes starting at aBuffer,
|
||||
* with the initial accumulators seeded from *aChecksum, and final checksum
|
||||
* returned in *aChecksum. The return value is the number of unchecked bytes,
|
||||
* which may be non-zero if aBuffer is misaligned or aLength is odd. Callers
|
||||
* should copy any remaining bytes to the front of the next buffer.
|
||||
*
|
||||
* If aLastBuffer is false, do not check any bytes remaining due to misaligned
|
||||
* aBuffer or odd aLength, instead returning the remaining byte count. But if
|
||||
* aLastBuffer is true, treat aBuffer as the last buffer in the file and check
|
||||
* every byte, returning 0. Here's a read-loop checksumming sketch:
|
||||
*
|
||||
* char buf[BUFSIZE];
|
||||
* PRUint32 len, rem = 0;
|
||||
* PRUint32 checksum = 0;
|
||||
*
|
||||
* while (NS_SUCCEEDED(rv = Read(buf + rem, sizeof buf - rem, &len)) && len) {
|
||||
* len += rem;
|
||||
* rem = NS_AccumulateFastLoadChecksum(&checksum,
|
||||
* reinterpret_cast<PRUint8*>(buf),
|
||||
* len,
|
||||
* PR_FALSE);
|
||||
* if (rem)
|
||||
* memcpy(buf, buf + len - rem, rem);
|
||||
* }
|
||||
*
|
||||
* if (rem) {
|
||||
* NS_AccumulateFastLoadChecksum(&checksum,
|
||||
* reinterpret_cast<PRUint8*>(buf),
|
||||
* rem,
|
||||
* PR_TRUE);
|
||||
* }
|
||||
*
|
||||
* After this, if NS_SUCCEEDED(rv), checksum contains a valid FastLoad sum.
|
||||
*/
|
||||
NS_COM PRUint32
|
||||
NS_AccumulateFastLoadChecksum(PRUint32 *aChecksum,
|
||||
const PRUint8* aBuffer,
|
||||
PRUint32 aLength,
|
||||
PRBool aLastBuffer);
|
||||
|
||||
NS_COM PRUint32
|
||||
NS_AddFastLoadChecksums(PRUint32 sum1, PRUint32 sum2, PRUint32 sum2ByteCount);
|
||||
|
||||
/**
|
||||
* Header at the start of a FastLoad file.
|
||||
*/
|
||||
struct nsFastLoadHeader {
|
||||
char mMagic[MFL_FILE_MAGIC_SIZE];
|
||||
PRUint32 mChecksum;
|
||||
PRUint32 mVersion;
|
||||
PRUint32 mFooterOffset;
|
||||
PRUint32 mFileSize;
|
||||
};
|
||||
|
||||
/**
|
||||
* Footer prefix structure (footer header, ugh), after which come arrays of
|
||||
* structures or strings counted by these members.
|
||||
*/
|
||||
struct nsFastLoadFooterPrefix {
|
||||
PRUint32 mNumIDs;
|
||||
PRUint32 mNumSharpObjects;
|
||||
PRUint32 mNumMuxedDocuments;
|
||||
PRUint32 mNumDependencies;
|
||||
};
|
||||
|
||||
struct nsFastLoadSharpObjectInfo {
|
||||
PRUint32 mCIDOffset; // offset of object's NSFastLoadID and data
|
||||
PRUint16 mStrongRefCnt;
|
||||
PRUint16 mWeakRefCnt; // high bit is singleton flag, see below
|
||||
};
|
||||
|
||||
#define MFL_SINGLETON_FLAG 0x8000
|
||||
#define MFL_WEAK_REFCNT_MASK 0x7fff
|
||||
|
||||
#define MFL_GET_SINGLETON_FLAG(ip) ((ip)->mWeakRefCnt & MFL_SINGLETON_FLAG)
|
||||
#define MFL_GET_WEAK_REFCNT(ip) ((ip)->mWeakRefCnt & MFL_WEAK_REFCNT_MASK)
|
||||
|
||||
#define MFL_SET_SINGLETON_FLAG(ip) \
|
||||
((ip)->mWeakRefCnt |= MFL_SINGLETON_FLAG)
|
||||
#define MFL_SET_WEAK_REFCNT(ip,rc) \
|
||||
((ip)->mWeakRefCnt = (((ip)->mWeakRefCnt & MFL_SINGLETON_FLAG) | (rc)))
|
||||
|
||||
#define MFL_BUMP_WEAK_REFCNT(ip) (++(ip)->mWeakRefCnt)
|
||||
#define MFL_DROP_WEAK_REFCNT(ip) (--(ip)->mWeakRefCnt)
|
||||
|
||||
struct nsFastLoadMuxedDocumentInfo {
|
||||
const char* mURISpec;
|
||||
PRUint32 mInitialSegmentOffset;
|
||||
};
|
||||
|
||||
// forward declarations of opaque types defined in nsFastLoadFile.cpp
|
||||
struct nsDocumentMapReadEntry;
|
||||
struct nsDocumentMapWriteEntry;
|
||||
|
||||
// So nsFastLoadFileUpdater can verify that its nsIObjectInputStream parameter
|
||||
// is an nsFastLoadFileReader.
|
||||
#define NS_FASTLOADFILEREADER_IID \
|
||||
{0x7d37d1bb,0xcef3,0x4c5f,{0x97,0x68,0x0f,0x89,0x7f,0x1a,0xe1,0x40}}
|
||||
|
||||
struct nsIFastLoadFileReader : public nsISupports {
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_FASTLOADFILEREADER_IID)
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsIFastLoadFileReader, NS_FASTLOADFILEREADER_IID)
|
||||
|
||||
/**
|
||||
* Inherit from the concrete class nsBinaryInputStream, which inherits from
|
||||
* abstract nsIObjectInputStream but does not implement its direct methods.
|
||||
* Though the names are not as clear as I'd like, this seems to be the best
|
||||
* way to share nsBinaryStream.cpp code.
|
||||
*/
|
||||
class nsFastLoadFileReader
|
||||
: public nsBinaryInputStream,
|
||||
public nsIFastLoadReadControl,
|
||||
public nsISeekableStream,
|
||||
public nsIFastLoadFileReader
|
||||
{
|
||||
public:
|
||||
nsFastLoadFileReader(nsIFile *aFile)
|
||||
: mCurrentDocumentMapEntry(nsnull), mFile(aFile),
|
||||
mFileLen(0), mFilePos(0), mFileMap(nsnull), mFileData(nsnull)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsFastLoadFileReader);
|
||||
}
|
||||
|
||||
virtual ~nsFastLoadFileReader() {
|
||||
Close();
|
||||
MOZ_COUNT_DTOR(nsFastLoadFileReader);
|
||||
}
|
||||
|
||||
private:
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// overridden nsIObjectInputStream methods
|
||||
NS_IMETHOD ReadObject(PRBool aIsStrongRef, nsISupports* *_retval);
|
||||
NS_IMETHOD ReadID(nsID *aResult);
|
||||
|
||||
void SeekTo(PRInt64 aOffset) {
|
||||
mFilePos = NS_MAX<PRInt64>(0, NS_MIN<PRInt64>(aOffset, mFileLen));
|
||||
NS_ASSERTION(aOffset == mFilePos, "Attempt to seek out of bounds");
|
||||
}
|
||||
|
||||
// nsIFastLoadFileControl methods
|
||||
NS_DECL_NSIFASTLOADFILECONTROL
|
||||
|
||||
// nsIFastLoadReadControl methods
|
||||
NS_DECL_NSIFASTLOADREADCONTROL
|
||||
|
||||
// nsISeekableStream methods
|
||||
NS_DECL_NSISEEKABLESTREAM
|
||||
|
||||
// Override Read so we can demultiplex a document interleaved with others.
|
||||
NS_IMETHOD Read(char* aBuffer, PRUint32 aCount, PRUint32 *aBytesRead);
|
||||
nsresult ReadHeader(nsFastLoadHeader *aHeader);
|
||||
|
||||
/**
|
||||
* In-memory representation of an indexed nsFastLoadSharpObjectInfo record.
|
||||
*/
|
||||
struct nsObjectMapEntry : public nsFastLoadSharpObjectInfo {
|
||||
nsCOMPtr<nsISupports> mReadObject;
|
||||
PRInt64 mSkipOffset;
|
||||
PRUint16 mSaveStrongRefCnt; // saved for an Update
|
||||
PRUint16 mSaveWeakRefCnt; // after a Read
|
||||
};
|
||||
|
||||
NS_IMETHODIMP ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
|
||||
PRUint32 aCount, PRUint32 *aResult);
|
||||
|
||||
/**
|
||||
* In-memory representation of the FastLoad file footer.
|
||||
*/
|
||||
struct nsFastLoadFooter : public nsFastLoadFooterPrefix {
|
||||
nsFastLoadFooter()
|
||||
: mIDMap(nsnull),
|
||||
mObjectMap(nsnull) {
|
||||
mDocumentMap.ops = mURIMap.ops = nsnull;
|
||||
}
|
||||
|
||||
~nsFastLoadFooter() {
|
||||
delete[] mIDMap;
|
||||
delete[] mObjectMap;
|
||||
if (mDocumentMap.ops)
|
||||
PL_DHashTableFinish(&mDocumentMap);
|
||||
if (mURIMap.ops)
|
||||
PL_DHashTableFinish(&mURIMap);
|
||||
}
|
||||
|
||||
// These can't be static within GetID and GetSharpObjectEntry or the
|
||||
// toolchains on HP-UX 10.20's, RH 7.0, and Mac OS X all barf at link
|
||||
// time ("common symbols not allowed with MY_DHLIB output format", to
|
||||
// quote the OS X rev of gcc).
|
||||
static nsID gDummyID;
|
||||
static nsObjectMapEntry gDummySharpObjectEntry;
|
||||
|
||||
const nsID& GetID(NSFastLoadID aFastId) const {
|
||||
PRUint32 index = aFastId - 1;
|
||||
NS_ASSERTION(index < mNumIDs, "aFastId out of range");
|
||||
if (index >= mNumIDs)
|
||||
return gDummyID;
|
||||
return mIDMap[index];
|
||||
}
|
||||
|
||||
nsObjectMapEntry&
|
||||
GetSharpObjectEntry(NSFastLoadOID aOID) const {
|
||||
PRUint32 index = MFL_OID_TO_SHARP_INDEX(aOID);
|
||||
NS_ASSERTION(index < mNumSharpObjects, "aOID out of range");
|
||||
if (index >= mNumSharpObjects)
|
||||
return gDummySharpObjectEntry;
|
||||
return mObjectMap[index];
|
||||
}
|
||||
|
||||
// Map from dense, zero-based, uint32 NSFastLoadID to 16-byte nsID.
|
||||
nsID* mIDMap;
|
||||
|
||||
// Map from dense, zero-based MFL_OID_TO_SHARP_INDEX(oid) to sharp
|
||||
// object offset and refcnt information.
|
||||
nsObjectMapEntry* mObjectMap;
|
||||
|
||||
// Map from URI spec string to nsDocumentMapReadEntry, which helps us
|
||||
// demultiplex a document's objects from among the interleaved object
|
||||
// stream segments in the FastLoad file.
|
||||
PLDHashTable mDocumentMap;
|
||||
|
||||
// Fast mapping from URI object pointer to mDocumentMap entry, valid
|
||||
// only while the muxed document is loading.
|
||||
PLDHashTable mURIMap;
|
||||
|
||||
// List of source filename dependencies that should trigger regeneration
|
||||
// of the FastLoad file.
|
||||
nsCOMPtr<nsISupportsArray> mDependencies;
|
||||
};
|
||||
|
||||
nsresult ReadFooter(nsFastLoadFooter *aFooter);
|
||||
nsresult ReadFooterPrefix(nsFastLoadFooterPrefix *aFooterPrefix);
|
||||
nsresult ReadSlowID(nsID *aID);
|
||||
nsresult ReadFastID(NSFastLoadID *aID);
|
||||
nsresult ReadSharpObjectInfo(nsFastLoadSharpObjectInfo *aInfo);
|
||||
nsresult ReadMuxedDocumentInfo(nsFastLoadMuxedDocumentInfo *aInfo);
|
||||
nsresult DeserializeObject(nsISupports* *aObject);
|
||||
|
||||
nsresult Open();
|
||||
NS_IMETHOD Close();
|
||||
|
||||
protected:
|
||||
nsFastLoadHeader mHeader;
|
||||
nsFastLoadFooter mFooter;
|
||||
|
||||
nsDocumentMapReadEntry* mCurrentDocumentMapEntry;
|
||||
|
||||
friend class nsFastLoadFileUpdater;
|
||||
nsIFile *mFile; // .mfasl file
|
||||
PRUint32 mFileLen; // length of file
|
||||
PRUint32 mFilePos; // current position within file
|
||||
PRFileMap *mFileMap;// nspr datastructure for mmap
|
||||
PRUint8 *mFileData; // pointer to mmaped file
|
||||
};
|
||||
|
||||
NS_COM nsresult
|
||||
NS_NewFastLoadFileReader(nsIObjectInputStream* *aResult NS_OUTPARAM,
|
||||
nsIFile* aFile);
|
||||
|
||||
/**
|
||||
* Inherit from the concrete class nsBinaryInputStream, which inherits from
|
||||
* abstract nsIObjectInputStream but does not implement its direct methods.
|
||||
* Though the names are not as clear as I'd like, this seems to be the best
|
||||
* way to share nsBinaryStream.cpp code.
|
||||
*/
|
||||
class nsFastLoadFileWriter
|
||||
: public nsBinaryOutputStream,
|
||||
public nsIFastLoadWriteControl,
|
||||
public nsISeekableStream
|
||||
{
|
||||
public:
|
||||
nsFastLoadFileWriter(nsIOutputStream *aStream, nsIFastLoadFileIO* aFileIO)
|
||||
: mCurrentDocumentMapEntry(nsnull),
|
||||
mFileIO(aFileIO)
|
||||
{
|
||||
SetOutputStream(aStream);
|
||||
mHeader.mChecksum = 0;
|
||||
mIDMap.ops = mObjectMap.ops = mDocumentMap.ops = mURIMap.ops = nsnull;
|
||||
mDependencyMap.ops = nsnull;
|
||||
MOZ_COUNT_CTOR(nsFastLoadFileWriter);
|
||||
}
|
||||
|
||||
virtual ~nsFastLoadFileWriter()
|
||||
{
|
||||
if (mIDMap.ops)
|
||||
PL_DHashTableFinish(&mIDMap);
|
||||
if (mObjectMap.ops)
|
||||
PL_DHashTableFinish(&mObjectMap);
|
||||
if (mDocumentMap.ops)
|
||||
PL_DHashTableFinish(&mDocumentMap);
|
||||
if (mURIMap.ops)
|
||||
PL_DHashTableFinish(&mURIMap);
|
||||
if (mDependencyMap.ops)
|
||||
PL_DHashTableFinish(&mDependencyMap);
|
||||
MOZ_COUNT_DTOR(nsFastLoadFileWriter);
|
||||
}
|
||||
|
||||
private:
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// overridden nsIObjectOutputStream methods
|
||||
NS_IMETHOD WriteObject(nsISupports* aObject, PRBool aIsStrongRef);
|
||||
NS_IMETHOD WriteSingleRefObject(nsISupports* aObject);
|
||||
NS_IMETHOD WriteCompoundObject(nsISupports* aObject,
|
||||
const nsIID& aIID,
|
||||
PRBool aIsStrongRef);
|
||||
NS_IMETHOD WriteID(const nsID& aID);
|
||||
|
||||
// Override SetOutputStream so we can update mSeekableOutput
|
||||
NS_IMETHOD SetOutputStream(nsIOutputStream* aOutputStream);
|
||||
|
||||
// nsIFastLoadFileControl methods
|
||||
NS_DECL_NSIFASTLOADFILECONTROL
|
||||
|
||||
// nsIFastLoadWriteControl methods
|
||||
NS_DECL_NSIFASTLOADWRITECONTROL
|
||||
|
||||
// nsISeekableStream methods
|
||||
NS_DECL_NSISEEKABLESTREAM
|
||||
|
||||
nsresult MapID(const nsID& aSlowID, NSFastLoadID *aResult);
|
||||
|
||||
nsresult WriteHeader(nsFastLoadHeader *aHeader);
|
||||
nsresult WriteFooter();
|
||||
nsresult WriteFooterPrefix(const nsFastLoadFooterPrefix& aFooterPrefix);
|
||||
nsresult WriteSlowID(const nsID& aID);
|
||||
nsresult WriteFastID(NSFastLoadID aID);
|
||||
nsresult WriteSharpObjectInfo(const nsFastLoadSharpObjectInfo& aInfo);
|
||||
nsresult WriteMuxedDocumentInfo(const nsFastLoadMuxedDocumentInfo& aInfo);
|
||||
|
||||
nsresult Init();
|
||||
nsresult Open();
|
||||
NS_IMETHOD Close();
|
||||
|
||||
nsresult WriteObjectCommon(nsISupports* aObject,
|
||||
PRBool aIsStrongRef,
|
||||
PRUint32 aQITag);
|
||||
|
||||
static PLDHashOperator
|
||||
IDMapEnumerate(PLDHashTable *aTable,
|
||||
PLDHashEntryHdr *aHdr,
|
||||
PRUint32 aNumber,
|
||||
void *aData);
|
||||
|
||||
static PLDHashOperator
|
||||
ObjectMapEnumerate(PLDHashTable *aTable,
|
||||
PLDHashEntryHdr *aHdr,
|
||||
PRUint32 aNumber,
|
||||
void *aData);
|
||||
|
||||
static PLDHashOperator
|
||||
DocumentMapEnumerate(PLDHashTable *aTable,
|
||||
PLDHashEntryHdr *aHdr,
|
||||
PRUint32 aNumber,
|
||||
void *aData);
|
||||
|
||||
static PLDHashOperator
|
||||
DependencyMapEnumerate(PLDHashTable *aTable,
|
||||
PLDHashEntryHdr *aHdr,
|
||||
PRUint32 aNumber,
|
||||
void *aData);
|
||||
|
||||
protected:
|
||||
// Kept in sync with mOutputStream to avoid repeated QI
|
||||
nsCOMPtr<nsISeekableStream> mSeekableOutput;
|
||||
|
||||
nsFastLoadHeader mHeader;
|
||||
|
||||
PLDHashTable mIDMap;
|
||||
PLDHashTable mObjectMap;
|
||||
PLDHashTable mDocumentMap;
|
||||
PLDHashTable mURIMap;
|
||||
PLDHashTable mDependencyMap;
|
||||
|
||||
nsDocumentMapWriteEntry* mCurrentDocumentMapEntry;
|
||||
nsCOMPtr<nsIFastLoadFileIO> mFileIO;
|
||||
};
|
||||
|
||||
NS_COM nsresult
|
||||
NS_NewFastLoadFileWriter(nsIObjectOutputStream* *aResult NS_OUTPARAM,
|
||||
nsIOutputStream* aDestStream,
|
||||
nsIFastLoadFileIO* aFileIO);
|
||||
|
||||
/**
|
||||
* Subclass of nsFastLoadFileWriter, friend of nsFastLoadFileReader which it
|
||||
* wraps when a FastLoad file needs to be updated. The wrapped reader can be
|
||||
* used to demulitplex data for documents already in the FastLoad file, while
|
||||
* the updater writes new data over the old footer, then writes a new footer
|
||||
* that maps all data on Close.
|
||||
*/
|
||||
class nsFastLoadFileUpdater
|
||||
: public nsFastLoadFileWriter
|
||||
{
|
||||
public:
|
||||
nsFastLoadFileUpdater(nsIOutputStream* aOutputStream, nsIFastLoadFileIO *aFileIO)
|
||||
: nsFastLoadFileWriter(aOutputStream, aFileIO) {
|
||||
MOZ_COUNT_CTOR(nsFastLoadFileUpdater);
|
||||
}
|
||||
|
||||
virtual ~nsFastLoadFileUpdater() {
|
||||
MOZ_COUNT_DTOR(nsFastLoadFileUpdater);
|
||||
}
|
||||
|
||||
private:
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
nsresult Open(nsFastLoadFileReader* aReader);
|
||||
NS_IMETHOD Close();
|
||||
|
||||
static PLDHashOperator
|
||||
CopyReadDocumentMapEntryToUpdater(PLDHashTable *aTable,
|
||||
PLDHashEntryHdr *aHdr,
|
||||
PRUint32 aNumber,
|
||||
void *aData);
|
||||
|
||||
friend class nsFastLoadFileReader;
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
|
||||
// Kept in sync with mInputStream to avoid repeated QI
|
||||
nsCOMPtr<nsISeekableStream> mSeekableInput;
|
||||
};
|
||||
|
||||
NS_COM nsresult
|
||||
NS_NewFastLoadFileUpdater(nsIObjectOutputStream* *aResult NS_OUTPARAM,
|
||||
nsIFastLoadFileIO* aFileIO,
|
||||
nsIObjectInputStream* aReaderAsStream);
|
||||
|
||||
#endif // nsFastLoadFile_h___
|
|
@ -1,558 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla 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/MPL/
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brendan Eich <brendan@mozilla.org> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prio.h"
|
||||
#include "prtime.h"
|
||||
#include "pldhash.h"
|
||||
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsFastLoadFile.h"
|
||||
#include "nsFastLoadService.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsIFastLoadFileControl.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIObjectInputStream.h"
|
||||
#include "nsIObjectOutputStream.h"
|
||||
#include "nsISeekableStream.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsFastLoadService, nsIFastLoadService)
|
||||
|
||||
nsFastLoadService::nsFastLoadService()
|
||||
: mLock("nsFastLoadService.mLock"),
|
||||
mFastLoadPtrMap(nsnull),
|
||||
mDirection(0)
|
||||
{
|
||||
}
|
||||
|
||||
nsFastLoadService::~nsFastLoadService()
|
||||
{
|
||||
if (mInputStream)
|
||||
mInputStream->Close();
|
||||
if (mOutputStream)
|
||||
mOutputStream->Close();
|
||||
|
||||
if (mFastLoadPtrMap)
|
||||
PL_DHashTableDestroy(mFastLoadPtrMap);
|
||||
}
|
||||
|
||||
nsresult
|
||||
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;
|
||||
|
||||
NS_ADDREF(fastLoadService);
|
||||
nsresult rv = fastLoadService->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(fastLoadService);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFastLoadService::NewFastLoadFile(const char* aBaseName, nsIFile* *aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Try "ProfDS" first, so that we can get the profile directory
|
||||
// during startup.
|
||||
nsCOMPtr<nsIFile> profFile;
|
||||
rv = NS_GetSpecialDirectory("ProfDS",
|
||||
getter_AddRefs(profFile));
|
||||
if (NS_FAILED(rv)) {
|
||||
// The directory service doesn't know about "ProfDS", so just ask
|
||||
// for the regular profile directory key. Note, however, that this
|
||||
// will fail if a profile hasn't yet been selected.
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
|
||||
getter_AddRefs(profFile));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// Try "ProfLDS" first, so that we can get the local profile directory
|
||||
// during startup.
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) {
|
||||
// The directory service doesn't know about "ProfLDS", so just ask
|
||||
// for the regular local profile directory key. Note, however, that
|
||||
// this will fail if a profile hasn't yet been selected.
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_LOCAL_50_DIR,
|
||||
getter_AddRefs(file));
|
||||
}
|
||||
if (NS_FAILED(rv))
|
||||
file = profFile;
|
||||
|
||||
PRBool sameDir;
|
||||
rv = file->Equals(profFile, &sameDir);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCAutoString name(aBaseName);
|
||||
name += PLATFORM_FASL_SUFFIX;
|
||||
rv = file->AppendNative(name);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (!sameDir) {
|
||||
// Cleanup any pre-existing fastload files that may live in the profile
|
||||
// directory from previous versions of the code that didn't store them
|
||||
// in the profile temp directory.
|
||||
rv = profFile->AppendNative(name);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
profFile->Remove(PR_FALSE); // OK if this fails
|
||||
}
|
||||
|
||||
*aResult = file;
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::NewInputStream(nsIFile *aFile, nsIObjectInputStream* *aResult)
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
nsCOMPtr<nsIObjectInputStream> stream;
|
||||
nsresult rv = NS_NewFastLoadFileReader(getter_AddRefs(stream), aFile);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
mFileIO->DisableTruncate();
|
||||
*aResult = stream;
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::NewOutputStream(nsIOutputStream* aDestStream,
|
||||
nsIObjectOutputStream* *aResult)
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
return NS_NewFastLoadFileWriter(aResult, aDestStream, mFileIO);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::GetInputStream(nsIObjectInputStream* *aResult)
|
||||
{
|
||||
NS_IF_ADDREF(*aResult = mInputStream);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::SetInputStream(nsIObjectInputStream* aStream)
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
mInputStream = aStream;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::GetOutputStream(nsIObjectOutputStream* *aResult)
|
||||
{
|
||||
NS_IF_ADDREF(*aResult = mOutputStream);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::SetOutputStream(nsIObjectOutputStream* aStream)
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
mOutputStream = aStream;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::GetFileIO(nsIFastLoadFileIO* *aResult)
|
||||
{
|
||||
NS_IF_ADDREF(*aResult = mFileIO);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::SetFileIO(nsIFastLoadFileIO* aFileIO)
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
mFileIO = aFileIO;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::GetDirection(PRInt32 *aResult)
|
||||
{
|
||||
*aResult = mDirection;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::HasMuxedDocument(const char* aURISpec, PRBool *aResult)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
||||
nsCOMPtr<nsIFastLoadFileControl> control;
|
||||
|
||||
*aResult = PR_FALSE;
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
if (mInputStream) {
|
||||
control = do_QueryInterface(mInputStream);
|
||||
if (control)
|
||||
rv = control->HasMuxedDocument(aURISpec, aResult);
|
||||
}
|
||||
|
||||
if (! *aResult && mOutputStream) {
|
||||
control = do_QueryInterface(mOutputStream);
|
||||
if (control)
|
||||
rv = control->HasMuxedDocument(aURISpec, aResult);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::StartMuxedDocument(nsISupports* aURI, const char* aURISpec,
|
||||
PRInt32 aDirectionFlags)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
||||
nsCOMPtr<nsIFastLoadFileControl> control;
|
||||
MutexAutoLock 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) {
|
||||
control = do_QueryInterface(mInputStream);
|
||||
if (control) {
|
||||
// If aURISpec is not in the multiplex, control->StartMuxedDocument
|
||||
// will return NS_ERROR_NOT_AVAILABLE.
|
||||
rv = control->StartMuxedDocument(aURI, aURISpec);
|
||||
if (NS_SUCCEEDED(rv) || rv != NS_ERROR_NOT_AVAILABLE)
|
||||
return rv;
|
||||
|
||||
// Ok, aURISpec is not in the existing mux. If we have no output
|
||||
// stream yet, wrap the reader with a FastLoad file updater.
|
||||
if (!mOutputStream && mFileIO) {
|
||||
// NB: mInputStream must be an nsFastLoadFileReader!
|
||||
rv = NS_NewFastLoadFileUpdater(getter_AddRefs(mOutputStream),
|
||||
mFileIO, mInputStream);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((aDirectionFlags & NS_FASTLOAD_WRITE) && mOutputStream) {
|
||||
control = do_QueryInterface(mOutputStream);
|
||||
if (control)
|
||||
rv = control->StartMuxedDocument(aURI, aURISpec);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::SelectMuxedDocument(nsISupports* aURI, nsISupports** aResult)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
||||
nsCOMPtr<nsIFastLoadFileControl> control;
|
||||
MutexAutoLock 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) {
|
||||
control = do_QueryInterface(mInputStream);
|
||||
if (control) {
|
||||
rv = control->SelectMuxedDocument(aURI, aResult);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mDirection = NS_FASTLOAD_READ;
|
||||
}
|
||||
}
|
||||
|
||||
if (rv == NS_ERROR_NOT_AVAILABLE && mOutputStream) {
|
||||
control = do_QueryInterface(mOutputStream);
|
||||
if (control) {
|
||||
rv = control->SelectMuxedDocument(aURI, aResult);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mDirection = NS_FASTLOAD_WRITE;
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::EndMuxedDocument(nsISupports* aURI)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
||||
nsCOMPtr<nsIFastLoadFileControl> control;
|
||||
MutexAutoLock 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.
|
||||
if (mInputStream) {
|
||||
control = do_QueryInterface(mInputStream);
|
||||
if (control)
|
||||
rv = control->EndMuxedDocument(aURI);
|
||||
}
|
||||
|
||||
if (rv == NS_ERROR_NOT_AVAILABLE && mOutputStream) {
|
||||
control = do_QueryInterface(mOutputStream);
|
||||
if (control)
|
||||
rv = control->EndMuxedDocument(aURI);
|
||||
}
|
||||
|
||||
mDirection = 0;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::AddDependency(nsIFile* aFile)
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
nsCOMPtr<nsIFastLoadWriteControl> control(do_QueryInterface(mOutputStream));
|
||||
if (!control)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return control->AddDependency(aFile);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::ComputeChecksum(nsIFile* aFile,
|
||||
nsIFastLoadReadControl* aControl,
|
||||
PRUint32 *aChecksum)
|
||||
{
|
||||
nsCAutoString path;
|
||||
nsresult rv = aFile->GetNativePath(path);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCStringKey key(path);
|
||||
PRUint32 checksum = NS_PTR_TO_INT32(mChecksumTable.Get(&key));
|
||||
if (checksum) {
|
||||
*aChecksum = checksum;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
rv = aControl->ComputeChecksum(&checksum);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
mChecksumTable.Put(&key, NS_INT32_TO_PTR(checksum));
|
||||
*aChecksum = checksum;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFastLoadService::CacheChecksum(nsIFile* aFile, nsIObjectOutputStream *aStream)
|
||||
{
|
||||
nsCOMPtr<nsIFastLoadFileControl> control(do_QueryInterface(aStream));
|
||||
if (!control)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRUint32 checksum;
|
||||
nsresult rv = control->GetChecksum(&checksum);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCAutoString path;
|
||||
rv = aFile->GetNativePath(path);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCStringKey key(path);
|
||||
mChecksumTable.Put(&key, NS_INT32_TO_PTR(checksum));
|
||||
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?");
|
||||
|
||||
MutexAutoLock lock(mLock);
|
||||
if (!mFastLoadPtrMap || !mInputStream)
|
||||
return NS_OK;
|
||||
|
||||
nsFastLoadPtrEntry* entry =
|
||||
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 = PL_DHASH_TABLE_SIZE(mFastLoadPtrMap);
|
||||
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;
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
rv = aInputStream->Read32(&nextOffset);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsISeekableStream> seekable(do_QueryInterface(aInputStream));
|
||||
if (!seekable)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRInt64 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 =
|
||||
static_cast<nsFastLoadPtrEntry*>
|
||||
(PL_DHashTableOperate(mFastLoadPtrMap, aPtrAddr,
|
||||
PL_DHASH_ADD));
|
||||
NS_ASSERTION(entry->mPtrAddr == nsnull, "duplicate nsFastLoadPtr?!");
|
||||
|
||||
entry->mPtrAddr = aPtrAddr;
|
||||
|
||||
LL_L2UI(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;
|
||||
MutexAutoLock lock(mLock); // serialize writes to aOutputStream
|
||||
|
||||
nsCOMPtr<nsISeekableStream> seekable(do_QueryInterface(aOutputStream));
|
||||
if (!seekable)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRInt64 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;
|
||||
|
||||
PRInt64 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;
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla 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/MPL/
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brendan Eich <brendan@mozilla.org> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "prtypes.h"
|
||||
#include "pldhash.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsIFastLoadService.h"
|
||||
#include "nsIObjectInputStream.h"
|
||||
#include "nsIObjectOutputStream.h"
|
||||
|
||||
class nsFastLoadFileReader;
|
||||
class nsFastLoadFileWriter;
|
||||
|
||||
class nsFastLoadService : public nsIFastLoadService
|
||||
{
|
||||
public:
|
||||
nsFastLoadService();
|
||||
private:
|
||||
~nsFastLoadService();
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIFASTLOADSERVICE
|
||||
|
||||
static nsresult
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
private:
|
||||
mozilla::Mutex mLock;
|
||||
PLDHashTable* mFastLoadPtrMap;
|
||||
nsCOMPtr<nsIObjectInputStream> mInputStream;
|
||||
nsCOMPtr<nsIObjectOutputStream> mOutputStream;
|
||||
nsCOMPtr<nsIFastLoadFileIO> mFileIO;
|
||||
PRInt32 mDirection;
|
||||
nsHashtable mChecksumTable;
|
||||
};
|
|
@ -1,123 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla 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/MPL/
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brendan Eich <brendan@mozilla.org> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsrootidl.idl"
|
||||
|
||||
interface nsIFile;
|
||||
interface nsISimpleEnumerator;
|
||||
|
||||
/**
|
||||
* The nsIFastLoadFileControl interface and its subinterfaces are mix-ins for
|
||||
* classes implementing nsIObjectInputStream and nsIObjectOutputStream, so that
|
||||
* those stream types can be used with nsIFastLoadService to access and compute
|
||||
* FastLoad file checksums, update and check FastLoad file dependencies, and
|
||||
* multiplex documents loaded via non-blocking i/o.
|
||||
*
|
||||
* If an nsIObjectInputStream class doesn't support nsIFastLoadReadControl, or
|
||||
* an nsIObjectOutputStream class doesn't support nsIFastLoadWriteControl, that
|
||||
* implementation may still be useful for object serialization, but it can't be
|
||||
* used to read or write a Mozilla FastLoad file.
|
||||
*/
|
||||
[scriptable, uuid(e7c8c14f-c273-4e70-826f-b85864303dc6)]
|
||||
interface nsIFastLoadFileControl : nsISupports
|
||||
{
|
||||
/**
|
||||
* Get the recorded checksum value from the FastLoad file header.
|
||||
*/
|
||||
readonly attribute PRUint32 checksum;
|
||||
|
||||
/**
|
||||
* Multiplexed document control methods. A FastLoad file may contain
|
||||
* multiple interleaved documents identified by a URI specifier string,
|
||||
* and indexed for fast multiplexor select by an opaque URI object key.
|
||||
* You StartMuxedDocument when initiating a document load, then Select
|
||||
* before every batch of calls to (de)serialize document data, and End
|
||||
* when the load completes.
|
||||
*
|
||||
* Document multiplexing is necessary to support incremental FastLoad
|
||||
* development in a non-blocking i/o architecture such as Mozilla, where
|
||||
* some (but not all, at first, or for a while during development) of the
|
||||
* results of parsing and compiling various inputs can be multiplexed to
|
||||
* or from a FastLoad file.
|
||||
*
|
||||
* Note: Select returns the previously selected URI object in case the
|
||||
* caller is synchronously selecting and writing data to the FastLoad
|
||||
* file, so the caller can reselect the previous URI and return to code
|
||||
* the continues to write FastLoad data for the previous URI, unaware of
|
||||
* the nested select/write/reselect.
|
||||
*/
|
||||
void startMuxedDocument(in nsISupports aURI, in string aURISpec);
|
||||
nsISupports selectMuxedDocument(in nsISupports aURI);
|
||||
void endMuxedDocument(in nsISupports aURI);
|
||||
|
||||
/**
|
||||
* Return true if aURISpec identifies a muxed document in the FastLoad
|
||||
* file, false otherwise.
|
||||
*/
|
||||
boolean hasMuxedDocument(in string aURISpec);
|
||||
};
|
||||
|
||||
[scriptable, uuid(7604429c-6090-40fe-a87b-928221a1ca67)]
|
||||
interface nsIFastLoadReadControl : nsIFastLoadFileControl
|
||||
{
|
||||
/**
|
||||
* Computes the correct checksum of the FastLoad file, independent of the
|
||||
* header's checksum value. The header checksum field is treated as zero
|
||||
* when computing the checksum.
|
||||
*/
|
||||
PRUint32 computeChecksum();
|
||||
|
||||
/**
|
||||
* Get the collection of dependency nsIFile instances recorded during the
|
||||
* FastLoad file write or read/update process, and checked during the read
|
||||
* process to invalidate the FastLoad file if any dependencies are newer.
|
||||
*/
|
||||
readonly attribute nsISimpleEnumerator dependencies;
|
||||
};
|
||||
|
||||
[scriptable, uuid(3dbdca8f-0631-4826-a29c-8aba1deea09d)]
|
||||
interface nsIFastLoadWriteControl : nsIFastLoadFileControl
|
||||
{
|
||||
/**
|
||||
* Add a file dependency of the FastLoad file (e.g., a .jar file) to the
|
||||
* set of dependencies that trigger regeneration if any dependency has a
|
||||
* last-modified-time greater than the FastLoad file's mtime.
|
||||
*/
|
||||
void addDependency(in nsIFile aFile);
|
||||
};
|
|
@ -1,171 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla 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/MPL/
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brendan Eich <brendan@mozilla.org> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsrootidl.idl"
|
||||
|
||||
interface nsIFastLoadReadControl;
|
||||
interface nsIFile;
|
||||
interface nsIInputStream;
|
||||
interface nsIOutputStream;
|
||||
interface nsIObjectInputStream;
|
||||
interface nsIObjectOutputStream;
|
||||
|
||||
[scriptable, uuid(61cd17e0-b07a-4158-9817-36a206b100e9)]
|
||||
interface nsIFastLoadFileIO : nsISupports
|
||||
{
|
||||
readonly attribute nsIInputStream inputStream;
|
||||
readonly attribute nsIOutputStream outputStream;
|
||||
/**
|
||||
* Causes outputStream to be created in non-truncating mode
|
||||
*/
|
||||
[noscript] void disableTruncate();
|
||||
};
|
||||
|
||||
[scriptable, uuid(c18df300-c2e4-4115-a61c-9110655f7dd8)]
|
||||
interface nsIFastLoadService : nsISupports
|
||||
{
|
||||
nsIFile newFastLoadFile(in string aBaseName);
|
||||
|
||||
nsIObjectInputStream newInputStream(in nsIFile aFile);
|
||||
nsIObjectOutputStream newOutputStream(in nsIOutputStream aDestStream);
|
||||
|
||||
// Flag values for the direction attribute and the aDirectionFlags
|
||||
// parameter to startMuxedDocument.
|
||||
const PRInt32 NS_FASTLOAD_READ = 1;
|
||||
const PRInt32 NS_FASTLOAD_WRITE = 2;
|
||||
|
||||
attribute nsIObjectInputStream inputStream;
|
||||
attribute nsIObjectOutputStream outputStream;
|
||||
attribute nsIFastLoadFileIO fileIO;
|
||||
readonly attribute PRInt32 direction;
|
||||
|
||||
/**
|
||||
* These methods associate a URI object with its spec, for faster select
|
||||
* using the object pointer as a key, rather than the spec string. The
|
||||
* selectMuxedDocument method returns the previously selected URI object,
|
||||
* in case a caller needs to reselect the previous after muxing data for
|
||||
* a given URI synchronously. For the non-blocking or "asynchronous" i/o
|
||||
* case, the caller must select the source URI from the FastLoad multiplex
|
||||
* before writing a new burst of data parsed from the slow-loaded source.
|
||||
*
|
||||
* Clients of inputStream and outputStream should try to demultiplex data
|
||||
* from the input stream only if fastLoadService->StartMuxedDocument(uri,
|
||||
* urispec, NS_FASTLOAD_READ) succeeds. If StartMuxedDocument fails with
|
||||
* NS_ERROR_NOT_AVAILABLE, callers should slow-load the documents, muxing
|
||||
* their data to the current output stream.
|
||||
*/
|
||||
void startMuxedDocument(in nsISupports aURI,
|
||||
in string aURISpec,
|
||||
in PRInt32 aDirectionFlags);
|
||||
nsISupports selectMuxedDocument(in nsISupports aURI);
|
||||
void endMuxedDocument(in nsISupports aURI);
|
||||
|
||||
void addDependency(in nsIFile aFile);
|
||||
|
||||
PRUint32 computeChecksum(in nsIFile aFile,
|
||||
in nsIFastLoadReadControl aControl);
|
||||
void cacheChecksum(in nsIFile aFile,
|
||||
in nsIObjectOutputStream aStream);
|
||||
|
||||
[noscript] void getFastLoadReferent(inout nsISupports aPtr);
|
||||
|
||||
[noscript] void readFastLoadPtr(in nsIObjectInputStream aInputStream,
|
||||
inout nsISupports aPtr);
|
||||
|
||||
[noscript] void writeFastLoadPtr(in nsIObjectOutputStream aOutputStream,
|
||||
in nsISupports aPtr);
|
||||
|
||||
/**
|
||||
* Return true if aURISpec identifies a muxed document in the FastLoad
|
||||
* file, false otherwise.
|
||||
*/
|
||||
boolean hasMuxedDocument(in string aURISpec);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_FASTLOADSERVICE_CLASSNAME "Mozilla FastLoad Service"
|
||||
|
||||
#define NS_FASTLOADSERVICE_CID \
|
||||
{0xc943093c,0xac94,0x4bee,{0x84,0x0b,0x8b,0x5a,0x6e,0x31,0x4f,0xa7}}
|
||||
|
||||
#define NS_FASTLOADSERVICE_CONTRACTID \
|
||||
"@mozilla.org/fast-load-service;1"
|
||||
|
||||
#ifndef nsCOMPtr_h___
|
||||
# include "nsCOMPtr.h"
|
||||
#endif
|
||||
#ifndef __gen_nsIFile_h__
|
||||
# include "nsIFile.h"
|
||||
#endif
|
||||
#ifndef nsIServiceManager_h___
|
||||
# include "nsIServiceManager.h"
|
||||
#endif
|
||||
|
||||
inline const nsGetServiceByContractID
|
||||
do_GetFastLoadService()
|
||||
{
|
||||
return nsGetServiceByContractID(NS_FASTLOADSERVICE_CONTRACTID);
|
||||
}
|
||||
|
||||
inline const nsGetServiceByContractIDWithError
|
||||
do_GetFastLoadService(nsresult *aResultCode)
|
||||
{
|
||||
return nsGetServiceByContractIDWithError(NS_FASTLOADSERVICE_CONTRACTID,
|
||||
aResultCode);
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_AddFastLoadDependency(nsIFile* aFile)
|
||||
{
|
||||
nsCOMPtr<nsIFastLoadService> fastLoadService(do_GetFastLoadService());
|
||||
if (fastLoadService) {
|
||||
nsresult rv = fastLoadService->AddDependency(aFile);
|
||||
if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE)
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#if defined(XP_UNIX) || defined(XP_BEOS)
|
||||
#define PLATFORM_FASL_SUFFIX ".mfasl"
|
||||
#elif defined(XP_WIN) || defined(XP_OS2)
|
||||
#define PLATFORM_FASL_SUFFIX ".mfl"
|
||||
#endif
|
||||
|
||||
%}
|
Загрузка…
Ссылка в новой задаче