2014-04-10 14:47:20 +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/. */
|
|
|
|
|
|
|
|
#ifndef CacheIndexIterator__h__
|
|
|
|
#define CacheIndexIterator__h__
|
|
|
|
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "mozilla/SHA1.h"
|
2021-06-22 00:18:38 +03:00
|
|
|
#include "mozilla/StaticMutex.h"
|
2014-04-10 14:47:20 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
class CacheIndex;
|
2021-05-18 00:16:33 +03:00
|
|
|
class CacheIndexRecordWrapper;
|
2014-04-10 14:47:20 +04:00
|
|
|
|
|
|
|
class CacheIndexIterator {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CacheIndexIterator)
|
|
|
|
|
|
|
|
CacheIndexIterator(CacheIndex* aIndex, bool aAddNew);
|
2014-06-20 15:08:24 +04:00
|
|
|
|
|
|
|
protected:
|
2014-04-10 14:47:20 +04:00
|
|
|
virtual ~CacheIndexIterator();
|
|
|
|
|
2014-06-20 15:08:24 +04:00
|
|
|
public:
|
2014-04-10 14:47:20 +04:00
|
|
|
// Returns a hash of a next entry. If there is no entry NS_ERROR_NOT_AVAILABLE
|
|
|
|
// is returned and the iterator is closed. Other error is returned when the
|
|
|
|
// iterator is closed for other reason, e.g. shutdown.
|
|
|
|
nsresult GetNextHash(SHA1Sum::Hash* aHash);
|
|
|
|
|
|
|
|
// Closes the iterator. This means the iterator is removed from the list of
|
|
|
|
// iterators in CacheIndex.
|
|
|
|
nsresult Close();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class CacheIndex;
|
|
|
|
|
|
|
|
nsresult CloseInternal(nsresult aStatus);
|
|
|
|
|
|
|
|
bool ShouldBeNewAdded() { return mAddNew; }
|
2021-06-22 00:18:38 +03:00
|
|
|
virtual void AddRecord(CacheIndexRecordWrapper* aRecord,
|
|
|
|
const StaticMutexAutoLock& aProofOfLock);
|
|
|
|
bool RemoveRecord(CacheIndexRecordWrapper* aRecord,
|
|
|
|
const StaticMutexAutoLock& aProofOfLock);
|
2021-05-18 00:16:33 +03:00
|
|
|
bool ReplaceRecord(CacheIndexRecordWrapper* aOldRecord,
|
2021-06-22 00:18:38 +03:00
|
|
|
CacheIndexRecordWrapper* aNewRecord,
|
|
|
|
const StaticMutexAutoLock& aProofOfLock);
|
|
|
|
void ClearRecords(const StaticMutexAutoLock& aProofOfLock);
|
2014-04-10 14:47:20 +04:00
|
|
|
|
|
|
|
nsresult mStatus;
|
2015-10-22 13:11:00 +03:00
|
|
|
RefPtr<CacheIndex> mIndex;
|
2021-05-18 00:16:33 +03:00
|
|
|
nsTArray<RefPtr<CacheIndexRecordWrapper>> mRecords;
|
2014-04-10 14:47:20 +04:00
|
|
|
bool mAddNew;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
2014-04-10 14:47:20 +04:00
|
|
|
|
|
|
|
#endif
|