Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1019)

Unified Diff: chrome/browser/autocomplete/autocomplete_controller.cc

Issue 11316057: Omnibox: Log Elapsed Time Since Last Time The Default Match Changed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/autocomplete_controller.cc
diff --git a/chrome/browser/autocomplete/autocomplete_controller.cc b/chrome/browser/autocomplete/autocomplete_controller.cc
index 9c2a4064a385d96adad1f9f255ccaafc2583947d..c00b7dedde0fa18627fc11698b33e5e80be5654d 100644
--- a/chrome/browser/autocomplete/autocomplete_controller.cc
+++ b/chrome/browser/autocomplete/autocomplete_controller.cc
@@ -14,6 +14,7 @@
#include "base/string_number_conversions.h"
#include "base/stringprintf.h"
#include "base/time.h"
+#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
#include "chrome/browser/autocomplete/bookmark_provider.h"
#include "chrome/browser/autocomplete/builtin_provider.h"
@@ -213,7 +214,7 @@ void AutocompleteController::Start(
}
in_start_ = false;
CheckIfDone();
- UpdateResult(true);
+ UpdateResult(false, true); // force saying the default match has changed
Peter Kasting 2012/11/16 23:57:18 Nit: Comment adds nothing over the function declar
Mark P 2012/11/19 22:21:45 Expanded greatly, new with useful information (lar
if (!done_)
StartExpireTimer();
@@ -263,13 +264,14 @@ void AutocompleteController::DeleteMatch(const AutocompleteMatch& match) {
}
void AutocompleteController::ExpireCopiedEntries() {
- // Clear out the results. This ensures no results from the previous result set
- // are copied over.
- result_.Reset();
- // We allow matches from the previous result set to starve out matches from
- // the new result set. This means in order to expire matches we have to query
- // the providers again.
- UpdateResult(false);
+ // The first true makes UpdateResult() clear out the results. This
+ // ensures no results from the previous result set are copied over.
+ // (We allow matches from the previous result set to starve out
+ // matches from the new result set. This means in order to expire
+ // matches we have to query the providers again.)
Peter Kasting 2012/11/16 23:57:18 I'm not sure this parenthetical comment really bel
Mark P 2012/11/19 22:21:45 Moved to the UpdateResults declaration, largely re
+ // The second true says to pretend the default match changed (even
+ // if it did not).
Peter Kasting 2012/11/16 23:57:18 Again, this just says what we're doing; we need to
Mark P 2012/11/19 22:21:45 Added somewhat of an explanation, largely culled f
+ UpdateResult(true, true);
}
void AutocompleteController::OnProviderUpdate(bool updated_matches) {
@@ -282,10 +284,10 @@ void AutocompleteController::OnProviderUpdate(bool updated_matches) {
NotifyChanged(true);
} else {
CheckIfDone();
- // Multiple providers may provide synchronous results, so we only update the
- // results if we're not in Start().
+ // Multiple providers may provide synchronous results, so we only
+ // update the results if we're not in Start().
Peter Kasting 2012/11/16 23:57:18 Nit: Line wrapping change unnecessary
Mark P 2012/11/19 22:21:45 Fine, put back.
if (!in_start_ && (updated_matches || done_))
- UpdateResult(false);
+ UpdateResult(false, false);
}
}
@@ -302,7 +304,23 @@ void AutocompleteController::AddProvidersInfo(
}
}
-void AutocompleteController::UpdateResult(bool is_synchronous_pass) {
+void AutocompleteController::UpdateResult(
+ bool regenerate_result, bool force_notify_default_match_changed) {
Peter Kasting 2012/11/16 23:57:18 Nit: One arg per line (your style is legal, but do
Mark P 2012/11/19 22:21:45 Okay, fixed.
+ const bool last_default_was_valid = result_.default_match() != result_.end();
+ // The following two variables are only set and used if
+ // |last_default_was_valid|.
+ string16 last_default_fill_into_edit(ASCIIToUTF16(""));
Peter Kasting 2012/11/16 23:57:18 Nit: remove "(ASCIIToUTF16(""))" as it does nothin
Mark P 2012/11/19 22:21:45 Fixed all three.
+ string16 last_default_associated_keyword(ASCIIToUTF16(""));
+ if (last_default_was_valid) {
+ last_default_fill_into_edit = result_.default_match()->fill_into_edit;
+ if (result_.default_match()->associated_keyword != NULL)
+ last_default_associated_keyword =
+ result_.default_match()->associated_keyword->keyword;
+ }
+
+ if (regenerate_result)
+ result_.Reset();
+
AutocompleteResult last_result;
last_result.Swap(&result_);
@@ -329,27 +347,30 @@ void AutocompleteController::UpdateResult(bool is_synchronous_pass) {
UpdateAssociatedKeywords(&result_);
UpdateAssistedQueryStats(&result_);
- bool notify_default_match = is_synchronous_pass;
- if (!is_synchronous_pass) {
- const bool last_default_was_valid =
- last_result.default_match() != last_result.end();
- const bool default_is_valid = result_.default_match() != result_.end();
- // We've gotten async results. Send notification that the default match
- // updated if fill_into_edit differs or associated_keyword differ. (The
- // latter can change if we've just started Chrome and the keyword database
- // finishes loading while processing this request.) We don't check the URL
- // as that may change for the default match even though the fill into edit
- // hasn't changed (see SearchProvider for one case of this).
- notify_default_match =
- (last_default_was_valid != default_is_valid) ||
- (default_is_valid &&
- ((result_.default_match()->fill_into_edit !=
- last_result.default_match()->fill_into_edit) ||
- (result_.default_match()->associated_keyword.get() !=
- last_result.default_match()->associated_keyword.get())));
+ const bool default_is_valid = result_.default_match() != result_.end();
+ string16 default_associated_keyword(ASCIIToUTF16(""));
+ if (default_is_valid &&
+ (result_.default_match()->associated_keyword != NULL)) {
+ default_associated_keyword =
+ result_.default_match()->associated_keyword->keyword;
+ }
+ // We've gotten async results. Send notification that the default match
+ // updated if fill_into_edit differs or associated_keyword differ. (The
+ // latter can change if we've just started Chrome and the keyword database
+ // finishes loading while processing this request.) We don't check the URL
+ // as that may change for the default match even though the fill into edit
+ // hasn't changed (see SearchProvider for one case of this).
+ const bool notify_default_match =
+ (last_default_was_valid != default_is_valid) ||
+ (default_is_valid && last_default_was_valid &&
Peter Kasting 2012/11/16 23:57:18 Nit: Adding "last_default_was_valid &&" is unneces
Mark P 2012/11/19 22:21:45 I know. However, I think it makes the logic clean
Peter Kasting 2012/11/20 06:49:19 In that case what about removing the "default_is_v
Mark P 2012/11/20 17:34:40 I'm comfortable with that. Done.
+ ((result_.default_match()->fill_into_edit !=
+ last_default_fill_into_edit) ||
+ (default_associated_keyword != last_default_associated_keyword)));
+ if (notify_default_match) {
Peter Kasting 2012/11/16 23:57:18 Nit: {} unnecessary
Mark P 2012/11/19 22:21:45 Removed.
+ last_time_default_match_changed_ = base::TimeTicks::Now();
}
- NotifyChanged(notify_default_match);
+ NotifyChanged(force_notify_default_match_changed || notify_default_match);
}
void AutocompleteController::UpdateAssociatedKeywords(

Powered by Google App Engine
This is Rietveld 408576698