toolkit/components/url-classifier/Classifier.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/url-classifier/Classifier.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef Classifier_h__
    1.10 +#define Classifier_h__
    1.11 +
    1.12 +#include "Entries.h"
    1.13 +#include "HashStore.h"
    1.14 +#include "ProtocolParser.h"
    1.15 +#include "LookupCache.h"
    1.16 +#include "nsCOMPtr.h"
    1.17 +#include "nsString.h"
    1.18 +#include "nsIFile.h"
    1.19 +#include "nsICryptoHash.h"
    1.20 +#include "nsDataHashtable.h"
    1.21 +
    1.22 +namespace mozilla {
    1.23 +namespace safebrowsing {
    1.24 +
    1.25 +/**
    1.26 + * Maintains the stores and LookupCaches for the url classifier.
    1.27 + */
    1.28 +class Classifier {
    1.29 +public:
    1.30 +  Classifier();
    1.31 +  ~Classifier();
    1.32 +
    1.33 +  nsresult Open(nsIFile& aCacheDirectory);
    1.34 +  void Close();
    1.35 +  void Reset();
    1.36 +
    1.37 +  /**
    1.38 +   * Get the list of active tables and their chunks in a format
    1.39 +   * suitable for an update request.
    1.40 +   */
    1.41 +  void TableRequest(nsACString& aResult);
    1.42 +
    1.43 +  /*
    1.44 +   * Get all tables that we know about.
    1.45 +   */
    1.46 +  nsresult ActiveTables(nsTArray<nsCString>& aTables);
    1.47 +
    1.48 +  /**
    1.49 +   * Check a URL against the specified tables.
    1.50 +   */
    1.51 +  nsresult Check(const nsACString& aSpec,
    1.52 +                 const nsACString& tables,
    1.53 +                 LookupResultArray& aResults);
    1.54 +
    1.55 +  /**
    1.56 +   * Apply the table updates in the array.  Takes ownership of
    1.57 +   * the updates in the array and clears it.  Wacky!
    1.58 +   */
    1.59 +  nsresult ApplyUpdates(nsTArray<TableUpdate*>* aUpdates);
    1.60 +  /**
    1.61 +   * Failed update. Spoil the entries so we don't block hosts
    1.62 +   * unnecessarily
    1.63 +   */
    1.64 +  nsresult MarkSpoiled(nsTArray<nsCString>& aTables);
    1.65 +  nsresult CacheCompletions(const CacheResultArray& aResults);
    1.66 +  uint32_t GetHashKey(void) { return mHashKey; }
    1.67 +  void SetFreshTime(uint32_t aTime) { mFreshTime = aTime; }
    1.68 +  /*
    1.69 +   * Get a bunch of extra prefixes to query for completion
    1.70 +   * and mask the real entry being requested
    1.71 +   */
    1.72 +  nsresult ReadNoiseEntries(const Prefix& aPrefix,
    1.73 +                            const nsACString& aTableName,
    1.74 +                            uint32_t aCount,
    1.75 +                            PrefixArray* aNoiseEntries);
    1.76 +  static void SplitTables(const nsACString& str, nsTArray<nsCString>& tables);
    1.77 +
    1.78 +private:
    1.79 +  void DropStores();
    1.80 +  nsresult CreateStoreDirectory();
    1.81 +  nsresult SetupPathNames();
    1.82 +  nsresult RecoverBackups();
    1.83 +  nsresult CleanToDelete();
    1.84 +  nsresult BackupTables();
    1.85 +  nsresult RemoveBackupTables();
    1.86 +  nsresult RegenActiveTables();
    1.87 +  nsresult ScanStoreDir(nsTArray<nsCString>& aTables);
    1.88 +
    1.89 +  nsresult ApplyTableUpdates(nsTArray<TableUpdate*>* aUpdates,
    1.90 +                             const nsACString& aTable);
    1.91 +
    1.92 +  LookupCache *GetLookupCache(const nsACString& aTable);
    1.93 +
    1.94 +  // Root dir of the Local profile.
    1.95 +  nsCOMPtr<nsIFile> mCacheDirectory;
    1.96 +  // Main directory where to store the databases.
    1.97 +  nsCOMPtr<nsIFile> mStoreDirectory;
    1.98 +  // Used for atomically updating the other dirs.
    1.99 +  nsCOMPtr<nsIFile> mBackupDirectory;
   1.100 +  nsCOMPtr<nsIFile> mToDeleteDirectory;
   1.101 +  nsCOMPtr<nsICryptoHash> mCryptoHash;
   1.102 +  nsTArray<HashStore*> mHashStores;
   1.103 +  nsTArray<LookupCache*> mLookupCaches;
   1.104 +  nsTArray<nsCString> mActiveTablesCache;
   1.105 +  uint32_t mHashKey;
   1.106 +  // Stores the last time a given table was updated (seconds).
   1.107 +  nsDataHashtable<nsCStringHashKey, int64_t> mTableFreshness;
   1.108 +  uint32_t mFreshTime;
   1.109 +};
   1.110 +
   1.111 +}
   1.112 +}
   1.113 +
   1.114 +#endif

mercurial