Bug 669410 - Make the url-classifier PrefixSet persistent on startup/shutdown. r=tony

This commit is contained in:
Gian-Carlo Pascutto
2011-09-08 22:16:59 +02:00
parent 810b6cbcef
commit bf8f39caba
5 changed files with 216 additions and 24 deletions

View File

@@ -43,10 +43,12 @@
#include "nsISupportsUtils.h"
#include "nsID.h"
#include "nsIFile.h"
#include "nsIUrlClassifierPrefixSet.h"
#include "nsToolkitCompsCID.h"
#include "mozilla/Mutex.h"
#include "mozilla/CondVar.h"
#include "mozilla/FileUtils.h"
class nsUrlClassifierPrefixSet : public nsIUrlClassifierPrefixSet
{
@@ -57,7 +59,7 @@ public:
// Can send an empty Array to clean the tree
NS_IMETHOD SetPrefixes(const PRUint32* aArray, PRUint32 aLength);
// Given prefixes must be in sorted order and bigger than
// anything currently in the Prefix Tree
// anything currently in the Prefix Set
NS_IMETHOD AddPrefixes(const PRUint32* aArray, PRUint32 aLength);
// Does the PrefixSet contain this prefix? not thread-safe
NS_IMETHOD Contains(PRUint32 aPrefix, PRBool* aFound);
@@ -66,17 +68,23 @@ public:
// if not set, we will return in aReady whether we were ready or not
NS_IMETHOD Probe(PRUint32 aPrefix, PRBool* aReady, PRBool* aFound);
NS_IMETHOD EstimateSize(PRUint32* aSize);
NS_IMETHOD IsEmpty(PRBool * aEmpty);
NS_IMETHOD LoadFromFile(nsIFile * aFile);
NS_IMETHOD StoreToFile(nsIFile * aFile);
NS_DECL_ISUPPORTS
protected:
static const PRUint32 DELTAS_LIMIT = 100;
static const PRUint32 MAX_INDEX_DIFF = (1 << 16);
static const PRUint32 PREFIXSET_VERSION_MAGIC = 1;
mozilla::Mutex mPrefixTreeLock;
mozilla::CondVar mTreeIsReady;
mozilla::Mutex mPrefixSetLock;
mozilla::CondVar mSetIsReady;
PRUint32 BinSearch(PRUint32 start, PRUint32 end, PRUint32 target);
nsresult LoadFromFd(mozilla::AutoFDClose & fileFd);
nsresult StoreToFd(mozilla::AutoFDClose & fileFd);
// boolean indicating whether |setPrefixes| has been
// called with a non-empty array.