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
3 // found in the LICENSE file.
5 #include "chrome/browser/autocomplete/autocomplete_controller.h"
10 #include "base/format_macros.h"
11 #include "base/logging.h"
12 #include "base/metrics/histogram.h"
13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h"
15 #include "base/time/time.h"
16 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
17 #include "chrome/browser/autocomplete/bookmark_provider.h"
18 #include "chrome/browser/autocomplete/builtin_provider.h"
19 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
20 #include "chrome/browser/autocomplete/history_quick_provider.h"
21 #include "chrome/browser/autocomplete/history_url_provider.h"
22 #include "chrome/browser/autocomplete/shortcuts_provider.h"
23 #include "chrome/browser/autocomplete/zero_suggest_provider.h"
24 #include "chrome/browser/chrome_notification_types.h"
25 #include "components/omnibox/keyword_provider.h"
26 #include "components/omnibox/omnibox_field_trial.h"
27 #include "components/omnibox/search_provider.h"
28 #include "components/search_engines/template_url.h"
29 #include "components/search_engines/template_url_service.h"
30 #include "content/public/browser/notification_service.h"
31 #include "grit/components_strings.h"
32 #include "ui/base/l10n/l10n_util.h"
34 #if defined(ENABLE_EXTENSIONS)
35 #include "chrome/browser/autocomplete/keyword_extensions_delegate_impl.h"
40 // Converts the given match to a type (and possibly subtype) based on the AQS
41 // specification. For more details, see
42 // http://goto.google.com/binary-clients-logging.
43 void AutocompleteMatchToAssistedQuery(
44 const AutocompleteMatch::Type
& match
,
45 const AutocompleteProvider
* provider
,
48 // This type indicates a native chrome suggestion.
50 // Default value, indicating no subtype.
51 *subtype
= base::string16::npos
;
53 // If provider is TYPE_ZERO_SUGGEST, set the subtype accordingly.
54 // Type will be set in the switch statement below where we'll enter one of
55 // SEARCH_SUGGEST or NAVSUGGEST. This subtype indicates context-aware zero
58 (provider
->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST
) &&
59 (match
!= AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED
)) {
60 DCHECK((match
== AutocompleteMatchType::SEARCH_SUGGEST
) ||
61 (match
== AutocompleteMatchType::NAVSUGGEST
));
66 case AutocompleteMatchType::SEARCH_SUGGEST
: {
67 // Do not set subtype here; subtype may have been set above.
71 case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY
: {
75 case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE
: {
79 case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED
: {
83 case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE
: {
87 case AutocompleteMatchType::SEARCH_SUGGEST_ANSWER
: {
91 case AutocompleteMatchType::NAVSUGGEST
: {
92 // Do not set subtype here; subtype may have been set above.
96 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED
: {
100 case AutocompleteMatchType::URL_WHAT_YOU_TYPED
: {
104 case AutocompleteMatchType::SEARCH_HISTORY
: {
108 case AutocompleteMatchType::HISTORY_URL
: {
112 case AutocompleteMatchType::HISTORY_TITLE
: {
116 case AutocompleteMatchType::HISTORY_BODY
: {
120 case AutocompleteMatchType::HISTORY_KEYWORD
: {
124 case AutocompleteMatchType::BOOKMARK_TITLE
: {
128 case AutocompleteMatchType::NAVSUGGEST_PERSONALIZED
: {
133 // This value indicates a native chrome suggestion with no named subtype
140 // Appends available autocompletion of the given type, subtype, and number to
141 // the existing available autocompletions string, encoding according to the
143 void AppendAvailableAutocompletion(size_t type
,
146 std::string
* autocompletions
) {
147 if (!autocompletions
->empty())
148 autocompletions
->append("j");
149 base::StringAppendF(autocompletions
, "%" PRIuS
, type
);
150 // Subtype is optional - base::string16::npos indicates no subtype.
151 if (subtype
!= base::string16::npos
)
152 base::StringAppendF(autocompletions
, "i%" PRIuS
, subtype
);
154 base::StringAppendF(autocompletions
, "l%d", count
);
157 // Returns whether the autocompletion is trivial enough that we consider it
158 // an autocompletion for which the omnibox autocompletion code did not add
160 bool IsTrivialAutocompletion(const AutocompleteMatch
& match
) {
161 return match
.type
== AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED
||
162 match
.type
== AutocompleteMatchType::URL_WHAT_YOU_TYPED
||
163 match
.type
== AutocompleteMatchType::SEARCH_OTHER_ENGINE
;
166 // Whether this autocomplete match type supports custom descriptions.
167 bool AutocompleteMatchHasCustomDescription(const AutocompleteMatch
& match
) {
168 return match
.type
== AutocompleteMatchType::SEARCH_SUGGEST_ENTITY
||
169 match
.type
== AutocompleteMatchType::SEARCH_SUGGEST_PROFILE
;
174 AutocompleteController::AutocompleteController(
176 TemplateURLService
* template_url_service
,
177 AutocompleteControllerDelegate
* delegate
,
179 : delegate_(delegate
),
180 history_url_provider_(NULL
),
181 keyword_provider_(NULL
),
182 search_provider_(NULL
),
183 zero_suggest_provider_(NULL
),
184 stop_timer_duration_(OmniboxFieldTrial::StopTimerFieldTrialDuration()),
187 template_url_service_(template_url_service
) {
188 provider_types
&= ~OmniboxFieldTrial::GetDisabledProviderTypes();
189 if (provider_types
& AutocompleteProvider::TYPE_BOOKMARK
)
190 providers_
.push_back(new BookmarkProvider(profile
));
191 if (provider_types
& AutocompleteProvider::TYPE_BUILTIN
)
192 providers_
.push_back(new BuiltinProvider());
193 if (provider_types
& AutocompleteProvider::TYPE_HISTORY_QUICK
)
194 providers_
.push_back(new HistoryQuickProvider(profile
));
195 if (provider_types
& AutocompleteProvider::TYPE_HISTORY_URL
) {
196 history_url_provider_
= new HistoryURLProvider(this, profile
);
197 providers_
.push_back(history_url_provider_
);
199 // "Tab to search" can be used on all platforms other than Android.
200 #if !defined(OS_ANDROID)
201 if (provider_types
& AutocompleteProvider::TYPE_KEYWORD
) {
202 keyword_provider_
= new KeywordProvider(this, template_url_service
);
203 #if defined(ENABLE_EXTENSIONS)
204 keyword_provider_
->set_extensions_delegate(
205 scoped_ptr
<KeywordExtensionsDelegate
>(
206 new KeywordExtensionsDelegateImpl(profile
, keyword_provider_
)));
208 providers_
.push_back(keyword_provider_
);
211 if (provider_types
& AutocompleteProvider::TYPE_SEARCH
) {
212 search_provider_
= new SearchProvider(
213 this, template_url_service
, scoped_ptr
<AutocompleteProviderClient
>(
214 new ChromeAutocompleteProviderClient(profile
)));
215 providers_
.push_back(search_provider_
);
217 if (provider_types
& AutocompleteProvider::TYPE_SHORTCUTS
)
218 providers_
.push_back(new ShortcutsProvider(profile
));
219 if (provider_types
& AutocompleteProvider::TYPE_ZERO_SUGGEST
) {
220 zero_suggest_provider_
= ZeroSuggestProvider::Create(
221 this, template_url_service
, profile
);
222 if (zero_suggest_provider_
)
223 providers_
.push_back(zero_suggest_provider_
);
227 AutocompleteController::~AutocompleteController() {
228 // The providers may have tasks outstanding that hold refs to them. We need
229 // to ensure they won't call us back if they outlive us. (Practically,
230 // calling Stop() should also cancel those tasks and make it so that we hold
231 // the only refs.) We also don't want to bother notifying anyone of our
232 // result changes here, because the notification observer is in the midst of
233 // shutdown too, so we don't ask Stop() to clear |result_| (and notify).
234 result_
.Reset(); // Not really necessary.
238 void AutocompleteController::Start(const AutocompleteInput
& input
) {
239 const base::string16
old_input_text(input_
.text());
240 const bool old_want_asynchronous_matches
= input_
.want_asynchronous_matches();
243 // See if we can avoid rerunning autocomplete when the query hasn't changed
244 // much. When the user presses or releases the ctrl key, the desired_tld
245 // changes, and when the user finishes an IME composition, inline autocomplete
246 // may no longer be prevented. In both these cases the text itself hasn't
247 // changed since the last query, and some providers can do much less work (and
248 // get matches back more quickly). Taking advantage of this reduces flicker.
250 // NOTE: This comes after constructing |input_| above since that construction
251 // can change the text string (e.g. by stripping off a leading '?').
252 const bool minimal_changes
= (input_
.text() == old_input_text
) &&
253 (input_
.want_asynchronous_matches() == old_want_asynchronous_matches
);
255 expire_timer_
.Stop();
258 // Start the new query.
260 base::TimeTicks start_time
= base::TimeTicks::Now();
261 for (Providers::iterator
i(providers_
.begin()); i
!= providers_
.end(); ++i
) {
262 // TODO(mpearson): Remove timing code once bugs 178705 / 237703 / 168933
264 base::TimeTicks provider_start_time
= base::TimeTicks::Now();
266 // Call Start() on ZeroSuggestProvider with an INVALID AutocompleteInput
267 // to clear out zero-suggest |matches_|.
268 if (i
->get() == zero_suggest_provider_
)
269 (*i
)->Start(AutocompleteInput(), minimal_changes
);
271 (*i
)->Start(input_
, minimal_changes
);
273 if (!input
.want_asynchronous_matches())
274 DCHECK((*i
)->done());
275 base::TimeTicks provider_end_time
= base::TimeTicks::Now();
276 std::string name
= std::string("Omnibox.ProviderTime.") + (*i
)->GetName();
277 base::HistogramBase
* counter
= base::Histogram::FactoryGet(
278 name
, 1, 5000, 20, base::Histogram::kUmaTargetedHistogramFlag
);
279 counter
->Add(static_cast<int>(
280 (provider_end_time
- provider_start_time
).InMilliseconds()));
282 if (input
.want_asynchronous_matches() && (input
.text().length() < 6)) {
283 base::TimeTicks end_time
= base::TimeTicks::Now();
284 std::string name
= "Omnibox.QueryTime." + base::IntToString(
285 input
.text().length());
286 base::HistogramBase
* counter
= base::Histogram::FactoryGet(
287 name
, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag
);
288 counter
->Add(static_cast<int>((end_time
- start_time
).InMilliseconds()));
292 // The second true forces saying the default match has changed.
293 // This triggers the edit model to update things such as the inline
294 // autocomplete state. In particular, if the user has typed a key
295 // since the last notification, and we're now re-running
296 // autocomplete, then we need to update the inline autocompletion
297 // even if the current match is for the same URL as the last run's
298 // default match. Likewise, the controller doesn't know what's
299 // happened in the edit since the last time it ran autocomplete.
300 // The user might have selected all the text and hit delete, then
301 // typed a new character. The selection and delete won't send any
302 // signals to the controller so it doesn't realize that anything was
303 // cleared or changed. Even if the default match hasn't changed, we
304 // need the edit model to update the display.
305 UpdateResult(false, true);
313 void AutocompleteController::Stop(bool clear_result
) {
314 for (Providers::const_iterator
i(providers_
.begin()); i
!= providers_
.end();
316 (*i
)->Stop(clear_result
);
319 expire_timer_
.Stop();
322 if (clear_result
&& !result_
.empty()) {
324 // NOTE: We pass in false since we're trying to only clear the popup, not
325 // touch the edit... this is all a mess and should be cleaned up :(
326 NotifyChanged(false);
330 void AutocompleteController::OnOmniboxFocused(const AutocompleteInput
& input
) {
331 DCHECK(!in_start_
); // We should not be already running a query.
333 // Call Start() on all prefix-based providers with an INVALID
334 // AutocompleteInput to clear out cached |matches_|, which ensures that
335 // they aren't used with zero suggest.
336 for (Providers::iterator
i(providers_
.begin()); i
!= providers_
.end(); ++i
) {
337 if ((*i
)->ProvidesMatchesOnOmniboxFocus())
338 (*i
)->Start(input
, false);
340 (*i
)->Start(AutocompleteInput(), false);
343 UpdateResult(false, false);
346 void AutocompleteController::DeleteMatch(const AutocompleteMatch
& match
) {
347 DCHECK(match
.SupportsDeletion());
349 // Delete duplicate matches attached to the main match first.
350 for (ACMatches::const_iterator
it(match
.duplicate_matches
.begin());
351 it
!= match
.duplicate_matches
.end(); ++it
) {
353 it
->provider
->DeleteMatch(*it
);
357 match
.provider
->DeleteMatch(match
);
359 OnProviderUpdate(true);
361 // If we're not done, we might attempt to redisplay the deleted match. Make
362 // sure we aren't displaying it by removing any old entries.
363 ExpireCopiedEntries();
366 void AutocompleteController::ExpireCopiedEntries() {
367 // The first true makes UpdateResult() clear out the results and
368 // regenerate them, thus ensuring that no results from the previous
369 // result set remain.
370 UpdateResult(true, false);
373 void AutocompleteController::OnProviderUpdate(bool updated_matches
) {
375 // Multiple providers may provide synchronous results, so we only update the
376 // results if we're not in Start().
377 if (!in_start_
&& (updated_matches
|| done_
))
378 UpdateResult(false, false);
381 void AutocompleteController::AddProvidersInfo(
382 ProvidersInfo
* provider_info
) const {
383 provider_info
->clear();
384 for (Providers::const_iterator
i(providers_
.begin()); i
!= providers_
.end();
386 // Add per-provider info, if any.
387 (*i
)->AddProviderInfo(provider_info
);
389 // This is also a good place to put code to add info that you want to
390 // add for every provider.
394 void AutocompleteController::ResetSession() {
395 for (Providers::const_iterator
i(providers_
.begin()); i
!= providers_
.end();
397 (*i
)->ResetSession();
400 void AutocompleteController::UpdateMatchDestinationURLWithQueryFormulationTime(
401 base::TimeDelta query_formulation_time
,
402 AutocompleteMatch
* match
) const {
403 if (!match
->search_terms_args
.get() ||
404 match
->search_terms_args
->assisted_query_stats
.empty())
407 // Append the query formulation time (time from when the user first typed a
408 // character into the omnibox to when the user selected a query) and whether
409 // a field trial has triggered to the AQS parameter.
410 TemplateURLRef::SearchTermsArgs
search_terms_args(*match
->search_terms_args
);
411 search_terms_args
.assisted_query_stats
+= base::StringPrintf(
412 ".%" PRId64
"j%dj%d",
413 query_formulation_time
.InMilliseconds(),
415 search_provider_
->field_trial_triggered_in_session()) ||
416 (zero_suggest_provider_
&&
417 zero_suggest_provider_
->field_trial_triggered_in_session()),
418 input_
.current_page_classification());
419 UpdateMatchDestinationURL(search_terms_args
, match
);
422 void AutocompleteController::UpdateMatchDestinationURL(
423 const TemplateURLRef::SearchTermsArgs
& search_terms_args
,
424 AutocompleteMatch
* match
) const {
425 TemplateURL
* template_url
= match
->GetTemplateURL(
426 template_url_service_
, false);
430 match
->destination_url
= GURL(template_url
->url_ref().ReplaceSearchTerms(
431 search_terms_args
, template_url_service_
->search_terms_data()));
434 void AutocompleteController::UpdateResult(
435 bool regenerate_result
,
436 bool force_notify_default_match_changed
) {
437 const bool last_default_was_valid
= result_
.default_match() != result_
.end();
438 // The following three variables are only set and used if
439 // |last_default_was_valid|.
440 base::string16 last_default_fill_into_edit
, last_default_keyword
,
441 last_default_associated_keyword
;
442 if (last_default_was_valid
) {
443 last_default_fill_into_edit
= result_
.default_match()->fill_into_edit
;
444 last_default_keyword
= result_
.default_match()->keyword
;
445 if (result_
.default_match()->associated_keyword
!= NULL
)
446 last_default_associated_keyword
=
447 result_
.default_match()->associated_keyword
->keyword
;
450 if (regenerate_result
)
453 AutocompleteResult last_result
;
454 last_result
.Swap(&result_
);
456 for (Providers::const_iterator
i(providers_
.begin());
457 i
!= providers_
.end(); ++i
)
458 result_
.AppendMatches((*i
)->matches());
460 // Sort the matches and trim to a small number of "best" matches.
461 result_
.SortAndCull(input_
, template_url_service_
);
463 // Need to validate before invoking CopyOldMatches as the old matches are not
464 // valid against the current input.
470 // This conditional needs to match the conditional in Start that invokes
472 result_
.CopyOldMatches(input_
, last_result
, template_url_service_
);
475 UpdateKeywordDescriptions(&result_
);
476 UpdateAssociatedKeywords(&result_
);
477 UpdateAssistedQueryStats(&result_
);
478 if (search_provider_
)
479 search_provider_
->RegisterDisplayedAnswers(result_
);
481 const bool default_is_valid
= result_
.default_match() != result_
.end();
482 base::string16 default_associated_keyword
;
483 if (default_is_valid
&&
484 (result_
.default_match()->associated_keyword
!= NULL
)) {
485 default_associated_keyword
=
486 result_
.default_match()->associated_keyword
->keyword
;
488 // We've gotten async results. Send notification that the default match
489 // updated if fill_into_edit, associated_keyword, or keyword differ. (The
490 // second can change if we've just started Chrome and the keyword database
491 // finishes loading while processing this request. The third can change
492 // if we swapped from interpreting the input as a search--which gets
493 // labeled with the default search provider's keyword--to a URL.)
494 // We don't check the URL as that may change for the default match
495 // even though the fill into edit hasn't changed (see SearchProvider
496 // for one case of this).
497 const bool notify_default_match
=
498 (last_default_was_valid
!= default_is_valid
) ||
499 (last_default_was_valid
&&
500 ((result_
.default_match()->fill_into_edit
!=
501 last_default_fill_into_edit
) ||
502 (default_associated_keyword
!= last_default_associated_keyword
) ||
503 (result_
.default_match()->keyword
!= last_default_keyword
)));
504 if (notify_default_match
)
505 last_time_default_match_changed_
= base::TimeTicks::Now();
507 NotifyChanged(force_notify_default_match_changed
|| notify_default_match
);
510 void AutocompleteController::UpdateAssociatedKeywords(
511 AutocompleteResult
* result
) {
512 if (!keyword_provider_
)
515 // Determine if the user's input is an exact keyword match.
516 base::string16 exact_keyword
= keyword_provider_
->GetKeywordForText(
517 TemplateURLService::CleanUserInputKeyword(input_
.text()));
519 std::set
<base::string16
> keywords
;
520 for (ACMatches::iterator
match(result
->begin()); match
!= result
->end();
522 base::string16
keyword(
523 match
->GetSubstitutingExplicitlyInvokedKeyword(template_url_service_
));
524 if (!keyword
.empty()) {
525 keywords
.insert(keyword
);
529 // When the user has typed an exact keyword, we want tab-to-search on the
530 // default match to select that keyword, even if the match
531 // inline-autocompletes to a different keyword. (This prevents inline
532 // autocompletions from blocking a user's attempts to use an explicitly-set
533 // keyword of their own creation.) So use |exact_keyword| if it's
535 if (!exact_keyword
.empty() && !keywords
.count(exact_keyword
)) {
536 keywords
.insert(exact_keyword
);
537 match
->associated_keyword
.reset(new AutocompleteMatch(
538 keyword_provider_
->CreateVerbatimMatch(exact_keyword
,
539 exact_keyword
, input_
)));
543 // Otherwise, set a match's associated keyword based on the match's
544 // fill_into_edit, which should take inline autocompletions into account.
545 keyword
= keyword_provider_
->GetKeywordForText(match
->fill_into_edit
);
547 // Only add the keyword if the match does not have a duplicate keyword with
548 // a more relevant match.
549 if (!keyword
.empty() && !keywords
.count(keyword
)) {
550 keywords
.insert(keyword
);
551 match
->associated_keyword
.reset(new AutocompleteMatch(
552 keyword_provider_
->CreateVerbatimMatch(match
->fill_into_edit
,
555 match
->associated_keyword
.reset();
560 void AutocompleteController::UpdateKeywordDescriptions(
561 AutocompleteResult
* result
) {
562 base::string16 last_keyword
;
563 for (AutocompleteResult::iterator
i(result
->begin()); i
!= result
->end();
565 if (AutocompleteMatch::IsSearchType(i
->type
)) {
566 if (AutocompleteMatchHasCustomDescription(*i
))
568 i
->description
.clear();
569 i
->description_class
.clear();
570 DCHECK(!i
->keyword
.empty());
571 if (i
->keyword
!= last_keyword
) {
572 const TemplateURL
* template_url
=
573 i
->GetTemplateURL(template_url_service_
, false);
575 // For extension keywords, just make the description the extension
576 // name -- don't assume that the normal search keyword description is
578 i
->description
= template_url
->AdjustedShortNameForLocaleDirection();
579 if (template_url
->GetType() != TemplateURL::OMNIBOX_API_EXTENSION
) {
580 i
->description
= l10n_util::GetStringFUTF16(
581 IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION
, i
->description
);
583 i
->description_class
.push_back(
584 ACMatchClassification(0, ACMatchClassification::DIM
));
586 last_keyword
= i
->keyword
;
589 last_keyword
.clear();
594 void AutocompleteController::UpdateAssistedQueryStats(
595 AutocompleteResult
* result
) {
599 // Build the impressions string (the AQS part after ".").
600 std::string autocompletions
;
602 size_t last_type
= base::string16::npos
;
603 size_t last_subtype
= base::string16::npos
;
604 for (ACMatches::iterator
match(result
->begin()); match
!= result
->end();
606 size_t type
= base::string16::npos
;
607 size_t subtype
= base::string16::npos
;
608 AutocompleteMatchToAssistedQuery(
609 match
->type
, match
->provider
, &type
, &subtype
);
610 if (last_type
!= base::string16::npos
&&
611 (type
!= last_type
|| subtype
!= last_subtype
)) {
612 AppendAvailableAutocompletion(
613 last_type
, last_subtype
, count
, &autocompletions
);
619 last_subtype
= subtype
;
621 AppendAvailableAutocompletion(
622 last_type
, last_subtype
, count
, &autocompletions
);
623 // Go over all matches and set AQS if the match supports it.
624 for (size_t index
= 0; index
< result
->size(); ++index
) {
625 AutocompleteMatch
* match
= result
->match_at(index
);
626 const TemplateURL
* template_url
=
627 match
->GetTemplateURL(template_url_service_
, false);
628 if (!template_url
|| !match
->search_terms_args
.get())
630 std::string selected_index
;
631 // Prevent trivial suggestions from getting credit for being selected.
632 if (!IsTrivialAutocompletion(*match
))
633 selected_index
= base::StringPrintf("%" PRIuS
, index
);
634 match
->search_terms_args
->assisted_query_stats
=
635 base::StringPrintf("chrome.%s.%s",
636 selected_index
.c_str(),
637 autocompletions
.c_str());
638 match
->destination_url
= GURL(template_url
->url_ref().ReplaceSearchTerms(
639 *match
->search_terms_args
, template_url_service_
->search_terms_data()));
643 void AutocompleteController::NotifyChanged(bool notify_default_match
) {
645 delegate_
->OnResultChanged(notify_default_match
);
647 content::NotificationService::current()->Notify(
648 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY
,
649 content::Source
<AutocompleteController
>(this),
650 content::NotificationService::NoDetails());
654 void AutocompleteController::CheckIfDone() {
655 for (Providers::const_iterator
i(providers_
.begin()); i
!= providers_
.end();
665 void AutocompleteController::StartExpireTimer() {
666 // Amount of time (in ms) between when the user stops typing and
667 // when we remove any copied entries. We do this from the time the
668 // user stopped typing as some providers (such as SearchProvider)
669 // wait for the user to stop typing before they initiate a query.
670 const int kExpireTimeMS
= 500;
672 if (result_
.HasCopiedMatches())
673 expire_timer_
.Start(FROM_HERE
,
674 base::TimeDelta::FromMilliseconds(kExpireTimeMS
),
675 this, &AutocompleteController::ExpireCopiedEntries
);
678 void AutocompleteController::StartStopTimer() {
679 stop_timer_
.Start(FROM_HERE
,
680 stop_timer_duration_
,
681 base::Bind(&AutocompleteController::Stop
,
682 base::Unretained(this),