summaryrefslogtreecommitdiffstats
path: root/chrome/browser/safe_browsing/prefix_set.h
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 19:10:05 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 19:10:05 +0000
commiteeb0af285a61c37c0fbcb046174bf29741324a08 (patch)
tree2dc7dc0ca940cd7d86bd934626ed8123017e196e /chrome/browser/safe_browsing/prefix_set.h
parent11901ef2cd6ef17b08116d3dc19d03e9be87dd25 (diff)
downloadchromium_src-eeb0af285a61c37c0fbcb046174bf29741324a08.zip
chromium_src-eeb0af285a61c37c0fbcb046174bf29741324a08.tar.gz
chromium_src-eeb0af285a61c37c0fbcb046174bf29741324a08.tar.bz2
safe_browsing::PrefixSet persistence code.
Just the ability to read/write the data structure to a file. File format is a simple header, the contents of the vectors, and a checksum. BUG=71832 TEST=none Review URL: http://codereview.chromium.org/6625002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77314 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing/prefix_set.h')
-rw-r--r--chrome/browser/safe_browsing/prefix_set.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/chrome/browser/safe_browsing/prefix_set.h b/chrome/browser/safe_browsing/prefix_set.h
index cb2cd9f..246beea 100644
--- a/chrome/browser/safe_browsing/prefix_set.h
+++ b/chrome/browser/safe_browsing/prefix_set.h
@@ -37,8 +37,7 @@
// 2^16 apart, which would need 512k (versus 256k to store the raw
// data).
//
-// TODO(shess): Write serialization code. Something like this should
-// work:
+// The on-disk format looks like:
// 4 byte magic number
// 4 byte version number
// 4 byte |index_.size()|
@@ -55,6 +54,8 @@
#include "chrome/browser/safe_browsing/safe_browsing_util.h"
+class FilePath;
+
namespace safe_browsing {
class PrefixSet {
@@ -65,6 +66,10 @@ class PrefixSet {
// |true| if |prefix| was in |prefixes| passed to the constructor.
bool Exists(SBPrefix prefix) const;
+ // Persist the set on disk.
+ static PrefixSet* LoadFile(const FilePath& filter_name);
+ bool WriteFile(const FilePath& filter_name) const;
+
// Regenerate the vector of prefixes passed to the constructor into
// |prefixes|. Prefixes will be added in sorted order.
void GetPrefixes(std::vector<SBPrefix>* prefixes);
@@ -78,6 +83,11 @@ class PrefixSet {
// for |Exists()| under control.
static const size_t kMaxRun = 100;
+ // Helper for |LoadFile()|. Steals the contents of |index| and
+ // |deltas| using |swap()|.
+ PrefixSet(std::vector<std::pair<SBPrefix,size_t> > *index,
+ std::vector<uint16> *deltas);
+
// 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