2011-09-08 13:15:08 -07:00
|
|
|
//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-09-08 13:15:08 -07:00
|
|
|
|
|
|
|
#ifndef nsUrlClassifierPrefixSet_h_
|
|
|
|
#define nsUrlClassifierPrefixSet_h_
|
|
|
|
|
|
|
|
#include "nsISupportsUtils.h"
|
|
|
|
#include "nsID.h"
|
2011-09-08 13:16:59 -07:00
|
|
|
#include "nsIFile.h"
|
2011-09-08 13:15:08 -07:00
|
|
|
#include "nsIUrlClassifierPrefixSet.h"
|
2011-11-13 02:25:48 -08:00
|
|
|
#include "nsIMemoryReporter.h"
|
2011-09-08 13:15:08 -07:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2011-09-08 13:15:27 -07:00
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
#include "mozilla/CondVar.h"
|
2011-09-08 13:16:59 -07:00
|
|
|
#include "mozilla/FileUtils.h"
|
2011-09-08 13:15:08 -07:00
|
|
|
|
2011-11-13 02:25:48 -08:00
|
|
|
class nsPrefixSetReporter;
|
|
|
|
|
2011-09-08 13:15:08 -07:00
|
|
|
class nsUrlClassifierPrefixSet : public nsIUrlClassifierPrefixSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsUrlClassifierPrefixSet();
|
2011-11-13 02:25:48 -08:00
|
|
|
virtual ~nsUrlClassifierPrefixSet();
|
2011-09-08 13:15:08 -07:00
|
|
|
|
2011-09-08 13:15:27 -07:00
|
|
|
NS_IMETHOD SetPrefixes(const PRUint32* aArray, PRUint32 aLength);
|
2012-04-19 22:46:47 -07:00
|
|
|
NS_IMETHOD Probe(PRUint32 aPrefix, PRUint32 aKey, bool* aReady, bool* aFound);
|
|
|
|
NS_IMETHOD IsEmpty(bool * aEmpty);
|
2011-09-08 13:17:25 -07:00
|
|
|
NS_IMETHOD LoadFromFile(nsIFile* aFile);
|
|
|
|
NS_IMETHOD StoreToFile(nsIFile* aFile);
|
2012-04-19 22:46:47 -07:00
|
|
|
NS_IMETHOD GetKey(PRUint32* aKey);
|
2011-09-08 13:15:08 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2011-12-13 20:54:18 -08:00
|
|
|
// Return the estimated size of the set on disk and in memory,
|
|
|
|
// in bytes
|
|
|
|
size_t SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf);
|
|
|
|
|
2011-09-08 13:15:08 -07:00
|
|
|
protected:
|
|
|
|
static const PRUint32 DELTAS_LIMIT = 100;
|
|
|
|
static const PRUint32 MAX_INDEX_DIFF = (1 << 16);
|
2011-09-08 13:16:59 -07:00
|
|
|
static const PRUint32 PREFIXSET_VERSION_MAGIC = 1;
|
2011-09-08 13:15:08 -07:00
|
|
|
|
2011-09-08 13:16:59 -07:00
|
|
|
mozilla::Mutex mPrefixSetLock;
|
|
|
|
mozilla::CondVar mSetIsReady;
|
2011-11-13 02:25:48 -08:00
|
|
|
nsRefPtr<nsPrefixSetReporter> mReporter;
|
2011-09-08 13:15:27 -07:00
|
|
|
|
2012-01-10 08:09:32 -08:00
|
|
|
nsresult Contains(PRUint32 aPrefix, bool* aFound);
|
|
|
|
nsresult MakePrefixSet(const PRUint32* aArray, PRUint32 aLength);
|
2011-09-08 13:15:08 -07:00
|
|
|
PRUint32 BinSearch(PRUint32 start, PRUint32 end, PRUint32 target);
|
2012-04-19 22:46:47 -07:00
|
|
|
nsresult LoadFromFd(mozilla::AutoFDClose & fileFd);
|
|
|
|
nsresult StoreToFd(mozilla::AutoFDClose & fileFd);
|
|
|
|
nsresult InitKey();
|
2011-09-08 13:15:08 -07:00
|
|
|
|
2011-09-08 13:15:27 -07:00
|
|
|
// boolean indicating whether |setPrefixes| has been
|
2011-09-08 13:15:08 -07:00
|
|
|
// called with a non-empty array.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHasPrefixes;
|
2012-04-19 22:46:47 -07:00
|
|
|
// key used to randomize hash collisions
|
|
|
|
PRUint32 mRandomKey;
|
2011-09-08 13:15:08 -07:00
|
|
|
// the prefix for each index.
|
2012-01-10 08:09:32 -08:00
|
|
|
FallibleTArray<PRUint32> mIndexPrefixes;
|
2011-09-08 13:15:08 -07:00
|
|
|
// the value corresponds to the beginning of the run
|
|
|
|
// (an index in |_deltas|) for the index
|
2012-01-10 08:09:32 -08:00
|
|
|
FallibleTArray<PRUint32> mIndexStarts;
|
2011-09-08 13:15:27 -07:00
|
|
|
// array containing deltas from indices.
|
2012-01-10 08:09:32 -08:00
|
|
|
FallibleTArray<PRUint16> mDeltas;
|
2012-04-19 22:46:47 -07:00
|
|
|
|
2011-09-08 13:15:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|