| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // A read-only set implementation for |SBPrefix| items. Prefixes are | 5 // A read-only set implementation for |SBPrefix| items. Prefixes are |
| 6 // sorted and stored as 16-bit deltas from the previous prefix. An | 6 // sorted and stored as 16-bit deltas from the previous prefix. An |
| 7 // index structure provides quick random access, and also handles | 7 // index structure provides quick random access, and also handles |
| 8 // cases where 16 bits cannot encode a delta. | 8 // cases where 16 bits cannot encode a delta. |
| 9 // | 9 // |
| 10 // For example, the sequence {20, 25, 41, 65432, 150000, 160000} would | 10 // For example, the sequence {20, 25, 41, 65432, 150000, 160000} would |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 // m * 2 byte |&deltas_[0]..&deltas_[m]| | 46 // m * 2 byte |&deltas_[0]..&deltas_[m]| |
| 47 // 16 byte digest | 47 // 16 byte digest |
| 48 | 48 |
| 49 #ifndef CHROME_BROWSER_SAFE_BROWSING_PREFIX_SET_H_ | 49 #ifndef CHROME_BROWSER_SAFE_BROWSING_PREFIX_SET_H_ |
| 50 #define CHROME_BROWSER_SAFE_BROWSING_PREFIX_SET_H_ | 50 #define CHROME_BROWSER_SAFE_BROWSING_PREFIX_SET_H_ |
| 51 | 51 |
| 52 #include <vector> | 52 #include <vector> |
| 53 | 53 |
| 54 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 54 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 55 | 55 |
| 56 namespace base { |
| 56 class FilePath; | 57 class FilePath; |
| 58 } |
| 57 | 59 |
| 58 namespace safe_browsing { | 60 namespace safe_browsing { |
| 59 | 61 |
| 60 class PrefixSet { | 62 class PrefixSet { |
| 61 public: | 63 public: |
| 62 explicit PrefixSet(const std::vector<SBPrefix>& sorted_prefixes); | 64 explicit PrefixSet(const std::vector<SBPrefix>& sorted_prefixes); |
| 63 ~PrefixSet(); | 65 ~PrefixSet(); |
| 64 | 66 |
| 65 // |true| if |prefix| was in |prefixes| passed to the constructor. | 67 // |true| if |prefix| was in |prefixes| passed to the constructor. |
| 66 bool Exists(SBPrefix prefix) const; | 68 bool Exists(SBPrefix prefix) const; |
| 67 | 69 |
| 68 // Persist the set on disk. | 70 // Persist the set on disk. |
| 69 static PrefixSet* LoadFile(const FilePath& filter_name); | 71 static PrefixSet* LoadFile(const base::FilePath& filter_name); |
| 70 bool WriteFile(const FilePath& filter_name) const; | 72 bool WriteFile(const base::FilePath& filter_name) const; |
| 71 | 73 |
| 72 // Regenerate the vector of prefixes passed to the constructor into | 74 // Regenerate the vector of prefixes passed to the constructor into |
| 73 // |prefixes|. Prefixes will be added in sorted order. | 75 // |prefixes|. Prefixes will be added in sorted order. |
| 74 void GetPrefixes(std::vector<SBPrefix>* prefixes) const; | 76 void GetPrefixes(std::vector<SBPrefix>* prefixes) const; |
| 75 | 77 |
| 76 private: | 78 private: |
| 77 // Maximum number of consecutive deltas to encode before generating | 79 // Maximum number of consecutive deltas to encode before generating |
| 78 // a new index entry. This helps keep the worst-case performance | 80 // a new index entry. This helps keep the worst-case performance |
| 79 // for |Exists()| under control. | 81 // for |Exists()| under control. |
| 80 static const size_t kMaxRun = 100; | 82 static const size_t kMaxRun = 100; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 94 // prefixes. Deltas are only valid between consecutive items from | 96 // prefixes. Deltas are only valid between consecutive items from |
| 95 // |index_|, or the end of |deltas_| for the last |index_| pair. | 97 // |index_|, or the end of |deltas_| for the last |index_| pair. |
| 96 std::vector<uint16> deltas_; | 98 std::vector<uint16> deltas_; |
| 97 | 99 |
| 98 DISALLOW_COPY_AND_ASSIGN(PrefixSet); | 100 DISALLOW_COPY_AND_ASSIGN(PrefixSet); |
| 99 }; | 101 }; |
| 100 | 102 |
| 101 } // namespace safe_browsing | 103 } // namespace safe_browsing |
| 102 | 104 |
| 103 #endif // CHROME_BROWSER_SAFE_BROWSING_PREFIX_SET_H_ | 105 #endif // CHROME_BROWSER_SAFE_BROWSING_PREFIX_SET_H_ |
| OLD | NEW |