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 #ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 virtual ~HistoryQuickProvider(); | 31 virtual ~HistoryQuickProvider(); |
32 | 32 |
33 // AutocompleteProvider. |minimal_changes| is ignored since there | 33 // AutocompleteProvider. |minimal_changes| is ignored since there |
34 // is no asynch completion performed. | 34 // is no asynch completion performed. |
35 virtual void Start(const AutocompleteInput& input, | 35 virtual void Start(const AutocompleteInput& input, |
36 bool minimal_changes) OVERRIDE; | 36 bool minimal_changes) OVERRIDE; |
37 | 37 |
38 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; | 38 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; |
39 | 39 |
40 // Performs the autocomplete matching and scoring. | |
41 void DoAutocomplete(); | |
42 | |
43 // Disable this provider. For unit testing purposes only. This is required | 40 // Disable this provider. For unit testing purposes only. This is required |
44 // because this provider is closely associated with the HistoryURLProvider | 41 // because this provider is closely associated with the HistoryURLProvider |
45 // and in order to properly test the latter the HistoryQuickProvider must | 42 // and in order to properly test the latter the HistoryQuickProvider must |
46 // be disabled. | 43 // be disabled. |
47 // TODO(mrossetti): Eliminate this once the HUP has been refactored. | 44 // TODO(mrossetti): Eliminate this once the HUP has been refactored. |
48 static void set_disabled(bool disabled) { disabled_ = disabled; } | 45 static void set_disabled(bool disabled) { disabled_ = disabled; } |
49 | 46 |
50 private: | 47 private: |
51 friend class HistoryQuickProviderTest; | 48 friend class HistoryQuickProviderTest; |
52 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Spans); | 49 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Spans); |
53 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Relevance); | 50 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Relevance); |
54 | 51 |
| 52 // Performs the autocomplete matching and scoring. |
| 53 void DoAutocomplete(); |
| 54 |
55 // Creates an AutocompleteMatch from |history_match|. |max_match_score| gives | 55 // Creates an AutocompleteMatch from |history_match|. |max_match_score| gives |
56 // the maximum possible score for the match. |history_matches| is the full set | 56 // the maximum possible score for the match. |history_matches| is the full set |
57 // of matches to compare each match to when calculating confidence. | 57 // of matches to compare each match to when calculating confidence. |
58 AutocompleteMatch QuickMatchToACMatch( | 58 AutocompleteMatch QuickMatchToACMatch( |
59 const history::ScoredHistoryMatch& history_match, | 59 const history::ScoredHistoryMatch& history_match, |
60 const history::ScoredHistoryMatches& history_matches, | 60 const history::ScoredHistoryMatches& history_matches, |
61 bool prevent_inline_autocomplete, | 61 bool prevent_inline_autocomplete, |
62 int* max_match_score); | 62 int* max_match_score); |
63 | 63 |
64 // Determines the relevance score of |history_match|. The maximum allowed | 64 // Determines the relevance score of |history_match|. The maximum allowed |
65 // score for the match is passed in |max_match_score|. The |max_match_score| | 65 // score for the match is passed in |max_match_score|. The |max_match_score| |
66 // is always set to the resulting score minus 1 whenever the match's score | 66 // is always set to the resulting score minus 1 whenever the match's score |
67 // has to be limited or is <= to |max_match_score|. This function should be | 67 // has to be limited or is <= to |max_match_score|. This function should be |
68 // called in a loop with each match in decreasing order of raw score. | 68 // called in a loop with each match in decreasing order of raw score. |
69 static int CalculateRelevance( | 69 static int CalculateRelevance( |
70 const history::ScoredHistoryMatch& history_match, | 70 const history::ScoredHistoryMatch& history_match, |
71 int* max_match_score); | 71 int* max_match_score); |
72 | 72 |
73 // Returns the index that should be used for history lookups. | 73 // Returns the index that should be used for history lookups. |
74 history::InMemoryURLIndex* GetIndex(); | 74 history::InMemoryURLIndex* GetIndex(); |
75 | 75 |
76 // Fill and return an ACMatchClassifications structure given the term | 76 // Fill and return an ACMatchClassifications structure given the term |
77 // matches (|matches|) to highlight where terms were found. | 77 // matches (|matches|) to highlight where terms were found. |
78 static ACMatchClassifications SpansFromTermMatch( | 78 static ACMatchClassifications SpansFromTermMatch( |
79 const history::TermMatches& matches, | 79 const history::TermMatches& matches, |
80 size_t text_length, | 80 size_t text_length, |
81 bool is_url); | 81 bool is_url); |
82 | 82 |
83 // Only for use in unittests. Takes ownership of |index|. | 83 // Only for use in unittests. Takes ownership of |index|. |
84 void SetIndexForTesting(history::InMemoryURLIndex* index); | 84 void set_index(history::InMemoryURLIndex* index); |
| 85 |
85 AutocompleteInput autocomplete_input_; | 86 AutocompleteInput autocomplete_input_; |
86 std::string languages_; | 87 std::string languages_; |
87 | 88 |
88 // Only used for testing. | 89 // Only used for testing. |
89 scoped_ptr<history::InMemoryURLIndex> index_for_testing_; | 90 scoped_ptr<history::InMemoryURLIndex> index_for_testing_; |
90 | 91 |
91 // This provider is disabled when true. | 92 // This provider is disabled when true. |
92 static bool disabled_; | 93 static bool disabled_; |
93 }; | 94 }; |
94 | 95 |
95 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ | 96 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |
OLD | NEW |