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"
|
2012-08-15 00:04:19 -07:00
|
|
|
#include "nsIMutableArray.h"
|
2011-09-08 13:15:08 -07:00
|
|
|
#include "nsIUrlClassifierPrefixSet.h"
|
2013-03-17 00:55:16 -07:00
|
|
|
#include "nsTArray.h"
|
2011-09-08 13:15:08 -07:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.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
|
|
|
|
2013-01-17 21:43:21 -08:00
|
|
|
class nsIMemoryReporter;
|
2011-11-13 02:25:48 -08:00
|
|
|
|
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
|
|
|
|
2012-08-15 00:04:19 -07:00
|
|
|
NS_IMETHOD Init(const nsACString& aName);
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD SetPrefixes(const uint32_t* aArray, uint32_t aLength);
|
|
|
|
NS_IMETHOD GetPrefixes(uint32_t* aCount, uint32_t** aPrefixes);
|
|
|
|
NS_IMETHOD Contains(uint32_t aPrefix, bool* aFound);
|
2012-08-15 00:04:19 -07:00
|
|
|
NS_IMETHOD IsEmpty(bool* aEmpty);
|
2011-09-08 13:17:25 -07:00
|
|
|
NS_IMETHOD LoadFromFile(nsIFile* aFile);
|
|
|
|
NS_IMETHOD StoreToFile(nsIFile* aFile);
|
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
|
2013-06-23 05:03:39 -07:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
|
2011-12-13 20:54:18 -08:00
|
|
|
|
2011-09-08 13:15:08 -07:00
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
static const uint32_t DELTAS_LIMIT = 100;
|
|
|
|
static const uint32_t MAX_INDEX_DIFF = (1 << 16);
|
|
|
|
static const uint32_t PREFIXSET_VERSION_MAGIC = 1;
|
2011-09-08 13:15:08 -07:00
|
|
|
|
2013-01-17 21:43:21 -08:00
|
|
|
nsCOMPtr<nsIMemoryReporter> mReporter;
|
2011-09-08 13:15:27 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult MakePrefixSet(const uint32_t* aArray, uint32_t aLength);
|
|
|
|
uint32_t BinSearch(uint32_t start, uint32_t end, uint32_t target);
|
2012-08-15 00:04:19 -07:00
|
|
|
nsresult LoadFromFd(mozilla::AutoFDClose& fileFd);
|
|
|
|
nsresult StoreToFd(mozilla::AutoFDClose& fileFd);
|
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;
|
2011-09-08 13:15:08 -07:00
|
|
|
// the prefix for each index.
|
2012-08-22 08:56:38 -07:00
|
|
|
FallibleTArray<uint32_t> 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-08-22 08:56:38 -07:00
|
|
|
FallibleTArray<uint32_t> mIndexStarts;
|
2011-09-08 13:15:27 -07:00
|
|
|
// array containing deltas from indices.
|
2012-08-22 08:56:38 -07:00
|
|
|
FallibleTArray<uint16_t> mDeltas;
|
2011-09-08 13:15:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|