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/phishing_classifier.h" | 5 #include "chrome/renderer/safe_browsing/phishing_classifier.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Note that cancelling the feature extractors is simply a no-op if they | 141 // Note that cancelling the feature extractors is simply a no-op if they |
142 // were not running. | 142 // were not running. |
143 DCHECK(is_ready()); | 143 DCHECK(is_ready()); |
144 dom_extractor_->CancelPendingExtraction(); | 144 dom_extractor_->CancelPendingExtraction(); |
145 term_extractor_->CancelPendingExtraction(); | 145 term_extractor_->CancelPendingExtraction(); |
146 weak_factory_.InvalidateWeakPtrs(); | 146 weak_factory_.InvalidateWeakPtrs(); |
147 Clear(); | 147 Clear(); |
148 } | 148 } |
149 | 149 |
150 void PhishingClassifier::DOMExtractionFinished(bool success) { | 150 void PhishingClassifier::DOMExtractionFinished(bool success) { |
151 shingle_hashes_.reset(new std::set<uint32>); | 151 shingle_hashes_.reset(new std::set<uint32_t>); |
152 if (success) { | 152 if (success) { |
153 // Term feature extraction can take awhile, so it runs asynchronously | 153 // Term feature extraction can take awhile, so it runs asynchronously |
154 // in several chunks of work and invokes the callback when finished. | 154 // in several chunks of work and invokes the callback when finished. |
155 term_extractor_->ExtractFeatures( | 155 term_extractor_->ExtractFeatures( |
156 page_text_, | 156 page_text_, |
157 features_.get(), | 157 features_.get(), |
158 shingle_hashes_.get(), | 158 shingle_hashes_.get(), |
159 base::Bind(&PhishingClassifier::TermExtractionFinished, | 159 base::Bind(&PhishingClassifier::TermExtractionFinished, |
160 base::Unretained(this))); | 160 base::Unretained(this))); |
161 } else { | 161 } else { |
(...skipping 15 matching lines...) Expand all Loading... |
177 features_->features().begin(); | 177 features_->features().begin(); |
178 it != features_->features().end(); ++it) { | 178 it != features_->features().end(); ++it) { |
179 DVLOG(2) << "Feature: " << it->first << " = " << it->second; | 179 DVLOG(2) << "Feature: " << it->first << " = " << it->second; |
180 bool result = hashed_features.AddRealFeature( | 180 bool result = hashed_features.AddRealFeature( |
181 crypto::SHA256HashString(it->first), it->second); | 181 crypto::SHA256HashString(it->first), it->second); |
182 DCHECK(result); | 182 DCHECK(result); |
183 ClientPhishingRequest::Feature* feature = verdict.add_feature_map(); | 183 ClientPhishingRequest::Feature* feature = verdict.add_feature_map(); |
184 feature->set_name(it->first); | 184 feature->set_name(it->first); |
185 feature->set_value(it->second); | 185 feature->set_value(it->second); |
186 } | 186 } |
187 for (std::set<uint32>::const_iterator it = shingle_hashes_->begin(); | 187 for (std::set<uint32_t>::const_iterator it = shingle_hashes_->begin(); |
188 it != shingle_hashes_->end(); ++it) { | 188 it != shingle_hashes_->end(); ++it) { |
189 verdict.add_shingle_hashes(*it); | 189 verdict.add_shingle_hashes(*it); |
190 } | 190 } |
191 float score = static_cast<float>(scorer_->ComputeScore(hashed_features)); | 191 float score = static_cast<float>(scorer_->ComputeScore(hashed_features)); |
192 verdict.set_client_score(score); | 192 verdict.set_client_score(score); |
193 verdict.set_is_phishing(score >= kPhishyThreshold); | 193 verdict.set_is_phishing(score >= kPhishyThreshold); |
194 RunCallback(verdict); | 194 RunCallback(verdict); |
195 } else { | 195 } else { |
196 RunFailureCallback(); | 196 RunFailureCallback(); |
197 } | 197 } |
(...skipping 24 matching lines...) Expand all Loading... |
222 } | 222 } |
223 | 223 |
224 void PhishingClassifier::Clear() { | 224 void PhishingClassifier::Clear() { |
225 page_text_ = NULL; | 225 page_text_ = NULL; |
226 done_callback_.Reset(); | 226 done_callback_.Reset(); |
227 features_.reset(NULL); | 227 features_.reset(NULL); |
228 shingle_hashes_.reset(NULL); | 228 shingle_hashes_.reset(NULL); |
229 } | 229 } |
230 | 230 |
231 } // namespace safe_browsing | 231 } // namespace safe_browsing |
OLD | NEW |