Landing initial version of SQL-based disk cache (NOT PART OF THE BUILD)

This commit is contained in:
darin%meer.net 2004-10-20 05:00:23 +00:00
Родитель c237a6d197
Коммит a628d4c8c8
11 изменённых файлов: 1513 добавлений и 41 удалений

9
netwerk/cache/src/Makefile.in поставляемый
Просмотреть файл

@ -1,3 +1,4 @@
# vim:set ts=8 sw=8 sts=8 noet:
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -66,6 +67,13 @@ CPPSRCS = \
$(NULL)
ifdef NECKO_DISK_CACHE
ifdef NECKO_DISK_CACHE_SQL
DEFINES += -DNECKO_DISK_CACHE_SQL
REQUIRES += storage
CPPSRCS += \
nsDiskCacheDeviceSQL.cpp \
$(NULL)
else
CPPSRCS += \
nsDiskCacheBinding.cpp \
nsDiskCacheBlockFile.cpp \
@ -75,6 +83,7 @@ CPPSRCS += \
nsDiskCacheStreams.cpp \
$(NULL)
endif
endif
include $(topsrcdir)/config/config.mk

9
netwerk/cache/src/nsCacheEntry.cpp поставляемый
Просмотреть файл

@ -129,15 +129,6 @@ nsCacheEntry::GetDeviceID()
}
nsresult
nsCacheEntry::GetData(nsISupports **result)
{
NS_ENSURE_ARG_POINTER(result);
NS_IF_ADDREF(*result = mData);
return NS_OK;
}
void
nsCacheEntry::TouchData()
{

6
netwerk/cache/src/nsCacheEntry.h поставляемый
Просмотреть файл

@ -102,8 +102,8 @@ public:
/**
* Data accessors
*/
nsresult GetData( nsISupports ** result);
void SetData( nsISupports * data) { mData = data; }
nsISupports *Data() { return mData; }
void SetData( nsISupports * data) { mData = data; }
PRUint32 DataSize() { return mDataSize; }
void SetDataSize( PRUint32 size) { mDataSize = size; }
@ -120,7 +120,7 @@ public:
const char * value) { return mMetaData.SetElement(key, value); }
nsresult VisitMetaDataElements( nsICacheMetaDataVisitor * visitor) { return mMetaData.VisitElements(visitor); }
nsresult FlattenMetaData(char * buffer, PRUint32 bufSize) { return mMetaData.FlattenMetaData(buffer, bufSize); }
nsresult UnflattenMetaData(char * buffer, PRUint32 bufSize) { return mMetaData.UnflattenMetaData(buffer, bufSize); }
nsresult UnflattenMetaData(const char * buffer, PRUint32 bufSize) { return mMetaData.UnflattenMetaData(buffer, bufSize); }
PRUint32 MetaDataSize() { return mMetaData.Size(); }
void TouchMetaData();

Просмотреть файл

@ -304,7 +304,8 @@ nsCacheEntryDescriptor::GetCacheElement(nsISupports ** result)
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM;
return mCacheEntry->GetData(result);
NS_IF_ADDREF(*result = mCacheEntry->Data());
return NS_OK;
}

4
netwerk/cache/src/nsCacheMetaData.cpp поставляемый
Просмотреть файл

@ -167,11 +167,11 @@ nsCacheMetaData::FlattenMetaData(char * buffer, PRUint32 bufSize)
}
nsresult
nsCacheMetaData::UnflattenMetaData(char * data, PRUint32 size)
nsCacheMetaData::UnflattenMetaData(const char * data, PRUint32 size)
{
if (size == 0) return NS_OK;
char* limit = data + size;
const char* limit = data + size;
MetaElement * last = nsnull;
while (data < limit) {

2
netwerk/cache/src/nsCacheMetaData.h поставляемый
Просмотреть файл

@ -65,7 +65,7 @@ public:
nsresult FlattenMetaData(char * buffer, PRUint32 bufSize);
nsresult UnflattenMetaData(char * buffer, PRUint32 bufSize);
nsresult UnflattenMetaData(const char * buffer, PRUint32 bufSize);
nsresult VisitElements(nsICacheMetaDataVisitor * visitor);

16
netwerk/cache/src/nsCacheService.cpp поставляемый
Просмотреть файл

@ -46,11 +46,16 @@
#include "nsCacheEntry.h"
#include "nsCacheEntryDescriptor.h"
#include "nsCacheDevice.h"
#include "nsDiskCacheDevice.h"
#include "nsMemoryCacheDevice.h"
#include "nsICacheVisitor.h"
#include "nsCRT.h"
#ifdef NECKO_DISK_CACHE_SQL
#include "nsDiskCacheDeviceSQL.h"
#else
#include "nsDiskCacheDevice.h"
#endif
#include "nsAutoLock.h"
#include "nsIEventQueue.h"
#include "nsIObserverService.h"
@ -341,10 +346,11 @@ nsCacheProfilePrefObserver::ReadPrefs(nsIPrefBranch* branch)
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(directory));
#if DEBUG
} else if (NS_FAILED(rv)) {
// use current process directory during development
rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR,
getter_AddRefs(directory));
if (NS_FAILED(rv)) {
// use current process directory during development
rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR,
getter_AddRefs(directory));
}
#endif
}
if (directory)

15
netwerk/cache/src/nsDiskCacheBinding.cpp поставляемый
Просмотреть файл

@ -111,11 +111,7 @@ ClearEntry(PLDHashTable * /* table */,
nsDiskCacheBinding *
GetCacheEntryBinding(nsCacheEntry * entry)
{
nsCOMPtr<nsISupports> data;
nsresult rv = entry->GetData(getter_AddRefs(data));
if (NS_FAILED(rv)) return nsnull;
return (nsDiskCacheBinding *)data.get();
return (nsDiskCacheBinding *) entry->Data();
}
@ -219,10 +215,9 @@ nsDiskCacheBindery::CreateBinding(nsCacheEntry * entry,
nsDiskCacheRecord * record)
{
NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
nsCOMPtr<nsISupports> data;
nsresult rv = entry->GetData(getter_AddRefs(data));
if (NS_FAILED(rv) || data) {
NS_ASSERTION(!data, "cache entry already has bind data");
nsCOMPtr<nsISupports> data = entry->Data();
if (data) {
NS_ERROR("cache entry already has bind data");
return nsnull;
}
@ -233,7 +228,7 @@ nsDiskCacheBindery::CreateBinding(nsCacheEntry * entry,
entry->SetData(binding);
// add binding to collision detection system
rv = AddBinding(binding);
nsresult rv = AddBinding(binding);
if (NS_FAILED(rv)) {
entry->SetData(nsnull);
return nsnull;

1355
netwerk/cache/src/nsDiskCacheDeviceSQL.cpp поставляемый Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

121
netwerk/cache/src/nsDiskCacheDeviceSQL.h поставляемый Normal file
Просмотреть файл

@ -0,0 +1,121 @@
/* vim:set ts=2 sw=2 sts=2 et cin: */
/* ***** 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.
*
* The Initial Developer of the Original Code is IBM Corporation.
* Portions created by IBM Corporation are Copyright (C) 2004
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* 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 ***** */
#ifndef nsDiskCacheDeviceSQL_h__
#define nsDiskCacheDeviceSQL_h__
#include "nsCacheDevice.h"
#include "nsILocalFile.h"
#include "nsIObserver.h"
#include "mozIStorageConnection.h"
#include "nsCOMPtr.h"
class nsDiskCacheDevice : public nsCacheDevice
{
public:
nsDiskCacheDevice();
/**
* nsCacheDevice methods
*/
virtual ~nsDiskCacheDevice();
virtual nsresult Init();
virtual nsresult Shutdown();
virtual const char * GetDeviceID(void);
virtual nsCacheEntry * FindEntry(nsCString * key);
virtual nsresult DeactivateEntry(nsCacheEntry * entry);
virtual nsresult BindEntry(nsCacheEntry * entry);
virtual void DoomEntry( nsCacheEntry * entry );
virtual nsresult OpenInputStreamForEntry(nsCacheEntry * entry,
nsCacheAccessMode mode,
PRUint32 offset,
nsIInputStream ** result);
virtual nsresult OpenOutputStreamForEntry(nsCacheEntry * entry,
nsCacheAccessMode mode,
PRUint32 offset,
nsIOutputStream ** result);
virtual nsresult GetFileForEntry(nsCacheEntry * entry,
nsIFile ** result);
virtual nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
virtual nsresult Visit(nsICacheVisitor * visitor);
virtual nsresult EvictEntries(const char * clientID);
/**
* Preference accessors
*/
void SetCacheParentDirectory(nsILocalFile * parentDir);
void SetCapacity(PRUint32 capacity);
nsILocalFile * CacheDirectory() { return mCacheDirectory; }
PRUint32 CacheCapacity() { return mCacheCapacity; }
PRUint32 CacheSize();
PRUint32 EntryCount();
private:
PRBool Initialized() { return mDB != nsnull; }
nsresult EvictDiskCacheEntries(PRUint32 targetCapacity);
nsresult UpdateEntry(nsCacheEntry *entry);
nsresult UpdateEntrySize(nsCacheEntry *entry, PRUint32 newSize);
nsresult DeleteEntry(nsCacheEntry *entry, PRBool deleteData);
nsresult DeleteData(nsCacheEntry *entry);
nsresult EnableEvictionObserver();
nsresult DisableEvictionObserver();
#if 0
// sqlite function for observing DELETE events
static void EvictionObserver(struct sqlite3_context *, int, struct Mem **);
#endif
nsCOMPtr<mozIStorageConnection> mDB;
nsCOMPtr<nsILocalFile> mCacheDirectory;
PRUint32 mCacheCapacity; // XXX need soft/hard limits, currentTotal
PRInt32 mDeltaCounter;
};
#endif // nsDiskCacheDeviceSQL_h__

14
netwerk/cache/src/nsMemoryCacheDevice.cpp поставляемый
Просмотреть файл

@ -235,13 +235,10 @@ nsMemoryCacheDevice::OpenInputStreamForEntry( nsCacheEntry * entry,
NS_ENSURE_ARG_POINTER(entry);
NS_ENSURE_ARG_POINTER(result);
nsCOMPtr<nsISupports> data;
nsCOMPtr<nsIStorageStream> storage;
nsresult rv;
nsresult rv = entry->GetData(getter_AddRefs(data));
if (NS_FAILED(rv))
return rv;
nsISupports *data = entry->Data();
if (data) {
storage = do_QueryInterface(data, &rv);
if (NS_FAILED(rv))
@ -267,13 +264,10 @@ nsMemoryCacheDevice::OpenOutputStreamForEntry( nsCacheEntry * entry,
NS_ENSURE_ARG_POINTER(entry);
NS_ENSURE_ARG_POINTER(result);
nsCOMPtr<nsISupports> data;
nsCOMPtr<nsIStorageStream> storage;
nsresult rv;
nsresult rv = entry->GetData(getter_AddRefs(data));
if (NS_FAILED(rv))
return rv;
nsISupports *data = entry->Data();
if (data) {
storage = do_QueryInterface(data, &rv);
if (NS_FAILED(rv))