toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,69 @@
     1.4 +//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsUrlClassifierPrefixSet_h_
    1.11 +#define nsUrlClassifierPrefixSet_h_
    1.12 +
    1.13 +#include "nsISupportsUtils.h"
    1.14 +#include "nsID.h"
    1.15 +#include "nsIFile.h"
    1.16 +#include "nsIMemoryReporter.h"
    1.17 +#include "nsIMutableArray.h"
    1.18 +#include "nsIUrlClassifierPrefixSet.h"
    1.19 +#include "nsTArray.h"
    1.20 +#include "nsToolkitCompsCID.h"
    1.21 +#include "mozilla/MemoryReporting.h"
    1.22 +#include "mozilla/Mutex.h"
    1.23 +#include "mozilla/CondVar.h"
    1.24 +#include "mozilla/FileUtils.h"
    1.25 +
    1.26 +class nsUrlClassifierPrefixSet
    1.27 +  : public nsIUrlClassifierPrefixSet
    1.28 +  , public nsIMemoryReporter
    1.29 +{
    1.30 +public:
    1.31 +  nsUrlClassifierPrefixSet();
    1.32 +  virtual ~nsUrlClassifierPrefixSet();
    1.33 +
    1.34 +  NS_IMETHOD Init(const nsACString& aName);
    1.35 +  NS_IMETHOD SetPrefixes(const uint32_t* aArray, uint32_t aLength);
    1.36 +  NS_IMETHOD GetPrefixes(uint32_t* aCount, uint32_t** aPrefixes);
    1.37 +  NS_IMETHOD Contains(uint32_t aPrefix, bool* aFound);
    1.38 +  NS_IMETHOD IsEmpty(bool* aEmpty);
    1.39 +  NS_IMETHOD LoadFromFile(nsIFile* aFile);
    1.40 +  NS_IMETHOD StoreToFile(nsIFile* aFile);
    1.41 +
    1.42 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.43 +  NS_DECL_NSIMEMORYREPORTER
    1.44 +
    1.45 +  // Return the estimated size of the set on disk and in memory, in bytes.
    1.46 +  size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
    1.47 +
    1.48 +protected:
    1.49 +  static const uint32_t DELTAS_LIMIT = 100;
    1.50 +  static const uint32_t MAX_INDEX_DIFF = (1 << 16);
    1.51 +  static const uint32_t PREFIXSET_VERSION_MAGIC = 1;
    1.52 +
    1.53 +  nsresult MakePrefixSet(const uint32_t* aArray, uint32_t aLength);
    1.54 +  uint32_t BinSearch(uint32_t start, uint32_t end, uint32_t target);
    1.55 +  nsresult LoadFromFd(mozilla::AutoFDClose& fileFd);
    1.56 +  nsresult StoreToFd(mozilla::AutoFDClose& fileFd);
    1.57 +
    1.58 +  // boolean indicating whether |setPrefixes| has been
    1.59 +  // called with a non-empty array.
    1.60 +  bool mHasPrefixes;
    1.61 +  // the prefix for each index.
    1.62 +  FallibleTArray<uint32_t> mIndexPrefixes;
    1.63 +  // the value corresponds to the beginning of the run
    1.64 +  // (an index in |_deltas|) for the index
    1.65 +  FallibleTArray<uint32_t> mIndexStarts;
    1.66 +  // array containing deltas from indices.
    1.67 +  FallibleTArray<uint16_t> mDeltas;
    1.68 +
    1.69 +  nsCString mMemoryReportPath;
    1.70 +};
    1.71 +
    1.72 +#endif

mercurial