gecko-dev/network/cache/nu/public/nsCacheManager.h

169 строки
3.7 KiB
C
Исходник Обычный вид История

1998-05-02 06:29:42 +04:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _CacheManager_H_
#define _CacheManager_H_
/*
* nsCacheManager
1998-06-25 09:44:21 +04:00
* Design and original implementation
* by Gagan Saksena 02/02/98
1998-05-02 06:29:42 +04:00
*
*/
#if 0
# include "nsISupports.h"
1998-05-02 06:29:42 +04:00
#endif
#include "prlog.h"
#include "nsMonitorable.h"
1998-05-02 06:29:42 +04:00
#include "nsCacheModule.h"
#include "nsCacheObject.h"
1998-05-07 00:29:20 +04:00
class nsMemModule;
class nsDiskModule;
class nsCachePref;
class nsCacheBkgThd;
1998-05-07 00:29:20 +04:00
class nsCacheManager : public nsMonitorable //: public nsISupports
1998-05-02 06:29:42 +04:00
{
1998-05-02 06:29:42 +04:00
public:
//Reserved modules
enum modules
{
MEM =0,
DISK=1
};
nsCacheManager();
~nsCacheManager();
1998-05-02 06:29:42 +04:00
PRInt32 AddModule(nsCacheModule* i_cacheModule);
// InsertModule
PRBool Contains(const char* i_url) const;
1998-05-07 00:29:20 +04:00
/* Number of modules in the cache manager */
PRInt16 Entries() const;
1998-05-07 00:29:20 +04:00
/* Singleton */
static nsCacheManager* GetInstance();
1998-05-07 00:29:20 +04:00
nsCacheObject* GetObj(const char* i_url) const;
nsCacheModule* GetModule(PRInt16 i_index) const;
nsMemModule* GetMemModule() const;
nsDiskModule* GetDiskModule() const;
1998-05-07 00:29:20 +04:00
PRBool IsOffline(void) const;
1998-05-07 00:29:20 +04:00
void Offline(PRBool bSet);
PRBool Remove(const char* i_url);
const char* Trace() const;
1998-05-07 00:29:20 +04:00
1998-05-05 04:37:53 +04:00
/* Performance measure- microseconds */
PRUint32 WorstCaseTime(void) const;
1998-05-07 00:29:20 +04:00
1998-05-02 06:29:42 +04:00
protected:
PRBool ContainsExactly(const char* i_url) const;
void Init();
nsCacheModule* LastModule() const;
//PRBool Lock(void);
//void Unlock(void);
/*
class MgrMonitor
{
public:
MgrMonitor() { nsCacheManager::GetInstance()->Lock();}
~MgrMonitor() { nsCacheManager::GetInstance()->Unlock();}
};
friend MgrMonitor;
*/
1998-05-02 06:29:42 +04:00
private:
nsCacheModule* m_pFirstModule;
PRMonitor* m_pMonitor;
1998-05-02 06:29:42 +04:00
nsCacheManager(const nsCacheManager& cm);
nsCacheManager& operator=(const nsCacheManager& cm);
nsCacheBkgThd* m_pBkgThd;
PRBool m_bOffline;
1998-05-02 06:29:42 +04:00
};
inline
nsDiskModule* nsCacheManager::GetDiskModule() const
{
PR_ASSERT(m_pFirstModule && m_pFirstModule->NextModule());
return (m_pFirstModule) ? (nsDiskModule*) m_pFirstModule->NextModule() : NULL;
}
inline
nsMemModule* nsCacheManager::GetMemModule() const
{
PR_ASSERT(m_pFirstModule);
return (nsMemModule*) m_pFirstModule;
}
inline
PRBool nsCacheManager::IsOffline(void) const
{
return m_bOffline;
}
/*
inline
PRBool nsCacheManager::Lock(void)
{
if (!m_pMonitor)
{
m_pMonitor = PR_NewMonitor();
if (!m_pMonitor)
return PR_FALSE;
}
PR_EnterMonitor(m_pMonitor);
return PR_TRUE;
}
*/
inline
void nsCacheManager::Offline(PRBool i_bSet)
{
m_bOffline = i_bSet;
}
/*
inline
void nsCacheManager::Unlock(void)
{
PR_ASSERT(m_pMonitor);
if (m_pMonitor)
PR_ExitMonitor(m_pMonitor);
}
*/
1998-05-02 06:29:42 +04:00
#endif