OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "chrome/browser/autocomplete/history_provider.h" | 12 #include "chrome/browser/autocomplete/history_provider.h" |
13 #include "chrome/browser/autocomplete/in_memory_url_index.h" | 13 #include "chrome/browser/autocomplete/in_memory_url_index.h" |
14 #include "components/history/core/browser/history_types.h" | 14 #include "components/history/core/browser/history_types.h" |
15 #include "components/omnibox/autocomplete_input.h" | 15 #include "components/omnibox/autocomplete_input.h" |
16 #include "components/omnibox/autocomplete_match.h" | 16 #include "components/omnibox/autocomplete_match.h" |
17 | 17 |
18 class Profile; | 18 class Profile; |
19 | |
20 namespace history { | |
21 struct ScoredHistoryMatch; | 19 struct ScoredHistoryMatch; |
22 } | |
23 | 20 |
24 // This class is an autocomplete provider (a pseudo-internal component of | 21 // This class is an autocomplete provider (a pseudo-internal component of |
25 // the history system) which quickly (and synchronously) provides matching | 22 // the history system) which quickly (and synchronously) provides matching |
26 // results from recently or frequently visited sites in the profile's | 23 // results from recently or frequently visited sites in the profile's |
27 // history. | 24 // history. |
28 class HistoryQuickProvider : public HistoryProvider { | 25 class HistoryQuickProvider : public HistoryProvider { |
29 public: | 26 public: |
30 explicit HistoryQuickProvider(Profile* profile); | 27 explicit HistoryQuickProvider(Profile* profile); |
31 | 28 |
32 // AutocompleteProvider. |minimal_changes| is ignored since there is no asynch | 29 // AutocompleteProvider. |minimal_changes| is ignored since there is no asynch |
(...skipping 14 matching lines...) Expand all Loading... |
47 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Spans); | 44 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Spans); |
48 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Relevance); | 45 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Relevance); |
49 | 46 |
50 ~HistoryQuickProvider() override; | 47 ~HistoryQuickProvider() override; |
51 | 48 |
52 // Performs the autocomplete matching and scoring. | 49 // Performs the autocomplete matching and scoring. |
53 void DoAutocomplete(); | 50 void DoAutocomplete(); |
54 | 51 |
55 // Creates an AutocompleteMatch from |history_match|, assigning it | 52 // Creates an AutocompleteMatch from |history_match|, assigning it |
56 // the score |score|. | 53 // the score |score|. |
57 AutocompleteMatch QuickMatchToACMatch( | 54 AutocompleteMatch QuickMatchToACMatch(const ScoredHistoryMatch& history_match, |
58 const history::ScoredHistoryMatch& history_match, | 55 int score); |
59 int score); | |
60 | 56 |
61 // Returns the index that should be used for history lookups. | 57 // Returns the index that should be used for history lookups. |
62 history::InMemoryURLIndex* GetIndex(); | 58 InMemoryURLIndex* GetIndex(); |
63 | 59 |
64 // Only for use in unittests. Takes ownership of |index|. | 60 // Only for use in unittests. Takes ownership of |index|. |
65 void set_index(history::InMemoryURLIndex* index) { | 61 void set_index(InMemoryURLIndex* index) { index_for_testing_.reset(index); } |
66 index_for_testing_.reset(index); | |
67 } | |
68 | 62 |
69 AutocompleteInput autocomplete_input_; | 63 AutocompleteInput autocomplete_input_; |
70 std::string languages_; | 64 std::string languages_; |
71 | 65 |
72 // Only used for testing. | 66 // Only used for testing. |
73 scoped_ptr<history::InMemoryURLIndex> index_for_testing_; | 67 scoped_ptr<InMemoryURLIndex> index_for_testing_; |
74 | 68 |
75 // This provider is disabled when true. | 69 // This provider is disabled when true. |
76 static bool disabled_; | 70 static bool disabled_; |
77 | 71 |
78 DISALLOW_COPY_AND_ASSIGN(HistoryQuickProvider); | 72 DISALLOW_COPY_AND_ASSIGN(HistoryQuickProvider); |
79 }; | 73 }; |
80 | 74 |
81 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ | 75 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |
OLD | NEW |