2014-05-05 21:30:43 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-11-16 22:14:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The storage stream provides an internal buffer that can be filled by a
|
|
|
|
* client using a single output stream. One or more independent input streams
|
|
|
|
* can be created to read the data out non-destructively. The implementation
|
|
|
|
* uses a segmented buffer internally to avoid realloc'ing of large buffers,
|
|
|
|
* with the attendant performance loss and heap fragmentation.
|
|
|
|
*/
|
|
|
|
|
2011-06-02 16:56:50 +04:00
|
|
|
#include "nsAlgorithm.h"
|
1999-11-16 22:14:08 +03:00
|
|
|
#include "nsStorageStream.h"
|
|
|
|
#include "nsSegmentedBuffer.h"
|
2006-01-02 05:30:32 +03:00
|
|
|
#include "nsStreamUtils.h"
|
1999-11-16 22:14:08 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2015-02-11 07:55:43 +03:00
|
|
|
#include "nsICloneableInputStream.h"
|
2000-08-22 11:03:33 +04:00
|
|
|
#include "nsIInputStream.h"
|
2014-06-17 14:52:59 +04:00
|
|
|
#include "nsIIPCSerializableInputStream.h"
|
2002-01-25 05:13:00 +03:00
|
|
|
#include "nsISeekableStream.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2012-06-06 03:51:58 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2013-11-13 04:22:38 +04:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2014-06-17 14:52:59 +04:00
|
|
|
#include "mozilla/ipc/InputStreamUtils.h"
|
|
|
|
|
2016-09-29 07:20:00 +03:00
|
|
|
using mozilla::Maybe;
|
|
|
|
using mozilla::Some;
|
2014-06-17 14:52:59 +04:00
|
|
|
using mozilla::ipc::InputStreamParams;
|
|
|
|
using mozilla::ipc::StringInputStreamParams;
|
2006-01-02 05:30:32 +03:00
|
|
|
|
2000-01-22 02:16:35 +03:00
|
|
|
//
|
|
|
|
// Log module for StorageStream logging...
|
|
|
|
//
|
|
|
|
// To enable logging (see prlog.h for full details):
|
|
|
|
//
|
2016-05-26 01:26:10 +03:00
|
|
|
// set MOZ_LOG=StorageStreamLog:5
|
|
|
|
// set MOZ_LOG_FILE=storage.log
|
2000-01-22 02:16:35 +03:00
|
|
|
//
|
2016-05-26 01:26:10 +03:00
|
|
|
// This enables LogLevel::Debug level information and places all output in
|
|
|
|
// the file storage.log.
|
2000-01-22 02:16:35 +03:00
|
|
|
//
|
2015-10-19 22:50:14 +03:00
|
|
|
static LazyLogModule sStorageStreamLog("nsStorageStream");
|
2013-11-19 06:34:00 +04:00
|
|
|
#ifdef LOG
|
|
|
|
# undef LOG
|
|
|
|
#endif
|
2015-10-19 22:50:14 +03:00
|
|
|
#define LOG(args) MOZ_LOG(sStorageStreamLog, mozilla::LogLevel::Debug, args)
|
2000-01-22 02:16:35 +03:00
|
|
|
|
1999-11-16 22:14:08 +03:00
|
|
|
nsStorageStream::nsStorageStream()
|
2018-06-15 14:41:20 +03:00
|
|
|
: mSegmentedBuffer(0),
|
|
|
|
mSegmentSize(0),
|
|
|
|
mSegmentSizeLog2(0),
|
|
|
|
mWriteInProgress(false),
|
|
|
|
mLastSegmentNum(-1),
|
|
|
|
mWriteCursor(0),
|
|
|
|
mSegmentEnd(0),
|
|
|
|
mLogicalLength(0) {
|
2014-05-05 21:30:43 +04:00
|
|
|
LOG(("Creating nsStorageStream [%p].\n", this));
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsStorageStream::~nsStorageStream() { delete mSegmentedBuffer; }
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsStorageStream, nsIStorageStream, nsIOutputStream)
|
1999-11-16 22:14:08 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageStream::Init(uint32_t aSegmentSize, uint32_t aMaxSize) {
|
2014-05-05 21:30:43 +04:00
|
|
|
mSegmentedBuffer = new nsSegmentedBuffer();
|
2014-05-15 00:15:46 +04:00
|
|
|
mSegmentSize = aSegmentSize;
|
|
|
|
mSegmentSizeLog2 = mozilla::FloorLog2(aSegmentSize);
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
// Segment size must be a power of two
|
2014-05-15 00:15:46 +04:00
|
|
|
if (mSegmentSize != ((uint32_t)1 << mSegmentSizeLog2)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
return mSegmentedBuffer->Init(aSegmentSize, aMaxSize);
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-05 21:30:43 +04:00
|
|
|
nsStorageStream::GetOutputStream(int32_t aStartingOffset,
|
2014-05-15 00:15:46 +04:00
|
|
|
nsIOutputStream** aOutputStream) {
|
|
|
|
if (NS_WARN_IF(!aOutputStream)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
|
|
|
if (NS_WARN_IF(!mSegmentedBuffer)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
if (mWriteInProgress) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
nsresult rv = Seek(aStartingOffset);
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
// Enlarge the last segment in the buffer so that it is the same size as
|
|
|
|
// all the other segments in the buffer. (It may have been realloc'ed
|
|
|
|
// smaller in the Close() method.)
|
|
|
|
if (mLastSegmentNum >= 0)
|
|
|
|
if (mSegmentedBuffer->ReallocLastSegment(mSegmentSize)) {
|
|
|
|
// Need to re-Seek, since realloc changed segment base pointer
|
|
|
|
rv = Seek(aStartingOffset);
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(this);
|
|
|
|
*aOutputStream = static_cast<nsIOutputStream*>(this);
|
|
|
|
mWriteInProgress = true;
|
|
|
|
return NS_OK;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStorageStream::Close() {
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_WARN_IF(!mSegmentedBuffer)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
1999-11-16 22:14:08 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
mWriteInProgress = false;
|
2000-01-22 02:16:35 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
int32_t segmentOffset = SegOffset(mLogicalLength);
|
|
|
|
|
|
|
|
// Shrink the final segment in the segmented buffer to the minimum size
|
|
|
|
// needed to contain the data, so as to conserve memory.
|
2014-05-15 00:15:46 +04:00
|
|
|
if (segmentOffset) {
|
2014-05-05 21:30:43 +04:00
|
|
|
mSegmentedBuffer->ReallocLastSegment(segmentOffset);
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
mWriteCursor = 0;
|
|
|
|
mSegmentEnd = 0;
|
|
|
|
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG(("nsStorageStream [%p] Close mWriteCursor=%p mSegmentEnd=%p\n", this,
|
2014-05-05 21:30:43 +04:00
|
|
|
mWriteCursor, mSegmentEnd));
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStorageStream::Flush() { return NS_OK; }
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageStream::Write(const char* aBuffer, uint32_t aCount,
|
|
|
|
uint32_t* aNumWritten) {
|
|
|
|
if (NS_WARN_IF(!aNumWritten) || NS_WARN_IF(!aBuffer)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
|
|
|
if (NS_WARN_IF(!mSegmentedBuffer)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
const char* readCursor;
|
|
|
|
uint32_t count, availableInSegment, remaining;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG(("nsStorageStream [%p] Write mWriteCursor=%p mSegmentEnd=%p aCount=%d\n",
|
2014-05-05 21:30:43 +04:00
|
|
|
this, mWriteCursor, mSegmentEnd, aCount));
|
|
|
|
|
|
|
|
remaining = aCount;
|
|
|
|
readCursor = aBuffer;
|
|
|
|
// If no segments have been created yet, create one even if we don't have
|
|
|
|
// to write any data; this enables creating an input stream which reads from
|
|
|
|
// the very end of the data for any amount of data in the stream (i.e.
|
|
|
|
// this stream contains N bytes of data and newInputStream(N) is called),
|
|
|
|
// even for N=0 (with the caveat that we require .write("", 0) be called to
|
|
|
|
// initialize internal buffers).
|
|
|
|
bool firstTime = mSegmentedBuffer->GetSegmentCount() == 0;
|
|
|
|
while (remaining || MOZ_UNLIKELY(firstTime)) {
|
|
|
|
firstTime = false;
|
|
|
|
availableInSegment = mSegmentEnd - mWriteCursor;
|
|
|
|
if (!availableInSegment) {
|
|
|
|
mWriteCursor = mSegmentedBuffer->AppendNewSegment();
|
|
|
|
if (!mWriteCursor) {
|
|
|
|
mSegmentEnd = 0;
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
mLastSegmentNum++;
|
|
|
|
mSegmentEnd = mWriteCursor + mSegmentSize;
|
|
|
|
availableInSegment = mSegmentEnd - mWriteCursor;
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG(
|
|
|
|
("nsStorageStream [%p] Write (new seg) mWriteCursor=%p "
|
|
|
|
"mSegmentEnd=%p\n",
|
2014-05-05 21:30:43 +04:00
|
|
|
this, mWriteCursor, mSegmentEnd));
|
|
|
|
}
|
|
|
|
|
|
|
|
count = XPCOM_MIN(availableInSegment, remaining);
|
|
|
|
memcpy(mWriteCursor, readCursor, count);
|
|
|
|
remaining -= count;
|
|
|
|
readCursor += count;
|
|
|
|
mWriteCursor += count;
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG(
|
|
|
|
("nsStorageStream [%p] Writing mWriteCursor=%p mSegmentEnd=%p "
|
|
|
|
"count=%d\n",
|
2014-05-05 21:30:43 +04:00
|
|
|
this, mWriteCursor, mSegmentEnd, count));
|
2016-01-22 18:58:49 +03:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
*aNumWritten = aCount - remaining;
|
|
|
|
mLogicalLength += *aNumWritten;
|
|
|
|
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG(
|
|
|
|
("nsStorageStream [%p] Wrote mWriteCursor=%p mSegmentEnd=%p "
|
|
|
|
"numWritten=%d\n",
|
2014-05-05 21:30:43 +04:00
|
|
|
this, mWriteCursor, mSegmentEnd, *aNumWritten));
|
|
|
|
return rv;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageStream::WriteFrom(nsIInputStream* aInStr, uint32_t aCount,
|
|
|
|
uint32_t* aResult) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2000-08-22 11:03:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageStream::WriteSegments(nsReadSegmentFun aReader, void* aClosure,
|
|
|
|
uint32_t aCount, uint32_t* aResult) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2000-08-22 11:03:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageStream::IsNonBlocking(bool* aNonBlocking) {
|
2014-05-05 21:30:43 +04:00
|
|
|
*aNonBlocking = false;
|
|
|
|
return NS_OK;
|
2000-08-22 11:03:33 +04:00
|
|
|
}
|
|
|
|
|
1999-11-16 22:14:08 +03:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageStream::GetLength(uint32_t* aLength) {
|
2014-05-05 21:30:43 +04:00
|
|
|
*aLength = mLogicalLength;
|
|
|
|
return NS_OK;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Truncate the buffer by deleting the end segments
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsStorageStream::SetLength(uint32_t aLength) {
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_WARN_IF(!mSegmentedBuffer)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
1999-11-16 22:14:08 +03:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
if (mWriteInProgress) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
if (aLength > mLogicalLength) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
int32_t newLastSegmentNum = SegNum(aLength);
|
|
|
|
int32_t segmentOffset = SegOffset(aLength);
|
2014-05-15 00:15:46 +04:00
|
|
|
if (segmentOffset == 0) {
|
2014-05-05 21:30:43 +04:00
|
|
|
newLastSegmentNum--;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
while (newLastSegmentNum < mLastSegmentNum) {
|
|
|
|
mSegmentedBuffer->DeleteLastSegment();
|
|
|
|
mLastSegmentNum--;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLogicalLength = aLength;
|
|
|
|
return NS_OK;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageStream::GetWriteInProgress(bool* aWriteInProgress) {
|
2014-05-05 21:30:43 +04:00
|
|
|
*aWriteInProgress = mWriteInProgress;
|
|
|
|
return NS_OK;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsStorageStream::Seek(int32_t aPosition) {
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_WARN_IF(!mSegmentedBuffer)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
1999-11-16 22:14:08 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
// An argument of -1 means "seek to end of stream"
|
2014-05-15 00:15:46 +04:00
|
|
|
if (aPosition == -1) {
|
2014-05-05 21:30:43 +04:00
|
|
|
aPosition = mLogicalLength;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
// Seeking beyond the buffer end is illegal
|
2014-05-15 00:15:46 +04:00
|
|
|
if ((uint32_t)aPosition > mLogicalLength) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
// Seeking backwards in the write stream results in truncation
|
|
|
|
SetLength(aPosition);
|
|
|
|
|
|
|
|
// Special handling for seek to start-of-buffer
|
|
|
|
if (aPosition == 0) {
|
|
|
|
mWriteCursor = 0;
|
|
|
|
mSegmentEnd = 0;
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG(("nsStorageStream [%p] Seek mWriteCursor=%p mSegmentEnd=%p\n", this,
|
2014-05-05 21:30:43 +04:00
|
|
|
mWriteCursor, mSegmentEnd));
|
1999-11-16 22:14:08 +03:00
|
|
|
return NS_OK;
|
2014-05-05 21:30:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Segment may have changed, so reset pointers
|
|
|
|
mWriteCursor = mSegmentedBuffer->GetSegment(mLastSegmentNum);
|
|
|
|
NS_ASSERTION(mWriteCursor, "null mWriteCursor");
|
|
|
|
mSegmentEnd = mWriteCursor + mSegmentSize;
|
|
|
|
|
|
|
|
// Adjust write cursor for current segment offset. This test is necessary
|
|
|
|
// because SegNum may reference the next-to-be-allocated segment, in which
|
|
|
|
// case we need to be pointing at the end of the last segment.
|
|
|
|
int32_t segmentOffset = SegOffset(aPosition);
|
2014-05-15 00:15:46 +04:00
|
|
|
if (segmentOffset == 0 && (SegNum(aPosition) > (uint32_t)mLastSegmentNum)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
mWriteCursor = mSegmentEnd;
|
2014-05-15 00:15:46 +04:00
|
|
|
} else {
|
2014-05-05 21:30:43 +04:00
|
|
|
mWriteCursor += segmentOffset;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG(("nsStorageStream [%p] Seek mWriteCursor=%p mSegmentEnd=%p\n", this,
|
2014-05-05 21:30:43 +04:00
|
|
|
mWriteCursor, mSegmentEnd));
|
|
|
|
return NS_OK;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
2000-01-22 02:16:35 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-11-16 22:14:08 +03:00
|
|
|
// There can be many nsStorageInputStreams for a single nsStorageStream
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsStorageInputStream final : public nsIInputStream,
|
2014-05-15 00:15:46 +04:00
|
|
|
public nsISeekableStream,
|
2014-06-17 14:52:59 +04:00
|
|
|
public nsIIPCSerializableInputStream,
|
2015-02-11 07:55:43 +03:00
|
|
|
public nsICloneableInputStream {
|
1999-11-16 22:14:08 +03:00
|
|
|
public:
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageInputStream(nsStorageStream* aStorageStream, uint32_t aSegmentSize)
|
2014-05-05 21:30:43 +04:00
|
|
|
: mStorageStream(aStorageStream),
|
|
|
|
mReadCursor(0),
|
|
|
|
mSegmentEnd(0),
|
|
|
|
mSegmentNum(0),
|
|
|
|
mSegmentSize(aSegmentSize),
|
|
|
|
mLogicalCursor(0),
|
|
|
|
mStatus(NS_OK) {}
|
|
|
|
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
|
|
|
NS_DECL_NSISEEKABLESTREAM
|
Bug 1496581 - Split nsISeekableStream in 2 classes: nsISeekableStream and nsITellableStream, f=mayhemer, r=froydnj
In the current code there are 3 main issues:
1. nsFileStream is not really thread-safe. There is nothing to protect the
internal members and we see crashes.
2. nsPipeInputStream doesn't implement ::Seek() method and that caused issues
in devtools when a nsHttpChannel sends POST data using a pipe. In order to fix
this, bug 1494176 added a check in nsHttpChannel: if the stream doesn't
implement ::Seek(), let's clone it. This was an hack around nsPipeInputStream,
and it's bad.
3. When nsHttpChannel sends POST data using a file stream, nsFileStream does
I/O on main-thread because of the issue 2. Plus, ::Seek() is called on the
main-thread causing issue 1.
Note that nsPipeInputStream implements only ::Tell(), of the nsISeekableStream
methods. It doesn't implement ::Seek() and it doesn't implement ::SetEOF().
With this patch I want to fix point 2 and point 3 (and consequentially issue 1
- but we need a separate fix for it - follow up). The patch does:
1. it splits nsISeekableStream in 2 interfaces: nsITellableStream and
nsISeekableStream.
2. nsPipeInputStream implements only nsITellableStream. Doing this, we don't
need the ::Seek() check for point 2 in nsHttpChannel: a simple QI check is
enough.
3. Because we don't call ::Seek() in nsHttpChannel, nsFileStream doesn't do I/O
on the main-thread, and we don't crash doing so.
2018-10-18 14:35:35 +03:00
|
|
|
NS_DECL_NSITELLABLESTREAM
|
2014-06-17 14:52:59 +04:00
|
|
|
NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM
|
2015-02-11 07:55:43 +03:00
|
|
|
NS_DECL_NSICLONEABLEINPUTSTREAM
|
1999-11-16 22:14:08 +03:00
|
|
|
|
2004-01-15 09:14:18 +03:00
|
|
|
private:
|
2014-05-05 21:30:43 +04:00
|
|
|
~nsStorageInputStream() {}
|
2004-01-15 09:14:18 +03:00
|
|
|
|
1999-11-16 22:14:08 +03:00
|
|
|
protected:
|
2016-08-15 07:30:32 +03:00
|
|
|
nsresult Seek(uint32_t aPosition);
|
1999-11-16 22:14:08 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
friend class nsStorageStream;
|
1999-11-16 22:14:08 +03:00
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsStorageStream> mStorageStream;
|
2014-05-05 21:30:43 +04:00
|
|
|
uint32_t mReadCursor; // Next memory location to read byte, or 0
|
|
|
|
uint32_t mSegmentEnd; // One byte past end of current buffer segment
|
|
|
|
uint32_t mSegmentNum; // Segment number containing read cursor
|
|
|
|
uint32_t mSegmentSize; // All segments, except the last, are of this size
|
|
|
|
uint32_t mLogicalCursor; // Logical offset into stream
|
|
|
|
nsresult mStatus;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
uint32_t SegNum(uint32_t aPosition) {
|
|
|
|
return aPosition >> mStorageStream->mSegmentSizeLog2;
|
|
|
|
}
|
|
|
|
uint32_t SegOffset(uint32_t aPosition) {
|
|
|
|
return aPosition & (mSegmentSize - 1);
|
|
|
|
}
|
2019-01-28 12:48:35 +03:00
|
|
|
|
|
|
|
template <typename M>
|
|
|
|
void SerializeInternal(InputStreamParams& aParams, bool aDelayedStart,
|
2019-02-05 01:50:51 +03:00
|
|
|
uint32_t aMaxSize, uint32_t* aSizeUsed, M* aManager);
|
1999-11-16 22:14:08 +03:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsStorageInputStream, nsIInputStream, nsISeekableStream,
|
2015-02-11 07:55:43 +03:00
|
|
|
nsITellableStream, nsIIPCSerializableInputStream,
|
|
|
|
nsICloneableInputStream)
|
1999-11-16 22:14:08 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageStream::NewInputStream(int32_t aStartingOffset,
|
|
|
|
nsIInputStream** aInputStream) {
|
|
|
|
if (NS_WARN_IF(!mSegmentedBuffer)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2007-03-09 15:28:55 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsStorageInputStream> inputStream =
|
2014-05-15 00:15:46 +04:00
|
|
|
new nsStorageInputStream(this, mSegmentSize);
|
1999-11-16 22:14:08 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
nsresult rv = inputStream->Seek(aStartingOffset);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-11-16 22:14:08 +03:00
|
|
|
|
2015-07-01 19:27:43 +03:00
|
|
|
inputStream.forget(aInputStream);
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_OK;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStorageInputStream::Close() {
|
2014-05-05 21:30:43 +04:00
|
|
|
mStatus = NS_BASE_STREAM_CLOSED;
|
|
|
|
return NS_OK;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageInputStream::Available(uint64_t* aAvailable) {
|
|
|
|
if (NS_FAILED(mStatus)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return mStatus;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2006-01-02 05:30:32 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
*aAvailable = mStorageStream->mLogicalLength - mLogicalCursor;
|
|
|
|
return NS_OK;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageInputStream::Read(char* aBuffer, uint32_t aCount, uint32_t* aNumRead) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return ReadSegments(NS_CopySegmentToBuffer, aBuffer, aCount, aNumRead);
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageInputStream::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
|
|
|
|
uint32_t aCount, uint32_t* aNumRead) {
|
2014-05-05 21:30:43 +04:00
|
|
|
*aNumRead = 0;
|
2014-05-15 00:15:46 +04:00
|
|
|
if (mStatus == NS_BASE_STREAM_CLOSED) {
|
2006-01-02 05:30:32 +03:00
|
|
|
return NS_OK;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
|
|
|
if (NS_FAILED(mStatus)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return mStatus;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
uint32_t count, availableInSegment, remainingCapacity, bytesConsumed;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
remainingCapacity = aCount;
|
|
|
|
while (remainingCapacity) {
|
|
|
|
availableInSegment = mSegmentEnd - mReadCursor;
|
|
|
|
if (!availableInSegment) {
|
|
|
|
uint32_t available = mStorageStream->mLogicalLength - mLogicalCursor;
|
2014-05-15 00:15:46 +04:00
|
|
|
if (!available) {
|
2014-05-05 21:30:43 +04:00
|
|
|
goto out;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2015-09-15 20:15:45 +03:00
|
|
|
// We have data in the stream, but if mSegmentEnd is zero, then we
|
|
|
|
// were likely constructed prior to any data being written into
|
|
|
|
// the stream. Therefore, if mSegmentEnd is non-zero, we should
|
|
|
|
// move into the next segment; otherwise, we should stay in this
|
|
|
|
// segment so our input state can be updated and we can properly
|
|
|
|
// perform the initial read.
|
|
|
|
if (mSegmentEnd > 0) {
|
|
|
|
mSegmentNum++;
|
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
mReadCursor = 0;
|
|
|
|
mSegmentEnd = XPCOM_MIN(mSegmentSize, available);
|
|
|
|
availableInSegment = mSegmentEnd;
|
|
|
|
}
|
2014-05-15 00:15:46 +04:00
|
|
|
const char* cur = mStorageStream->mSegmentedBuffer->GetSegment(mSegmentNum);
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
count = XPCOM_MIN(availableInSegment, remainingCapacity);
|
2014-05-15 00:15:46 +04:00
|
|
|
rv = aWriter(this, aClosure, cur + mReadCursor, aCount - remainingCapacity,
|
2014-08-25 23:17:15 +04:00
|
|
|
count, &bytesConsumed);
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_FAILED(rv) || (bytesConsumed == 0)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
break;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
remainingCapacity -= bytesConsumed;
|
|
|
|
mReadCursor += bytesConsumed;
|
|
|
|
mLogicalCursor += bytesConsumed;
|
2016-01-22 18:58:49 +03:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
*aNumRead = aCount - remainingCapacity;
|
|
|
|
|
|
|
|
bool isWriteInProgress = false;
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_FAILED(mStorageStream->GetWriteInProgress(&isWriteInProgress))) {
|
2014-05-05 21:30:43 +04:00
|
|
|
isWriteInProgress = false;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
if (*aNumRead == 0 && isWriteInProgress) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_BASE_STREAM_WOULD_BLOCK;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-08-22 11:03:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageInputStream::IsNonBlocking(bool* aNonBlocking) {
|
2014-05-05 21:30:43 +04:00
|
|
|
// TODO: This class should implement nsIAsyncInputStream so that callers
|
|
|
|
// have some way of dealing with NS_BASE_STREAM_WOULD_BLOCK errors.
|
|
|
|
|
|
|
|
*aNonBlocking = true;
|
|
|
|
return NS_OK;
|
2000-08-22 11:03:33 +04:00
|
|
|
}
|
|
|
|
|
2002-01-25 05:13:00 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsStorageInputStream::Seek(int32_t aWhence, int64_t aOffset) {
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_FAILED(mStatus)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return mStatus;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2006-01-02 05:30:32 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
int64_t pos = aOffset;
|
2002-01-25 05:13:00 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
switch (aWhence) {
|
2002-01-25 05:13:00 +03:00
|
|
|
case NS_SEEK_SET:
|
2014-05-05 21:30:43 +04:00
|
|
|
break;
|
2002-01-25 05:13:00 +03:00
|
|
|
case NS_SEEK_CUR:
|
2014-05-05 21:30:43 +04:00
|
|
|
pos += mLogicalCursor;
|
|
|
|
break;
|
2002-01-25 05:13:00 +03:00
|
|
|
case NS_SEEK_END:
|
2014-05-05 21:30:43 +04:00
|
|
|
pos += mStorageStream->mLogicalLength;
|
|
|
|
break;
|
2002-01-25 13:47:24 +03:00
|
|
|
default:
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected whence value");
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2014-05-15 00:15:46 +04:00
|
|
|
if (pos == int64_t(mLogicalCursor)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_OK;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2003-01-18 05:15:14 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
return Seek(pos);
|
2002-01-25 05:13:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsStorageInputStream::Tell(int64_t* aResult) {
|
|
|
|
if (NS_FAILED(mStatus)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return mStatus;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2006-01-02 05:30:32 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
*aResult = mLogicalCursor;
|
|
|
|
return NS_OK;
|
2002-01-25 05:13:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStorageInputStream::SetEOF() {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("nsStorageInputStream::SetEOF");
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2002-01-25 05:13:00 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsStorageInputStream::Seek(uint32_t aPosition) {
|
2014-05-05 21:30:43 +04:00
|
|
|
uint32_t length = mStorageStream->mLogicalLength;
|
2014-05-15 00:15:46 +04:00
|
|
|
if (aPosition > length) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
if (length == 0) {
|
1999-11-16 22:14:08 +03:00
|
|
|
return NS_OK;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
mSegmentNum = SegNum(aPosition);
|
|
|
|
mReadCursor = SegOffset(aPosition);
|
|
|
|
uint32_t available = length - aPosition;
|
|
|
|
mSegmentEnd = mReadCursor + XPCOM_MIN(mSegmentSize - mReadCursor, available);
|
|
|
|
mLogicalCursor = aPosition;
|
|
|
|
return NS_OK;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
|
|
|
|
2014-06-17 14:52:59 +04:00
|
|
|
void nsStorageInputStream::Serialize(InputStreamParams& aParams,
|
2019-01-28 12:48:35 +03:00
|
|
|
FileDescriptorArray&, bool aDelayedStart,
|
2019-02-05 01:50:51 +03:00
|
|
|
uint32_t aMaxSize, uint32_t* aSizeUsed,
|
2019-02-25 23:04:49 +03:00
|
|
|
mozilla::dom::ContentChild* aManager) {
|
2019-02-05 01:50:51 +03:00
|
|
|
SerializeInternal(aParams, aDelayedStart, aMaxSize, aSizeUsed, aManager);
|
2019-01-28 12:48:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsStorageInputStream::Serialize(InputStreamParams& aParams,
|
|
|
|
FileDescriptorArray&, bool aDelayedStart,
|
2019-02-05 01:50:51 +03:00
|
|
|
uint32_t aMaxSize, uint32_t* aSizeUsed,
|
2019-01-28 12:48:35 +03:00
|
|
|
mozilla::ipc::PBackgroundChild* aManager) {
|
2019-02-05 01:50:51 +03:00
|
|
|
SerializeInternal(aParams, aDelayedStart, aMaxSize, aSizeUsed, aManager);
|
2019-01-28 12:48:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsStorageInputStream::Serialize(InputStreamParams& aParams,
|
|
|
|
FileDescriptorArray&, bool aDelayedStart,
|
2019-02-05 01:50:51 +03:00
|
|
|
uint32_t aMaxSize, uint32_t* aSizeUsed,
|
2019-02-25 23:04:47 +03:00
|
|
|
mozilla::dom::ContentParent* aManager) {
|
2019-02-05 01:50:51 +03:00
|
|
|
SerializeInternal(aParams, aDelayedStart, aMaxSize, aSizeUsed, aManager);
|
2019-01-28 12:48:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsStorageInputStream::Serialize(
|
|
|
|
InputStreamParams& aParams, FileDescriptorArray&, bool aDelayedStart,
|
2019-02-05 01:50:51 +03:00
|
|
|
uint32_t aMaxSize, uint32_t* aSizeUsed,
|
2019-01-28 12:48:35 +03:00
|
|
|
mozilla::ipc::PBackgroundParent* aManager) {
|
2019-02-05 01:50:51 +03:00
|
|
|
SerializeInternal(aParams, aDelayedStart, aMaxSize, aSizeUsed, aManager);
|
2019-01-28 12:48:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename M>
|
|
|
|
void nsStorageInputStream::SerializeInternal(InputStreamParams& aParams,
|
2019-02-05 01:50:51 +03:00
|
|
|
bool aDelayedStart,
|
|
|
|
uint32_t aMaxSize,
|
|
|
|
uint32_t* aSizeUsed, M* aManager) {
|
|
|
|
MOZ_ASSERT(aSizeUsed);
|
|
|
|
*aSizeUsed = 0;
|
|
|
|
|
2019-01-28 12:48:35 +03:00
|
|
|
uint64_t remaining = 0;
|
|
|
|
nsresult rv = Available(&remaining);
|
2014-06-17 14:52:59 +04:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
|
2019-02-05 01:50:51 +03:00
|
|
|
if (remaining >= aMaxSize) {
|
2019-01-28 12:49:28 +03:00
|
|
|
InputStreamHelper::SerializeInputStreamAsPipe(this, aParams, aDelayedStart,
|
|
|
|
aManager);
|
|
|
|
return;
|
2019-01-28 12:48:35 +03:00
|
|
|
}
|
|
|
|
|
2019-02-05 01:50:51 +03:00
|
|
|
*aSizeUsed = remaining;
|
|
|
|
|
2019-01-28 12:48:35 +03:00
|
|
|
nsCString combined;
|
|
|
|
int64_t offset;
|
|
|
|
rv = Tell(&offset);
|
2014-06-17 14:52:59 +04:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
|
2018-08-30 14:09:27 +03:00
|
|
|
auto handle = combined.BulkWrite(remaining, 0, false, rv);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
|
2014-06-17 14:52:59 +04:00
|
|
|
uint32_t numRead = 0;
|
|
|
|
|
2018-08-30 14:09:27 +03:00
|
|
|
rv = Read(handle.Elements(), remaining, &numRead);
|
2014-06-17 14:52:59 +04:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2018-08-30 14:09:27 +03:00
|
|
|
|
2014-06-17 14:52:59 +04:00
|
|
|
MOZ_ASSERT(numRead == remaining);
|
2018-08-30 14:09:27 +03:00
|
|
|
handle.Finish(numRead, false);
|
2014-06-17 14:52:59 +04:00
|
|
|
|
|
|
|
rv = Seek(NS_SEEK_SET, offset);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
|
|
|
|
StringInputStreamParams params;
|
|
|
|
params.data() = combined;
|
|
|
|
aParams = params;
|
|
|
|
}
|
|
|
|
|
2014-08-25 23:17:15 +04:00
|
|
|
bool nsStorageInputStream::Deserialize(const InputStreamParams& aParams,
|
|
|
|
const FileDescriptorArray&) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"We should never attempt to deserialize a storage "
|
|
|
|
"input stream.");
|
2014-06-17 14:52:59 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-11 07:55:43 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStorageInputStream::GetCloneable(bool* aCloneableOut) {
|
|
|
|
*aCloneableOut = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStorageInputStream::Clone(nsIInputStream** aCloneOut) {
|
|
|
|
return mStorageStream->NewInputStream(mLogicalCursor, aCloneOut);
|
|
|
|
}
|
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
nsresult NS_NewStorageStream(uint32_t aSegmentSize, uint32_t aMaxSize,
|
|
|
|
nsIStorageStream** aResult) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsStorageStream> storageStream = new nsStorageStream();
|
2014-05-15 00:15:46 +04:00
|
|
|
nsresult rv = storageStream->Init(aSegmentSize, aMaxSize);
|
2014-05-05 21:30:43 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-07-01 19:27:43 +03:00
|
|
|
storageStream.forget(aResult);
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_OK;
|
1999-11-16 22:14:08 +03:00
|
|
|
}
|
2013-11-26 21:42:58 +04:00
|
|
|
|
|
|
|
// Undefine LOG, so that other .cpp files (or their includes) won't complain
|
|
|
|
// about it already being defined, when we build in unified mode.
|
|
|
|
#undef LOG
|