[email protected] | 7c6821d | 2010-08-04 16:07:34 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |
| 6 | #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |
[email protected] | bbf7e53f | 2010-08-21 03:48:22 | [diff] [blame] | 7 | #pragma once |
[email protected] | 7c6821d | 2010-08-04 16:07:34 | [diff] [blame] | 8 | |
[email protected] | 497606b | 2010-10-12 17:31:23 | [diff] [blame] | 9 | #include <string> |
| 10 | |
| 11 | #include "chrome/browser/autocomplete/history_provider.h" |
| 12 | #include "chrome/browser/history/history_types.h" |
| 13 | #include "chrome/browser/history/in_memory_url_index.h" |
| 14 | |
| 15 | class Profile; |
| 16 | |
| 17 | namespace history { |
| 18 | class HistoryBackend; |
| 19 | } // namespace history |
[email protected] | 7c6821d | 2010-08-04 16:07:34 | [diff] [blame] | 20 | |
| 21 | // This class is an autocomplete provider (a pseudo-internal component of |
| 22 | // the history system) which quickly (and synchronously) provides matching |
| 23 | // results from recently or frequently visited sites in the profile's |
| 24 | // history. |
| 25 | // |
| 26 | // TODO(mrossetti): Review to see if the following applies since we're not |
| 27 | // using the database during the autocomplete pass. |
[email protected] | 497606b | 2010-10-12 17:31:23 | [diff] [blame] | 28 | class HistoryQuickProvider : public HistoryProvider { |
[email protected] | 7c6821d | 2010-08-04 16:07:34 | [diff] [blame] | 29 | public: |
[email protected] | 497606b | 2010-10-12 17:31:23 | [diff] [blame] | 30 | HistoryQuickProvider(ACProviderListener* listener, Profile* profile); |
[email protected] | 7c6821d | 2010-08-04 16:07:34 | [diff] [blame] | 31 | |
[email protected] | 497606b | 2010-10-12 17:31:23 | [diff] [blame] | 32 | ~HistoryQuickProvider(); |
[email protected] | 7c6821d | 2010-08-04 16:07:34 | [diff] [blame] | 33 | |
[email protected] | 497606b | 2010-10-12 17:31:23 | [diff] [blame] | 34 | // AutocompleteProvider. |minimal_changes| is ignored since there |
| 35 | // is no asynch completion performed. |
[email protected] | 0b9d27b | 2010-12-22 00:51:39 | [diff] [blame^] | 36 | virtual void Start(const AutocompleteInput& input, |
| 37 | bool minimal_changes) OVERRIDE; |
| 38 | |
| 39 | virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; |
[email protected] | 7c6821d | 2010-08-04 16:07:34 | [diff] [blame] | 40 | |
[email protected] | 497606b | 2010-10-12 17:31:23 | [diff] [blame] | 41 | // Performs the autocomplete matching and scoring. |
| 42 | void DoAutocomplete(); |
| 43 | |
[email protected] | 7c6821d | 2010-08-04 16:07:34 | [diff] [blame] | 44 | private: |
[email protected] | 497606b | 2010-10-12 17:31:23 | [diff] [blame] | 45 | friend class HistoryQuickProviderTest; |
| 46 | |
| 47 | AutocompleteMatch QuickMatchToACMatch( |
| 48 | const history::ScoredHistoryMatch& history_match, |
| 49 | MatchType match_type, |
| 50 | size_t match_number); |
| 51 | |
| 52 | // Breaks a string down into individual words and return as a vector with |
| 53 | // the individual words in their original order. |
| 54 | static history::InMemoryURLIndex::String16Vector WordVectorFromString16( |
| 55 | const string16& uni_string); |
| 56 | |
| 57 | // Determines the relevance for some input, given its type and which match it |
| 58 | // is. If |match_type| is NORMAL, |match_number| is a number |
| 59 | // [0, kMaxSuggestions) indicating the relevance of the match (higher == more |
| 60 | // relevant). For other values of |match_type|, |match_number| is ignored. |
| 61 | static int CalculateRelevance(int raw_score, |
| 62 | AutocompleteInput::Type input_type, |
| 63 | MatchType match_type, |
| 64 | size_t match_number); |
| 65 | |
| 66 | // Returns the index that should be used for history lookups. |
| 67 | history::InMemoryURLIndex* GetIndex(); |
| 68 | |
| 69 | // Only for use in unittests. Takes ownership of |index|. |
| 70 | void SetIndexForTesting(history::InMemoryURLIndex* index); |
| 71 | AutocompleteInput autocomplete_input_; |
| 72 | bool trim_http_; |
| 73 | std::string languages_; |
| 74 | |
| 75 | // Only used for testing. |
| 76 | scoped_ptr<history::InMemoryURLIndex> index_for_testing_; |
[email protected] | 7c6821d | 2010-08-04 16:07:34 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |