OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/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 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
734 // this row's data available during the first pass. That means we | 734 // this row's data available during the first pass. That means we |
735 // either scored it as WHAT_YOU_TYPED or UNVISITED_INTRANET, and to | 735 // either scored it as WHAT_YOU_TYPED or UNVISITED_INTRANET, and to |
736 // maintain the ordering between passes consistent, we need to score it | 736 // maintain the ordering between passes consistent, we need to score it |
737 // the same way here. | 737 // the same way here. |
738 type = CanFindIntranetURL(db, input) ? | 738 type = CanFindIntranetURL(db, input) ? |
739 UNVISITED_INTRANET : WHAT_YOU_TYPED; | 739 UNVISITED_INTRANET : WHAT_YOU_TYPED; |
740 } | 740 } |
741 break; | 741 break; |
742 } | 742 } |
743 | 743 |
744 const GURL& url = match->destination_url; | |
745 const url_parse::Parsed& parsed = url.parsed_for_possibly_invalid_spec(); | |
746 // If the what-you-typed result looks like a single word (which can be | |
747 // interpreted as an intranet address) followed by a pound sign ("#"), | |
748 // leave the score for the url-what-you-typed result as is. The top | |
749 // result be a search query from SearchProvider. This test fixes cases | |
Peter Kasting
2013/04/03 21:43:49
Nit: be -> will be, from -> from the?
This sounds
Mark P
2013/04/03 22:58:18
Done. (x2)
| |
750 // such as "c#" and "c# foo" where the user has visited an intranet | |
751 // site "c". We want the search-what-you-typed to beat the | |
Peter Kasting
2013/04/03 21:43:49
Nit: to beat -> score to beat?
Mark P
2013/04/03 22:58:18
Okay.
| |
752 // URL-what-you-typed in this case. Most of the below test tries to make | |
Peter Kasting
2013/04/03 21:43:49
Nit: in -> score in?
Mark P
2013/04/03 22:58:18
Done.
| |
753 // sure that this code does not trigger if the user did anything to | |
754 // indicate the desired match is a URL. For instance, "c/# foo" will not | |
755 // pass the test because those will be classified as input type URL. The | |
Peter Kasting
2013/04/03 21:43:49
Nit: those -> that
Mark P
2013/04/03 22:58:18
Done.
| |
756 // parsed.CountCharactersBefore() in the test looks for the presence of a | |
757 // reference fragment in the URL by checking whether the position differs | |
758 // included the delimiter (pound sign) versus not including the delimiter. | |
759 // (One cannot simply check url.ref() because it will not distinguish | |
760 // between the input "c" and the input "c#", both of which will have empty | |
761 // reference fragments.) | |
762 if ((type == UNVISITED_INTRANET) && | |
763 (input.type() != AutocompleteInput::URL) && | |
764 url.username().empty() && url.password().empty() && url.port().empty() && | |
765 (url.path() == "/") && url.query().empty() && | |
Peter Kasting
2013/04/03 21:43:49
Nit: Fractionally faster: url.path().length() == 1
Mark P
2013/04/03 22:58:18
A seriously less readable. It also makes me nervo
| |
766 (parsed.CountCharactersBefore(url_parse::Parsed::REF, true) != | |
767 parsed.CountCharactersBefore(url_parse::Parsed::REF, false))) { | |
768 return false; | |
769 } | |
770 | |
744 match->relevance = CalculateRelevance(type, 0); | 771 match->relevance = CalculateRelevance(type, 0); |
745 | 772 |
773 // If there are any other matches, then don't promote this match here, in | |
774 // hopes the caller will be able to inline autocomplete a better suggestion. | |
775 // DoAutocomplete() will fall back on this match if inline autocompletion | |
776 // fails. This matches how we react to never-visited URL inputs in the non- | |
777 // intranet case. | |
746 if (type == UNVISITED_INTRANET && !matches->empty()) { | 778 if (type == UNVISITED_INTRANET && !matches->empty()) { |
Peter Kasting
2013/04/03 21:43:49
Nit: No {}
Mark P
2013/04/03 22:58:18
Done.
| |
747 // If there are any other matches, then don't promote this match here, in | |
748 // hopes the caller will be able to inline autocomplete a better suggestion. | |
749 // DoAutocomplete() will fall back on this match if inline autocompletion | |
750 // fails. This matches how we react to never-visited URL inputs in the non- | |
751 // intranet case. | |
752 return false; | 779 return false; |
753 } | 780 } |
754 | 781 |
755 // Put it on the front of the HistoryMatches for redirect culling. | 782 // Put it on the front of the HistoryMatches for redirect culling. |
756 CreateOrPromoteMatch(classifier.url_row(), string16::npos, false, matches, | 783 CreateOrPromoteMatch(classifier.url_row(), string16::npos, false, matches, |
757 true, true); | 784 true, true); |
758 return true; | 785 return true; |
759 } | 786 } |
760 | 787 |
761 bool HistoryURLProvider::CanFindIntranetURL( | 788 bool HistoryURLProvider::CanFindIntranetURL( |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1048 &match.contents_class); | 1075 &match.contents_class); |
1049 } | 1076 } |
1050 match.description = info.title(); | 1077 match.description = info.title(); |
1051 AutocompleteMatch::ClassifyMatchInString(params->input.text(), | 1078 AutocompleteMatch::ClassifyMatchInString(params->input.text(), |
1052 info.title(), | 1079 info.title(), |
1053 ACMatchClassification::NONE, | 1080 ACMatchClassification::NONE, |
1054 &match.description_class); | 1081 &match.description_class); |
1055 RecordAdditionalInfoFromUrlRow(info, &match); | 1082 RecordAdditionalInfoFromUrlRow(info, &match); |
1056 return match; | 1083 return match; |
1057 } | 1084 } |
OLD | NEW |