diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-24 02:46:11 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-24 02:46:11 +0000 |
commit | bdf1d86216f0d2a3f8600e3bc69147799225807d (patch) | |
tree | 9ea4800aa2947e962cd5a365abe9351ffd297d89 | |
parent | 9cbfc3b8be01d655b307eb8e79fa53ca53ba14db (diff) | |
download | chromium_src-bdf1d86216f0d2a3f8600e3bc69147799225807d.zip chromium_src-bdf1d86216f0d2a3f8600e3bc69147799225807d.tar.gz chromium_src-bdf1d86216f0d2a3f8600e3bc69147799225807d.tar.bz2 |
Instant: refactor code intended to prevent extra work.
current symptoms:
- when you send two OnChanges in a row, the second one will get the a blank |suggested_text|.
- if you type alaska, the suggestion is "alaska air". Pressing space returns a blank |suggested_text|.
fix:
- return last suggestion. Also consolidate two points in the code where we tried to prevent Update from doing extra work.
BUG=64245
TEST=manual (see bug and above)
Review URL: http://codereview.chromium.org/5330003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67206 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 21 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.cc | 25 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.h | 3 |
3 files changed, 27 insertions, 22 deletions
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index 5f7d4b6..c1b32b7 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -161,6 +161,8 @@ void InstantController::Update(TabContentsWrapper* tab_contents, const string16& user_text, bool verbatim, string16* suggested_text) { + suggested_text->clear(); + if (tab_contents != tab_contents_) DestroyPreviewContents(); @@ -170,20 +172,6 @@ void InstantController::Update(TabContentsWrapper* tab_contents, commit_on_mouse_up_ = false; last_transition_type_ = match.transition; - const TemplateURL* template_url = GetTemplateURL(match); - TemplateURLID template_url_id = template_url ? template_url->id() : 0; - // Verbatim only makes sense if the search engines supports instant. - bool real_verbatim = template_url_id ? verbatim : false; - - if (loader_manager_.get()) { - InstantLoader* active_loader = loader_manager_->active_loader(); - if (active_loader->url() == url && - active_loader->template_url_id() == template_url_id && - (!template_url_id || active_loader->verbatim() == real_verbatim)) { - return; - } - } - if (url.is_empty() || !url.is_valid() || !ShouldShowPreviewFor(match)) { DestroyPreviewContents(); return; @@ -195,6 +183,11 @@ void InstantController::Update(TabContentsWrapper* tab_contents, if (!is_active_) delegate_->PrepareForInstant(); + const TemplateURL* template_url = GetTemplateURL(match); + TemplateURLID template_url_id = template_url ? template_url->id() : 0; + // Verbatim only makes sense if the search engines supports instant. + bool real_verbatim = template_url_id ? verbatim : false; + if (ShouldUpdateNow(template_url_id, match.destination_url)) { UpdateLoader(template_url, match.destination_url, match.transition, user_text, real_verbatim, suggested_text); diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index 9ef682d..90f6689 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -407,17 +407,25 @@ void InstantLoader::Update(TabContentsWrapper* tab_contents, const string16& user_text, bool verbatim, string16* suggested_text) { - if (url_ == url && verbatim == verbatim_) + // Strip leading ?. + string16 new_user_text = + !user_text.empty() && (UTF16ToWide(user_text)[0] == L'?') ? + user_text.substr(1) : user_text; + + // If state hasn't changed, just reuse the last suggestion. + if (url_ == url && verbatim == verbatim_ && user_text_ == new_user_text && + last_transition_type_ == transition_type) { + suggested_text->assign(last_suggestion_); return; + } DCHECK(!url.is_empty() && url.is_valid()); last_transition_type_ = transition_type; url_ = url; - // Strip leading ?. - user_text_ = !user_text.empty() && (UTF16ToWide(user_text)[0] == L'?') ? - user_text.substr(1) : user_text; + user_text_ = new_user_text; verbatim_ = verbatim; + last_suggestion_.clear(); bool created_preview_contents; if (preview_contents_.get() == NULL) { @@ -480,7 +488,8 @@ void InstantLoader::Update(TabContentsWrapper* tab_contents, complete_suggested_text_lower.size() > user_text_lower.size() && !complete_suggested_text_lower.compare(0, user_text_lower.size(), user_text_lower)) { - *suggested_text = complete_suggested_text_.substr(user_text_.size()); + *suggested_text = last_suggestion_ = + complete_suggested_text_.substr(user_text_.size()); } } else { // Load the instant URL. We don't reflect the url we load in url() as @@ -616,6 +625,7 @@ void InstantLoader::SetCompleteSuggestedText( string16 user_text_lower = l10n_util::ToLower(user_text_); string16 complete_suggested_text_lower = l10n_util::ToLower( complete_suggested_text); + last_suggestion_.clear(); if (user_text_lower.compare(0, user_text_lower.size(), complete_suggested_text_lower, 0, user_text_lower.size())) { @@ -626,9 +636,8 @@ void InstantLoader::SetCompleteSuggestedText( } complete_suggested_text_ = complete_suggested_text; - delegate_->SetSuggestedTextFor( - this, - complete_suggested_text_.substr(user_text_.size())); + last_suggestion_ = complete_suggested_text_.substr(user_text_.size()); + delegate_->SetSuggestedTextFor(this, last_suggestion_); } void InstantLoader::PreviewPainted() { diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h index f19b239..7527bf4 100644 --- a/chrome/browser/instant/instant_loader.h +++ b/chrome/browser/instant/instant_loader.h @@ -162,6 +162,9 @@ class InstantLoader : public NotificationObserver { // The latest suggestion from the page. string16 complete_suggested_text_; + // The latest suggestion (suggested text less the user text). + string16 last_suggestion_; + // See description above setter. gfx::Rect omnibox_bounds_; |