michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef CacheIndexIterator__h__ michael@0: #define CacheIndexIterator__h__ michael@0: michael@0: #include "nsTArray.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "mozilla/SHA1.h" michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: class CacheIndex; michael@0: struct CacheIndexRecord; michael@0: michael@0: class CacheIndexIterator michael@0: { michael@0: public: michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CacheIndexIterator) michael@0: michael@0: CacheIndexIterator(CacheIndex *aIndex, bool aAddNew); michael@0: virtual ~CacheIndexIterator(); michael@0: michael@0: // Returns a hash of a next entry. If there is no entry NS_ERROR_NOT_AVAILABLE michael@0: // is returned and the iterator is closed. Other error is returned when the michael@0: // iterator is closed for other reason, e.g. shutdown. michael@0: nsresult GetNextHash(SHA1Sum::Hash *aHash); michael@0: michael@0: // Closes the iterator. This means the iterator is removed from the list of michael@0: // iterators in CacheIndex. michael@0: nsresult Close(); michael@0: michael@0: protected: michael@0: friend class CacheIndex; michael@0: michael@0: nsresult CloseInternal(nsresult aStatus); michael@0: michael@0: bool ShouldBeNewAdded() { return mAddNew; } michael@0: virtual void AddRecord(CacheIndexRecord *aRecord); michael@0: virtual void AddRecords(const nsTArray &aRecords); michael@0: bool RemoveRecord(CacheIndexRecord *aRecord); michael@0: bool ReplaceRecord(CacheIndexRecord *aOldRecord, michael@0: CacheIndexRecord *aNewRecord); michael@0: michael@0: nsresult mStatus; michael@0: nsRefPtr mIndex; michael@0: nsTArray mRecords; michael@0: bool mAddNew; michael@0: }; michael@0: michael@0: } // net michael@0: } // mozilla michael@0: michael@0: #endif