LookupCacheV4.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef LookupCacheV4_h__
  6. #define LookupCacheV4_h__
  7. #include "LookupCache.h"
  8. namespace mozilla {
  9. namespace safebrowsing {
  10. // Forward declaration.
  11. class TableUpdateV4;
  12. class LookupCacheV4 final : public LookupCache
  13. {
  14. public:
  15. explicit LookupCacheV4(const nsACString& aTableName,
  16. const nsACString& aProvider,
  17. nsIFile* aStoreFile)
  18. : LookupCache(aTableName, aProvider, aStoreFile) {}
  19. ~LookupCacheV4() {}
  20. virtual nsresult Init() override;
  21. virtual nsresult Has(const Completion& aCompletion,
  22. bool* aHas, bool* aComplete) override;
  23. nsresult Build(PrefixStringMap& aPrefixMap);
  24. nsresult GetPrefixes(PrefixStringMap& aPrefixMap);
  25. // ApplyUpdate will merge data stored in aTableUpdate with prefixes in aInputMap.
  26. nsresult ApplyUpdate(TableUpdateV4* aTableUpdate,
  27. PrefixStringMap& aInputMap,
  28. PrefixStringMap& aOutputMap);
  29. nsresult WriteMetadata(TableUpdateV4* aTableUpdate);
  30. nsresult LoadMetadata(nsACString& aState, nsACString& aChecksum);
  31. static const int VER;
  32. protected:
  33. virtual nsresult ClearPrefixes() override;
  34. virtual nsresult StoreToFile(nsIFile* aFile) override;
  35. virtual nsresult LoadFromFile(nsIFile* aFile) override;
  36. virtual size_t SizeOfPrefixSet() override;
  37. private:
  38. virtual int Ver() const override { return VER; }
  39. nsresult InitCrypto(nsCOMPtr<nsICryptoHash>& aCrypto);
  40. nsresult VerifyChecksum(const nsACString& aChecksum);
  41. enum UPDATE_ERROR_TYPES {
  42. DUPLICATE_PREFIX = 0,
  43. INFINITE_LOOP = 1,
  44. WRONG_REMOVAL_INDICES = 2,
  45. CHECKSUM_MISMATCH = 3,
  46. MISSING_CHECKSUM = 4,
  47. };
  48. RefPtr<VariableLengthPrefixSet> mVLPrefixSet;
  49. };
  50. } // namespace safebrowsing
  51. } // namespace mozilla
  52. #endif