Chromium Code Reviews| 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 #include "components/safe_browsing_db/prefix_set.h" | 5 #include "components/safe_browsing_db/prefix_set.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_file.h" | 10 #include "base/files/scoped_file.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/md5.h" | 12 #include "base/md5.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace safe_browsing { |
| 17 | 17 |
|
Nathan Parker
2015/11/05 22:00:53
anon-namespace
vakh (old account. dont use)
2015/11/07 01:22:57
Done.
| |
| 18 // |kMagic| should be reasonably unique, and not match itself across | 18 // |kMagic| should be reasonably unique, and not match itself across |
| 19 // endianness changes. I generated this value with: | 19 // endianness changes. I generated this value with: |
| 20 // md5 -qs chrome/browser/safe_browsing/prefix_set.cc | colrm 9 | 20 // md5 -qs chrome/browser/safe_browsing/prefix_set.cc | colrm 9 |
| 21 static uint32 kMagic = 0x864088dd; | 21 static uint32 kMagic = 0x864088dd; |
| 22 | 22 |
| 23 // Version history: | 23 // Version history: |
| 24 // Version 1: b6cb7cfe/r74487 by shess@chromium.org on 2011-02-10 | 24 // Version 1: b6cb7cfe/r74487 by shess@chromium.org on 2011-02-10 |
| 25 // Version 2: 2b59b0a6/r253924 by shess@chromium.org on 2014-02-27 | 25 // Version 2: 2b59b0a6/r253924 by shess@chromium.org on 2014-02-27 |
| 26 // Version 3: dd07faf5/r268145 by shess@chromium.org on 2014-05-05 | 26 // Version 3: dd07faf5/r268145 by shess@chromium.org on 2014-05-05 |
| 27 | 27 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 // For large input sets, estimated_max of 2^32 is close enough. | 67 // For large input sets, estimated_max of 2^32 is close enough. |
| 68 const size_t estimated_prefix_count = static_cast<size_t>( | 68 const size_t estimated_prefix_count = static_cast<size_t>( |
| 69 (static_cast<uint64>(current_count) << 32) / current_prefix); | 69 (static_cast<uint64>(current_count) << 32) / current_prefix); |
| 70 | 70 |
| 71 // The estimate has an error bar, if the final total is below the estimate, no | 71 // The estimate has an error bar, if the final total is below the estimate, no |
| 72 // harm, but if it is above a capacity resize will happen at nearly 100%. Add | 72 // harm, but if it is above a capacity resize will happen at nearly 100%. Add |
| 73 // some slop to make sure all cases are covered. | 73 // some slop to make sure all cases are covered. |
| 74 return estimated_prefix_count + estimated_prefix_count / 100; | 74 return estimated_prefix_count + estimated_prefix_count / 100; |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace | |
| 78 | |
| 79 namespace safe_browsing { | |
| 80 | |
| 81 // For |std::upper_bound()| to find a prefix w/in a vector of pairs. | 77 // For |std::upper_bound()| to find a prefix w/in a vector of pairs. |
| 82 // static | 78 // static |
| 83 bool PrefixSet::PrefixLess(const IndexPair& a, const IndexPair& b) { | 79 bool PrefixSet::PrefixLess(const IndexPair& a, const IndexPair& b) { |
| 84 return a.first < b.first; | 80 return a.first < b.first; |
| 85 } | 81 } |
| 86 | 82 |
| 87 PrefixSet::PrefixSet() { | 83 PrefixSet::PrefixSet() { |
| 88 } | 84 } |
| 89 | 85 |
| 90 PrefixSet::PrefixSet(IndexVector* index, | 86 PrefixSet::PrefixSet(IndexVector* index, |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 } | 436 } |
| 441 buffer_.push_back(prefix); | 437 buffer_.push_back(prefix); |
| 442 | 438 |
| 443 // Flush buffer when a run can be constructed. +1 for the index item, and +1 | 439 // Flush buffer when a run can be constructed. +1 for the index item, and +1 |
| 444 // to leave at least one item in the buffer for dropping duplicates. | 440 // to leave at least one item in the buffer for dropping duplicates. |
| 445 if (buffer_.size() > PrefixSet::kMaxRun + 2) | 441 if (buffer_.size() > PrefixSet::kMaxRun + 2) |
| 446 EmitRun(); | 442 EmitRun(); |
| 447 } | 443 } |
| 448 | 444 |
| 449 } // namespace safe_browsing | 445 } // namespace safe_browsing |
| OLD | NEW |