Chromium Code Reviews| 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 // The initial maximum allowable score for a match which cannot be inlined. | |
| 53 static const int kMaxNonInliningScore; | |
|
Peter Kasting
2011/10/05 00:11:42
I suspect this is leftover from merges, since we r
mrossetti
2011/10/07 17:04:14
Done.
| |
| 54 | |
| 55 // Performs the autocomplete matching and scoring. | |
| 56 void DoAutocomplete(); | |
| 57 | |
| 55 // Creates an AutocompleteMatch from |history_match|. |max_match_score| gives | 58 // Creates an AutocompleteMatch from |history_match|. |max_match_score| gives |
| 56 // the maximum possible score for the match. |history_matches| is the full set | 59 // the maximum possible score for the match. |history_matches| is the full set |
| 57 // of matches to compare each match to when calculating confidence. | 60 // of matches to compare each match to when calculating confidence. |
| 58 AutocompleteMatch QuickMatchToACMatch( | 61 AutocompleteMatch QuickMatchToACMatch( |
| 59 const history::ScoredHistoryMatch& history_match, | 62 const history::ScoredHistoryMatch& history_match, |
| 60 const history::ScoredHistoryMatches& history_matches, | 63 const history::ScoredHistoryMatches& history_matches, |
| 61 bool prevent_inline_autocomplete, | 64 bool prevent_inline_autocomplete, |
| 62 int* max_match_score); | 65 int* max_match_score); |
| 63 | 66 |
| 64 // Determines the relevance score of |history_match|. The maximum allowed | 67 // 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| | 68 // 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 | 69 // 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 | 70 // 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. | 71 // called in a loop with each match in decreasing order of raw score. |
| 69 static int CalculateRelevance( | 72 static int CalculateRelevance( |
| 70 const history::ScoredHistoryMatch& history_match, | 73 const history::ScoredHistoryMatch& history_match, |
| 71 int* max_match_score); | 74 int* max_match_score); |
| 72 | 75 |
| 73 // Returns the index that should be used for history lookups. | 76 // Returns the index that should be used for history lookups. |
| 74 history::InMemoryURLIndex* GetIndex(); | 77 history::InMemoryURLIndex* GetIndex(); |
| 75 | 78 |
| 76 // Fill and return an ACMatchClassifications structure given the term | 79 // Fill and return an ACMatchClassifications structure given the term |
| 77 // matches (|matches|) to highlight where terms were found. | 80 // matches (|matches|) to highlight where terms were found. |
| 78 static ACMatchClassifications SpansFromTermMatch( | 81 static ACMatchClassifications SpansFromTermMatch( |
| 79 const history::TermMatches& matches, | 82 const history::TermMatches& matches, |
| 80 size_t text_length, | 83 size_t text_length, |
| 81 bool is_url); | 84 bool is_url); |
| 82 | 85 |
| 83 // Only for use in unittests. Takes ownership of |index|. | 86 // Only for use in unittests. Takes ownership of |index|. |
| 84 void SetIndexForTesting(history::InMemoryURLIndex* index); | 87 void set_index(history::InMemoryURLIndex* index); |
| 88 | |
| 85 AutocompleteInput autocomplete_input_; | 89 AutocompleteInput autocomplete_input_; |
| 86 std::string languages_; | 90 std::string languages_; |
| 87 | 91 |
| 88 // Only used for testing. | 92 // Only used for testing. |
| 89 scoped_ptr<history::InMemoryURLIndex> index_for_testing_; | 93 scoped_ptr<history::InMemoryURLIndex> index_for_testing_; |
| 90 | 94 |
| 91 // This provider is disabled when true. | 95 // This provider is disabled when true. |
| 92 static bool disabled_; | 96 static bool disabled_; |
| 93 }; | 97 }; |
| 94 | 98 |
| 95 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ | 99 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |
| OLD | NEW |