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

Side by Side Diff: components/omnibox/keyword_provider.h

Issue 1192373002: Prepare AutocompleteController for componentization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@componentize_zero_suggest_provider
Patch Set: Response to review Created 5 years, 6 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
« no previous file with comments | « components/omnibox/history_quick_provider.cc ('k') | components/omnibox/keyword_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // This file contains the keyword autocomplete provider. The keyword provider 5 // This file contains the keyword autocomplete provider. The keyword provider
6 // is responsible for remembering/suggesting user "search keyword queries" 6 // is responsible for remembering/suggesting user "search keyword queries"
7 // (e.g. "imdb Godzilla") and then fixing them up into valid URLs. An 7 // (e.g. "imdb Godzilla") and then fixing them up into valid URLs. An
8 // instance of it gets created and managed by the autocomplete controller. 8 // instance of it gets created and managed by the autocomplete controller.
9 // KeywordProvider uses a TemplateURLService to find the set of keywords. 9 // KeywordProvider uses a TemplateURLService to find the set of keywords.
10 10
11 #ifndef COMPONENTS_OMNIBOX_KEYWORD_PROVIDER_H_ 11 #ifndef COMPONENTS_OMNIBOX_KEYWORD_PROVIDER_H_
12 #define COMPONENTS_OMNIBOX_KEYWORD_PROVIDER_H_ 12 #define COMPONENTS_OMNIBOX_KEYWORD_PROVIDER_H_
13 13
14 #include <string> 14 #include <string>
15 15
16 #include "base/basictypes.h" 16 #include "base/basictypes.h"
17 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "components/metrics/proto/omnibox_input_type.pb.h" 19 #include "components/metrics/proto/omnibox_input_type.pb.h"
20 #include "components/omnibox/autocomplete_input.h" 20 #include "components/omnibox/autocomplete_input.h"
21 #include "components/omnibox/autocomplete_provider.h" 21 #include "components/omnibox/autocomplete_provider.h"
22 #include "components/omnibox/keyword_extensions_delegate.h" 22 #include "components/omnibox/keyword_extensions_delegate.h"
23 23
24 class AutocompleteProviderClient;
24 class AutocompleteProviderListener; 25 class AutocompleteProviderListener;
25 class KeywordExtensionsDelegate; 26 class KeywordExtensionsDelegate;
26 class TemplateURL; 27 class TemplateURL;
27 class TemplateURLService; 28 class TemplateURLService;
28 29
29 // Autocomplete provider for keyword input. 30 // Autocomplete provider for keyword input.
30 // 31 //
31 // After construction, the autocomplete controller repeatedly calls Start() 32 // After construction, the autocomplete controller repeatedly calls Start()
32 // with some user input, each time expecting to receive a small set of the best 33 // with some user input, each time expecting to receive a small set of the best
33 // matches (either synchronously or asynchronously). 34 // matches (either synchronously or asynchronously).
34 // 35 //
35 // To construct these matches, the provider treats user input as a series of 36 // To construct these matches, the provider treats user input as a series of
36 // whitespace-delimited tokens and tries to match the first token as the prefix 37 // whitespace-delimited tokens and tries to match the first token as the prefix
37 // of a known "keyword". A keyword is some string that maps to a search query 38 // of a known "keyword". A keyword is some string that maps to a search query
38 // URL; the rest of the user's input is taken as the input to the query. For 39 // URL; the rest of the user's input is taken as the input to the query. For
39 // example, the keyword "bug" might map to the URL "http://b/issue?id=%s", so 40 // example, the keyword "bug" might map to the URL "http://b/issue?id=%s", so
40 // input like "bug 123" would become "http://b/issue?id=123". 41 // input like "bug 123" would become "http://b/issue?id=123".
41 // 42 //
42 // Because we do prefix matching, user input could match more than one keyword 43 // Because we do prefix matching, user input could match more than one keyword
43 // at once. (Example: the input "f jazz" matches all keywords starting with 44 // at once. (Example: the input "f jazz" matches all keywords starting with
44 // "f".) We return the best matches, up to three. 45 // "f".) We return the best matches, up to three.
45 // 46 //
46 // The resulting matches are shown with content specified by the keyword 47 // The resulting matches are shown with content specified by the keyword
47 // (usually "Search [name] for %s"), description "(Keyword: [keyword])", and 48 // (usually "Search [name] for %s"), description "(Keyword: [keyword])", and
48 // action "[keyword] %s". If the user has typed a (possibly partial) keyword 49 // action "[keyword] %s". If the user has typed a (possibly partial) keyword
49 // but no search terms, the suggested result is shown greyed out, with 50 // but no search terms, the suggested result is shown greyed out, with
50 // "<enter term(s)>" as the substituted input, and does nothing when selected. 51 // "<enter term(s)>" as the substituted input, and does nothing when selected.
51 class KeywordProvider : public AutocompleteProvider { 52 class KeywordProvider : public AutocompleteProvider {
52 public: 53 public:
53 KeywordProvider(AutocompleteProviderListener* listener, 54 KeywordProvider(AutocompleteProviderClient* client,
54 TemplateURLService* model); 55 AutocompleteProviderListener* listener);
55
56 void set_extensions_delegate(
57 scoped_ptr<KeywordExtensionsDelegate> extensions_delegate) {
58 extensions_delegate_ = extensions_delegate.Pass();
59 }
60 56
61 // Extracts the next whitespace-delimited token from input and returns it. 57 // Extracts the next whitespace-delimited token from input and returns it.
62 // Sets |remaining_input| to everything after the first token (skipping over 58 // Sets |remaining_input| to everything after the first token (skipping over
63 // the first intervening whitespace). 59 // the first intervening whitespace).
64 // If |trim_leading_whitespace| is true then leading whitespace in 60 // If |trim_leading_whitespace| is true then leading whitespace in
65 // |*remaining_input| will be trimmed. 61 // |*remaining_input| will be trimmed.
66 static base::string16 SplitKeywordFromInput(const base::string16& input, 62 static base::string16 SplitKeywordFromInput(const base::string16& input,
67 bool trim_leading_whitespace, 63 bool trim_leading_whitespace,
68 base::string16* remaining_input); 64 base::string16* remaining_input);
69 65
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 TemplateURLService* model_; 145 TemplateURLService* model_;
150 146
151 // Delegate to handle the extensions-only logic for KeywordProvider. 147 // Delegate to handle the extensions-only logic for KeywordProvider.
152 // NULL when extensions are not enabled. May be NULL for tests. 148 // NULL when extensions are not enabled. May be NULL for tests.
153 scoped_ptr<KeywordExtensionsDelegate> extensions_delegate_; 149 scoped_ptr<KeywordExtensionsDelegate> extensions_delegate_;
154 150
155 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); 151 DISALLOW_COPY_AND_ASSIGN(KeywordProvider);
156 }; 152 };
157 153
158 #endif // COMPONENTS_OMNIBOX_KEYWORD_PROVIDER_H_ 154 #endif // COMPONENTS_OMNIBOX_KEYWORD_PROVIDER_H_
OLDNEW
« no previous file with comments | « components/omnibox/history_quick_provider.cc ('k') | components/omnibox/keyword_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698