Source code

Revision control

Other Tools

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/. */
4
5
#ifndef CacheIndexIterator__h__
6
#define CacheIndexIterator__h__
7
8
#include "nsTArray.h"
9
#include "nsCOMPtr.h"
10
#include "nsAutoPtr.h"
11
#include "mozilla/SHA1.h"
12
13
namespace mozilla {
14
namespace net {
15
16
class CacheIndex;
17
struct CacheIndexRecord;
18
19
class CacheIndexIterator {
20
public:
21
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CacheIndexIterator)
22
23
CacheIndexIterator(CacheIndex* aIndex, bool aAddNew);
24
25
protected:
26
virtual ~CacheIndexIterator();
27
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);
33
34
// Closes the iterator. This means the iterator is removed from the list of
35
// iterators in CacheIndex.
36
nsresult Close();
37
38
protected:
39
friend class CacheIndex;
40
41
nsresult CloseInternal(nsresult aStatus);
42
43
bool ShouldBeNewAdded() { return mAddNew; }
44
virtual void AddRecord(CacheIndexRecord* aRecord);
45
bool RemoveRecord(CacheIndexRecord* aRecord);
46
bool ReplaceRecord(CacheIndexRecord* aOldRecord,
47
CacheIndexRecord* aNewRecord);
48
49
nsresult mStatus;
50
RefPtr<CacheIndex> mIndex;
51
nsTArray<CacheIndexRecord*> mRecords;
52
bool mAddNew;
53
};
54
55
} // namespace net
56
} // namespace mozilla
57
58
#endif