summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/renderer/safe_browsing/phishing_classifier_delegate.cc28
-rw-r--r--chrome/renderer/safe_browsing/phishing_classifier_delegate.h27
2 files changed, 42 insertions, 13 deletions
diff --git a/chrome/renderer/safe_browsing/phishing_classifier_delegate.cc b/chrome/renderer/safe_browsing/phishing_classifier_delegate.cc
index c58f061..cc767ca 100644
--- a/chrome/renderer/safe_browsing/phishing_classifier_delegate.cc
+++ b/chrome/renderer/safe_browsing/phishing_classifier_delegate.cc
@@ -72,6 +72,11 @@ class ScorerCallback {
scoped_ptr<base::ScopedCallbackFactory<ScorerCallback> > callback_factory_;
};
+PhishingClassifierFilter::PhishingClassifierFilter()
+ : RenderProcessObserver() {}
+
+PhishingClassifierFilter::~PhishingClassifierFilter() {}
+
bool PhishingClassifierFilter::OnControlMessageReceived(
const IPC::Message& message) {
bool handled = true;
@@ -95,7 +100,8 @@ PhishingClassifierDelegate::PhishingClassifierDelegate(
PhishingClassifier* classifier)
: RenderViewObserver(render_view),
last_main_frame_transition_(PageTransition::LINK),
- have_page_text_(false) {
+ have_page_text_(false),
+ is_classifying_(false) {
g_delegates.Get().insert(this);
if (!classifier) {
classifier = new PhishingClassifier(render_view,
@@ -109,7 +115,7 @@ PhishingClassifierDelegate::PhishingClassifierDelegate(
}
PhishingClassifierDelegate::~PhishingClassifierDelegate() {
- CancelPendingClassification();
+ CancelPendingClassification(SHUTDOWN);
g_delegates.Get().erase(this);
}
@@ -143,10 +149,8 @@ void PhishingClassifierDelegate::DidCommitProvisionalLoad(
// swap out the page text while the term feature extractor is still running.
NavigationState* state = NavigationState::FromDataSource(
frame->dataSource());
- if (state->was_within_same_page()) {
- UMA_HISTOGRAM_COUNTS("SBClientPhishing.CanceledForInPageNavigation", 1);
- }
- CancelPendingClassification();
+ CancelPendingClassification(state->was_within_same_page() ?
+ NAVIGATE_WITHIN_PAGE : NAVIGATE_AWAY);
if (frame == render_view()->webview()->mainFrame()) {
last_main_frame_transition_ = state->transition_type();
}
@@ -162,14 +166,21 @@ void PhishingClassifierDelegate::PageCaptured(string16* page_text,
//
// Note: Currently, if the url hasn't changed, we won't restart
// classification in this case. We may want to adjust this.
- CancelPendingClassification();
+ CancelPendingClassification(PAGE_RECAPTURED);
last_finished_load_url_ = GetToplevelUrl();
classifier_page_text_.swap(*page_text);
have_page_text_ = true;
MaybeStartClassification();
}
-void PhishingClassifierDelegate::CancelPendingClassification() {
+void PhishingClassifierDelegate::CancelPendingClassification(
+ CancelClassificationReason reason) {
+ if (is_classifying_) {
+ UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.CancelClassificationReason",
+ reason,
+ CANCEL_CLASSIFICATION_MAX);
+ is_classifying_ = false;
+ }
if (classifier_->is_ready()) {
classifier_->CancelPendingClassification();
}
@@ -267,6 +278,7 @@ void PhishingClassifierDelegate::MaybeStartClassification() {
VLOG(2) << "Starting classification for " << last_finished_load_url_;
last_url_sent_to_classifier_ = last_finished_load_url_;
+ is_classifying_ = true;
classifier_->BeginClassification(
&classifier_page_text_,
NewCallback(this, &PhishingClassifierDelegate::ClassificationDone));
diff --git a/chrome/renderer/safe_browsing/phishing_classifier_delegate.h b/chrome/renderer/safe_browsing/phishing_classifier_delegate.h
index c86be3f..9761c4a 100644
--- a/chrome/renderer/safe_browsing/phishing_classifier_delegate.h
+++ b/chrome/renderer/safe_browsing/phishing_classifier_delegate.h
@@ -23,8 +23,15 @@ class Scorer;
class PhishingClassifierFilter : public RenderProcessObserver {
public:
+ PhishingClassifierFilter();
+ virtual ~PhishingClassifierFilter();
+
virtual bool OnControlMessageReceived(const IPC::Message& message);
+
+ private:
void OnSetPhishingModel(IPC::PlatformFileForTransit model_file);
+
+ DISALLOW_COPY_AND_ASSIGN(PhishingClassifierFilter);
};
class PhishingClassifierDelegate : public RenderViewObserver {
@@ -34,7 +41,7 @@ class PhishingClassifierDelegate : public RenderViewObserver {
// will be used.
PhishingClassifierDelegate(RenderView* render_view,
PhishingClassifier* classifier);
- ~PhishingClassifierDelegate();
+ virtual ~PhishingClassifierDelegate();
// Called by the RenderView once there is a phishing scorer available.
// The scorer is passed on to the classifier.
@@ -56,13 +63,20 @@ class PhishingClassifierDelegate : public RenderViewObserver {
virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame,
bool is_new_navigation);
- // Cancels any pending classification and frees the page text. Called by
- // the RenderView when the RenderView is going away.
- void CancelPendingClassification();
-
private:
friend class PhishingClassifierDelegateTest;
+ enum CancelClassificationReason {
+ NAVIGATE_AWAY,
+ NAVIGATE_WITHIN_PAGE,
+ PAGE_RECAPTURED,
+ SHUTDOWN,
+ CANCEL_CLASSIFICATION_MAX // Always add new values before this one.
+ };
+
+ // Cancels any pending classification and frees the page text.
+ void CancelPendingClassification(CancelClassificationReason reason);
+
// RenderViewObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message);
@@ -117,6 +131,9 @@ class PhishingClassifierDelegate : public RenderViewObserver {
// PageCaptured has not been called.
bool have_page_text_;
+ // Set to true if the classifier is currently running.
+ bool is_classifying_;
+
DISALLOW_COPY_AND_ASSIGN(PhishingClassifierDelegate);
};