blob: 561336b9b468389a124b3c3afd6184b36a1c5023 [file] [log] [blame]
[email protected]7c6821d2010-08-04 16:07:341// 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]bbf7e53f2010-08-21 03:48:227#pragma once
[email protected]7c6821d2010-08-04 16:07:348
[email protected]497606b2010-10-12 17:31:239#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
[email protected]7c6821d2010-08-04 16:07:3420
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]497606b2010-10-12 17:31:2328class HistoryQuickProvider : public HistoryProvider {
[email protected]7c6821d2010-08-04 16:07:3429 public:
[email protected]497606b2010-10-12 17:31:2330 HistoryQuickProvider(ACProviderListener* listener, Profile* profile);
[email protected]7c6821d2010-08-04 16:07:3431
[email protected]497606b2010-10-12 17:31:2332 ~HistoryQuickProvider();
[email protected]7c6821d2010-08-04 16:07:3433
[email protected]497606b2010-10-12 17:31:2334 // AutocompleteProvider. |minimal_changes| is ignored since there
35 // is no asynch completion performed.
[email protected]0b9d27b2010-12-22 00:51:3936 virtual void Start(const AutocompleteInput& input,
37 bool minimal_changes) OVERRIDE;
38
39 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE;
[email protected]7c6821d2010-08-04 16:07:3440
[email protected]497606b2010-10-12 17:31:2341 // Performs the autocomplete matching and scoring.
42 void DoAutocomplete();
43
[email protected]7c6821d2010-08-04 16:07:3444 private:
[email protected]497606b2010-10-12 17:31:2345 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]7c6821d2010-08-04 16:07:3477};
78
79#endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_