michael@0: //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ 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 nsUrlClassifierPrefixSet_h_ michael@0: #define nsUrlClassifierPrefixSet_h_ michael@0: michael@0: #include "nsISupportsUtils.h" michael@0: #include "nsID.h" michael@0: #include "nsIFile.h" michael@0: #include "nsIMemoryReporter.h" michael@0: #include "nsIMutableArray.h" michael@0: #include "nsIUrlClassifierPrefixSet.h" michael@0: #include "nsTArray.h" michael@0: #include "nsToolkitCompsCID.h" michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "mozilla/Mutex.h" michael@0: #include "mozilla/CondVar.h" michael@0: #include "mozilla/FileUtils.h" michael@0: michael@0: class nsUrlClassifierPrefixSet michael@0: : public nsIUrlClassifierPrefixSet michael@0: , public nsIMemoryReporter michael@0: { michael@0: public: michael@0: nsUrlClassifierPrefixSet(); michael@0: virtual ~nsUrlClassifierPrefixSet(); michael@0: michael@0: NS_IMETHOD Init(const nsACString& aName); michael@0: NS_IMETHOD SetPrefixes(const uint32_t* aArray, uint32_t aLength); michael@0: NS_IMETHOD GetPrefixes(uint32_t* aCount, uint32_t** aPrefixes); michael@0: NS_IMETHOD Contains(uint32_t aPrefix, bool* aFound); michael@0: NS_IMETHOD IsEmpty(bool* aEmpty); michael@0: NS_IMETHOD LoadFromFile(nsIFile* aFile); michael@0: NS_IMETHOD StoreToFile(nsIFile* aFile); michael@0: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIMEMORYREPORTER michael@0: michael@0: // Return the estimated size of the set on disk and in memory, in bytes. michael@0: size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf); michael@0: michael@0: protected: michael@0: static const uint32_t DELTAS_LIMIT = 100; michael@0: static const uint32_t MAX_INDEX_DIFF = (1 << 16); michael@0: static const uint32_t PREFIXSET_VERSION_MAGIC = 1; michael@0: michael@0: nsresult MakePrefixSet(const uint32_t* aArray, uint32_t aLength); michael@0: uint32_t BinSearch(uint32_t start, uint32_t end, uint32_t target); michael@0: nsresult LoadFromFd(mozilla::AutoFDClose& fileFd); michael@0: nsresult StoreToFd(mozilla::AutoFDClose& fileFd); michael@0: michael@0: // boolean indicating whether |setPrefixes| has been michael@0: // called with a non-empty array. michael@0: bool mHasPrefixes; michael@0: // the prefix for each index. michael@0: FallibleTArray mIndexPrefixes; michael@0: // the value corresponds to the beginning of the run michael@0: // (an index in |_deltas|) for the index michael@0: FallibleTArray mIndexStarts; michael@0: // array containing deltas from indices. michael@0: FallibleTArray mDeltas; michael@0: michael@0: nsCString mMemoryReportPath; michael@0: }; michael@0: michael@0: #endif