OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 for (history::Prefixes::const_iterator i(prefixes_.begin()); | 393 for (history::Prefixes::const_iterator i(prefixes_.begin()); |
394 i != prefixes_.end(); ++i) { | 394 i != prefixes_.end(); ++i) { |
395 if (params->cancel_flag.IsSet()) | 395 if (params->cancel_flag.IsSet()) |
396 return; // Canceled in the middle of a query, give up. | 396 return; // Canceled in the middle of a query, give up. |
397 // We only need kMaxMatches results in the end, but before we get there we | 397 // We only need kMaxMatches results in the end, but before we get there we |
398 // need to promote lower-quality matches that are prefixes of | 398 // need to promote lower-quality matches that are prefixes of |
399 // higher-quality matches, and remove lower-quality redirects. So we ask | 399 // higher-quality matches, and remove lower-quality redirects. So we ask |
400 // for more results than we need, of every prefix type, in hopes this will | 400 // for more results than we need, of every prefix type, in hopes this will |
401 // give us far more than enough to work with. CullRedirects() will then | 401 // give us far more than enough to work with. CullRedirects() will then |
402 // reduce the list to the best kMaxMatches results. | 402 // reduce the list to the best kMaxMatches results. |
403 db->AutocompleteForPrefix(i->prefix + params->input.text(), | 403 db->AutocompleteForPrefix(UTF16ToUTF8(i->prefix + params->input.text()), |
404 kMaxMatches * 2, (backend == NULL), &url_matches); | 404 kMaxMatches * 2, (backend == NULL), &url_matches); |
405 for (URLRowVector::const_iterator j(url_matches.begin()); | 405 for (URLRowVector::const_iterator j(url_matches.begin()); |
406 j != url_matches.end(); ++j) { | 406 j != url_matches.end(); ++j) { |
407 const history::Prefix* best_prefix = BestPrefix(j->url(), string16()); | 407 const history::Prefix* best_prefix = BestPrefix(j->url(), string16()); |
408 DCHECK(best_prefix != NULL); | 408 DCHECK(best_prefix != NULL); |
409 history_matches.push_back(history::HistoryMatch(*j, i->prefix.length(), | 409 history_matches.push_back(history::HistoryMatch(*j, i->prefix.length(), |
410 !i->num_components, | 410 !i->num_components, |
411 i->num_components >= best_prefix->num_components)); | 411 i->num_components >= best_prefix->num_components)); |
412 } | 412 } |
413 } | 413 } |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 history::URLDatabase* db, | 743 history::URLDatabase* db, |
744 const AutocompleteInput& input) const { | 744 const AutocompleteInput& input) const { |
745 // Normally passing the first two conditions below ought to guarantee the | 745 // Normally passing the first two conditions below ought to guarantee the |
746 // third condition, but because FixupUserInput() can run and modify the | 746 // third condition, but because FixupUserInput() can run and modify the |
747 // input's text and parts between Parse() and here, it seems better to be | 747 // input's text and parts between Parse() and here, it seems better to be |
748 // paranoid and check. | 748 // paranoid and check. |
749 if ((input.type() != AutocompleteInput::UNKNOWN) || | 749 if ((input.type() != AutocompleteInput::UNKNOWN) || |
750 !LowerCaseEqualsASCII(input.scheme(), chrome::kHttpScheme) || | 750 !LowerCaseEqualsASCII(input.scheme(), chrome::kHttpScheme) || |
751 !input.parts().host.is_nonempty()) | 751 !input.parts().host.is_nonempty()) |
752 return false; | 752 return false; |
753 const string16 host(input.text().substr(input.parts().host.begin, | 753 const std::string host(UTF16ToUTF8( |
754 input.parts().host.len)); | 754 input.text().substr(input.parts().host.begin, input.parts().host.len))); |
755 if (net::RegistryControlledDomainService::GetRegistryLength( | 755 if (net::RegistryControlledDomainService::GetRegistryLength(host, false) != 0) |
756 UTF16ToUTF8(host), false) != 0) | |
757 return false; | 756 return false; |
758 std::vector<history::URLRow> dummy; | 757 return db->IsTypedHost(host); |
759 for (history::Prefixes::const_iterator i(prefixes_.begin()); | |
760 i != prefixes_.end(); ++i) { | |
761 if ((i->num_components == 1) && | |
762 (db->AutocompleteForPrefix(i->prefix + host + ASCIIToUTF16("/"), 1, | |
763 true, &dummy) || | |
764 db->AutocompleteForPrefix(i->prefix + host + ASCIIToUTF16(":"), 1, | |
765 true, &dummy))) | |
766 return true; | |
767 } | |
768 return false; | |
769 } | 758 } |
770 | 759 |
771 bool HistoryURLProvider::PromoteMatchForInlineAutocomplete( | 760 bool HistoryURLProvider::PromoteMatchForInlineAutocomplete( |
772 HistoryURLProviderParams* params, | 761 HistoryURLProviderParams* params, |
773 const history::HistoryMatch& match, | 762 const history::HistoryMatch& match, |
774 const history::HistoryMatches& matches) { | 763 const history::HistoryMatches& matches) { |
775 // Promote the first match if it's been typed at least n times, where n == 1 | 764 // Promote the first match if it's been typed at least n times, where n == 1 |
776 // for "simple" (host-only) URLs and n == 2 for others. We set a higher bar | 765 // for "simple" (host-only) URLs and n == 2 for others. We set a higher bar |
777 // for these long URLs because it's less likely that users will want to visit | 766 // for these long URLs because it's less likely that users will want to visit |
778 // them again. Even though we don't increment the typed_count for pasted-in | 767 // them again. Even though we don't increment the typed_count for pasted-in |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 &match.contents_class); | 933 &match.contents_class); |
945 } | 934 } |
946 match.description = info.title(); | 935 match.description = info.title(); |
947 AutocompleteMatch::ClassifyMatchInString(params->input.text(), | 936 AutocompleteMatch::ClassifyMatchInString(params->input.text(), |
948 info.title(), | 937 info.title(), |
949 ACMatchClassification::NONE, | 938 ACMatchClassification::NONE, |
950 &match.description_class); | 939 &match.description_class); |
951 | 940 |
952 return match; | 941 return match; |
953 } | 942 } |
OLD | NEW |