Commit 52895b59 authored by Varun Khaneja's avatar Varun Khaneja Committed by Commit Bot

Remove prefix_set.* as part of removing SafeBrowsing PVer3 protocol

Bug: 754341
Change-Id: Ib8dcfcba25ea2f563365fca13f79873499639c52
Reviewed-on: https://chromium-review.googlesource.com/1211979Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarNathan Parker <nparker@chromium.org>
Commit-Queue: Varun Khaneja <vakh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590070}
parent a223d957
...@@ -31,7 +31,6 @@ group("safe_browsing_db_shared") { ...@@ -31,7 +31,6 @@ group("safe_browsing_db_shared") {
deps = [ deps = [
":database_manager", ":database_manager",
":hit_report", ":hit_report",
":prefix_set",
":safebrowsing_proto", ":safebrowsing_proto",
":util", ":util",
":v4_feature_list", # Used by SafeBrowsingService ":v4_feature_list", # Used by SafeBrowsingService
...@@ -84,17 +83,6 @@ static_library("hit_report") { ...@@ -84,17 +83,6 @@ static_library("hit_report") {
] ]
} }
static_library("prefix_set") {
sources = [
"prefix_set.cc",
"prefix_set.h",
]
deps = [
":util",
"//base",
]
}
static_library("test_database_manager") { static_library("test_database_manager") {
sources = [ sources = [
"test_database_manager.cc", "test_database_manager.cc",
...@@ -390,7 +378,6 @@ source_set("unit_tests_shared") { ...@@ -390,7 +378,6 @@ source_set("unit_tests_shared") {
testonly = true testonly = true
sources = [ sources = [
"database_manager_unittest.cc", "database_manager_unittest.cc",
"prefix_set_unittest.cc",
"util_unittest.cc", "util_unittest.cc",
"v4_get_hash_protocol_manager_unittest.cc", "v4_get_hash_protocol_manager_unittest.cc",
"v4_protocol_manager_util_unittest.cc", "v4_protocol_manager_util_unittest.cc",
...@@ -398,7 +385,6 @@ source_set("unit_tests_shared") { ...@@ -398,7 +385,6 @@ source_set("unit_tests_shared") {
] ]
deps = [ deps = [
":database_manager", ":database_manager",
":prefix_set",
":safebrowsing_proto", ":safebrowsing_proto",
":test_database_manager", ":test_database_manager",
":util", ":util",
......
This diff is collapsed.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// A read-only set implementation for |SBPrefix| items. Prefixes are
// sorted and stored as 16-bit deltas from the previous prefix. An
// index structure provides quick random access, and also handles
// cases where 16 bits cannot encode a delta.
//
// For example, the sequence {20, 25, 41, 65432, 150000, 160000} would
// be stored as:
// A pair {20, 0} in |index_|.
// 5, 16, 65391 in |deltas_|.
// A pair {150000, 3} in |index_|.
// 10000 in |deltas_|.
// |index_.size()| will be 2, |deltas_.size()| will be 4.
//
// This structure is intended for storage of sparse uniform sets of
// prefixes of a certain size. As of this writing, my safe-browsing
// database contains:
// 653132 add prefixes
// 6446 are duplicates (from different chunks)
// 24301 w/in 2^8 of the prior prefix
// 622337 w/in 2^16 of the prior prefix
// 47 further than 2^16 from the prior prefix
// For this input, the memory usage is approximately 2 bytes per
// prefix, a bit over 1.2M. The bloom filter used 25 bits per prefix,
// a bit over 1.9M on this data.
//
// Experimenting with random selections of the above data, storage
// size drops almost linearly as prefix count drops, until the index
// overhead starts to become a problem a bit under 200k prefixes. The
// memory footprint gets worse than storing the raw prefix data around
// 75k prefixes. Fortunately, the actual memory footprint also falls.
// If the prefix count increases the memory footprint should increase
// approximately linearly. The worst-case would be 2^16 items all
// 2^16 apart, which would need 512k (versus 256k to store the raw
// data).
//
// The on-disk format looks like:
// 4 byte magic number
// 4 byte version number
// 4 byte |index_.size()|
// 4 byte |deltas_.size()|
// n * 8 byte |&index_[0]..&index_[n]|
// m * 2 byte |&deltas_[0]..&deltas_[m]|
// 16 byte digest
#ifndef COMPONENTS_SAFE_BROWSING_DB_PREFIX_SET_H_
#define COMPONENTS_SAFE_BROWSING_DB_PREFIX_SET_H_
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <utility>
#include <vector>
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "components/safe_browsing/db/util.h"
namespace base {
class FilePath;
}
namespace safe_browsing {
class PrefixSet {
public:
~PrefixSet();
// |true| if |hash| is in the hashes passed to the set's builder, or if
// |hash.prefix| is one of the prefixes passed to the set's builder.
bool Exists(const SBFullHash& hash) const;
// Persist the set on disk.
static std::unique_ptr<const PrefixSet> LoadFile(
const base::FilePath& filter_name);
bool WriteFile(const base::FilePath& filter_name) const;
private:
friend class PrefixSetBuilder;
friend class PrefixSetTest;
FRIEND_TEST_ALL_PREFIXES(PrefixSetTest, AllBig);
FRIEND_TEST_ALL_PREFIXES(PrefixSetTest, EdgeCases);
FRIEND_TEST_ALL_PREFIXES(PrefixSetTest, Empty);
FRIEND_TEST_ALL_PREFIXES(PrefixSetTest, FullHashBuild);
FRIEND_TEST_ALL_PREFIXES(PrefixSetTest, IntMinMax);
FRIEND_TEST_ALL_PREFIXES(PrefixSetTest, OneElement);
FRIEND_TEST_ALL_PREFIXES(PrefixSetTest, ReadWrite);
FRIEND_TEST_ALL_PREFIXES(PrefixSetTest, ReadWriteSigned);
FRIEND_TEST_ALL_PREFIXES(PrefixSetTest, Version3);
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingStoreFileTest, BasicStore);
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingStoreFileTest, DeleteChunks);
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingStoreFileTest, DetectsCorruption);
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingStoreFileTest, Empty);
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingStoreFileTest, PrefixMinMax);
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingStoreFileTest, SubKnockout);
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingStoreFileTest, Version7);
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingStoreFileTest, Version8);
// Maximum number of consecutive deltas to encode before generating
// a new index entry. This helps keep the worst-case performance
// for |Exists()| under control.
static const size_t kMaxRun = 100;
// Helpers to make |index_| easier to deal with.
typedef std::pair<SBPrefix, uint32_t> IndexPair;
typedef std::vector<IndexPair> IndexVector;
static bool PrefixLess(const IndexPair& a, const IndexPair& b);
// Helper to let |PrefixSetBuilder| add a run of data. |index_prefix| is
// added to |index_|, with the other elements added into |deltas_|.
void AddRun(SBPrefix index_prefix,
const uint16_t* run_begin,
const uint16_t* run_end);
// |true| if |prefix| is one of the prefixes passed to the set's builder.
// Provided for testing purposes.
bool PrefixExists(SBPrefix prefix) const;
// Regenerate the vector of prefixes passed to the constructor into
// |prefixes|. Prefixes will be added in sorted order. Useful for testing.
void GetPrefixes(std::vector<SBPrefix>* prefixes) const;
// Used by |PrefixSetBuilder|.
PrefixSet();
// Helper for |LoadFile()|. Steals vector contents using |swap()|.
PrefixSet(IndexVector* index,
std::vector<uint16_t>* deltas,
std::vector<SBFullHash>* full_hashes);
// Top-level index of prefix to offset in |deltas_|. Each pair
// indicates a base prefix and where the deltas from that prefix
// begin in |deltas_|. The deltas for a pair end at the next pair's
// index into |deltas_|.
IndexVector index_;
// Deltas which are added to the prefix in |index_| to generate
// prefixes. Deltas are only valid between consecutive items from
// |index_|, or the end of |deltas_| for the last |index_| pair.
std::vector<uint16_t> deltas_;
// Full hashes ordered by SBFullHashLess.
std::vector<SBFullHash> full_hashes_;
DISALLOW_COPY_AND_ASSIGN(PrefixSet);
};
// Helper to incrementally build a PrefixSet from a stream of sorted prefixes.
class PrefixSetBuilder {
public:
PrefixSetBuilder();
~PrefixSetBuilder();
// Helper for unit tests and format conversion.
explicit PrefixSetBuilder(const std::vector<SBPrefix>& prefixes);
// Add a prefix to the set. Prefixes must arrive in ascending order.
// Duplicate prefixes are dropped.
void AddPrefix(SBPrefix prefix);
// Flush any buffered prefixes, and return the final PrefixSet instance.
// |hashes| are sorted and stored in |full_hashes_|. Any call other than the
// destructor is illegal after this call.
std::unique_ptr<const PrefixSet> GetPrefixSet(
const std::vector<SBFullHash>& hashes);
// Helper for clients which only track prefixes. Calls GetPrefixSet() with
// empty hash vector.
std::unique_ptr<const PrefixSet> GetPrefixSetNoHashes();
private:
// Encode a run of deltas for |AddRun()|. The run is broken by a too-large
// delta, or kMaxRun, whichever comes first.
void EmitRun();
// Buffers prefixes until enough are avaliable to emit a run.
std::vector<SBPrefix> buffer_;
// The PrefixSet being built.
std::unique_ptr<PrefixSet> prefix_set_;
};
} // namespace safe_browsing
#endif // COMPONENTS_SAFE_BROWSING_DB_PREFIX_SET_H_
This diff is collapsed.
...@@ -87816,6 +87816,9 @@ uploading your change for review. ...@@ -87816,6 +87816,9 @@ uploading your change for review.
</histogram> </histogram>
<histogram name="SB2.PrefixSetBitsPerPrefix" units="bits"> <histogram name="SB2.PrefixSetBitsPerPrefix" units="bits">
<obsolete>
Deprecated in M58 (Aug 2017). No longer generated.
</obsolete>
<owner>vakh@chromium.org</owner> <owner>vakh@chromium.org</owner>
<summary> <summary>
The size of the PrefixSet storage in bits, divided by the number of prefixes The size of the PrefixSet storage in bits, divided by the number of prefixes
...@@ -87843,6 +87846,9 @@ uploading your change for review. ...@@ -87843,6 +87846,9 @@ uploading your change for review.
</histogram> </histogram>
<histogram name="SB2.PrefixSetLoad" units="ms"> <histogram name="SB2.PrefixSetLoad" units="ms">
<obsolete>
Deprecated in M58 (Aug 2017). No longer generated.
</obsolete>
<owner>vakh@chromium.org</owner> <owner>vakh@chromium.org</owner>
<summary>Time to load one of the PrefixSet files.</summary> <summary>Time to load one of the PrefixSet files.</summary>
</histogram> </histogram>
...@@ -87868,6 +87874,9 @@ uploading your change for review. ...@@ -87868,6 +87874,9 @@ uploading your change for review.
</histogram> </histogram>
<histogram name="SB2.PrefixSetSizeKilobytes" units="KB"> <histogram name="SB2.PrefixSetSizeKilobytes" units="KB">
<obsolete>
Deprecated in M58 (Aug 2017). No longer generated.
</obsolete>
<owner>vakh@chromium.org</owner> <owner>vakh@chromium.org</owner>
<summary> <summary>
The size of one of the PrefixSet files in kilobytes. Logged after a database The size of one of the PrefixSet files in kilobytes. Logged after a database
...@@ -87920,11 +87929,17 @@ uploading your change for review. ...@@ -87920,11 +87929,17 @@ uploading your change for review.
</histogram> </histogram>
<histogram name="SB2.PrefixSetVersionRead"> <histogram name="SB2.PrefixSetVersionRead">
<obsolete>
Deprecated in M58 (Aug 2017). No longer generated.
</obsolete>
<owner>vakh@chromium.org</owner> <owner>vakh@chromium.org</owner>
<summary>Version read from one of the PrefixSet files.</summary> <summary>Version read from one of the PrefixSet files.</summary>
</histogram> </histogram>
<histogram name="SB2.PrefixSetWrite" units="ms"> <histogram name="SB2.PrefixSetWrite" units="ms">
<obsolete>
Deprecated in M58 (Aug 2017). No longer generated.
</obsolete>
<owner>vakh@chromium.org</owner> <owner>vakh@chromium.org</owner>
<summary>Time to store one of the PrefixSet files.</summary> <summary>Time to store one of the PrefixSet files.</summary>
</histogram> </histogram>
...@@ -88165,6 +88180,9 @@ uploading your change for review. ...@@ -88165,6 +88180,9 @@ uploading your change for review.
</histogram> </histogram>
<histogram name="SB2.SubPrefixes"> <histogram name="SB2.SubPrefixes">
<obsolete>
Deprecated in M58 (Aug 2017). No longer generated.
</obsolete>
<owner>vakh@chromium.org</owner> <owner>vakh@chromium.org</owner>
<summary> <summary>
The number of sub prefixes stored in the database after the last update. The number of sub prefixes stored in the database after the last update.
...@@ -88172,6 +88190,9 @@ uploading your change for review. ...@@ -88172,6 +88190,9 @@ uploading your change for review.
</histogram> </histogram>
<histogram name="SB2.Update" units="ms"> <histogram name="SB2.Update" units="ms">
<obsolete>
Deprecated in M58 (Aug 2017). No longer generated.
</obsolete>
<owner>vakh@chromium.org</owner> <owner>vakh@chromium.org</owner>
<summary> <summary>
The time from the receipt of the update request to the receipt of the final The time from the receipt of the update request to the receipt of the final
...@@ -88180,16 +88201,25 @@ uploading your change for review. ...@@ -88180,16 +88201,25 @@ uploading your change for review.
</histogram> </histogram>
<histogram name="SB2.UpdateRequestSize" units="bytes"> <histogram name="SB2.UpdateRequestSize" units="bytes">
<obsolete>
Deprecated in M58 (Aug 2017). No longer generated.
</obsolete>
<owner>vakh@chromium.org</owner> <owner>vakh@chromium.org</owner>
<summary>The payload size of update requests to the server.</summary> <summary>The payload size of update requests to the server.</summary>
</histogram> </histogram>
<histogram name="SB2.UpdateResult" enum="SB2UpdateResult"> <histogram name="SB2.UpdateResult" enum="SB2UpdateResult">
<obsolete>
Deprecated in M58 (Aug 2017). No longer generated.
</obsolete>
<owner>vakh@chromium.org</owner> <owner>vakh@chromium.org</owner>
<summary>Result from trying to update the SafeBrowsing data.</summary> <summary>Result from trying to update the SafeBrowsing data.</summary>
</histogram> </histogram>
<histogram name="SB2.UpdateSize" units="bytes"> <histogram name="SB2.UpdateSize" units="bytes">
<obsolete>
Deprecated in M58 (Aug 2017). No longer generated.
</obsolete>
<owner>vakh@chromium.org</owner> <owner>vakh@chromium.org</owner>
<summary>The size of all the chunk URLs in an update response.</summary> <summary>The size of all the chunk URLs in an update response.</summary>
</histogram> </histogram>
...@@ -88217,6 +88247,9 @@ uploading your change for review. ...@@ -88217,6 +88247,9 @@ uploading your change for review.
</histogram> </histogram>
<histogram name="SB2.UpdateUrls"> <histogram name="SB2.UpdateUrls">
<obsolete>
Deprecated in M58 (Aug 2017). No longer generated.
</obsolete>
<owner>vakh@chromium.org</owner> <owner>vakh@chromium.org</owner>
<summary>The number of chunk URLs in an update response.</summary> <summary>The number of chunk URLs in an update response.</summary>
</histogram> </histogram>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment