Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: components/omnibox/browser/shortcuts_provider.h

Issue 1877833002: Optimize shortcuts provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added new files Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_PROVIDER_H_ 5 #ifndef COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_PROVIDER_H_
6 #define COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_PROVIDER_H_ 6 #define COMPONENTS_OMNIBOX_BROWSER_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 "components/omnibox/browser/autocomplete_provider.h" 13 #include "components/omnibox/browser/autocomplete_provider.h"
14 #include "components/omnibox/browser/shortcuts_backend.h" 14 #include "components/omnibox/browser/shortcuts_backend.h"
15 15
16 class AutocompleteProviderClient; 16 class AutocompleteProviderClient;
17 class ShortcutsProviderTest; 17 class ShortcutsProviderTest;
18 struct ShortcutMatch;
18 19
19 // Provider of recently autocompleted links. Provides autocomplete suggestions 20 // Provider of recently autocompleted links. Provides autocomplete suggestions
20 // from previously selected suggestions. The more often a user selects a 21 // from previously selected suggestions. The more often a user selects a
21 // 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
22 // ranking for future uses of that search term. 23 // ranking for future uses of that search term.
23 class ShortcutsProvider : public AutocompleteProvider, 24 class ShortcutsProvider : public AutocompleteProvider,
24 public ShortcutsBackend::ShortcutsBackendObserver { 25 public ShortcutsBackend::ShortcutsBackendObserver {
25 public: 26 public:
26 explicit ShortcutsProvider(AutocompleteProviderClient* client); 27 explicit ShortcutsProvider(AutocompleteProviderClient* client);
27 28
(...skipping 17 matching lines...) Expand all
45 void OnShortcutsLoaded() override; 46 void OnShortcutsLoaded() override;
46 47
47 // Performs the autocomplete matching and scoring. 48 // Performs the autocomplete matching and scoring.
48 void GetMatches(const AutocompleteInput& input); 49 void GetMatches(const AutocompleteInput& input);
49 50
50 // Returns an AutocompleteMatch corresponding to |shortcut|. Assigns it 51 // Returns an AutocompleteMatch corresponding to |shortcut|. Assigns it
51 // |relevance| score in the process, and highlights the description and 52 // |relevance| score in the process, and highlights the description and
52 // contents against |input|, which should be the lower-cased version of 53 // contents against |input|, which should be the lower-cased version of
53 // the user's input. |input| and |fixed_up_input_text| are used to decide 54 // the user's input. |input| and |fixed_up_input_text| are used to decide
54 // what can be inlined. 55 // what can be inlined.
55 AutocompleteMatch ShortcutToACMatch( 56 AutocompleteMatch ShortcutMatchToACMatch(
56 const ShortcutsDatabase::Shortcut& shortcut, 57 const ShortcutMatch& shortcut_match,
57 int relevance,
58 const AutocompleteInput& input, 58 const AutocompleteInput& input,
59 const base::string16& fixed_up_input_text); 59 const base::string16& fixed_up_input_text,
60 const base::string16 term_string,
61 const WordMap& terms_map);
60 62
61 // Returns a map mapping characters to groups of words from |text| that start 63 // Returns a map mapping characters to groups of words from |text| that start
62 // with those characters, ordered lexicographically descending so that longer 64 // with those characters, ordered lexicographically descending so that longer
63 // words appear before their prefixes (if any) within a particular 65 // words appear before their prefixes (if any) within a particular
64 // equal_range(). 66 // equal_range().
65 static WordMap CreateWordMapForString(const base::string16& text); 67 static WordMap CreateWordMapForString(const base::string16& text);
66 68
67 // Given |text| and a corresponding base set of classifications 69 // Given |text| and a corresponding base set of classifications
68 // |original_class|, adds ACMatchClassification::MATCH markers for all 70 // |original_class|, adds ACMatchClassification::MATCH markers for all
69 // instances of the words from |find_words| within |text| and returns the 71 // instances of the words from |find_words| within |text| and returns the
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 104
103 // The default max relevance unless overridden by a field trial. 105 // The default max relevance unless overridden by a field trial.
104 static const int kShortcutsProviderDefaultMaxRelevance; 106 static const int kShortcutsProviderDefaultMaxRelevance;
105 107
106 AutocompleteProviderClient* client_; 108 AutocompleteProviderClient* client_;
107 std::string languages_; 109 std::string languages_;
108 bool initialized_; 110 bool initialized_;
109 }; 111 };
110 112
111 #endif // COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_PROVIDER_H_ 113 #endif // COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698