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 |
| 11 #include "chrome/browser/autocomplete/autocomplete_match.h" | |
| 11 #include "chrome/browser/autocomplete/history_provider.h" | 12 #include "chrome/browser/autocomplete/history_provider.h" |
| 12 #include "chrome/browser/history/history_types.h" | 13 #include "chrome/browser/history/history_types.h" |
| 13 #include "chrome/browser/history/in_memory_url_index.h" | 14 #include "chrome/browser/history/in_memory_url_index.h" |
| 14 | 15 |
| 15 class Profile; | 16 class Profile; |
| 17 class TermMatches; | |
| 16 | 18 |
| 17 namespace history { | 19 namespace history { |
| 18 class HistoryBackend; | 20 class HistoryBackend; |
| 19 } // namespace history | 21 } // namespace history |
| 20 | 22 |
| 21 // This class is an autocomplete provider (a pseudo-internal component of | 23 // This class is an autocomplete provider (a pseudo-internal component of |
| 22 // the history system) which quickly (and synchronously) provides matching | 24 // the history system) which quickly (and synchronously) provides matching |
| 23 // results from recently or frequently visited sites in the profile's | 25 // results from recently or frequently visited sites in the profile's |
| 24 // history. | 26 // history. |
| 25 class HistoryQuickProvider : public HistoryProvider { | 27 class HistoryQuickProvider : public HistoryProvider { |
| 26 public: | 28 public: |
| 27 HistoryQuickProvider(ACProviderListener* listener, Profile* profile); | 29 HistoryQuickProvider(ACProviderListener* listener, Profile* profile); |
| 28 | 30 |
| 29 ~HistoryQuickProvider(); | 31 ~HistoryQuickProvider(); |
| 30 | 32 |
| 31 // AutocompleteProvider. |minimal_changes| is ignored since there | 33 // AutocompleteProvider. |minimal_changes| is ignored since there |
| 32 // is no asynch completion performed. | 34 // is no asynch completion performed. |
| 33 virtual void Start(const AutocompleteInput& input, | 35 virtual void Start(const AutocompleteInput& input, |
| 34 bool minimal_changes) OVERRIDE; | 36 bool minimal_changes) OVERRIDE; |
| 35 | 37 |
| 36 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; | 38 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; |
| 37 | 39 |
| 38 // Performs the autocomplete matching and scoring. | 40 // Performs the autocomplete matching and scoring. |
| 39 void DoAutocomplete(); | 41 void DoAutocomplete(); |
| 40 | 42 |
| 41 private: | 43 private: |
| 42 friend class HistoryQuickProviderTest; | 44 friend class HistoryQuickProviderTest; |
| 45 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Spans); | |
| 43 | 46 |
| 44 AutocompleteMatch QuickMatchToACMatch( | 47 AutocompleteMatch QuickMatchToACMatch( |
| 45 const history::ScoredHistoryMatch& history_match, | 48 const history::ScoredHistoryMatch& history_match, |
| 46 MatchType match_type, | |
| 47 size_t match_number); | 49 size_t match_number); |
| 48 | 50 |
| 49 // Breaks a string down into individual words and return as a vector with | |
| 50 // the individual words in their original order. | |
| 51 static history::InMemoryURLIndex::String16Vector WordVectorFromString16( | |
| 52 const string16& uni_string); | |
| 53 | |
| 54 // Determines the relevance for some input, given its type and which match it | 51 // Determines the relevance for some input, given its type and which match it |
| 55 // is. If |match_type| is NORMAL, |match_number| is a number | 52 // is. If |match_type| is NORMAL, |match_number| is a number |
| 56 // [0, kMaxSuggestions) indicating the relevance of the match (higher == more | 53 // [0, kMaxSuggestions) indicating the relevance of the match (higher == more |
| 57 // relevant). For other values of |match_type|, |match_number| is ignored. | 54 // relevant). For other values of |match_type|, |match_number| is ignored. |
| 58 static int CalculateRelevance(int raw_score, | 55 static int CalculateRelevance(int raw_score, |
| 59 AutocompleteInput::Type input_type, | 56 AutocompleteInput::Type input_type, |
| 60 MatchType match_type, | 57 MatchType match_type, |
| 61 size_t match_number); | 58 size_t match_number); |
| 62 | 59 |
| 63 // Returns the index that should be used for history lookups. | 60 // Returns the index that should be used for history lookups. |
| 64 history::InMemoryURLIndex* GetIndex(); | 61 history::InMemoryURLIndex* GetIndex(); |
| 65 | 62 |
| 63 // Fill and return an ACMatchClassifications structure given the term | |
| 64 // matches (|matches|) to highlight where terms were found. |adjust| is | |
| 65 // subtracted form each offset and is used to account for any leading | |
| 66 // 'http://' in the potential result. | |
| 67 static ACMatchClassifications SpansFromTermMatch( | |
| 68 const history::TermMatches& matches, size_t text_length, size_t adjust); | |
|
Peter Kasting
2011/03/09 02:31:48
Nit: One arg per line
mrossetti
2011/03/10 01:31:14
Done.
| |
| 69 | |
| 66 // Only for use in unittests. Takes ownership of |index|. | 70 // Only for use in unittests. Takes ownership of |index|. |
| 67 void SetIndexForTesting(history::InMemoryURLIndex* index); | 71 void SetIndexForTesting(history::InMemoryURLIndex* index); |
| 68 AutocompleteInput autocomplete_input_; | 72 AutocompleteInput autocomplete_input_; |
| 69 bool trim_http_; | |
| 70 std::string languages_; | 73 std::string languages_; |
| 71 | 74 |
| 72 // Only used for testing. | 75 // Only used for testing. |
| 73 scoped_ptr<history::InMemoryURLIndex> index_for_testing_; | 76 scoped_ptr<history::InMemoryURLIndex> index_for_testing_; |
| 74 }; | 77 }; |
| 75 | 78 |
| 76 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ | 79 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |
| OLD | NEW |