summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete/autocomplete_popup_model.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-31 20:32:16 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-31 20:32:16 +0000
commitaf581991ca3ac3eb9cfa267838ec5f129d3e496a (patch)
tree719796cfb9e83ad9541577ff541da112e7704ded /chrome/browser/autocomplete/autocomplete_popup_model.cc
parent8ebde6bb112957ea0ff13b9b2297967bacf0acb3 (diff)
downloadchromium_src-af581991ca3ac3eb9cfa267838ec5f129d3e496a.zip
chromium_src-af581991ca3ac3eb9cfa267838ec5f129d3e496a.tar.gz
chromium_src-af581991ca3ac3eb9cfa267838ec5f129d3e496a.tar.bz2
Reland r24920 without the other cruft that I had in my checkout, which broke the compile.
TBR=mmoss BUG=none TEST=none Review URL: http://codereview.chromium.org/176043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24928 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/autocomplete_popup_model.cc')
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.cc49
1 files changed, 22 insertions, 27 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc
index d3a6fe6..0e75699 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_model.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc
@@ -150,6 +150,7 @@ GURL AutocompletePopupModel::URLsForCurrentSelection(
PageTransition::Type* transition,
bool* is_history_what_you_typed_match,
GURL* alternate_nav_url) const {
+ CHECK(IsOpen());
const AutocompleteResult* result;
AutocompleteResult::const_iterator match;
if (!controller_->done()) {
@@ -170,8 +171,9 @@ GURL AutocompletePopupModel::URLsForCurrentSelection(
// controller_->latest_result() here too, since the controller keeps that
// up-to-date. However we generally try to avoid referring to that.
result = &controller_->result();
- // If there are no results, the popup is closed, so URLsForDefaultMatch()
- // should have been called instead.
+ // If there are no results, the popup should be closed (so we should have
+ // failed the CHECK above), and URLsForDefaultMatch() should have been
+ // called instead.
CHECK(!result->empty());
CHECK(selected_line_ < result->size());
match = result->begin() + selected_line_;
@@ -193,28 +195,32 @@ GURL AutocompletePopupModel::URLsForDefaultMatch(
GURL* alternate_nav_url) {
// We had better not already be doing anything, or this call will blow it
// away.
- DCHECK(!IsOpen());
- DCHECK(controller_->done());
+ CHECK(!IsOpen());
+ CHECK(controller_->done());
// Run the new query and get only the synchronously available matches.
inside_synchronous_query_ = true; // Tell Observe() not to notify the edit or
// update our appearance.
controller_->Start(text, desired_tld, true, false, true);
inside_synchronous_query_ = false;
- DCHECK(controller_->done());
+ CHECK(controller_->done());
+
const AutocompleteResult& result = controller_->result();
- if (result.empty())
- return GURL();
+ GURL destination_url;
+ if (!result.empty()) {
+ // 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();
+ destination_url = match->destination_url;
+ }
- // 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;
+ controller_->Stop(true); // Keeps our state consistent.
+ return destination_url;
}
bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match,
@@ -253,17 +259,6 @@ AutocompleteLog* AutocompletePopupModel::GetAutocompleteLog() {
}
void AutocompletePopupModel::Move(int count) {
- // TODO(pkasting): Temporary hack. If the query is running while the popup is
- // open, we might be showing the results of the previous query still. Force
- // the popup to display the latest results so the popup and the controller
- // aren't out of sync. The better fix here is to roll the controller back to
- // be in sync with what the popup is showing.
- if (IsOpen() && !controller_->done()) {
- Observe(NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED,
- Source<AutocompleteController>(controller_.get()),
- Details<const AutocompleteResult>(&controller_->result()));
- }
-
const AutocompleteResult& result = controller_->result();
if (result.empty())
return;