author dlee <>
Thu, 07 Mar 2019 14:40:28 +0000
changeset 520889 c7a253aed4508a8df4f1309d889dbfd669cd1693
parent 520888 c2331373e10707aa5259eb3d8436f65c8d59c684
child 520890 e083106dc24f6f562eb2d72aa02871a27a681ebe
permissions -rw-r--r--
Bug 1353956 - P2. Do not use SHA-256 while loading the V4 prefix files. r=gcp SHA256 is an expensive operation, we should avoid using them if possible. SafeBrowsing prefix files are loaded during startup and verify integrity with SHA256 which may affect the performance especially on the low-end device. This patch simply removes the SHA256 integrity check. CRC32 version integrity check will be introduced in the other patch. This patch also changes the behavior of recording "Telemetry::URLCLASSIFIER_VLPS_LOAD_CORRUPT" a little bit. It used to records only once per session(during startup, the first time we load prefix set), now it records per update. Differential Revision:

//* -*- 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 */

#ifndef LookupCacheV4_h__
#define LookupCacheV4_h__

#include "LookupCache.h"

namespace mozilla {
namespace safebrowsing {

// Forward declaration.
class TableUpdateV4;

class LookupCacheV4 final : public LookupCache {
  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 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;

  virtual nsresult ClearPrefixes() override;
  virtual nsresult StoreToFile(nsCOMPtr<nsIFile>& aFile) override;
  virtual nsresult LoadFromFile(nsCOMPtr<nsIFile>& aFile) override;
  virtual size_t SizeOfPrefixSet() const override;

  ~LookupCacheV4() {}

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

  RefPtr<VariableLengthPrefixSet> mVLPrefixSet;

}  // namespace safebrowsing
}  // namespace mozilla