| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/autocomplete_match.h" | 5 #include "components/omnibox/autocomplete_match.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "components/omnibox/autocomplete_provider.h" | 16 #include "components/omnibox/autocomplete_provider.h" |
| 17 #include "components/omnibox/omnibox_switches.h" |
| 16 #include "components/omnibox/suggestion_answer.h" | 18 #include "components/omnibox/suggestion_answer.h" |
| 17 #include "components/search_engines/template_url.h" | 19 #include "components/search_engines/template_url.h" |
| 18 #include "components/search_engines/template_url_service.h" | 20 #include "components/search_engines/template_url_service.h" |
| 19 #include "grit/components_scaled_resources.h" | 21 #include "grit/components_scaled_resources.h" |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 bool IsTrivialClassification(const ACMatchClassifications& classifications) { | 25 bool IsTrivialClassification(const ACMatchClassifications& classifications) { |
| 24 return classifications.empty() || | 26 return classifications.empty() || |
| 25 ((classifications.size() == 1) && | 27 ((classifications.size() == 1) && |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 return true; | 521 return true; |
| 520 | 522 |
| 521 for (ACMatches::const_iterator it(duplicate_matches.begin()); | 523 for (ACMatches::const_iterator it(duplicate_matches.begin()); |
| 522 it != duplicate_matches.end(); ++it) { | 524 it != duplicate_matches.end(); ++it) { |
| 523 if (it->deletable) | 525 if (it->deletable) |
| 524 return true; | 526 return true; |
| 525 } | 527 } |
| 526 return false; | 528 return false; |
| 527 } | 529 } |
| 528 | 530 |
| 531 void AutocompleteMatch::PossiblySwapContentsAndDescriptionForURLSuggestion( |
| 532 const AutocompleteInput& input) { |
| 533 if (!IsSearchType(type) && !description.empty() && |
| 534 base::CommandLine::ForCurrentProcess()-> |
| 535 HasSwitch(switches::kEmphasizeTitlesInOmniboxDropdown) && |
| 536 ((input.type() == metrics::OmniboxInputType::QUERY) || |
| 537 (input.type() == metrics::OmniboxInputType::FORCED_QUERY))) { |
| 538 std::swap(contents, description); |
| 539 std::swap(contents_class, description_class); |
| 540 } |
| 541 } |
| 542 |
| 529 #ifndef NDEBUG | 543 #ifndef NDEBUG |
| 530 void AutocompleteMatch::Validate() const { | 544 void AutocompleteMatch::Validate() const { |
| 531 ValidateClassifications(contents, contents_class); | 545 ValidateClassifications(contents, contents_class); |
| 532 ValidateClassifications(description, description_class); | 546 ValidateClassifications(description, description_class); |
| 533 } | 547 } |
| 534 | 548 |
| 535 void AutocompleteMatch::ValidateClassifications( | 549 void AutocompleteMatch::ValidateClassifications( |
| 536 const base::string16& text, | 550 const base::string16& text, |
| 537 const ACMatchClassifications& classifications) const { | 551 const ACMatchClassifications& classifications) const { |
| 538 if (text.empty()) { | 552 if (text.empty()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 557 << " is unsorted in relation to last offset of " << last_offset | 571 << " is unsorted in relation to last offset of " << last_offset |
| 558 << ". Provider: " << provider_name << "."; | 572 << ". Provider: " << provider_name << "."; |
| 559 DCHECK_LT(i->offset, text.length()) | 573 DCHECK_LT(i->offset, text.length()) |
| 560 << " Classification of [" << i->offset << "," << text.length() | 574 << " Classification of [" << i->offset << "," << text.length() |
| 561 << "] is out of bounds for \"" << text << "\". Provider: " | 575 << "] is out of bounds for \"" << text << "\". Provider: " |
| 562 << provider_name << "."; | 576 << provider_name << "."; |
| 563 last_offset = i->offset; | 577 last_offset = i->offset; |
| 564 } | 578 } |
| 565 } | 579 } |
| 566 #endif | 580 #endif |
| OLD | NEW |