diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-10 23:27:32 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-10 23:27:32 +0000 |
commit | 9e78974689a785e035d107fcf793880fd338e416 (patch) | |
tree | 5b670eeb39cd10aeb13e5c652342fb8abd9dab61 | |
parent | 5894335286ebbaf32decd466f8f54e42dbada9f8 (diff) | |
download | chromium_src-9e78974689a785e035d107fcf793880fd338e416.zip chromium_src-9e78974689a785e035d107fcf793880fd338e416.tar.gz chromium_src-9e78974689a785e035d107fcf793880fd338e416.tar.bz2 |
Adds lab for making instant suggest autocomplete immediately. As part
of this I encountered a bug in SearchProvider::FinalizeInstantQuery
which has been fixed (with test).
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6142008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70960 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 6 | ||||
-rw-r--r-- | chrome/browser/about_flags.cc | 7 | ||||
-rw-r--r-- | chrome/browser/autocomplete/search_provider.cc | 19 | ||||
-rw-r--r-- | chrome/browser/autocomplete/search_provider.h | 3 | ||||
-rw-r--r-- | chrome/browser/autocomplete/search_provider_unittest.cc | 36 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 17 | ||||
-rw-r--r-- | chrome/browser/ui/views/location_bar/location_bar_view.cc | 14 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 5 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 |
9 files changed, 104 insertions, 4 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index bf992dd..b14a851 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4074,6 +4074,12 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_TABBED_OPTIONS_DESCRIPTION" desc="Description of the 'Tabbed Settings' lab."> Uses an in-tab UI for the Settings (Options/Preferences) dialog instead of a stand-alone window. </message> + <message name="IDS_FLAGS_INSTANT_AUTOCOMPLETE_IMMEDIATELY_NAME" desc="Name of the 'Instant Autocomplete Immediately' lab."> + Instant Autocomplete Immediately + </message> + <message name="IDS_FLAGS_INSTANT_AUTOCOMPLETE_IMMEDIATELY_DESCRIPTION" desc="Description of the 'Instant Autocomplete Immediately' lab."> + Whether the search provider suggestion should be autocompleted immediately when instant is enabled. + </message> <message name="IDS_FLAGS_PREDICTIVE_INSTANT_NAME" desc="Description of the predictive 'Instant' lab."> Instant </message> diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 69b7a4e..9caa41c 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -266,6 +266,13 @@ const Experiment kExperiments[] = { kOsWin, MULTI_VALUE_TYPE(kInstantChoices) }, + { + "instant-autocomplete-immediately", // FLAGS:RECORD_UMA + IDS_FLAGS_INSTANT_AUTOCOMPLETE_IMMEDIATELY_NAME, + IDS_FLAGS_INSTANT_AUTOCOMPLETE_IMMEDIATELY_DESCRIPTION, + kOsWin | kOsLinux, + SINGLE_VALUE_TYPE(switches::kInstantAutocompleteImmediately) + }, }; const Experiment* experiments = kExperiments; diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index 4c9da21..f7c7cb3 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -78,6 +78,8 @@ void SearchProvider::FinalizeInstantQuery(const std::wstring& input_text, return; } + default_provider_suggest_text_ = suggest_text; + std::wstring adjusted_input_text(input_text); AutocompleteInput::RemoveForcedQueryStringIfNecessary(input_.type(), &adjusted_input_text); @@ -162,9 +164,12 @@ void SearchProvider::Start(const AutocompleteInput& input, // If we're still running an old query but have since changed the query text // or the providers, abort the query. - if (!done_ && (!minimal_changes || - !providers_.equals(default_provider, keyword_provider))) { - Stop(); + if (!minimal_changes || + !providers_.equals(default_provider, keyword_provider)) { + if (done_) + default_provider_suggest_text_.clear(); + else + Stop(); } providers_.Set(default_provider, keyword_provider); @@ -218,6 +223,7 @@ void SearchProvider::Run() { void SearchProvider::Stop() { StopSuggest(); done_ = true; + default_provider_suggest_text_.clear(); } void SearchProvider::OnURLFetchComplete(const URLFetcher* source, @@ -531,6 +537,13 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, did_not_accept_default_suggestion, false, input_.initial_prevent_inline_autocomplete(), &map); + if (!default_provider_suggest_text_.empty()) { + AddMatchToMap(input_.text() + default_provider_suggest_text_, + input_.text(), CalculateRelevanceForWhatYouTyped() + 1, + AutocompleteMatch::SEARCH_SUGGEST, + did_not_accept_default_suggestion, false, + input_.initial_prevent_inline_autocomplete(), &map); + } } AddHistoryResultsToMap(keyword_history_results_, true, diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h index 9b83c3d..6f1d462 100644 --- a/chrome/browser/autocomplete/search_provider.h +++ b/chrome/browser/autocomplete/search_provider.h @@ -317,6 +317,9 @@ class SearchProvider : public AutocompleteProvider, // Has FinalizeInstantQuery been invoked since the last |Start|? bool instant_finalized_; + // The |suggest_text| parameter passed to FinalizeInstantQuery. + std::wstring default_provider_suggest_text_; + DISALLOW_COPY_AND_ASSIGN(SearchProvider); }; diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index 7120a08..80ae91a 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -388,3 +388,39 @@ TEST_F(SearchProviderTest, FinalizeInstantQuery) { // The instant search should be more relevant. EXPECT_GT(instant_match.relevance, what_you_typed_match.relevance); } + +// Make sure that if FinalizeInstantQuery is invoked before suggest results +// return, the suggest text from FinalizeInstantQuery is remembered. +TEST_F(SearchProviderTest, RememberInstantQuery) { + PrefService* service = profile_.GetPrefs(); + service->SetBoolean(prefs::kInstantEnabled, true); + + QueryForInput(ASCIIToUTF16("foo"), false); + + // Finalize the instant query immediately. + provider_->FinalizeInstantQuery(L"foo", L"bar"); + + // There should be two matches, one for what you typed, the other for + // 'foobar'. + EXPECT_EQ(2u, provider_->matches().size()); + GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( + *default_t_url_, L"foobar", 0, std::wstring())); + AutocompleteMatch instant_match = FindMatchWithDestination(instant_url); + EXPECT_FALSE(instant_match.destination_url.is_empty()); + + // Wait until history and the suggest query complete. + profile_.BlockUntilHistoryProcessesPendingRequests(); + ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); + + // Provider should be done. + EXPECT_TRUE(provider_->done()); + + // There should be two matches, one for what you typed, the other for + // 'foobar'. + EXPECT_EQ(2u, provider_->matches().size()); + instant_match = FindMatchWithDestination(instant_url); + EXPECT_FALSE(instant_match.destination_url.is_empty()); + + // And the 'foobar' match should have a description. + EXPECT_FALSE(instant_match.description.empty()); +} diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 6bc7513..30279ca 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -10,6 +10,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/basictypes.h" +#include "base/command_line.h" #include "base/i18n/rtl.h" #include "base/logging.h" #include "base/string_util.h" @@ -45,6 +46,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/omnibox/location_bar_util.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_resource.h" @@ -624,7 +626,20 @@ void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { } void LocationBarViewGtk::SetSuggestedText(const string16& text) { - location_entry_->SetInstantSuggestion(UTF16ToUTF8(text)); + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kInstantAutocompleteImmediately)) { + // This method is internally invoked to reset suggest text, so we only do + // anything if the text isn't empty. + // TODO: if we keep autocomplete, make it so this isn't invoked with empty + // text. + if (!text.empty()) { + location_entry_->model()->FinalizeInstantQuery( + location_entry_->GetText(), + UTF16ToWide(text)); + } + } else { + location_entry_->SetInstantSuggestion(UTF16ToUTF8(text)); + } } std::wstring LocationBarViewGtk::GetInputString() const { diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index b5dad74..cc7b76a 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -12,6 +12,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/theme_provider.h" +#include "base/command_line.h" #include "base/stl_util-inl.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" @@ -36,6 +37,7 @@ #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" #include "chrome/browser/ui/views/location_bar/star_view.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "gfx/canvas_skia.h" #include "gfx/color_utils.h" @@ -1124,6 +1126,18 @@ void LocationBarView::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { } void LocationBarView::SetSuggestedText(const string16& input) { + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kInstantAutocompleteImmediately)) { + // This method is internally invoked to reset suggest text, so we only do + // anything if the text isn't empty. + // TODO: if we keep autocomplete, make it so this isn't invoked with empty + // text. + if (!input.empty()) { + location_entry_->model()->FinalizeInstantQuery(location_entry_->GetText(), + UTF16ToWide(input)); + } + return; + } #if defined(OS_WIN) // Don't show the suggested text if inline autocomplete is prevented. string16 text = location_entry_->model()->UseVerbatimInstant() ? diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index b993023..c69408e 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -745,6 +745,11 @@ const char kInProcessWebGL[] = "in-process-webgl"; // Causes the browser to launch directly in incognito mode. const char kIncognito[] = "incognito"; +// Whether the search provider suggestion should be autocompleted immediately +// when instant is enabled. +const char kInstantAutocompleteImmediately[] = + "instant-autocomplete-immediately"; + // URL to use for instant. If specified this overrides the url from the // TemplateURL. const char kInstantURL[] = "instant-url"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 63aef44..3e5e853 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -213,6 +213,7 @@ extern const char kImportFromFile[]; extern const char kInProcessPlugins[]; extern const char kInProcessWebGL[]; extern const char kIncognito[]; +extern const char kInstantAutocompleteImmediately[]; extern const char kInstantURL[]; extern const char kInternalNaCl[]; extern const char kInternalPepper[]; |