OLD | NEW |
---|---|
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 Loading... | |
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 if ((keyword_url != NULL) && | |
414 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION) && | |
msw
2014/08/22 00:48:00
nit: maybe make a local bool is_extension_keyword?
Mark P
2014/08/22 15:47:06
Good idea. Done.
| |
413 (FindTopMatch() == matches_.end())) { | 415 (FindTopMatch() == matches_.end())) { |
414 // In keyword mode, disregard the keyword verbatim suggested relevance | 416 // In non-extension keyword mode, disregard the keyword verbatim suggested |
415 // if necessary, so at least one match is allowed to be default. | 417 // relevance if necessary, so at least one match is allowed to be default. |
418 // (In extension keyword mode this is not necessary because the extension | |
419 // will return a default match.) | |
416 keyword_results_.verbatim_relevance = -1; | 420 keyword_results_.verbatim_relevance = -1; |
417 ConvertResultsToAutocompleteMatches(); | 421 ConvertResultsToAutocompleteMatches(); |
418 } | 422 } |
419 if (IsTopMatchSearchWithURLInput()) { | 423 if (IsTopMatchSearchWithURLInput()) { |
420 // Disregard the suggested search and verbatim relevances if the input | 424 // Disregard the suggested search and verbatim relevances if the input |
421 // type is URL and the top match is a highly-ranked search suggestion. | 425 // 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 | 426 // For example, prevent a search for "foo.com" from outranking another |
423 // provider's navigation for "foo.com" or "foo.com/url_from_history". | 427 // provider's navigation for "foo.com" or "foo.com/url_from_history". |
424 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); | 428 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); |
425 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); | 429 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); |
426 default_results_.verbatim_relevance = -1; | 430 default_results_.verbatim_relevance = -1; |
427 keyword_results_.verbatim_relevance = -1; | 431 keyword_results_.verbatim_relevance = -1; |
428 ConvertResultsToAutocompleteMatches(); | 432 ConvertResultsToAutocompleteMatches(); |
429 } | 433 } |
430 if (FindTopMatch() == matches_.end()) { | 434 if ((FindTopMatch() == matches_.end()) && |
431 // Guarantee that SearchProvider returns a legal default match. (The | 435 ((keyword_url == NULL) || |
432 // omnibox always needs at least one legal default match, and it relies | 436 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION))) { |
433 // on SearchProvider to always return one.) | 437 // Guarantee that SearchProvider returns a legal default match (except |
438 // when in an extension-based keyword mode). The omnibox always needs | |
Peter Kasting
2014/08/22 00:21:09
Nit: Remove "an"
Mark P
2014/08/22 15:47:06
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) && | |
448 (keyword_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION))); | |
439 } | 449 } |
440 UMA_HISTOGRAM_CUSTOM_COUNTS( | 450 UMA_HISTOGRAM_CUSTOM_COUNTS( |
441 "Omnibox.SearchProviderMatches", matches_.size(), 1, 6, 7); | 451 "Omnibox.SearchProviderMatches", matches_.size(), 1, 6, 7); |
442 UpdateDone(); | 452 UpdateDone(); |
443 } | 453 } |
444 | 454 |
445 void SearchProvider::Run() { | 455 void SearchProvider::Run() { |
446 // Start a new request with the current input. | 456 // Start a new request with the current input. |
447 suggest_results_pending_ = 0; | 457 suggest_results_pending_ = 0; |
448 time_suggest_request_sent_ = base::TimeTicks::Now(); | 458 time_suggest_request_sent_ = base::TimeTicks::Now(); |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1260 last_answer_seen_.query_type = match->answer_type; | 1270 last_answer_seen_.query_type = match->answer_type; |
1261 } | 1271 } |
1262 | 1272 |
1263 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { | 1273 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { |
1264 // If the query text starts with trimmed input, this is valid prefetch data. | 1274 // If the query text starts with trimmed input, this is valid prefetch data. |
1265 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, | 1275 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, |
1266 base::CollapseWhitespace(input.text(), false), | 1276 base::CollapseWhitespace(input.text(), false), |
1267 false) ? | 1277 false) ? |
1268 last_answer_seen_ : AnswersQueryData(); | 1278 last_answer_seen_ : AnswersQueryData(); |
1269 } | 1279 } |
OLD | NEW |