no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / netwerk / cache2 / CacheIndexIterator.h
blob2f9aedb659a328bf79264fb35f4e9d169b6d6f3c
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__
8 #include "nsTArray.h"
9 #include "nsCOMPtr.h"
10 #include "mozilla/SHA1.h"
11 #include "mozilla/StaticMutex.h"
13 namespace mozilla {
14 namespace net {
16 class CacheIndex;
17 class CacheIndexRecordWrapper;
19 class CacheIndexIterator {
20 public:
21 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CacheIndexIterator)
23 CacheIndexIterator(CacheIndex* aIndex, bool aAddNew);
25 protected:
26 virtual ~CacheIndexIterator();
28 public:
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.
36 nsresult Close();
38 protected:
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);
53 nsresult mStatus;
54 RefPtr<CacheIndex> mIndex;
55 nsTArray<RefPtr<CacheIndexRecordWrapper>> mRecords;
56 bool mAddNew;
59 } // namespace net
60 } // namespace mozilla
62 #endif