Line data Source code
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 :
6 : #ifndef LookupCacheV4_h__
7 : #define LookupCacheV4_h__
8 :
9 : #include "LookupCache.h"
10 :
11 : namespace mozilla {
12 : namespace safebrowsing {
13 :
14 : // Forward declaration.
15 : class TableUpdateV4;
16 :
17 : class LookupCacheV4 final : public LookupCache
18 : {
19 : public:
20 0 : explicit LookupCacheV4(const nsACString& aTableName,
21 : const nsACString& aProvider,
22 : nsIFile* aStoreFile)
23 0 : : LookupCache(aTableName, aProvider, aStoreFile) {}
24 0 : ~LookupCacheV4() {}
25 :
26 : virtual nsresult Init() override;
27 : virtual nsresult Has(const Completion& aCompletion,
28 : bool* aHas,
29 : uint32_t* aMatchLength,
30 : bool* aConfirmed) override;
31 :
32 : virtual bool IsEmpty() override;
33 :
34 : nsresult Build(PrefixStringMap& aPrefixMap);
35 :
36 : nsresult GetPrefixes(PrefixStringMap& aPrefixMap);
37 : nsresult GetFixedLengthPrefixes(FallibleTArray<uint32_t>& aPrefixes);
38 :
39 : // ApplyUpdate will merge data stored in aTableUpdate with prefixes in aInputMap.
40 : nsresult ApplyUpdate(TableUpdateV4* aTableUpdate,
41 : PrefixStringMap& aInputMap,
42 : PrefixStringMap& aOutputMap);
43 :
44 : nsresult AddFullHashResponseToCache(const FullHashResponseMap& aResponseMap);
45 :
46 : nsresult WriteMetadata(TableUpdateV4* aTableUpdate);
47 : nsresult LoadMetadata(nsACString& aState, nsACString& aChecksum);
48 :
49 : static const int VER;
50 :
51 : protected:
52 : virtual nsresult ClearPrefixes() override;
53 : virtual nsresult StoreToFile(nsIFile* aFile) override;
54 : virtual nsresult LoadFromFile(nsIFile* aFile) override;
55 : virtual size_t SizeOfPrefixSet() override;
56 :
57 : private:
58 0 : virtual int Ver() const override { return VER; }
59 :
60 : nsresult InitCrypto(nsCOMPtr<nsICryptoHash>& aCrypto);
61 : nsresult VerifyChecksum(const nsACString& aChecksum);
62 :
63 : RefPtr<VariableLengthPrefixSet> mVLPrefixSet;
64 : };
65 :
66 : } // namespace safebrowsing
67 : } // namespace mozilla
68 :
69 : #endif
|