| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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.h" | 5 #include "chrome/browser/autocomplete/autocomplete.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 DCHECK(i->offset > last_offset) << "Classification unsorted"; | 540 DCHECK(i->offset > last_offset) << "Classification unsorted"; |
| 541 DCHECK(i->offset < text.length()) << "Classification out of bounds"; | 541 DCHECK(i->offset < text.length()) << "Classification out of bounds"; |
| 542 last_offset = i->offset; | 542 last_offset = i->offset; |
| 543 } | 543 } |
| 544 } | 544 } |
| 545 #endif | 545 #endif |
| 546 | 546 |
| 547 // AutocompleteProvider ------------------------------------------------------- | 547 // AutocompleteProvider ------------------------------------------------------- |
| 548 | 548 |
| 549 // static | 549 // static |
| 550 size_t AutocompleteProvider::max_matches_ = 3; | 550 const size_t AutocompleteProvider::kMaxMatches = 3; |
| 551 | 551 |
| 552 AutocompleteProvider::~AutocompleteProvider() { | 552 AutocompleteProvider::~AutocompleteProvider() { |
| 553 Stop(); | 553 Stop(); |
| 554 } | 554 } |
| 555 | 555 |
| 556 void AutocompleteProvider::SetProfile(Profile* profile) { | 556 void AutocompleteProvider::SetProfile(Profile* profile) { |
| 557 DCHECK(profile); | 557 DCHECK(profile); |
| 558 DCHECK(done_); // The controller should have already stopped us. | 558 DCHECK(done_); // The controller should have already stopped us. |
| 559 profile_ = profile; | 559 profile_ = profile; |
| 560 } | 560 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::wstring(); | 601 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::wstring(); |
| 602 const net::FormatUrlTypes format_types = trim_http ? | 602 const net::FormatUrlTypes format_types = trim_http ? |
| 603 net::kFormatUrlOmitAll : net::kFormatUrlOmitUsernamePassword; | 603 net::kFormatUrlOmitAll : net::kFormatUrlOmitUsernamePassword; |
| 604 return net::FormatUrl(url, languages, format_types, UnescapeRule::SPACES, | 604 return net::FormatUrl(url, languages, format_types, UnescapeRule::SPACES, |
| 605 NULL, NULL, NULL); | 605 NULL, NULL, NULL); |
| 606 } | 606 } |
| 607 | 607 |
| 608 // AutocompleteResult --------------------------------------------------------- | 608 // AutocompleteResult --------------------------------------------------------- |
| 609 | 609 |
| 610 // static | 610 // static |
| 611 size_t AutocompleteResult::max_matches_ = 6; | 611 const size_t AutocompleteResult::kMaxMatches = 6; |
| 612 | 612 |
| 613 void AutocompleteResult::Selection::Clear() { | 613 void AutocompleteResult::Selection::Clear() { |
| 614 destination_url = GURL(); | 614 destination_url = GURL(); |
| 615 provider_affinity = NULL; | 615 provider_affinity = NULL; |
| 616 is_history_what_you_typed_match = false; | 616 is_history_what_you_typed_match = false; |
| 617 } | 617 } |
| 618 | 618 |
| 619 AutocompleteResult::AutocompleteResult() { | 619 AutocompleteResult::AutocompleteResult() { |
| 620 // Reserve space for the max number of matches we'll show. The +1 accounts | 620 // Reserve space for the max number of matches we'll show. The +1 accounts |
| 621 // for the history shortcut match as it isn't included in max_matches. | 621 // for the history shortcut match as it isn't included in max_matches. |
| 622 matches_.reserve(max_matches() + 1); | 622 matches_.reserve(kMaxMatches + 1); |
| 623 | 623 |
| 624 // It's probably safe to do this in the initializer list, but there's little | 624 // It's probably safe to do this in the initializer list, but there's little |
| 625 // penalty to doing it here and it ensures our object is fully constructed | 625 // penalty to doing it here and it ensures our object is fully constructed |
| 626 // before calling member functions. | 626 // before calling member functions. |
| 627 default_match_ = end(); | 627 default_match_ = end(); |
| 628 } | 628 } |
| 629 | 629 |
| 630 void AutocompleteResult::CopyFrom(const AutocompleteResult& rhs) { | 630 void AutocompleteResult::CopyFrom(const AutocompleteResult& rhs) { |
| 631 if (this == &rhs) | 631 if (this == &rhs) |
| 632 return; | 632 return; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 660 | 660 |
| 661 void AutocompleteResult::SortAndCull(const AutocompleteInput& input) { | 661 void AutocompleteResult::SortAndCull(const AutocompleteInput& input) { |
| 662 // Remove duplicates. | 662 // Remove duplicates. |
| 663 std::sort(matches_.begin(), matches_.end(), | 663 std::sort(matches_.begin(), matches_.end(), |
| 664 &AutocompleteMatch::DestinationSortFunc); | 664 &AutocompleteMatch::DestinationSortFunc); |
| 665 matches_.erase(std::unique(matches_.begin(), matches_.end(), | 665 matches_.erase(std::unique(matches_.begin(), matches_.end(), |
| 666 &AutocompleteMatch::DestinationsEqual), | 666 &AutocompleteMatch::DestinationsEqual), |
| 667 matches_.end()); | 667 matches_.end()); |
| 668 | 668 |
| 669 // Find the top max_matches. | 669 // Find the top max_matches. |
| 670 if (matches_.size() > max_matches()) { | 670 if (matches_.size() > kMaxMatches) { |
| 671 std::partial_sort(matches_.begin(), matches_.begin() + max_matches(), | 671 std::partial_sort(matches_.begin(), matches_.begin() + kMaxMatches, |
| 672 matches_.end(), &AutocompleteMatch::MoreRelevant); | 672 matches_.end(), &AutocompleteMatch::MoreRelevant); |
| 673 matches_.erase(matches_.begin() + max_matches(), matches_.end()); | 673 matches_.erase(matches_.begin() + kMaxMatches, matches_.end()); |
| 674 } | 674 } |
| 675 | 675 |
| 676 // HistoryContentsProvider uses a negative relevance as a way to avoid | 676 // HistoryContentsProvider uses a negative relevance as a way to avoid |
| 677 // starving out other provider matches, yet we may end up using this match. To | 677 // starving out other provider matches, yet we may end up using this match. To |
| 678 // make sure such matches are sorted correctly we search for all | 678 // make sure such matches are sorted correctly we search for all |
| 679 // relevances < 0 and negate them. If we change our relevance algorithm to | 679 // relevances < 0 and negate them. If we change our relevance algorithm to |
| 680 // properly mix different providers' matches, this can go away. | 680 // properly mix different providers' matches, this can go away. |
| 681 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) { | 681 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) { |
| 682 if (i->relevance < 0) | 682 if (i->relevance < 0) |
| 683 i->relevance = -i->relevance; | 683 i->relevance = -i->relevance; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 void AutocompleteController::CheckIfDone() { | 1020 void AutocompleteController::CheckIfDone() { |
| 1021 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); | 1021 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); |
| 1022 ++i) { | 1022 ++i) { |
| 1023 if (!(*i)->done()) { | 1023 if (!(*i)->done()) { |
| 1024 done_ = false; | 1024 done_ = false; |
| 1025 return; | 1025 return; |
| 1026 } | 1026 } |
| 1027 } | 1027 } |
| 1028 done_ = true; | 1028 done_ = true; |
| 1029 } | 1029 } |
| OLD | NEW |