Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 5 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" | 17 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" |
| 18 #include "chrome/browser/autocomplete/bookmark_provider.h" | 18 #include "chrome/browser/autocomplete/bookmark_provider.h" |
| 19 #include "chrome/browser/autocomplete/builtin_provider.h" | 19 #include "chrome/browser/autocomplete/builtin_provider.h" |
| 20 #include "chrome/browser/autocomplete/extension_app_provider.h" | 20 #include "chrome/browser/autocomplete/extension_app_provider.h" |
| 21 #include "chrome/browser/autocomplete/history_contents_provider.h" | 21 #include "chrome/browser/autocomplete/history_contents_provider.h" |
| 22 #include "chrome/browser/autocomplete/history_quick_provider.h" | 22 #include "chrome/browser/autocomplete/history_quick_provider.h" |
| 23 #include "chrome/browser/autocomplete/history_url_provider.h" | 23 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 24 #include "chrome/browser/autocomplete/keyword_provider.h" | 24 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 25 #include "chrome/browser/autocomplete/search_provider.h" | 25 #include "chrome/browser/autocomplete/search_provider.h" |
| 26 #include "chrome/browser/autocomplete/shortcuts_provider.h" | 26 #include "chrome/browser/autocomplete/shortcuts_provider.h" |
| 27 #include "chrome/browser/autocomplete/zero_suggest_provider.h" | 27 #include "chrome/browser/autocomplete/zero_suggest_provider.h" |
| 28 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 28 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/search/search.h" | |
| 30 #include "chrome/browser/search_engines/template_url.h" | 31 #include "chrome/browser/search_engines/template_url.h" |
| 31 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
| 32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 33 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 34 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
| 35 #include "grit/theme_resources.h" | 36 #include "grit/theme_resources.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 37 | 38 |
| 38 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
| 39 #include "chrome/browser/autocomplete/contact_provider_chromeos.h" | 40 #include "chrome/browser/autocomplete/contact_provider_chromeos.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 if (!autocompletions->empty()) | 112 if (!autocompletions->empty()) |
| 112 autocompletions->append("j"); | 113 autocompletions->append("j"); |
| 113 base::StringAppendF(autocompletions, "%" PRIuS, type); | 114 base::StringAppendF(autocompletions, "%" PRIuS, type); |
| 114 // Subtype is optional - string16::npos indicates no subtype. | 115 // Subtype is optional - string16::npos indicates no subtype. |
| 115 if (subtype != string16::npos) | 116 if (subtype != string16::npos) |
| 116 base::StringAppendF(autocompletions, "i%" PRIuS, subtype); | 117 base::StringAppendF(autocompletions, "i%" PRIuS, subtype); |
| 117 if (count > 1) | 118 if (count > 1) |
| 118 base::StringAppendF(autocompletions, "l%d", count); | 119 base::StringAppendF(autocompletions, "l%d", count); |
| 119 } | 120 } |
| 120 | 121 |
| 121 // Amount of time (in ms) between when the user stops typing and when we remove | |
| 122 // any copied entries. We do this from the time the user stopped typing as some | |
| 123 // providers (such as SearchProvider) wait for the user to stop typing before | |
| 124 // they initiate a query. | |
| 125 const int kExpireTimeMS = 500; | |
| 126 | |
| 127 } // namespace | 122 } // namespace |
| 128 | 123 |
| 129 const int AutocompleteController::kNoItemSelected = -1; | 124 const int AutocompleteController::kNoItemSelected = -1; |
| 130 | 125 |
| 131 AutocompleteController::AutocompleteController( | 126 AutocompleteController::AutocompleteController( |
| 132 Profile* profile, | 127 Profile* profile, |
| 133 AutocompleteControllerDelegate* delegate, | 128 AutocompleteControllerDelegate* delegate, |
| 134 int provider_types) | 129 int provider_types) |
| 135 : delegate_(delegate), | 130 : delegate_(delegate), |
| 136 history_url_provider_(NULL), | 131 history_url_provider_(NULL), |
| 137 keyword_provider_(NULL), | 132 keyword_provider_(NULL), |
| 138 search_provider_(NULL), | 133 search_provider_(NULL), |
| 139 zero_suggest_provider_(NULL), | 134 zero_suggest_provider_(NULL), |
| 135 in_stop_timer_field_trial_( | |
| 136 OmniboxFieldTrial::InStopTimerFieldTrialExperimentGroup()), | |
| 140 done_(true), | 137 done_(true), |
| 141 in_start_(false), | 138 in_start_(false), |
| 142 in_zero_suggest_(false), | 139 in_zero_suggest_(false), |
| 143 profile_(profile) { | 140 profile_(profile) { |
| 144 // AND with the disabled providers, if any. | 141 // AND with the disabled providers, if any. |
| 145 provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes(); | 142 provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes(); |
| 146 bool use_hqp = !!(provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK); | 143 bool use_hqp = !!(provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK); |
| 147 // TODO(mrossetti): Permanently modify the HistoryURLProvider to not search | 144 // TODO(mrossetti): Permanently modify the HistoryURLProvider to not search |
| 148 // titles once HQP is turned on permanently. | 145 // titles once HQP is turned on permanently. |
| 149 // History quick provider can be used on all platforms other than Android. | 146 // History quick provider can be used on all platforms other than Android. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 // may no longer be prevented. In both these cases the text itself hasn't | 226 // may no longer be prevented. In both these cases the text itself hasn't |
| 230 // changed since the last query, and some providers can do much less work (and | 227 // changed since the last query, and some providers can do much less work (and |
| 231 // get matches back more quickly). Taking advantage of this reduces flicker. | 228 // get matches back more quickly). Taking advantage of this reduces flicker. |
| 232 // | 229 // |
| 233 // NOTE: This comes after constructing |input_| above since that construction | 230 // NOTE: This comes after constructing |input_| above since that construction |
| 234 // can change the text string (e.g. by stripping off a leading '?'). | 231 // can change the text string (e.g. by stripping off a leading '?'). |
| 235 const bool minimal_changes = (input_.text() == old_input_text) && | 232 const bool minimal_changes = (input_.text() == old_input_text) && |
| 236 (input_.matches_requested() == old_matches_requested); | 233 (input_.matches_requested() == old_matches_requested); |
| 237 | 234 |
| 238 expire_timer_.Stop(); | 235 expire_timer_.Stop(); |
| 236 stop_timer_.Stop(); | |
| 239 | 237 |
| 240 // Start the new query. | 238 // Start the new query. |
| 241 in_zero_suggest_ = false; | 239 in_zero_suggest_ = false; |
| 242 in_start_ = true; | 240 in_start_ = true; |
| 243 base::TimeTicks start_time = base::TimeTicks::Now(); | 241 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 244 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); | 242 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); |
| 245 ++i) { | 243 ++i) { |
| 246 (*i)->Start(input_, minimal_changes); | 244 (*i)->Start(input_, minimal_changes); |
| 247 if (input.matches_requested() != AutocompleteInput::ALL_MATCHES) | 245 if (input.matches_requested() != AutocompleteInput::ALL_MATCHES) |
| 248 DCHECK((*i)->done()); | 246 DCHECK((*i)->done()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 266 // even if the current match is for the same URL as the last run's | 264 // even if the current match is for the same URL as the last run's |
| 267 // default match. Likewise, the controller doesn't know what's | 265 // default match. Likewise, the controller doesn't know what's |
| 268 // happened in the edit since the last time it ran autocomplete. | 266 // happened in the edit since the last time it ran autocomplete. |
| 269 // The user might have selected all the text and hit delete, then | 267 // The user might have selected all the text and hit delete, then |
| 270 // typed a new character. The selection and delete won't send any | 268 // typed a new character. The selection and delete won't send any |
| 271 // signals to the controller so it doesn't realize that anything was | 269 // signals to the controller so it doesn't realize that anything was |
| 272 // cleared or changed. Even if the default match hasn't changed, we | 270 // cleared or changed. Even if the default match hasn't changed, we |
| 273 // need the edit model to update the display. | 271 // need the edit model to update the display. |
| 274 UpdateResult(false, true); | 272 UpdateResult(false, true); |
| 275 | 273 |
| 276 if (!done_) | 274 if (!done_) { |
| 277 StartExpireTimer(); | 275 StartExpireTimer(); |
| 276 StartStopTimer(); | |
| 277 } | |
| 278 } | 278 } |
| 279 | 279 |
| 280 void AutocompleteController::Stop(bool clear_result) { | 280 void AutocompleteController::Stop(bool clear_result) { |
| 281 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); | 281 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); |
| 282 ++i) { | 282 ++i) { |
| 283 (*i)->Stop(clear_result); | 283 (*i)->Stop(clear_result); |
| 284 } | 284 } |
| 285 | 285 |
| 286 expire_timer_.Stop(); | 286 expire_timer_.Stop(); |
| 287 stop_timer_.Stop(); | |
| 287 done_ = true; | 288 done_ = true; |
| 288 if (clear_result && !result_.empty()) { | 289 if (clear_result && !result_.empty()) { |
| 289 result_.Reset(); | 290 result_.Reset(); |
| 290 // NOTE: We pass in false since we're trying to only clear the popup, not | 291 // NOTE: We pass in false since we're trying to only clear the popup, not |
| 291 // touch the edit... this is all a mess and should be cleaned up :( | 292 // touch the edit... this is all a mess and should be cleaned up :( |
| 292 NotifyChanged(false); | 293 NotifyChanged(false); |
| 293 } | 294 } |
| 294 } | 295 } |
| 295 | 296 |
| 296 void AutocompleteController::StartZeroSuggest( | 297 void AutocompleteController::StartZeroSuggest( |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 ++i) { | 582 ++i) { |
| 582 if (!(*i)->done()) { | 583 if (!(*i)->done()) { |
| 583 done_ = false; | 584 done_ = false; |
| 584 return; | 585 return; |
| 585 } | 586 } |
| 586 } | 587 } |
| 587 done_ = true; | 588 done_ = true; |
| 588 } | 589 } |
| 589 | 590 |
| 590 void AutocompleteController::StartExpireTimer() { | 591 void AutocompleteController::StartExpireTimer() { |
| 592 // Amount of time (in ms) between when the user stops typing and | |
| 593 // when we remove any copied entries. We do this from the time the | |
| 594 // user stopped typing as some providers (such as SearchProvider) | |
| 595 // wait for the user to stop typing before they initiate a query. | |
| 596 const int kExpireTimeMS = 500; | |
| 597 | |
| 591 if (result_.HasCopiedMatches()) | 598 if (result_.HasCopiedMatches()) |
| 592 expire_timer_.Start(FROM_HERE, | 599 expire_timer_.Start(FROM_HERE, |
| 593 base::TimeDelta::FromMilliseconds(kExpireTimeMS), | 600 base::TimeDelta::FromMilliseconds(kExpireTimeMS), |
| 594 this, &AutocompleteController::ExpireCopiedEntries); | 601 this, &AutocompleteController::ExpireCopiedEntries); |
| 595 } | 602 } |
| 603 | |
| 604 void AutocompleteController::StartStopTimer() { | |
| 605 if (!in_stop_timer_field_trial_) | |
| 606 return; | |
| 607 | |
| 608 // Amount of time (in ms) between when the user stops typing and | |
| 609 // when we send Stop() to every provider. This is intended to avoid | |
| 610 // the disruptive effect of belated omnibox updates, updates that | |
| 611 // come after the user has had to time to read the whole dropdown | |
| 612 // and doesn't expect it to change. This doesn't entirely prohibit | |
| 613 // late updates--some providers may ignore the Stop() call--but it | |
|
Peter Kasting
2013/04/19 19:48:53
This last sentence worries me. No one should be i
Mark P
2013/04/19 20:20:40
HCP cannot halt its in-processe SQL queries. It c
Peter Kasting
2013/04/19 20:26:17
Yes. Once Stop() is called we should not make any
Mark P
2013/04/19 21:11:25
Filed bug.
https://code.google.com/p/chromium/issu
| |
| 614 // does a fairly good job. | |
| 615 const int kStopTimeMS = 1500; | |
| 616 | |
| 617 // Only use the timer if Instant/InstantExtended is disabled. | |
| 618 // InstantExtended has its own logic for when to stop updating the | |
| 619 // dropdown. Furthermore, both Instant and InstantExtended expect | |
| 620 // all results they inject (regardless of how long they took) to make | |
| 621 // it to the edit model / dropdown display code. | |
| 622 if (!chrome::IsInstantExtendedAPIEnabled() && | |
| 623 !chrome::IsInstantEnabled(profile_)) { | |
| 624 stop_timer_.Start(FROM_HERE, | |
| 625 base::TimeDelta::FromMilliseconds(kStopTimeMS), | |
| 626 base::Bind(&AutocompleteController::Stop, | |
| 627 base::Unretained(this), | |
| 628 false)); | |
| 629 } | |
| 630 } | |
| OLD | NEW |