2001-02-23 16:18:01 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* ***** 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 nsCacheEntryDescriptor.h, released
|
|
|
|
* February 22, 2001.
|
|
|
|
*
|
|
|
|
* 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):
|
|
|
|
* Gordon Sheridan, 22-February-2001
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either 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 ***** */
|
2001-02-23 16:18:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef _nsCacheEntryDescriptor_h_
|
|
|
|
#define _nsCacheEntryDescriptor_h_
|
|
|
|
|
|
|
|
#include "nsICacheEntryDescriptor.h"
|
|
|
|
#include "nsCacheEntry.h"
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "nsIInputStream.h"
|
2001-03-07 12:27:36 +03:00
|
|
|
#include "nsIOutputStream.h"
|
2010-12-29 04:25:14 +03:00
|
|
|
#include "nsCacheService.h"
|
|
|
|
#include "nsIDiskCacheStreamInternal.h"
|
2001-02-23 16:18:01 +03:00
|
|
|
|
2001-03-21 01:42:03 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* nsCacheEntryDescriptor
|
|
|
|
*******************************************************************************/
|
2001-03-01 05:25:07 +03:00
|
|
|
class nsCacheEntryDescriptor :
|
2001-03-05 10:17:58 +03:00
|
|
|
public PRCList,
|
2001-03-07 12:27:36 +03:00
|
|
|
public nsICacheEntryDescriptor
|
2001-03-13 18:43:17 +03:00
|
|
|
{
|
2001-02-23 16:18:01 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICACHEENTRYDESCRIPTOR
|
2001-03-14 04:11:14 +03:00
|
|
|
NS_DECL_NSICACHEENTRYINFO
|
2001-02-23 16:18:01 +03:00
|
|
|
|
2001-02-24 04:36:11 +03:00
|
|
|
nsCacheEntryDescriptor(nsCacheEntry * entry, nsCacheAccessMode mode);
|
2001-02-23 16:18:01 +03:00
|
|
|
virtual ~nsCacheEntryDescriptor();
|
2001-03-13 18:43:17 +03:00
|
|
|
|
2001-03-01 22:52:06 +03:00
|
|
|
/**
|
|
|
|
* utility method to attempt changing data size of associated entry
|
|
|
|
*/
|
|
|
|
nsresult RequestDataSizeChange(PRInt32 deltaSize);
|
2001-03-13 18:43:17 +03:00
|
|
|
|
2001-03-01 22:52:06 +03:00
|
|
|
/**
|
|
|
|
* methods callbacks for nsCacheService
|
|
|
|
*/
|
2001-03-13 18:43:17 +03:00
|
|
|
nsCacheEntry * CacheEntry(void) { return mCacheEntry; }
|
|
|
|
void ClearCacheEntry(void) { mCacheEntry = nsnull; }
|
2001-03-01 22:52:06 +03:00
|
|
|
|
2010-12-29 04:25:14 +03:00
|
|
|
void CloseOutput(void)
|
|
|
|
{
|
|
|
|
if (mOutput) {
|
|
|
|
nsCOMPtr<nsIDiskCacheStreamInternal> tmp (do_QueryInterface(mOutput));
|
|
|
|
if (tmp)
|
|
|
|
tmp->CloseInternal();
|
|
|
|
else
|
|
|
|
mOutput->Close();
|
|
|
|
|
|
|
|
mOutput = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-07 12:27:36 +03:00
|
|
|
private:
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
|
2001-03-21 01:42:03 +03:00
|
|
|
/*************************************************************************
|
2003-01-18 05:15:14 +03:00
|
|
|
* input stream wrapper class -
|
2001-03-07 12:27:36 +03:00
|
|
|
*
|
2003-01-18 05:15:14 +03:00
|
|
|
* The input stream wrapper references the descriptor, but the descriptor
|
|
|
|
* doesn't need any references to the stream wrapper.
|
2001-03-21 01:42:03 +03:00
|
|
|
*************************************************************************/
|
2003-01-18 05:15:14 +03:00
|
|
|
class nsInputStreamWrapper : public nsIInputStream {
|
|
|
|
private:
|
|
|
|
nsCacheEntryDescriptor * mDescriptor;
|
|
|
|
nsCOMPtr<nsIInputStream> mInput;
|
|
|
|
PRUint32 mStartOffset;
|
|
|
|
PRBool mInitialized;
|
2001-03-07 12:27:36 +03:00
|
|
|
public:
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
2001-03-07 12:27:36 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsInputStreamWrapper(nsCacheEntryDescriptor * desc, PRUint32 off)
|
|
|
|
: mDescriptor(desc)
|
|
|
|
, mStartOffset(off)
|
|
|
|
, mInitialized(PR_FALSE)
|
|
|
|
{
|
|
|
|
NS_ADDREF(mDescriptor);
|
|
|
|
}
|
|
|
|
virtual ~nsInputStreamWrapper()
|
|
|
|
{
|
|
|
|
NS_RELEASE(mDescriptor);
|
|
|
|
}
|
2001-06-25 10:22:44 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
private:
|
|
|
|
nsresult LazyInit();
|
|
|
|
nsresult EnsureInit() { return mInitialized ? NS_OK : LazyInit(); }
|
|
|
|
};
|
|
|
|
friend class nsInputStreamWrapper;
|
2001-03-07 12:27:36 +03:00
|
|
|
|
|
|
|
|
2001-03-21 01:42:03 +03:00
|
|
|
/*************************************************************************
|
2001-03-07 12:27:36 +03:00
|
|
|
* output stream wrapper class -
|
|
|
|
*
|
2001-03-21 01:42:03 +03:00
|
|
|
* The output stream wrapper references the descriptor, but the descriptor
|
2003-01-18 05:15:14 +03:00
|
|
|
* doesn't need any references to the stream wrapper.
|
2001-03-21 01:42:03 +03:00
|
|
|
*************************************************************************/
|
2001-03-07 12:27:36 +03:00
|
|
|
class nsOutputStreamWrapper : public nsIOutputStream {
|
|
|
|
private:
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCacheEntryDescriptor * mDescriptor;
|
|
|
|
nsCOMPtr<nsIOutputStream> mOutput;
|
|
|
|
PRUint32 mStartOffset;
|
|
|
|
PRBool mInitialized;
|
2001-03-07 12:27:36 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_DECL_NSIOUTPUTSTREAM
|
2001-03-07 12:27:36 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsOutputStreamWrapper(nsCacheEntryDescriptor * desc, PRUint32 off)
|
|
|
|
: mDescriptor(desc)
|
|
|
|
, mStartOffset(off)
|
|
|
|
, mInitialized(PR_FALSE)
|
2001-03-07 12:27:36 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_ADDREF(mDescriptor); // owning ref
|
2001-03-07 12:27:36 +03:00
|
|
|
}
|
|
|
|
virtual ~nsOutputStreamWrapper()
|
2003-01-18 05:15:14 +03:00
|
|
|
{
|
|
|
|
// XXX _HACK_ the storage stream needs this!
|
|
|
|
Close();
|
2010-12-29 04:25:14 +03:00
|
|
|
{
|
|
|
|
nsCacheServiceAutoLock lock;
|
|
|
|
mDescriptor->mOutput = nsnull;
|
|
|
|
}
|
2001-03-07 12:27:36 +03:00
|
|
|
NS_RELEASE(mDescriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult LazyInit();
|
|
|
|
nsresult EnsureInit() { return mInitialized ? NS_OK : LazyInit(); }
|
2001-03-07 12:27:36 +03:00
|
|
|
nsresult OnWrite(PRUint32 count);
|
2003-01-18 05:15:14 +03:00
|
|
|
};
|
2001-03-07 12:27:36 +03:00
|
|
|
friend class nsOutputStreamWrapper;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* nsCacheEntryDescriptor data members
|
|
|
|
*/
|
|
|
|
nsCacheEntry * mCacheEntry; // we are a child of the entry
|
|
|
|
nsCacheAccessMode mAccessGranted;
|
2010-12-29 04:25:14 +03:00
|
|
|
nsIOutputStream * mOutput;
|
2001-02-23 16:18:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _nsCacheEntryDescriptor_h_
|