summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-29 17:53:21 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-29 17:53:21 +0000
commit90085af068d552aa301e2ea7408cb6847cdc591e (patch)
treee7ed2538a78794a32a5bcce47ab7505e7b4bf4c1 /chrome/browser/autocomplete
parentebdc76943e8909d261b6d776ed973a16c0086341 (diff)
downloadchromium_src-90085af068d552aa301e2ea7408cb6847cdc591e.zip
chromium_src-90085af068d552aa301e2ea7408cb6847cdc591e.tar.gz
chromium_src-90085af068d552aa301e2ea7408cb6847cdc591e.tar.bz2
Factor search vs. navigate classification into its own file to make it more broadly usable. Patch by Thiago Farina (see http://codereview.chromium.org/328031 ), r=me.
BUG=21317 TEST=none git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30473 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc84
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h14
2 files changed, 16 insertions, 82 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index cd7ea1e..218fdd5 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/search_versus_navigate_classifier.h"
#include "chrome/common/notification_service.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_util.h"
@@ -25,14 +26,6 @@
///////////////////////////////////////////////////////////////////////////////
// AutocompleteEditModel
-// A single AutocompleteController used solely for making synchronous calls. We
-// avoid using the popup's controller here because we don't want to interrupt
-// in-progress queries or modify the popup state. We don't need a controller
-// for every edit because this will always be accessed on the main thread, so we
-// won't have thread-safety problems.
-static AutocompleteController* synchronous_controller = NULL;
-static int synchronous_controller_refcount = 0;
-
AutocompleteEditModel::AutocompleteEditModel(
AutocompleteEditView* view,
AutocompleteEditController* controller,
@@ -52,16 +45,6 @@ AutocompleteEditModel::AutocompleteEditModel(
show_search_hint_(true),
paste_and_go_transition_(PageTransition::TYPED),
profile_(profile) {
- if (++synchronous_controller_refcount == 1) {
- // We don't have a controller yet, so create one. No profile is set since
- // we'll set this before each call to the controller.
- synchronous_controller = new AutocompleteController(NULL);
- }
-}
-
-AutocompleteEditModel::~AutocompleteEditModel() {
- if (--synchronous_controller_refcount == 0)
- delete synchronous_controller;
}
void AutocompleteEditModel::SetPopupModel(AutocompletePopupModel* popup_model) {
@@ -203,28 +186,13 @@ void AutocompleteEditModel::StartAutocomplete(
}
bool AutocompleteEditModel::CanPasteAndGo(const std::wstring& text) const {
- // Reset local state.
paste_and_go_url_ = GURL();
paste_and_go_transition_ = PageTransition::TYPED;
paste_and_go_alternate_nav_url_ = GURL();
- // Ask the controller what do do with this input.
- // Setting the profile is cheap, and since there's one synchronous_controller
- // for many tabs which may all have different profiles, it ensures we're
- // always using the right one.
- synchronous_controller->SetProfile(profile_);
- synchronous_controller->Start(text, std::wstring(), true, false, true);
- DCHECK(synchronous_controller->done());
- const AutocompleteResult& result = synchronous_controller->result();
- if (result.empty())
- return false;
-
- // Set local state based on the default action for this input.
- const AutocompleteResult::const_iterator match(result.default_match());
- DCHECK(match != result.end());
- paste_and_go_url_ = match->destination_url;
- paste_and_go_transition_ = match->transition;
- paste_and_go_alternate_nav_url_ = result.alternate_nav_url();
+ profile_->GetSearchVersusNavigateClassifier()->Classify(text, std::wstring(),
+ NULL, &paste_and_go_url_, &paste_and_go_transition_, NULL,
+ &paste_and_go_alternate_nav_url_);
return paste_and_go_url_.is_valid();
}
@@ -600,38 +568,16 @@ GURL AutocompleteEditModel::GetURLForCurrentText(
PageTransition::Type* transition,
bool* is_history_what_you_typed_match,
GURL* alternate_nav_url) const {
- return (popup_->IsOpen() || query_in_progress()) ?
- popup_->URLsForCurrentSelection(transition,
- is_history_what_you_typed_match,
- alternate_nav_url) :
- URLsForDefaultMatch(transition, is_history_what_you_typed_match,
- alternate_nav_url);
-}
+ if (popup_->IsOpen() || query_in_progress()) {
+ return popup_->URLsForCurrentSelection(transition,
+ is_history_what_you_typed_match,
+ alternate_nav_url);
+ }
-GURL AutocompleteEditModel::URLsForDefaultMatch(
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url) const {
- // Ask the controller what do do with this input.
- // Setting the profile is cheap, and since there's one synchronous_controller
- // for many tabs which may all have different profiles, it ensures we're
- // always using the right one.
- synchronous_controller->SetProfile(profile_);
- synchronous_controller->Start(UserTextFromDisplayText(view_->GetText()),
- GetDesiredTLD(), true, false, true);
- CHECK(synchronous_controller->done());
-
- const AutocompleteResult& result = synchronous_controller->result();
- if (result.empty())
- return GURL();
-
- // Get the URLs for the default match.
- const AutocompleteResult::const_iterator match = result.default_match();
- if (transition)
- *transition = match->transition;
- if (is_history_what_you_typed_match)
- *is_history_what_you_typed_match = match->is_history_what_you_typed_match;
- if (alternate_nav_url)
- *alternate_nav_url = result.alternate_nav_url();
- return match->destination_url;
+ GURL destination_url;
+ profile_->GetSearchVersusNavigateClassifier()->Classify(
+ UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), NULL,
+ &destination_url, transition, is_history_what_you_typed_match,
+ alternate_nav_url);
+ return destination_url;
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index 741b8a0..a4f4e69 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -101,7 +101,7 @@ class AutocompleteEditModel : public NotificationObserver {
AutocompleteEditModel(AutocompleteEditView* view,
AutocompleteEditController* controller,
Profile* profile);
- ~AutocompleteEditModel();
+ ~AutocompleteEditModel() {}
void SetPopupModel(AutocompletePopupModel* popup_model);
@@ -334,18 +334,6 @@ class AutocompleteEditModel : public NotificationObserver {
bool* is_history_what_you_typed_match,
GURL* alternate_nav_url) const;
- // Performs a query for only the synchronously available matches for the
- // current input, sets |transition|, |is_history_what_you_typed_match|, and
- // |alternate_nav_url| (if applicable) based on the default match, and returns
- // its url. |transition|, |is_history_what_you_typed_match| and/or
- // |alternate_nav_url| may be null, in which case they are not updated.
- //
- // If there are no matches for the input, leaves the outparams unset and
- // returns the empty string.
- GURL URLsForDefaultMatch(PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url) const;
-
AutocompleteEditView* view_;
AutocompletePopupModel* popup_;