history_quick_provider.h revision dc0f95d653279beabeb9817299e2902918ba123e
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/history_provider.h" 12#include "chrome/browser/history/history_types.h" 13#include "chrome/browser/history/in_memory_url_index.h" 14 15class Profile; 16 17namespace history { 18class HistoryBackend; 19} // namespace history 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. 25class HistoryQuickProvider : public HistoryProvider { 26 public: 27 HistoryQuickProvider(ACProviderListener* listener, Profile* profile); 28 29 ~HistoryQuickProvider(); 30 31 // AutocompleteProvider. |minimal_changes| is ignored since there 32 // is no asynch completion performed. 33 virtual void Start(const AutocompleteInput& input, 34 bool minimal_changes) OVERRIDE; 35 36 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; 37 38 // Performs the autocomplete matching and scoring. 39 void DoAutocomplete(); 40 41 private: 42 friend class HistoryQuickProviderTest; 43 44 AutocompleteMatch QuickMatchToACMatch( 45 const history::ScoredHistoryMatch& history_match, 46 MatchType match_type, 47 size_t match_number); 48 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 55 // is. If |match_type| is NORMAL, |match_number| is a number 56 // [0, kMaxSuggestions) indicating the relevance of the match (higher == more 57 // relevant). For other values of |match_type|, |match_number| is ignored. 58 static int CalculateRelevance(int raw_score, 59 AutocompleteInput::Type input_type, 60 MatchType match_type, 61 size_t match_number); 62 63 // Returns the index that should be used for history lookups. 64 history::InMemoryURLIndex* GetIndex(); 65 66 // Only for use in unittests. Takes ownership of |index|. 67 void SetIndexForTesting(history::InMemoryURLIndex* index); 68 AutocompleteInput autocomplete_input_; 69 bool trim_http_; 70 std::string languages_; 71 72 // Only used for testing. 73 scoped_ptr<history::InMemoryURLIndex> index_for_testing_; 74}; 75 76#endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ 77