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 const bool is_extension_keyword = (keyword_url != NULL) && | |
414 (keyword_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION); | |
415 if ((keyword_url != NULL) && !is_extension_keyword && | |
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()) && !is_extension_keyword) { |
msw
2014/08/22 17:57:35
optional nit: reverse conditions to match 415/416
Mark P
2014/08/22 18:02:18
Done.
| |
431 // Guarantee that SearchProvider returns a legal default match. (The | 436 // Guarantee that SearchProvider returns a legal default match (except |
432 // omnibox always needs at least one legal default match, and it relies | 437 // when in extension-based keyword mode). The omnibox always needs at |
433 // on SearchProvider to always return one.) | 438 // least one legal default match, and it relies on SearchProvider in |
439 // combination with KeywordProvider (for extension-based keywords) to | |
440 // always return one. | |
434 ApplyCalculatedRelevance(); | 441 ApplyCalculatedRelevance(); |
435 ConvertResultsToAutocompleteMatches(); | 442 ConvertResultsToAutocompleteMatches(); |
436 } | 443 } |
437 DCHECK(!IsTopMatchSearchWithURLInput()); | 444 DCHECK(!IsTopMatchSearchWithURLInput()); |
438 DCHECK(FindTopMatch() != matches_.end()); | 445 DCHECK((FindTopMatch() != matches_.end()) || is_extension_keyword); |
msw
2014/08/22 17:57:35
ditto nit: reverse conditions.
Mark P
2014/08/22 18:02:18
Done.
| |
439 } | 446 } |
440 UMA_HISTOGRAM_CUSTOM_COUNTS( | 447 UMA_HISTOGRAM_CUSTOM_COUNTS( |
441 "Omnibox.SearchProviderMatches", matches_.size(), 1, 6, 7); | 448 "Omnibox.SearchProviderMatches", matches_.size(), 1, 6, 7); |
442 UpdateDone(); | 449 UpdateDone(); |
443 } | 450 } |
444 | 451 |
445 void SearchProvider::Run() { | 452 void SearchProvider::Run() { |
446 // Start a new request with the current input. | 453 // Start a new request with the current input. |
447 suggest_results_pending_ = 0; | 454 suggest_results_pending_ = 0; |
448 time_suggest_request_sent_ = base::TimeTicks::Now(); | 455 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; | 1267 last_answer_seen_.query_type = match->answer_type; |
1261 } | 1268 } |
1262 | 1269 |
1263 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { | 1270 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { |
1264 // If the query text starts with trimmed input, this is valid prefetch data. | 1271 // If the query text starts with trimmed input, this is valid prefetch data. |
1265 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, | 1272 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, |
1266 base::CollapseWhitespace(input.text(), false), | 1273 base::CollapseWhitespace(input.text(), false), |
1267 false) ? | 1274 false) ? |
1268 last_answer_seen_ : AnswersQueryData(); | 1275 last_answer_seen_ : AnswersQueryData(); |
1269 } | 1276 } |
OLD | NEW |