toolkit/components/url-classifier/Classifier.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef Classifier_h__
michael@0 7 #define Classifier_h__
michael@0 8
michael@0 9 #include "Entries.h"
michael@0 10 #include "HashStore.h"
michael@0 11 #include "ProtocolParser.h"
michael@0 12 #include "LookupCache.h"
michael@0 13 #include "nsCOMPtr.h"
michael@0 14 #include "nsString.h"
michael@0 15 #include "nsIFile.h"
michael@0 16 #include "nsICryptoHash.h"
michael@0 17 #include "nsDataHashtable.h"
michael@0 18
michael@0 19 namespace mozilla {
michael@0 20 namespace safebrowsing {
michael@0 21
michael@0 22 /**
michael@0 23 * Maintains the stores and LookupCaches for the url classifier.
michael@0 24 */
michael@0 25 class Classifier {
michael@0 26 public:
michael@0 27 Classifier();
michael@0 28 ~Classifier();
michael@0 29
michael@0 30 nsresult Open(nsIFile& aCacheDirectory);
michael@0 31 void Close();
michael@0 32 void Reset();
michael@0 33
michael@0 34 /**
michael@0 35 * Get the list of active tables and their chunks in a format
michael@0 36 * suitable for an update request.
michael@0 37 */
michael@0 38 void TableRequest(nsACString& aResult);
michael@0 39
michael@0 40 /*
michael@0 41 * Get all tables that we know about.
michael@0 42 */
michael@0 43 nsresult ActiveTables(nsTArray<nsCString>& aTables);
michael@0 44
michael@0 45 /**
michael@0 46 * Check a URL against the specified tables.
michael@0 47 */
michael@0 48 nsresult Check(const nsACString& aSpec,
michael@0 49 const nsACString& tables,
michael@0 50 LookupResultArray& aResults);
michael@0 51
michael@0 52 /**
michael@0 53 * Apply the table updates in the array. Takes ownership of
michael@0 54 * the updates in the array and clears it. Wacky!
michael@0 55 */
michael@0 56 nsresult ApplyUpdates(nsTArray<TableUpdate*>* aUpdates);
michael@0 57 /**
michael@0 58 * Failed update. Spoil the entries so we don't block hosts
michael@0 59 * unnecessarily
michael@0 60 */
michael@0 61 nsresult MarkSpoiled(nsTArray<nsCString>& aTables);
michael@0 62 nsresult CacheCompletions(const CacheResultArray& aResults);
michael@0 63 uint32_t GetHashKey(void) { return mHashKey; }
michael@0 64 void SetFreshTime(uint32_t aTime) { mFreshTime = aTime; }
michael@0 65 /*
michael@0 66 * Get a bunch of extra prefixes to query for completion
michael@0 67 * and mask the real entry being requested
michael@0 68 */
michael@0 69 nsresult ReadNoiseEntries(const Prefix& aPrefix,
michael@0 70 const nsACString& aTableName,
michael@0 71 uint32_t aCount,
michael@0 72 PrefixArray* aNoiseEntries);
michael@0 73 static void SplitTables(const nsACString& str, nsTArray<nsCString>& tables);
michael@0 74
michael@0 75 private:
michael@0 76 void DropStores();
michael@0 77 nsresult CreateStoreDirectory();
michael@0 78 nsresult SetupPathNames();
michael@0 79 nsresult RecoverBackups();
michael@0 80 nsresult CleanToDelete();
michael@0 81 nsresult BackupTables();
michael@0 82 nsresult RemoveBackupTables();
michael@0 83 nsresult RegenActiveTables();
michael@0 84 nsresult ScanStoreDir(nsTArray<nsCString>& aTables);
michael@0 85
michael@0 86 nsresult ApplyTableUpdates(nsTArray<TableUpdate*>* aUpdates,
michael@0 87 const nsACString& aTable);
michael@0 88
michael@0 89 LookupCache *GetLookupCache(const nsACString& aTable);
michael@0 90
michael@0 91 // Root dir of the Local profile.
michael@0 92 nsCOMPtr<nsIFile> mCacheDirectory;
michael@0 93 // Main directory where to store the databases.
michael@0 94 nsCOMPtr<nsIFile> mStoreDirectory;
michael@0 95 // Used for atomically updating the other dirs.
michael@0 96 nsCOMPtr<nsIFile> mBackupDirectory;
michael@0 97 nsCOMPtr<nsIFile> mToDeleteDirectory;
michael@0 98 nsCOMPtr<nsICryptoHash> mCryptoHash;
michael@0 99 nsTArray<HashStore*> mHashStores;
michael@0 100 nsTArray<LookupCache*> mLookupCaches;
michael@0 101 nsTArray<nsCString> mActiveTablesCache;
michael@0 102 uint32_t mHashKey;
michael@0 103 // Stores the last time a given table was updated (seconds).
michael@0 104 nsDataHashtable<nsCStringHashKey, int64_t> mTableFreshness;
michael@0 105 uint32_t mFreshTime;
michael@0 106 };
michael@0 107
michael@0 108 }
michael@0 109 }
michael@0 110
michael@0 111 #endif

mercurial