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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" 18 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
18 #include "chrome/browser/autocomplete/bookmark_provider.h" 19 #include "chrome/browser/autocomplete/bookmark_provider.h"
19 #include "chrome/browser/autocomplete/builtin_provider.h" 20 #include "chrome/browser/autocomplete/builtin_provider.h"
20 #include "chrome/browser/autocomplete/extension_app_provider.h" 21 #include "chrome/browser/autocomplete/extension_app_provider.h"
21 #include "chrome/browser/autocomplete/history_contents_provider.h" 22 #include "chrome/browser/autocomplete/history_contents_provider.h"
22 #include "chrome/browser/autocomplete/history_quick_provider.h" 23 #include "chrome/browser/autocomplete/history_quick_provider.h"
23 #include "chrome/browser/autocomplete/history_url_provider.h" 24 #include "chrome/browser/autocomplete/history_url_provider.h"
24 #include "chrome/browser/autocomplete/keyword_provider.h" 25 #include "chrome/browser/autocomplete/keyword_provider.h"
25 #include "chrome/browser/autocomplete/search_provider.h" 26 #include "chrome/browser/autocomplete/search_provider.h"
26 #include "chrome/browser/autocomplete/shortcuts_provider.h" 27 #include "chrome/browser/autocomplete/shortcuts_provider.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 if (matches_requested == AutocompleteInput::ALL_MATCHES && 207 if (matches_requested == AutocompleteInput::ALL_MATCHES &&
207 (text.length() < 6)) { 208 (text.length() < 6)) {
208 base::TimeTicks end_time = base::TimeTicks::Now(); 209 base::TimeTicks end_time = base::TimeTicks::Now();
209 std::string name = "Omnibox.QueryTime." + base::IntToString(text.length()); 210 std::string name = "Omnibox.QueryTime." + base::IntToString(text.length());
210 base::Histogram* counter = base::Histogram::FactoryGet( 211 base::Histogram* counter = base::Histogram::FactoryGet(
211 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag); 212 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag);
212 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds())); 213 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds()));
213 } 214 }
214 in_start_ = false; 215 in_start_ = false;
215 CheckIfDone(); 216 CheckIfDone();
216 UpdateResult(true); 217 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
217 218
218 if (!done_) 219 if (!done_)
219 StartExpireTimer(); 220 StartExpireTimer();
220 } 221 }
221 222
222 void AutocompleteController::Stop(bool clear_result) { 223 void AutocompleteController::Stop(bool clear_result) {
223 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); 224 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end();
224 ++i) { 225 ++i) {
225 (*i)->Stop(clear_result); 226 (*i)->Stop(clear_result);
226 } 227 }
(...skipping 29 matching lines...) Expand all
256 DCHECK(match.deletable); 257 DCHECK(match.deletable);
257 match.provider->DeleteMatch(match); // This may synchronously call back to 258 match.provider->DeleteMatch(match); // This may synchronously call back to
258 // OnProviderUpdate(). 259 // OnProviderUpdate().
259 // If DeleteMatch resulted in a callback to OnProviderUpdate and we're 260 // If DeleteMatch resulted in a callback to OnProviderUpdate and we're
260 // not done, we might attempt to redisplay the deleted match. Make sure 261 // not done, we might attempt to redisplay the deleted match. Make sure
261 // we aren't displaying it by removing any old entries. 262 // we aren't displaying it by removing any old entries.
262 ExpireCopiedEntries(); 263 ExpireCopiedEntries();
263 } 264 }
264 265
265 void AutocompleteController::ExpireCopiedEntries() { 266 void AutocompleteController::ExpireCopiedEntries() {
266 // Clear out the results. This ensures no results from the previous result set 267 // The first true makes UpdateResult() clear out the results. This
267 // are copied over. 268 // ensures no results from the previous result set are copied over.
268 result_.Reset(); 269 // (We allow matches from the previous result set to starve out
269 // We allow matches from the previous result set to starve out matches from 270 // matches from the new result set. This means in order to expire
270 // the new result set. This means in order to expire matches we have to query 271 // 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
271 // the providers again. 272 // The second true says to pretend the default match changed (even
272 UpdateResult(false); 273 // 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
274 UpdateResult(true, true);
273 } 275 }
274 276
275 void AutocompleteController::OnProviderUpdate(bool updated_matches) { 277 void AutocompleteController::OnProviderUpdate(bool updated_matches) {
276 if (in_zero_suggest_) { 278 if (in_zero_suggest_) {
277 // We got ZeroSuggest results before Start(). Show only those results, 279 // We got ZeroSuggest results before Start(). Show only those results,
278 // because results from other providers are stale. 280 // because results from other providers are stale.
279 result_.Reset(); 281 result_.Reset();
280 result_.AppendMatches(zero_suggest_provider_->matches()); 282 result_.AppendMatches(zero_suggest_provider_->matches());
281 result_.SortAndCull(input_, profile_); 283 result_.SortAndCull(input_, profile_);
282 NotifyChanged(true); 284 NotifyChanged(true);
283 } else { 285 } else {
284 CheckIfDone(); 286 CheckIfDone();
285 // Multiple providers may provide synchronous results, so we only update the 287 // Multiple providers may provide synchronous results, so we only
286 // results if we're not in Start(). 288 // 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.
287 if (!in_start_ && (updated_matches || done_)) 289 if (!in_start_ && (updated_matches || done_))
288 UpdateResult(false); 290 UpdateResult(false, false);
289 } 291 }
290 } 292 }
291 293
292 void AutocompleteController::AddProvidersInfo( 294 void AutocompleteController::AddProvidersInfo(
293 ProvidersInfo* provider_info) const { 295 ProvidersInfo* provider_info) const {
294 provider_info->clear(); 296 provider_info->clear();
295 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); 297 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end();
296 ++i) { 298 ++i) {
297 // Add per-provider info, if any. 299 // Add per-provider info, if any.
298 (*i)->AddProviderInfo(provider_info); 300 (*i)->AddProviderInfo(provider_info);
299 301
300 // This is also a good place to put code to add info that you want to 302 // This is also a good place to put code to add info that you want to
301 // add for every provider. 303 // add for every provider.
302 } 304 }
303 } 305 }
304 306
305 void AutocompleteController::UpdateResult(bool is_synchronous_pass) { 307 void AutocompleteController::UpdateResult(
308 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.
309 const bool last_default_was_valid = result_.default_match() != result_.end();
310 // The following two variables are only set and used if
311 // |last_default_was_valid|.
312 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.
313 string16 last_default_associated_keyword(ASCIIToUTF16(""));
314 if (last_default_was_valid) {
315 last_default_fill_into_edit = result_.default_match()->fill_into_edit;
316 if (result_.default_match()->associated_keyword != NULL)
317 last_default_associated_keyword =
318 result_.default_match()->associated_keyword->keyword;
319 }
320
321 if (regenerate_result)
322 result_.Reset();
323
306 AutocompleteResult last_result; 324 AutocompleteResult last_result;
307 last_result.Swap(&result_); 325 last_result.Swap(&result_);
308 326
309 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); 327 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end();
310 ++i) 328 ++i)
311 result_.AppendMatches((*i)->matches()); 329 result_.AppendMatches((*i)->matches());
312 330
313 // Sort the matches and trim to a small number of "best" matches. 331 // Sort the matches and trim to a small number of "best" matches.
314 result_.SortAndCull(input_, profile_); 332 result_.SortAndCull(input_, profile_);
315 333
316 // Need to validate before invoking CopyOldMatches as the old matches are not 334 // Need to validate before invoking CopyOldMatches as the old matches are not
317 // valid against the current input. 335 // valid against the current input.
318 #ifndef NDEBUG 336 #ifndef NDEBUG
319 result_.Validate(); 337 result_.Validate();
320 #endif 338 #endif
321 339
322 if (!done_) { 340 if (!done_) {
323 // This conditional needs to match the conditional in Start that invokes 341 // This conditional needs to match the conditional in Start that invokes
324 // StartExpireTimer. 342 // StartExpireTimer.
325 result_.CopyOldMatches(input_, last_result, profile_); 343 result_.CopyOldMatches(input_, last_result, profile_);
326 } 344 }
327 345
328 UpdateKeywordDescriptions(&result_); 346 UpdateKeywordDescriptions(&result_);
329 UpdateAssociatedKeywords(&result_); 347 UpdateAssociatedKeywords(&result_);
330 UpdateAssistedQueryStats(&result_); 348 UpdateAssistedQueryStats(&result_);
331 349
332 bool notify_default_match = is_synchronous_pass; 350 const bool default_is_valid = result_.default_match() != result_.end();
333 if (!is_synchronous_pass) { 351 string16 default_associated_keyword(ASCIIToUTF16(""));
334 const bool last_default_was_valid = 352 if (default_is_valid &&
335 last_result.default_match() != last_result.end(); 353 (result_.default_match()->associated_keyword != NULL)) {
336 const bool default_is_valid = result_.default_match() != result_.end(); 354 default_associated_keyword =
337 // We've gotten async results. Send notification that the default match 355 result_.default_match()->associated_keyword->keyword;
338 // updated if fill_into_edit differs or associated_keyword differ. (The 356 }
339 // latter can change if we've just started Chrome and the keyword database 357 // We've gotten async results. Send notification that the default match
340 // finishes loading while processing this request.) We don't check the URL 358 // updated if fill_into_edit differs or associated_keyword differ. (The
341 // as that may change for the default match even though the fill into edit 359 // latter can change if we've just started Chrome and the keyword database
342 // hasn't changed (see SearchProvider for one case of this). 360 // finishes loading while processing this request.) We don't check the URL
343 notify_default_match = 361 // as that may change for the default match even though the fill into edit
344 (last_default_was_valid != default_is_valid) || 362 // hasn't changed (see SearchProvider for one case of this).
345 (default_is_valid && 363 const bool notify_default_match =
346 ((result_.default_match()->fill_into_edit != 364 (last_default_was_valid != default_is_valid) ||
347 last_result.default_match()->fill_into_edit) || 365 (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.
348 (result_.default_match()->associated_keyword.get() != 366 ((result_.default_match()->fill_into_edit !=
349 last_result.default_match()->associated_keyword.get()))); 367 last_default_fill_into_edit) ||
368 (default_associated_keyword != last_default_associated_keyword)));
369 if (notify_default_match) {
Peter Kasting 2012/11/16 23:57:18 Nit: {} unnecessary
Mark P 2012/11/19 22:21:45 Removed.
370 last_time_default_match_changed_ = base::TimeTicks::Now();
350 } 371 }
351 372
352 NotifyChanged(notify_default_match); 373 NotifyChanged(force_notify_default_match_changed || notify_default_match);
353 } 374 }
354 375
355 void AutocompleteController::UpdateAssociatedKeywords( 376 void AutocompleteController::UpdateAssociatedKeywords(
356 AutocompleteResult* result) { 377 AutocompleteResult* result) {
357 if (!keyword_provider_) 378 if (!keyword_provider_)
358 return; 379 return;
359 380
360 std::set<string16> keywords; 381 std::set<string16> keywords;
361 for (ACMatches::iterator match(result->begin()); match != result->end(); 382 for (ACMatches::iterator match(result->begin()); match != result->end();
362 ++match) { 383 ++match) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } 492 }
472 done_ = true; 493 done_ = true;
473 } 494 }
474 495
475 void AutocompleteController::StartExpireTimer() { 496 void AutocompleteController::StartExpireTimer() {
476 if (result_.HasCopiedMatches()) 497 if (result_.HasCopiedMatches())
477 expire_timer_.Start(FROM_HERE, 498 expire_timer_.Start(FROM_HERE,
478 base::TimeDelta::FromMilliseconds(kExpireTimeMS), 499 base::TimeDelta::FromMilliseconds(kExpireTimeMS),
479 this, &AutocompleteController::ExpireCopiedEntries); 500 this, &AutocompleteController::ExpireCopiedEntries);
480 } 501 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698