| 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/url_prefix.h" | |
| 15 #include "chrome/browser/history/shortcuts_backend.h" | 14 #include "chrome/browser/history/shortcuts_backend.h" |
| 16 | 15 |
| 17 class Profile; | 16 class Profile; |
| 18 | 17 |
| 19 namespace history { | 18 namespace history { |
| 20 class ShortcutsProviderTest; | 19 class ShortcutsProviderTest; |
| 21 } | 20 } |
| 22 | 21 |
| 23 // Provider of recently autocompleted links. Provides autocomplete suggestions | 22 // Provider of recently autocompleted links. Provides autocomplete suggestions |
| 24 // from previously selected suggestions. The more often a user selects a | 23 // from previously selected suggestions. The more often a user selects a |
| (...skipping 19 matching lines...) Expand all Loading... |
| 44 typedef std::multimap<char16, base::string16> WordMap; | 43 typedef std::multimap<char16, base::string16> WordMap; |
| 45 | 44 |
| 46 virtual ~ShortcutsProvider(); | 45 virtual ~ShortcutsProvider(); |
| 47 | 46 |
| 48 // ShortcutsBackendObserver: | 47 // ShortcutsBackendObserver: |
| 49 virtual void OnShortcutsLoaded() OVERRIDE; | 48 virtual void OnShortcutsLoaded() OVERRIDE; |
| 50 | 49 |
| 51 // Performs the autocomplete matching and scoring. | 50 // Performs the autocomplete matching and scoring. |
| 52 void GetMatches(const AutocompleteInput& input); | 51 void GetMatches(const AutocompleteInput& input); |
| 53 | 52 |
| 54 // Returns an AutocompleteMatch corresponding to |shortcut|. Assigns it | 53 // Returns an AutocompleteMatch corresponding to |shortcut|. Assigns it |
| 55 // |relevance| score in the process, and highlights the description and | 54 // |relevance| score in the process, and highlights the description |
| 56 // contents against |term_string|, which should be the lower-cased version | 55 // and contents against |term_string|, which should be the lower-cased |
| 57 // of the user's input. |term_string| and |fixed_up_term_string| are used | 56 // version of the user's input. If |prevent_inline_autocomplete|, no |
| 58 // to decide what can be inlined. If |prevent_inline_autocomplete|, no | |
| 59 // matches with inline completions will be allowed to be the default match. | 57 // matches with inline completions will be allowed to be the default match. |
| 60 AutocompleteMatch ShortcutToACMatch( | 58 AutocompleteMatch ShortcutToACMatch( |
| 61 const history::ShortcutsBackend::Shortcut& shortcut, | 59 const history::ShortcutsBackend::Shortcut& shortcut, |
| 62 int relevance, | 60 int relevance, |
| 63 const base::string16& term_string, | 61 const base::string16& term_string, |
| 64 const base::string16& fixed_up_term_string, | 62 bool prevent_inline_autocomplete); |
| 65 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); |
| 72 | 69 |
| 73 // Given |text| and a corresponding base set of classifications | 70 // Given |text| and a corresponding base set of classifications |
| 74 // |original_class|, adds ACMatchClassification::MATCH markers for all | 71 // |original_class|, adds ACMatchClassification::MATCH markers for all |
| 75 // instances of the words from |find_words| within |text| and returns the | 72 // instances of the words from |find_words| within |text| and returns the |
| (...skipping 24 matching lines...) Expand all Loading... |
| 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 history::ShortcutsBackend::ShortcutMap::const_iterator FindFirstMatch( |
| 102 const base::string16& keyword, | 99 const base::string16& keyword, |
| 103 history::ShortcutsBackend* backend); | 100 history::ShortcutsBackend* backend); |
| 104 | 101 |
| 105 int CalculateScore( | 102 int CalculateScore( |
| 106 const base::string16& terms, | 103 const base::string16& terms, |
| 107 const history::ShortcutsBackend::Shortcut& shortcut, | 104 const history::ShortcutsBackend::Shortcut& shortcut, |
| 108 int max_relevance); | 105 int max_relevance); |
| 109 | 106 |
| 110 // Like URLPrefix::BestURLPrefix() except also handles the prefix of | |
| 111 // "www.". This is needed because sometimes the string we're matching | |
| 112 // against here (which comes from |fill_into_edit|) can start with | |
| 113 // "www." without having a protocol at the beginning. Because "www." | |
| 114 // is not on the default prefix list, we test for it explicitly here | |
| 115 // and use that match if the default list didn't have a match or the | |
| 116 // default list's match was shorter than it could've been. | |
| 117 const URLPrefix* BestURLPrefixWithWWWCase( | |
| 118 const base::string16& text, | |
| 119 const base::string16& prefix_suffix) const; | |
| 120 | |
| 121 std::string languages_; | 107 std::string languages_; |
| 122 bool initialized_; | 108 bool initialized_; |
| 123 URLPrefix www_prefix_; | |
| 124 }; | 109 }; |
| 125 | 110 |
| 126 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ | 111 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ |
| OLD | NEW |