OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/renderer/safe_browsing/scorer.h" | 5 #include "chrome/renderer/safe_browsing/scorer.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
| 10 #include <unordered_map> |
10 | 11 |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
13 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
14 #include "chrome/common/safe_browsing/client_model.pb.h" | 15 #include "chrome/common/safe_browsing/client_model.pb.h" |
15 #include "chrome/renderer/safe_browsing/features.h" | 16 #include "chrome/renderer/safe_browsing/features.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 // Enum used to keep stats about the status of the Scorer creation. | 19 // Enum used to keep stats about the status of the Scorer creation. |
19 enum ScorerCreationStatus { | 20 enum ScorerCreationStatus { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 size_t Scorer::max_shingles_per_page() const { | 108 size_t Scorer::max_shingles_per_page() const { |
108 return model_.max_shingles_per_page(); | 109 return model_.max_shingles_per_page(); |
109 } | 110 } |
110 | 111 |
111 size_t Scorer::shingle_size() const { | 112 size_t Scorer::shingle_size() const { |
112 return model_.shingle_size(); | 113 return model_.shingle_size(); |
113 } | 114 } |
114 | 115 |
115 double Scorer::ComputeRuleScore(const ClientSideModel::Rule& rule, | 116 double Scorer::ComputeRuleScore(const ClientSideModel::Rule& rule, |
116 const FeatureMap& features) const { | 117 const FeatureMap& features) const { |
117 const base::hash_map<std::string, double>& feature_map = features.features(); | 118 const std::unordered_map<std::string, double>& feature_map = |
| 119 features.features(); |
118 double rule_score = 1.0; | 120 double rule_score = 1.0; |
119 for (int i = 0; i < rule.feature_size(); ++i) { | 121 for (int i = 0; i < rule.feature_size(); ++i) { |
120 base::hash_map<std::string, double>::const_iterator it = feature_map.find( | 122 const auto it = feature_map.find(model_.hashes(rule.feature(i))); |
121 model_.hashes(rule.feature(i))); | |
122 if (it == feature_map.end() || it->second == 0.0) { | 123 if (it == feature_map.end() || it->second == 0.0) { |
123 // If the feature of the rule does not exist in the given feature map the | 124 // If the feature of the rule does not exist in the given feature map the |
124 // feature weight is considered to be zero. If the feature weight is zero | 125 // feature weight is considered to be zero. If the feature weight is zero |
125 // we leave early since we know that the rule score will be zero. | 126 // we leave early since we know that the rule score will be zero. |
126 return 0.0; | 127 return 0.0; |
127 } | 128 } |
128 rule_score *= it->second; | 129 rule_score *= it->second; |
129 } | 130 } |
130 return rule_score * rule.weight(); | 131 return rule_score * rule.weight(); |
131 } | 132 } |
132 } // namespace safe_browsing | 133 } // namespace safe_browsing |
OLD | NEW |