|
1 //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef nsUrlClassifierPrefixSet_h_ |
|
8 #define nsUrlClassifierPrefixSet_h_ |
|
9 |
|
10 #include "nsISupportsUtils.h" |
|
11 #include "nsID.h" |
|
12 #include "nsIFile.h" |
|
13 #include "nsIMemoryReporter.h" |
|
14 #include "nsIMutableArray.h" |
|
15 #include "nsIUrlClassifierPrefixSet.h" |
|
16 #include "nsTArray.h" |
|
17 #include "nsToolkitCompsCID.h" |
|
18 #include "mozilla/MemoryReporting.h" |
|
19 #include "mozilla/Mutex.h" |
|
20 #include "mozilla/CondVar.h" |
|
21 #include "mozilla/FileUtils.h" |
|
22 |
|
23 class nsUrlClassifierPrefixSet |
|
24 : public nsIUrlClassifierPrefixSet |
|
25 , public nsIMemoryReporter |
|
26 { |
|
27 public: |
|
28 nsUrlClassifierPrefixSet(); |
|
29 virtual ~nsUrlClassifierPrefixSet(); |
|
30 |
|
31 NS_IMETHOD Init(const nsACString& aName); |
|
32 NS_IMETHOD SetPrefixes(const uint32_t* aArray, uint32_t aLength); |
|
33 NS_IMETHOD GetPrefixes(uint32_t* aCount, uint32_t** aPrefixes); |
|
34 NS_IMETHOD Contains(uint32_t aPrefix, bool* aFound); |
|
35 NS_IMETHOD IsEmpty(bool* aEmpty); |
|
36 NS_IMETHOD LoadFromFile(nsIFile* aFile); |
|
37 NS_IMETHOD StoreToFile(nsIFile* aFile); |
|
38 |
|
39 NS_DECL_THREADSAFE_ISUPPORTS |
|
40 NS_DECL_NSIMEMORYREPORTER |
|
41 |
|
42 // Return the estimated size of the set on disk and in memory, in bytes. |
|
43 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf); |
|
44 |
|
45 protected: |
|
46 static const uint32_t DELTAS_LIMIT = 100; |
|
47 static const uint32_t MAX_INDEX_DIFF = (1 << 16); |
|
48 static const uint32_t PREFIXSET_VERSION_MAGIC = 1; |
|
49 |
|
50 nsresult MakePrefixSet(const uint32_t* aArray, uint32_t aLength); |
|
51 uint32_t BinSearch(uint32_t start, uint32_t end, uint32_t target); |
|
52 nsresult LoadFromFd(mozilla::AutoFDClose& fileFd); |
|
53 nsresult StoreToFd(mozilla::AutoFDClose& fileFd); |
|
54 |
|
55 // boolean indicating whether |setPrefixes| has been |
|
56 // called with a non-empty array. |
|
57 bool mHasPrefixes; |
|
58 // the prefix for each index. |
|
59 FallibleTArray<uint32_t> mIndexPrefixes; |
|
60 // the value corresponds to the beginning of the run |
|
61 // (an index in |_deltas|) for the index |
|
62 FallibleTArray<uint32_t> mIndexStarts; |
|
63 // array containing deltas from indices. |
|
64 FallibleTArray<uint16_t> mDeltas; |
|
65 |
|
66 nsCString mMemoryReportPath; |
|
67 }; |
|
68 |
|
69 #endif |