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