| 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 "chrome/browser/safe_browsing/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 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 346 |
| 347 void PrefixSet::AddRun(SBPrefix index_prefix, | 347 void PrefixSet::AddRun(SBPrefix index_prefix, |
| 348 const uint16* run_begin, const uint16* run_end) { | 348 const uint16* run_begin, const uint16* run_end) { |
| 349 // Preempt organic capacity decisions for |delta_| once strong estimates can | 349 // Preempt organic capacity decisions for |delta_| once strong estimates can |
| 350 // be made. | 350 // be made. |
| 351 if (index_prefix > kEstimateThreshold && | 351 if (index_prefix > kEstimateThreshold && |
| 352 deltas_.capacity() < deltas_.size() + (run_end - run_begin)) { | 352 deltas_.capacity() < deltas_.size() + (run_end - run_begin)) { |
| 353 deltas_.reserve(EstimateFinalCount(index_prefix, deltas_.size())); | 353 deltas_.reserve(EstimateFinalCount(index_prefix, deltas_.size())); |
| 354 } | 354 } |
| 355 | 355 |
| 356 index_.push_back(std::make_pair(index_prefix, deltas_.size())); | 356 index_.push_back( |
| 357 std::make_pair(index_prefix, static_cast<uint32>(deltas_.size()))); |
| 357 deltas_.insert(deltas_.end(), run_begin, run_end); | 358 deltas_.insert(deltas_.end(), run_begin, run_end); |
| 358 } | 359 } |
| 359 | 360 |
| 360 PrefixSetBuilder::PrefixSetBuilder() | 361 PrefixSetBuilder::PrefixSetBuilder() |
| 361 : prefix_set_(new PrefixSet()) { | 362 : prefix_set_(new PrefixSet()) { |
| 362 } | 363 } |
| 363 | 364 |
| 364 PrefixSetBuilder::PrefixSetBuilder(const std::vector<SBPrefix>& prefixes) | 365 PrefixSetBuilder::PrefixSetBuilder(const std::vector<SBPrefix>& prefixes) |
| 365 : prefix_set_(new PrefixSet()) { | 366 : prefix_set_(new PrefixSet()) { |
| 366 for (size_t i = 0; i < prefixes.size(); ++i) { | 367 for (size_t i = 0; i < prefixes.size(); ++i) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } | 440 } |
| 440 buffer_.push_back(prefix); | 441 buffer_.push_back(prefix); |
| 441 | 442 |
| 442 // Flush buffer when a run can be constructed. +1 for the index item, and +1 | 443 // Flush buffer when a run can be constructed. +1 for the index item, and +1 |
| 443 // to leave at least one item in the buffer for dropping duplicates. | 444 // to leave at least one item in the buffer for dropping duplicates. |
| 444 if (buffer_.size() > PrefixSet::kMaxRun + 2) | 445 if (buffer_.size() > PrefixSet::kMaxRun + 2) |
| 445 EmitRun(); | 446 EmitRun(); |
| 446 } | 447 } |
| 447 | 448 |
| 448 } // namespace safe_browsing | 449 } // namespace safe_browsing |
| OLD | NEW |