toolkit/components/url-classifier/LookupCacheV4.h
author Dimi Lee <dlee@mozilla.com>
Thu, 07 Mar 2019 14:40:56 +0000
changeset 520890 e083106dc24f6f562eb2d72aa02871a27a681ebe
parent 520889 c7a253aed4508a8df4f1309d889dbfd669cd1693
child 520891 3b5da75b9c7b7912e31007b9bac31b4a1ff4a558
permissions -rw-r--r--
Bug 1353956 - P3. Separate file processing and prefix data processing for SafeBrowsing prefix set. r=gcp SafeBrowsing prefix files LOAD/SAVE operations are handled in xxxPrefixSet.cpp. It would be more clear if xxxPrefixSet.cpp only processes prefix data, while LookupCacheV2/LookupCacheV4 which use prefix set process file. This patch doesn't change any behavior, testcases need to update because the LookupCache & xxxPrefixSet APIs are changed. Differential Revision: https://phabricator.services.mozilla.com/D21462

//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef LookupCacheV4_h__
#define LookupCacheV4_h__

#include "LookupCache.h"

namespace mozilla {
namespace safebrowsing {

// Forward declaration.
class TableUpdateV4;

class LookupCacheV4 final : public LookupCache {
 public:
  explicit LookupCacheV4(const nsACString& aTableName,
                         const nsACString& aProvider,
                         nsCOMPtr<nsIFile>& aStoreFile)
      : LookupCache(aTableName, aProvider, aStoreFile) {}

  virtual nsresult Init() override;
  virtual nsresult Has(const Completion& aCompletion, bool* aHas,
                       uint32_t* aMatchLength, bool* aConfirmed) override;

  virtual nsresult StoreToFile(nsCOMPtr<nsIFile>& aFile) override;
  virtual nsresult LoadFromFile(nsCOMPtr<nsIFile>& aFile) override;

  virtual bool IsEmpty() const override;

  nsresult Build(PrefixStringMap& aPrefixMap);

  nsresult GetPrefixes(PrefixStringMap& aPrefixMap);
  nsresult GetFixedLengthPrefixes(FallibleTArray<uint32_t>& aPrefixes);

  // ApplyUpdate will merge data stored in aTableUpdate with prefixes in
  // aInputMap.
  nsresult ApplyUpdate(RefPtr<TableUpdateV4> aTableUpdate,
                       PrefixStringMap& aInputMap, PrefixStringMap& aOutputMap);

  nsresult AddFullHashResponseToCache(const FullHashResponseMap& aResponseMap);

  nsresult WriteMetadata(RefPtr<const TableUpdateV4> aTableUpdate);
  nsresult LoadMetadata(nsACString& aState, nsACString& aChecksum);

  static const int VER;
  static const uint32_t MAX_METADATA_VALUE_LENGTH;

 protected:
  virtual nsresult ClearPrefixes() override;
  virtual size_t SizeOfPrefixSet() const override;

 private:
  ~LookupCacheV4() {}

  virtual int Ver() const override { return VER; }

  RefPtr<VariableLengthPrefixSet> mVLPrefixSet;
};

}  // namespace safebrowsing
}  // namespace mozilla

#endif