| 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> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // performed |minimal_changes| is ignored. | 33 // performed |minimal_changes| is ignored. |
| 34 virtual void Start(const AutocompleteInput& input, | 34 virtual void Start(const AutocompleteInput& input, |
| 35 bool minimal_changes) OVERRIDE; | 35 bool minimal_changes) OVERRIDE; |
| 36 | 36 |
| 37 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; | 37 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 friend class ClassifyTest; | 40 friend class ClassifyTest; |
| 41 friend class history::ShortcutsProviderTest; | 41 friend class history::ShortcutsProviderTest; |
| 42 | 42 |
| 43 typedef std::multimap<char16, string16> WordMap; | 43 typedef std::multimap<char16, base::string16> WordMap; |
| 44 | 44 |
| 45 virtual ~ShortcutsProvider(); | 45 virtual ~ShortcutsProvider(); |
| 46 | 46 |
| 47 // ShortcutsBackendObserver: | 47 // ShortcutsBackendObserver: |
| 48 virtual void OnShortcutsLoaded() OVERRIDE; | 48 virtual void OnShortcutsLoaded() OVERRIDE; |
| 49 | 49 |
| 50 // Performs the autocomplete matching and scoring. | 50 // Performs the autocomplete matching and scoring. |
| 51 void GetMatches(const AutocompleteInput& input); | 51 void GetMatches(const AutocompleteInput& input); |
| 52 | 52 |
| 53 AutocompleteMatch ShortcutToACMatch( | 53 AutocompleteMatch ShortcutToACMatch( |
| 54 int relevance, | 54 int relevance, |
| 55 const string16& terms, | 55 const base::string16& terms, |
| 56 const history::ShortcutsBackend::Shortcut& shortcut); | 56 const history::ShortcutsBackend::Shortcut& shortcut); |
| 57 | 57 |
| 58 // Returns a map mapping characters to groups of words from |text| that start | 58 // Returns a map mapping characters to groups of words from |text| that start |
| 59 // with those characters, ordered lexicographically descending so that longer | 59 // with those characters, ordered lexicographically descending so that longer |
| 60 // words appear before their prefixes (if any) within a particular | 60 // words appear before their prefixes (if any) within a particular |
| 61 // equal_range(). | 61 // equal_range(). |
| 62 static WordMap CreateWordMapForString(const string16& text); | 62 static WordMap CreateWordMapForString(const base::string16& text); |
| 63 | 63 |
| 64 // Given |text| and a corresponding base set of classifications | 64 // Given |text| and a corresponding base set of classifications |
| 65 // |original_class|, adds ACMatchClassification::MATCH markers for all | 65 // |original_class|, adds ACMatchClassification::MATCH markers for all |
| 66 // instances of the words from |find_words| within |text| and returns the | 66 // instances of the words from |find_words| within |text| and returns the |
| 67 // resulting classifications. (|find_text| is provided as the original string | 67 // resulting classifications. (|find_text| is provided as the original string |
| 68 // used to create |find_words|. This is supplied because it's common for this | 68 // used to create |find_words|. This is supplied because it's common for this |
| 69 // to be a prefix of |text|, so we can quickly check for that and mark that | 69 // to be a prefix of |text|, so we can quickly check for that and mark that |
| 70 // entire substring as a match before proceeding with the more generic | 70 // entire substring as a match before proceeding with the more generic |
| 71 // algorithm.) | 71 // algorithm.) |
| 72 // | 72 // |
| 73 // For example, given the |text| | 73 // For example, given the |text| |
| 74 // "Sports and News at sports.somesite.com - visit us!" and |original_class| | 74 // "Sports and News at sports.somesite.com - visit us!" and |original_class| |
| 75 // {{0, NONE}, {18, URL}, {37, NONE}} (marking "sports.somesite.com" as a | 75 // {{0, NONE}, {18, URL}, {37, NONE}} (marking "sports.somesite.com" as a |
| 76 // URL), calling with |find_text| set to "sp ew" would return | 76 // URL), calling with |find_text| set to "sp ew" would return |
| 77 // {{0, MATCH}, {2, NONE}, {12, MATCH}, {14, NONE}, {18, URL|MATCH}, | 77 // {{0, MATCH}, {2, NONE}, {12, MATCH}, {14, NONE}, {18, URL|MATCH}, |
| 78 // {20, URL}, {37, NONE}}. | 78 // {20, URL}, {37, NONE}}. |
| 79 // | 79 // |
| 80 // |find_words| should be as constructed by CreateWordMapForString(find_text). | 80 // |find_words| should be as constructed by CreateWordMapForString(find_text). |
| 81 // | 81 // |
| 82 // |find_text| (and thus |find_words|) are expected to be lowercase. |text| | 82 // |find_text| (and thus |find_words|) are expected to be lowercase. |text| |
| 83 // will be lowercased in this function. | 83 // will be lowercased in this function. |
| 84 static ACMatchClassifications ClassifyAllMatchesInString( | 84 static ACMatchClassifications ClassifyAllMatchesInString( |
| 85 const string16& find_text, | 85 const base::string16& find_text, |
| 86 const WordMap& find_words, | 86 const WordMap& find_words, |
| 87 const string16& text, | 87 const base::string16& text, |
| 88 const ACMatchClassifications& original_class); | 88 const ACMatchClassifications& original_class); |
| 89 | 89 |
| 90 // Returns iterator to first item in |shortcuts_map_| matching |keyword|. | 90 // Returns iterator to first item in |shortcuts_map_| matching |keyword|. |
| 91 // Returns shortcuts_map_.end() if there are no matches. | 91 // Returns shortcuts_map_.end() if there are no matches. |
| 92 history::ShortcutsBackend::ShortcutMap::const_iterator FindFirstMatch( | 92 history::ShortcutsBackend::ShortcutMap::const_iterator FindFirstMatch( |
| 93 const string16& keyword, | 93 const base::string16& keyword, |
| 94 history::ShortcutsBackend* backend); | 94 history::ShortcutsBackend* backend); |
| 95 | 95 |
| 96 int CalculateScore( | 96 int CalculateScore( |
| 97 const string16& terms, | 97 const base::string16& terms, |
| 98 const history::ShortcutsBackend::Shortcut& shortcut, | 98 const history::ShortcutsBackend::Shortcut& shortcut, |
| 99 int max_relevance); | 99 int max_relevance); |
| 100 | 100 |
| 101 std::string languages_; | 101 std::string languages_; |
| 102 bool initialized_; | 102 bool initialized_; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ | 105 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ |
| OLD | NEW |