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_quick_provider.h" | 5 #include "chrome/browser/autocomplete/history_quick_provider.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 // BEST_MATCH and there is no inline autocompletion because none of the HQP | 52 // BEST_MATCH and there is no inline autocompletion because none of the HQP |
53 // matches can score highly enough to qualify. | 53 // matches can score highly enough to qualify. |
54 if ((input.type() == AutocompleteInput::INVALID) || | 54 if ((input.type() == AutocompleteInput::INVALID) || |
55 (input.type() == AutocompleteInput::FORCED_QUERY) || | 55 (input.type() == AutocompleteInput::FORCED_QUERY) || |
56 (input.matches_requested() == AutocompleteInput::BEST_MATCH && | 56 (input.matches_requested() == AutocompleteInput::BEST_MATCH && |
57 input.prevent_inline_autocomplete())) | 57 input.prevent_inline_autocomplete())) |
58 return; | 58 return; |
59 | 59 |
60 autocomplete_input_ = input; | 60 autocomplete_input_ = input; |
61 | 61 |
62 // Do some fixup on the user input before matching against it, so we provide | |
63 // good results for local file paths, input with spaces, etc. | |
64 if (!FixupUserInput(&autocomplete_input_)) | |
Peter Kasting
2011/11/21 20:31:02
I think removing this may be worse than keeping it
mrossetti
2011/11/21 21:38:25
Great! I'd appreciate the advice...
When give a s
Peter Kasting
2011/11/21 22:09:00
Hmm. I didn't think about the fact that we could
| |
65 return; | |
66 | |
67 // TODO(pkasting): We should just block here until this loads. Any time | 62 // TODO(pkasting): We should just block here until this loads. Any time |
68 // someone unloads the history backend, we'll get inconsistent inline | 63 // someone unloads the history backend, we'll get inconsistent inline |
69 // autocomplete behavior here. | 64 // autocomplete behavior here. |
70 if (GetIndex()) { | 65 if (GetIndex()) { |
71 base::TimeTicks start_time = base::TimeTicks::Now(); | 66 base::TimeTicks start_time = base::TimeTicks::Now(); |
72 DoAutocomplete(); | 67 DoAutocomplete(); |
73 if (input.text().length() < 6) { | 68 if (input.text().length() < 6) { |
74 base::TimeTicks end_time = base::TimeTicks::Now(); | 69 base::TimeTicks end_time = base::TimeTicks::Now(); |
75 std::string name = "HistoryQuickProvider.QueryIndexTime." + | 70 std::string name = "HistoryQuickProvider.QueryIndexTime." + |
76 base::IntToString(input.text().length()); | 71 base::IntToString(input.text().length()); |
77 base::Histogram* counter = base::Histogram::FactoryGet( | 72 base::Histogram* counter = base::Histogram::FactoryGet( |
78 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag); | 73 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag); |
79 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds())); | 74 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds())); |
80 } | 75 } |
81 UpdateStarredStateOfMatches(); | 76 UpdateStarredStateOfMatches(); |
82 } | 77 } |
83 } | 78 } |
84 | 79 |
85 // TODO(mrossetti): Implement this function. (Will happen in next CL.) | 80 // TODO(mrossetti): Implement this function. (Will happen in next CL.) |
86 void HistoryQuickProvider::DeleteMatch(const AutocompleteMatch& match) {} | 81 void HistoryQuickProvider::DeleteMatch(const AutocompleteMatch& match) {} |
87 | 82 |
88 void HistoryQuickProvider::DoAutocomplete() { | 83 void HistoryQuickProvider::DoAutocomplete() { |
89 // Get the matching URLs from the DB. | 84 // Get the matching URLs from the DB. |
90 string16 term_string = autocomplete_input_.text(); | 85 string16 term_string = autocomplete_input_.text(); |
91 term_string = net::UnescapeURLComponent(term_string, | 86 ScoredHistoryMatches matches = GetIndex()->HistoryItemsForTerms(term_string); |
92 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); | |
93 history::String16Vector terms( | |
94 history::String16VectorFromString16(term_string, false)); | |
95 ScoredHistoryMatches matches = GetIndex()->HistoryItemsForTerms(terms); | |
96 if (matches.empty()) | 87 if (matches.empty()) |
97 return; | 88 return; |
98 | 89 |
99 // Artificially reduce the score of high-scoring matches which should not be | 90 // Artificially reduce the score of high-scoring matches which should not be |
100 // inline autocompletd. Each such result gets the next available | 91 // inline autocompletd. Each such result gets the next available |
101 // |max_match_score|. Upon use of |max_match_score| it is decremented. | 92 // |max_match_score|. Upon use of |max_match_score| it is decremented. |
102 // All subsequent matches must be clamped to retain match results ordering. | 93 // All subsequent matches must be clamped to retain match results ordering. |
103 int max_match_score = autocomplete_input_.prevent_inline_autocomplete() ? | 94 int max_match_score = autocomplete_input_.prevent_inline_autocomplete() ? |
104 (AutocompleteResult::kLowestDefaultScore - 1) : -1; | 95 (AutocompleteResult::kLowestDefaultScore - 1) : -1; |
105 for (ScoredHistoryMatches::const_iterator match_iter = matches.begin(); | 96 for (ScoredHistoryMatches::const_iterator match_iter = matches.begin(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 do { | 199 do { |
209 offset += matches[i].length; | 200 offset += matches[i].length; |
210 ++i; | 201 ++i; |
211 } while ((i < match_count) && (offset == matches[i].offset)); | 202 } while ((i < match_count) && (offset == matches[i].offset)); |
212 if (offset < text_length) | 203 if (offset < text_length) |
213 spans.push_back(ACMatchClassification(offset, url_style)); | 204 spans.push_back(ACMatchClassification(offset, url_style)); |
214 } | 205 } |
215 | 206 |
216 return spans; | 207 return spans; |
217 } | 208 } |
OLD | NEW |