1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef CacheIndexIterator__h__
6 #define CacheIndexIterator__h__
10 #include "mozilla/SHA1.h"
11 #include "mozilla/StaticMutex.h"
17 class CacheIndexRecordWrapper
;
19 class CacheIndexIterator
{
21 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CacheIndexIterator
)
23 CacheIndexIterator(CacheIndex
* aIndex
, bool aAddNew
);
26 virtual ~CacheIndexIterator();
29 // Returns a hash of a next entry. If there is no entry NS_ERROR_NOT_AVAILABLE
30 // is returned and the iterator is closed. Other error is returned when the
31 // iterator is closed for other reason, e.g. shutdown.
32 nsresult
GetNextHash(SHA1Sum::Hash
* aHash
);
34 // Closes the iterator. This means the iterator is removed from the list of
35 // iterators in CacheIndex.
39 friend class CacheIndex
;
41 nsresult
CloseInternal(nsresult aStatus
);
43 bool ShouldBeNewAdded() { return mAddNew
; }
44 virtual void AddRecord(CacheIndexRecordWrapper
* aRecord
,
45 const StaticMutexAutoLock
& aProofOfLock
);
46 bool RemoveRecord(CacheIndexRecordWrapper
* aRecord
,
47 const StaticMutexAutoLock
& aProofOfLock
);
48 bool ReplaceRecord(CacheIndexRecordWrapper
* aOldRecord
,
49 CacheIndexRecordWrapper
* aNewRecord
,
50 const StaticMutexAutoLock
& aProofOfLock
);
51 void ClearRecords(const StaticMutexAutoLock
& aProofOfLock
);
54 RefPtr
<CacheIndex
> mIndex
;
55 nsTArray
<RefPtr
<CacheIndexRecordWrapper
>> mRecords
;
60 } // namespace mozilla