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 "components/omnibox/browser/autocomplete_controller.h" | 5 #include "components/omnibox/browser/autocomplete_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/trace_event/trace_event.h" |
18 #include "build/build_config.h" | 20 #include "build/build_config.h" |
19 #include "components/omnibox/browser/autocomplete_controller_delegate.h" | 21 #include "components/omnibox/browser/autocomplete_controller_delegate.h" |
20 #include "components/omnibox/browser/bookmark_provider.h" | 22 #include "components/omnibox/browser/bookmark_provider.h" |
21 #include "components/omnibox/browser/builtin_provider.h" | 23 #include "components/omnibox/browser/builtin_provider.h" |
22 #include "components/omnibox/browser/clipboard_url_provider.h" | 24 #include "components/omnibox/browser/clipboard_url_provider.h" |
23 #include "components/omnibox/browser/history_quick_provider.h" | 25 #include "components/omnibox/browser/history_quick_provider.h" |
24 #include "components/omnibox/browser/history_url_provider.h" | 26 #include "components/omnibox/browser/history_url_provider.h" |
25 #include "components/omnibox/browser/keyword_provider.h" | 27 #include "components/omnibox/browser/keyword_provider.h" |
26 #include "components/omnibox/browser/omnibox_field_trial.h" | 28 #include "components/omnibox/browser/omnibox_field_trial.h" |
27 #include "components/omnibox/browser/search_provider.h" | 29 #include "components/omnibox/browser/search_provider.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // to ensure they won't call us back if they outlive us. (Practically, | 226 // to ensure they won't call us back if they outlive us. (Practically, |
225 // calling Stop() should also cancel those tasks and make it so that we hold | 227 // calling Stop() should also cancel those tasks and make it so that we hold |
226 // the only refs.) We also don't want to bother notifying anyone of our | 228 // the only refs.) We also don't want to bother notifying anyone of our |
227 // result changes here, because the notification observer is in the midst of | 229 // result changes here, because the notification observer is in the midst of |
228 // shutdown too, so we don't ask Stop() to clear |result_| (and notify). | 230 // shutdown too, so we don't ask Stop() to clear |result_| (and notify). |
229 result_.Reset(); // Not really necessary. | 231 result_.Reset(); // Not really necessary. |
230 Stop(false); | 232 Stop(false); |
231 } | 233 } |
232 | 234 |
233 void AutocompleteController::Start(const AutocompleteInput& input) { | 235 void AutocompleteController::Start(const AutocompleteInput& input) { |
| 236 TRACE_EVENT1("omnibox", "AutocompleteController::Start", |
| 237 "text", base::UTF16ToUTF8(input.text())); |
234 const base::string16 old_input_text(input_.text()); | 238 const base::string16 old_input_text(input_.text()); |
235 const bool old_want_asynchronous_matches = input_.want_asynchronous_matches(); | 239 const bool old_want_asynchronous_matches = input_.want_asynchronous_matches(); |
236 const bool old_from_omnibox_focus = input_.from_omnibox_focus(); | 240 const bool old_from_omnibox_focus = input_.from_omnibox_focus(); |
237 input_ = input; | 241 input_ = input; |
238 | 242 |
239 // See if we can avoid rerunning autocomplete when the query hasn't changed | 243 // See if we can avoid rerunning autocomplete when the query hasn't changed |
240 // much. When the user presses or releases the ctrl key, the desired_tld | 244 // much. When the user presses or releases the ctrl key, the desired_tld |
241 // changes, and when the user finishes an IME composition, inline autocomplete | 245 // changes, and when the user finishes an IME composition, inline autocomplete |
242 // may no longer be prevented. In both these cases the text itself hasn't | 246 // may no longer be prevented. In both these cases the text itself hasn't |
243 // changed since the last query, and some providers can do much less work (and | 247 // changed since the last query, and some providers can do much less work (and |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 if (!template_url) | 392 if (!template_url) |
389 return; | 393 return; |
390 | 394 |
391 match->destination_url = GURL(template_url->url_ref().ReplaceSearchTerms( | 395 match->destination_url = GURL(template_url->url_ref().ReplaceSearchTerms( |
392 search_terms_args, template_url_service_->search_terms_data())); | 396 search_terms_args, template_url_service_->search_terms_data())); |
393 } | 397 } |
394 | 398 |
395 void AutocompleteController::UpdateResult( | 399 void AutocompleteController::UpdateResult( |
396 bool regenerate_result, | 400 bool regenerate_result, |
397 bool force_notify_default_match_changed) { | 401 bool force_notify_default_match_changed) { |
| 402 TRACE_EVENT0("omnibox", "AutocompleteController::UpdateResult"); |
398 const bool last_default_was_valid = result_.default_match() != result_.end(); | 403 const bool last_default_was_valid = result_.default_match() != result_.end(); |
399 // The following three variables are only set and used if | 404 // The following three variables are only set and used if |
400 // |last_default_was_valid|. | 405 // |last_default_was_valid|. |
401 base::string16 last_default_fill_into_edit, last_default_keyword, | 406 base::string16 last_default_fill_into_edit, last_default_keyword, |
402 last_default_associated_keyword; | 407 last_default_associated_keyword; |
403 if (last_default_was_valid) { | 408 if (last_default_was_valid) { |
404 last_default_fill_into_edit = result_.default_match()->fill_into_edit; | 409 last_default_fill_into_edit = result_.default_match()->fill_into_edit; |
405 last_default_keyword = result_.default_match()->keyword; | 410 last_default_keyword = result_.default_match()->keyword; |
406 if (result_.default_match()->associated_keyword != NULL) | 411 if (result_.default_match()->associated_keyword != NULL) |
407 last_default_associated_keyword = | 412 last_default_associated_keyword = |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 expire_timer_.Stop(); | 657 expire_timer_.Stop(); |
653 stop_timer_.Stop(); | 658 stop_timer_.Stop(); |
654 done_ = true; | 659 done_ = true; |
655 if (clear_result && !result_.empty()) { | 660 if (clear_result && !result_.empty()) { |
656 result_.Reset(); | 661 result_.Reset(); |
657 // NOTE: We pass in false since we're trying to only clear the popup, not | 662 // NOTE: We pass in false since we're trying to only clear the popup, not |
658 // touch the edit... this is all a mess and should be cleaned up :( | 663 // touch the edit... this is all a mess and should be cleaned up :( |
659 NotifyChanged(false); | 664 NotifyChanged(false); |
660 } | 665 } |
661 } | 666 } |
OLD | NEW |