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

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 490383002: Loosen DCHECK for Omnibox Extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Peter + Mike's comments Created 6 years, 3 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 void SearchProvider::UpdateMatches() { 402 void SearchProvider::UpdateMatches() {
403 ConvertResultsToAutocompleteMatches(); 403 ConvertResultsToAutocompleteMatches();
404 404
405 // Check constraints that may be violated by suggested relevances. 405 // Check constraints that may be violated by suggested relevances.
406 if (!matches_.empty() && 406 if (!matches_.empty() &&
407 (default_results_.HasServerProvidedScores() || 407 (default_results_.HasServerProvidedScores() ||
408 keyword_results_.HasServerProvidedScores())) { 408 keyword_results_.HasServerProvidedScores())) {
409 // These blocks attempt to repair undesirable behavior by suggested 409 // These blocks attempt to repair undesirable behavior by suggested
410 // relevances with minimal impact, preserving other suggested relevances. 410 // relevances with minimal impact, preserving other suggested relevances.
411 411
412 if ((providers_.GetKeywordProviderURL() != NULL) && 412 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
413 const bool is_extension_keyword =
414 (keyword_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION);
msw 2014/08/22 17:45:56 This should be keyword_url != NULL && ...
Mark P 2014/08/22 17:52:42 No wonder the tests are failing. (I hadn't looked
415 if ((keyword_url != NULL) && !is_extension_keyword &&
msw 2014/08/22 17:45:56 fyi: you'll still need this NULL check too.
Mark P 2014/08/22 17:52:42 Acknowledged.
413 (FindTopMatch() == matches_.end())) { 416 (FindTopMatch() == matches_.end())) {
414 // In keyword mode, disregard the keyword verbatim suggested relevance 417 // In non-extension keyword mode, disregard the keyword verbatim suggested
415 // if necessary, so at least one match is allowed to be default. 418 // relevance if necessary, so at least one match is allowed to be default.
419 // (In extension keyword mode this is not necessary because the extension
420 // will return a default match.)
416 keyword_results_.verbatim_relevance = -1; 421 keyword_results_.verbatim_relevance = -1;
417 ConvertResultsToAutocompleteMatches(); 422 ConvertResultsToAutocompleteMatches();
418 } 423 }
419 if (IsTopMatchSearchWithURLInput()) { 424 if (IsTopMatchSearchWithURLInput()) {
420 // Disregard the suggested search and verbatim relevances if the input 425 // Disregard the suggested search and verbatim relevances if the input
421 // type is URL and the top match is a highly-ranked search suggestion. 426 // type is URL and the top match is a highly-ranked search suggestion.
422 // For example, prevent a search for "foo.com" from outranking another 427 // For example, prevent a search for "foo.com" from outranking another
423 // provider's navigation for "foo.com" or "foo.com/url_from_history". 428 // provider's navigation for "foo.com" or "foo.com/url_from_history".
424 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); 429 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results);
425 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); 430 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results);
426 default_results_.verbatim_relevance = -1; 431 default_results_.verbatim_relevance = -1;
427 keyword_results_.verbatim_relevance = -1; 432 keyword_results_.verbatim_relevance = -1;
428 ConvertResultsToAutocompleteMatches(); 433 ConvertResultsToAutocompleteMatches();
429 } 434 }
430 if (FindTopMatch() == matches_.end()) { 435 if ((FindTopMatch() == matches_.end()) &&
431 // Guarantee that SearchProvider returns a legal default match. (The 436 ((keyword_url == NULL) || !is_extension_keyword)) {
msw 2014/08/22 17:45:56 nit: nix (keyword_url == NULL), use |is_extension_
Mark P 2014/08/22 17:52:42 Done.
432 // omnibox always needs at least one legal default match, and it relies 437 // Guarantee that SearchProvider returns a legal default match (except
433 // on SearchProvider to always return one.) 438 // when in n extension-based keyword mode). The omnibox always needs
msw 2014/08/22 17:45:56 Remove stray 'n'.
Mark P 2014/08/22 17:52:42 Done.
439 // at least one legal default match, and it relies on SearchProvider in
440 // combination with KeywordProvider (for extension-based keywords) to
441 // always return one.
434 ApplyCalculatedRelevance(); 442 ApplyCalculatedRelevance();
435 ConvertResultsToAutocompleteMatches(); 443 ConvertResultsToAutocompleteMatches();
436 } 444 }
437 DCHECK(!IsTopMatchSearchWithURLInput()); 445 DCHECK(!IsTopMatchSearchWithURLInput());
438 DCHECK(FindTopMatch() != matches_.end()); 446 DCHECK((FindTopMatch() != matches_.end()) ||
447 ((keyword_url != NULL) && is_extension_keyword));
msw 2014/08/22 17:45:56 nit: nix (keyword_url == NULL), use |is_extension_
Mark P 2014/08/22 17:52:41 Done.
439 } 448 }
440 UMA_HISTOGRAM_CUSTOM_COUNTS( 449 UMA_HISTOGRAM_CUSTOM_COUNTS(
441 "Omnibox.SearchProviderMatches", matches_.size(), 1, 6, 7); 450 "Omnibox.SearchProviderMatches", matches_.size(), 1, 6, 7);
442 UpdateDone(); 451 UpdateDone();
443 } 452 }
444 453
445 void SearchProvider::Run() { 454 void SearchProvider::Run() {
446 // Start a new request with the current input. 455 // Start a new request with the current input.
447 suggest_results_pending_ = 0; 456 suggest_results_pending_ = 0;
448 time_suggest_request_sent_ = base::TimeTicks::Now(); 457 time_suggest_request_sent_ = base::TimeTicks::Now();
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 last_answer_seen_.query_type = match->answer_type; 1269 last_answer_seen_.query_type = match->answer_type;
1261 } 1270 }
1262 1271
1263 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { 1272 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) {
1264 // If the query text starts with trimmed input, this is valid prefetch data. 1273 // If the query text starts with trimmed input, this is valid prefetch data.
1265 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, 1274 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text,
1266 base::CollapseWhitespace(input.text(), false), 1275 base::CollapseWhitespace(input.text(), false),
1267 false) ? 1276 false) ?
1268 last_answer_seen_ : AnswersQueryData(); 1277 last_answer_seen_ : AnswersQueryData();
1269 } 1278 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698