mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
82b549eebb
This patch introduces a new SeekableStreamWrapper class which handles adapting nsIInputStreams which support being cheaply cloned using nsICloneableInputStream into seekable input streams by operating on a clone of the original stream, and re-cloning that stream when seeking backwards. This wrapper is generally intended to be used with nsPipeInputStream as that type supports both a fairly cheap clone operation, and keeping a large internal buffer which is fairly cheap to seek using this method, but should also work with other types such as RemoteLazyInputStream or nsStringStream. An alternate strategy was considered where nsPipe was given internal support for a mSeekable flag to be set on creation. This flag would then have a similar effect, except with additional optimizations due to being visible within the implementation of the nsPipe, rather than relying on an unadvanced nsPipeInputStream to keep the buffer alive. I ended up choosing this approach instead for a few reasons: * The seekable adapter can be applied to an already-created nsPipeInputStream, such as one received from IPC. With the nsPipe approach, making an IPC stream seekable either requires telling IPCStreamDestination to use a seekable pipe ahead of time, or performing a NS_AsyncCopy from the IPC-provided pipe into a different seekable pipe, which is likely wasted effort and would prevent optimizations such as RemoteLazyInputStream and DelayedStart streams. * The adapter can support other features of the underlying stream, such as nsIInputStreamLength, without resorting to adding additional adapter layers on top of the returned nsPipe. * The performance is unlikely to be substantially different in the most common case, which is using Seek(NS_SEEK_SET, 0) to return to the beginning of the stream. * Less additional complexity is added to the already-complicated internals of nsPipe, and instead it is kept in a separate wrapper stream, which is easier to review. Using nsStorageStream, as is used by EnsureUploadStreamIsCloneable, was also considered, but was rejected as it has similar problems to the seekable nsPipe approach and also doesn't implement nsIAsyncStream, meaning that one must wait for the NS_AsyncCopy to be completed before reading the stream. It may actually be possible to replace the existing uses of nsStorageStream with a wrapped nsPipe in the future, but that is left as follow-up material, and may have memory overhead implications due to nsPipe not resizing the final segment, unlike nsStorageStream. Differential Revision: https://phabricator.services.mozilla.com/D101805
156 lines
3.9 KiB
Python
156 lines
3.9 KiB
Python
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
|
# vim: set filetype=python:
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
XPIDL_SOURCES += [
|
|
"nsIAsyncInputStream.idl",
|
|
"nsIAsyncOutputStream.idl",
|
|
"nsIBinaryInputStream.idl",
|
|
"nsIBinaryOutputStream.idl",
|
|
"nsICloneableInputStream.idl",
|
|
"nsIConverterInputStream.idl",
|
|
"nsIConverterOutputStream.idl",
|
|
"nsIDirectoryEnumerator.idl",
|
|
"nsIDirectoryService.idl",
|
|
"nsIFile.idl",
|
|
"nsIInputStream.idl",
|
|
"nsIInputStreamLength.idl",
|
|
"nsIInputStreamPriority.idl",
|
|
"nsIInputStreamTee.idl",
|
|
"nsIIOUtil.idl",
|
|
"nsILineInputStream.idl",
|
|
"nsILocalFileWin.idl",
|
|
"nsIMultiplexInputStream.idl",
|
|
"nsIObjectInputStream.idl",
|
|
"nsIObjectOutputStream.idl",
|
|
"nsIOutputStream.idl",
|
|
"nsIPipe.idl",
|
|
"nsISafeOutputStream.idl",
|
|
"nsIScriptableBase64Encoder.idl",
|
|
"nsIScriptableInputStream.idl",
|
|
"nsISeekableStream.idl",
|
|
"nsIStorageStream.idl",
|
|
"nsIStreamBufferAccess.idl",
|
|
"nsIStringStream.idl",
|
|
"nsITellableStream.idl",
|
|
"nsIUnicharInputStream.idl",
|
|
"nsIUnicharLineInputStream.idl",
|
|
"nsIUnicharOutputStream.idl",
|
|
]
|
|
|
|
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
|
|
XPIDL_SOURCES += [
|
|
"nsILocalFileMac.idl",
|
|
]
|
|
|
|
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows":
|
|
EXPORTS += ["nsLocalFileWin.h"]
|
|
EXPORTS.mozilla += [
|
|
"FileUtilsWin.h",
|
|
]
|
|
SOURCES += [
|
|
"FileUtilsWin.cpp",
|
|
"nsLocalFileWin.cpp",
|
|
]
|
|
else:
|
|
EXPORTS += ["nsLocalFileUnix.h"]
|
|
SOURCES += [
|
|
"nsLocalFileUnix.cpp",
|
|
]
|
|
|
|
XPIDL_MODULE = "xpcom_io"
|
|
|
|
XPCOM_MANIFESTS += [
|
|
"components.conf",
|
|
]
|
|
|
|
EXPORTS += [
|
|
"FileDescriptorFile.h",
|
|
"nsAnonymousTemporaryFile.h",
|
|
"nsAppDirectoryServiceDefs.h",
|
|
"nsDirectoryService.h",
|
|
"nsDirectoryServiceDefs.h",
|
|
"nsDirectoryServiceUtils.h",
|
|
"nsEscape.h",
|
|
"nsLinebreakConverter.h",
|
|
"nsLocalFile.h",
|
|
"nsLocalFileCommon.h",
|
|
"nsMultiplexInputStream.h",
|
|
"nsNativeCharsetUtils.h",
|
|
"nsScriptableInputStream.h",
|
|
"nsStorageStream.h",
|
|
"nsStreamUtils.h",
|
|
"nsStringStream.h",
|
|
"nsUnicharInputStream.h",
|
|
"nsWildCard.h",
|
|
"SpecialSystemDirectory.h",
|
|
]
|
|
|
|
EXPORTS.mozilla += [
|
|
"Base64.h",
|
|
"FilePreferences.h",
|
|
"InputStreamLengthHelper.h",
|
|
"InputStreamLengthWrapper.h",
|
|
"NonBlockingAsyncInputStream.h",
|
|
"SeekableStreamWrapper.h",
|
|
"SlicedInputStream.h",
|
|
"SnappyCompressOutputStream.h",
|
|
"SnappyFrameUtils.h",
|
|
"SnappyUncompressInputStream.h",
|
|
]
|
|
|
|
UNIFIED_SOURCES += [
|
|
"Base64.cpp",
|
|
"crc32c.c",
|
|
"FileDescriptorFile.cpp",
|
|
"FilePreferences.cpp",
|
|
"InputStreamLengthHelper.cpp",
|
|
"InputStreamLengthWrapper.cpp",
|
|
"NonBlockingAsyncInputStream.cpp",
|
|
"nsAnonymousTemporaryFile.cpp",
|
|
"nsAppFileLocationProvider.cpp",
|
|
"nsBinaryStream.cpp",
|
|
"nsDirectoryService.cpp",
|
|
"nsEscape.cpp",
|
|
"nsInputStreamTee.cpp",
|
|
"nsIOUtil.cpp",
|
|
"nsLinebreakConverter.cpp",
|
|
"nsLocalFileCommon.cpp",
|
|
"nsMultiplexInputStream.cpp",
|
|
"nsNativeCharsetUtils.cpp",
|
|
"nsPipe3.cpp",
|
|
"nsScriptableBase64Encoder.cpp",
|
|
"nsScriptableInputStream.cpp",
|
|
"nsSegmentedBuffer.cpp",
|
|
"nsStorageStream.cpp",
|
|
"nsStreamUtils.cpp",
|
|
"nsStringStream.cpp",
|
|
"nsUnicharInputStream.cpp",
|
|
"nsWildCard.cpp",
|
|
"SeekableStreamWrapper.cpp",
|
|
"SlicedInputStream.cpp",
|
|
"SnappyCompressOutputStream.cpp",
|
|
"SnappyFrameUtils.cpp",
|
|
"SnappyUncompressInputStream.cpp",
|
|
"SpecialSystemDirectory.cpp",
|
|
]
|
|
|
|
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
|
|
SOURCES += [
|
|
"CocoaFileUtils.mm",
|
|
]
|
|
|
|
include("/ipc/chromium/chromium-config.mozbuild")
|
|
|
|
FINAL_LIBRARY = "xul"
|
|
|
|
if CONFIG["OS_ARCH"] == "Linux" and "lib64" in CONFIG["libdir"]:
|
|
DEFINES["HAVE_USR_LIB64_DIR"] = True
|
|
|
|
LOCAL_INCLUDES += [
|
|
"!..",
|
|
"../build",
|
|
]
|