Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: components/safe_browsing_db/prefix_set.cc

Issue 1420053005: Move code in components/safe_browsing_db and chrome/browser/s_b/ under the safe_browsing namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_components_move
Patch Set: Remove '// namespace safe_browsing' for a small fwd decl block. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 safe_browsing {
17
16 namespace { 18 namespace {
17 19
18 // |kMagic| should be reasonably unique, and not match itself across 20 // |kMagic| should be reasonably unique, and not match itself across
19 // endianness changes. I generated this value with: 21 // endianness changes. I generated this value with:
20 // md5 -qs chrome/browser/safe_browsing/prefix_set.cc | colrm 9 22 // md5 -qs chrome/browser/safe_browsing/prefix_set.cc | colrm 9
21 static uint32 kMagic = 0x864088dd; 23 static uint32 kMagic = 0x864088dd;
22 24
23 // Version history: 25 // Version history:
24 // Version 1: b6cb7cfe/r74487 by shess@chromium.org on 2011-02-10 26 // 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 27 // Version 2: 2b59b0a6/r253924 by shess@chromium.org on 2014-02-27
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 (static_cast<uint64>(current_count) << 32) / current_prefix); 71 (static_cast<uint64>(current_count) << 32) / current_prefix);
70 72
71 // The estimate has an error bar, if the final total is below the estimate, no 73 // 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 74 // 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. 75 // some slop to make sure all cases are covered.
74 return estimated_prefix_count + estimated_prefix_count / 100; 76 return estimated_prefix_count + estimated_prefix_count / 100;
75 } 77 }
76 78
77 } // namespace 79 } // namespace
78 80
79 namespace safe_browsing {
80
81 // For |std::upper_bound()| to find a prefix w/in a vector of pairs. 81 // For |std::upper_bound()| to find a prefix w/in a vector of pairs.
82 // static 82 // static
83 bool PrefixSet::PrefixLess(const IndexPair& a, const IndexPair& b) { 83 bool PrefixSet::PrefixLess(const IndexPair& a, const IndexPair& b) {
84 return a.first < b.first; 84 return a.first < b.first;
85 } 85 }
86 86
87 PrefixSet::PrefixSet() { 87 PrefixSet::PrefixSet() {
88 } 88 }
89 89
90 PrefixSet::PrefixSet(IndexVector* index, 90 PrefixSet::PrefixSet(IndexVector* index,
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 440 }
441 buffer_.push_back(prefix); 441 buffer_.push_back(prefix);
442 442
443 // 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
444 // 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.
445 if (buffer_.size() > PrefixSet::kMaxRun + 2) 445 if (buffer_.size() > PrefixSet::kMaxRun + 2)
446 EmitRun(); 446 EmitRun();
447 } 447 }
448 448
449 } // namespace safe_browsing 449 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/test/ppapi/ppapi_filechooser_browsertest.cc ('k') | components/safe_browsing_db/prefix_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698