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/renderer/safe_browsing/phishing_term_feature_extractor.h" | 5 #include "chrome/renderer/safe_browsing/phishing_term_feature_extractor.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 // True if position has been initialized. | 61 // True if position has been initialized. |
62 bool position_initialized; | 62 bool position_initialized; |
63 | 63 |
64 // The time at which we started feature extraction for the current page. | 64 // The time at which we started feature extraction for the current page. |
65 base::TimeTicks start_time; | 65 base::TimeTicks start_time; |
66 | 66 |
67 // The number of iterations we've done for the current extraction. | 67 // The number of iterations we've done for the current extraction. |
68 int num_iterations; | 68 int num_iterations; |
69 | 69 |
70 ExtractionState(const string16& text, base::TimeTicks start_time_ticks) | 70 ExtractionState(const base::string16& text, base::TimeTicks start_time_ticks) |
71 : position(-1), | 71 : position(-1), |
72 position_initialized(false), | 72 position_initialized(false), |
73 start_time(start_time_ticks), | 73 start_time(start_time_ticks), |
74 num_iterations(0) { | 74 num_iterations(0) { |
75 UErrorCode status = U_ZERO_ERROR; | 75 UErrorCode status = U_ZERO_ERROR; |
76 // TODO(bryner): We should pass in the language for the document. | 76 // TODO(bryner): We should pass in the language for the document. |
77 iterator = ubrk_open(UBRK_WORD, NULL, | 77 iterator = ubrk_open(UBRK_WORD, NULL, |
78 text.data(), text.size(), | 78 text.data(), text.size(), |
79 &status); | 79 &status); |
80 if (U_FAILURE(status)) { | 80 if (U_FAILURE(status)) { |
(...skipping 25 matching lines...) Expand all Loading... |
106 Clear(); | 106 Clear(); |
107 } | 107 } |
108 | 108 |
109 PhishingTermFeatureExtractor::~PhishingTermFeatureExtractor() { | 109 PhishingTermFeatureExtractor::~PhishingTermFeatureExtractor() { |
110 // The RenderView should have called CancelPendingExtraction() before | 110 // The RenderView should have called CancelPendingExtraction() before |
111 // we are destroyed. | 111 // we are destroyed. |
112 CheckNoPendingExtraction(); | 112 CheckNoPendingExtraction(); |
113 } | 113 } |
114 | 114 |
115 void PhishingTermFeatureExtractor::ExtractFeatures( | 115 void PhishingTermFeatureExtractor::ExtractFeatures( |
116 const string16* page_text, | 116 const base::string16* page_text, |
117 FeatureMap* features, | 117 FeatureMap* features, |
118 const DoneCallback& done_callback) { | 118 const DoneCallback& done_callback) { |
119 // The RenderView should have called CancelPendingExtraction() before | 119 // The RenderView should have called CancelPendingExtraction() before |
120 // starting a new extraction, so DCHECK this. | 120 // starting a new extraction, so DCHECK this. |
121 CheckNoPendingExtraction(); | 121 CheckNoPendingExtraction(); |
122 // However, in an opt build, we will go ahead and clean up the pending | 122 // However, in an opt build, we will go ahead and clean up the pending |
123 // extraction so that we can start in a known state. | 123 // extraction so that we can start in a known state. |
124 CancelPendingExtraction(); | 124 CancelPendingExtraction(); |
125 | 125 |
126 page_text_ = page_text; | 126 page_text_ = page_text; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 301 |
302 void PhishingTermFeatureExtractor::Clear() { | 302 void PhishingTermFeatureExtractor::Clear() { |
303 page_text_ = NULL; | 303 page_text_ = NULL; |
304 features_ = NULL; | 304 features_ = NULL; |
305 done_callback_.Reset(); | 305 done_callback_.Reset(); |
306 state_.reset(NULL); | 306 state_.reset(NULL); |
307 negative_word_cache_.Clear(); | 307 negative_word_cache_.Clear(); |
308 } | 308 } |
309 | 309 |
310 } // namespace safe_browsing | 310 } // namespace safe_browsing |
OLD | NEW |