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 "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 84 } |
85 | 85 |
86 int Scorer::model_version() const { | 86 int Scorer::model_version() const { |
87 return model_.version(); | 87 return model_.version(); |
88 } | 88 } |
89 | 89 |
90 const base::hash_set<std::string>& Scorer::page_terms() const { | 90 const base::hash_set<std::string>& Scorer::page_terms() const { |
91 return page_terms_; | 91 return page_terms_; |
92 } | 92 } |
93 | 93 |
94 const base::hash_set<uint32>& Scorer::page_words() const { | 94 const base::hash_set<uint32_t>& Scorer::page_words() const { |
95 return page_words_; | 95 return page_words_; |
96 } | 96 } |
97 | 97 |
98 size_t Scorer::max_words_per_term() const { | 98 size_t Scorer::max_words_per_term() const { |
99 return model_.max_words_per_term(); | 99 return model_.max_words_per_term(); |
100 } | 100 } |
101 | 101 |
102 uint32 Scorer::murmurhash3_seed() const { | 102 uint32_t Scorer::murmurhash3_seed() const { |
103 return model_.murmur_hash_seed(); | 103 return model_.murmur_hash_seed(); |
104 } | 104 } |
105 | 105 |
106 size_t Scorer::max_shingles_per_page() const { | 106 size_t Scorer::max_shingles_per_page() const { |
107 return model_.max_shingles_per_page(); | 107 return model_.max_shingles_per_page(); |
108 } | 108 } |
109 | 109 |
110 size_t Scorer::shingle_size() const { | 110 size_t Scorer::shingle_size() const { |
111 return model_.shingle_size(); | 111 return model_.shingle_size(); |
112 } | 112 } |
113 | 113 |
114 double Scorer::ComputeRuleScore(const ClientSideModel::Rule& rule, | 114 double Scorer::ComputeRuleScore(const ClientSideModel::Rule& rule, |
115 const FeatureMap& features) const { | 115 const FeatureMap& features) const { |
116 const base::hash_map<std::string, double>& feature_map = features.features(); | 116 const base::hash_map<std::string, double>& feature_map = features.features(); |
117 double rule_score = 1.0; | 117 double rule_score = 1.0; |
118 for (int i = 0; i < rule.feature_size(); ++i) { | 118 for (int i = 0; i < rule.feature_size(); ++i) { |
119 base::hash_map<std::string, double>::const_iterator it = feature_map.find( | 119 base::hash_map<std::string, double>::const_iterator it = feature_map.find( |
120 model_.hashes(rule.feature(i))); | 120 model_.hashes(rule.feature(i))); |
121 if (it == feature_map.end() || it->second == 0.0) { | 121 if (it == feature_map.end() || it->second == 0.0) { |
122 // If the feature of the rule does not exist in the given feature map the | 122 // If the feature of the rule does not exist in the given feature map the |
123 // feature weight is considered to be zero. If the feature weight is zero | 123 // feature weight is considered to be zero. If the feature weight is zero |
124 // we leave early since we know that the rule score will be zero. | 124 // we leave early since we know that the rule score will be zero. |
125 return 0.0; | 125 return 0.0; |
126 } | 126 } |
127 rule_score *= it->second; | 127 rule_score *= it->second; |
128 } | 128 } |
129 return rule_score * rule.weight(); | 129 return rule_score * rule.weight(); |
130 } | 130 } |
131 } // namespace safe_browsing | 131 } // namespace safe_browsing |
OLD | NEW |