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_SHORTCUTS_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 13 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 14 #include "chrome/browser/autocomplete/shortcuts_backend.h" |
14 #include "chrome/browser/autocomplete/url_prefix.h" | 15 #include "chrome/browser/autocomplete/url_prefix.h" |
15 #include "chrome/browser/history/shortcuts_backend.h" | |
16 | 16 |
17 class Profile; | 17 class Profile; |
18 | |
19 namespace history { | |
20 class ShortcutsProviderTest; | 18 class ShortcutsProviderTest; |
21 } | |
22 | 19 |
23 // Provider of recently autocompleted links. Provides autocomplete suggestions | 20 // Provider of recently autocompleted links. Provides autocomplete suggestions |
24 // from previously selected suggestions. The more often a user selects a | 21 // from previously selected suggestions. The more often a user selects a |
25 // suggestion for a given search term the higher will be that suggestion's | 22 // suggestion for a given search term the higher will be that suggestion's |
26 // ranking for future uses of that search term. | 23 // ranking for future uses of that search term. |
27 class ShortcutsProvider | 24 class ShortcutsProvider |
28 : public AutocompleteProvider, | 25 : public AutocompleteProvider, |
29 public history::ShortcutsBackend::ShortcutsBackendObserver { | 26 public ShortcutsBackend::ShortcutsBackendObserver { |
30 public: | 27 public: |
31 ShortcutsProvider(AutocompleteProviderListener* listener, Profile* profile); | 28 ShortcutsProvider(AutocompleteProviderListener* listener, Profile* profile); |
32 | 29 |
33 // Performs the autocompletion synchronously. Since no asynch completion is | 30 // Performs the autocompletion synchronously. Since no asynch completion is |
34 // performed |minimal_changes| is ignored. | 31 // performed |minimal_changes| is ignored. |
35 virtual void Start(const AutocompleteInput& input, | 32 virtual void Start(const AutocompleteInput& input, |
36 bool minimal_changes) OVERRIDE; | 33 bool minimal_changes) OVERRIDE; |
37 | 34 |
38 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; | 35 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; |
39 | 36 |
40 private: | 37 private: |
41 friend class ClassifyTest; | 38 friend class ClassifyTest; |
42 friend class history::ShortcutsProviderTest; | 39 friend class ShortcutsProviderTest; |
43 | 40 |
44 typedef std::multimap<base::char16, base::string16> WordMap; | 41 typedef std::multimap<base::char16, base::string16> WordMap; |
45 | 42 |
46 virtual ~ShortcutsProvider(); | 43 virtual ~ShortcutsProvider(); |
47 | 44 |
48 // ShortcutsBackendObserver: | 45 // ShortcutsBackendObserver: |
49 virtual void OnShortcutsLoaded() OVERRIDE; | 46 virtual void OnShortcutsLoaded() OVERRIDE; |
50 | 47 |
51 // Performs the autocomplete matching and scoring. | 48 // Performs the autocomplete matching and scoring. |
52 void GetMatches(const AutocompleteInput& input); | 49 void GetMatches(const AutocompleteInput& input); |
53 | 50 |
54 // Returns an AutocompleteMatch corresponding to |shortcut|. Assigns it | 51 // Returns an AutocompleteMatch corresponding to |shortcut|. Assigns it |
55 // |relevance| score in the process, and highlights the description and | 52 // |relevance| score in the process, and highlights the description and |
56 // contents against |term_string|, which should be the lower-cased version | 53 // contents against |term_string|, which should be the lower-cased version |
57 // of the user's input. |term_string| and |fixed_up_term_string| are used | 54 // of the user's input. |term_string| and |fixed_up_term_string| are used |
58 // to decide what can be inlined. If |prevent_inline_autocomplete|, no | 55 // to decide what can be inlined. If |prevent_inline_autocomplete|, no |
59 // matches with inline completions will be allowed to be the default match. | 56 // matches with inline completions will be allowed to be the default match. |
60 AutocompleteMatch ShortcutToACMatch( | 57 AutocompleteMatch ShortcutToACMatch( |
61 const history::ShortcutsBackend::Shortcut& shortcut, | 58 const history::ShortcutsDatabase::Shortcut& shortcut, |
62 int relevance, | 59 int relevance, |
63 const base::string16& term_string, | 60 const base::string16& term_string, |
64 const base::string16& fixed_up_term_string, | 61 const base::string16& fixed_up_term_string, |
65 const bool prevent_inline_autocomplete); | 62 const bool prevent_inline_autocomplete); |
66 | 63 |
67 // Returns a map mapping characters to groups of words from |text| that start | 64 // Returns a map mapping characters to groups of words from |text| that start |
68 // with those characters, ordered lexicographically descending so that longer | 65 // with those characters, ordered lexicographically descending so that longer |
69 // words appear before their prefixes (if any) within a particular | 66 // words appear before their prefixes (if any) within a particular |
70 // equal_range(). | 67 // equal_range(). |
71 static WordMap CreateWordMapForString(const base::string16& text); | 68 static WordMap CreateWordMapForString(const base::string16& text); |
(...skipping 19 matching lines...) Expand all Loading... |
91 // |find_text| (and thus |find_words|) are expected to be lowercase. |text| | 88 // |find_text| (and thus |find_words|) are expected to be lowercase. |text| |
92 // will be lowercased in this function. | 89 // will be lowercased in this function. |
93 static ACMatchClassifications ClassifyAllMatchesInString( | 90 static ACMatchClassifications ClassifyAllMatchesInString( |
94 const base::string16& find_text, | 91 const base::string16& find_text, |
95 const WordMap& find_words, | 92 const WordMap& find_words, |
96 const base::string16& text, | 93 const base::string16& text, |
97 const ACMatchClassifications& original_class); | 94 const ACMatchClassifications& original_class); |
98 | 95 |
99 // Returns iterator to first item in |shortcuts_map_| matching |keyword|. | 96 // Returns iterator to first item in |shortcuts_map_| matching |keyword|. |
100 // Returns shortcuts_map_.end() if there are no matches. | 97 // Returns shortcuts_map_.end() if there are no matches. |
101 history::ShortcutsBackend::ShortcutMap::const_iterator FindFirstMatch( | 98 ShortcutsBackend::ShortcutMap::const_iterator FindFirstMatch( |
102 const base::string16& keyword, | 99 const base::string16& keyword, |
103 history::ShortcutsBackend* backend); | 100 ShortcutsBackend* backend); |
104 | 101 |
105 int CalculateScore( | 102 int CalculateScore(const base::string16& terms, |
106 const base::string16& terms, | 103 const history::ShortcutsDatabase::Shortcut& shortcut, |
107 const history::ShortcutsBackend::Shortcut& shortcut, | 104 int max_relevance); |
108 int max_relevance); | |
109 | 105 |
110 std::string languages_; | 106 std::string languages_; |
111 bool initialized_; | 107 bool initialized_; |
112 }; | 108 }; |
113 | 109 |
114 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ | 110 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ |
OLD | NEW |