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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_input.h

Issue 343523003: Remove AutocompleteInput Type and PageClassification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 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 | Annotate | Revision Log
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 CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_
6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "components/metrics/proto/omnibox_event.pb.h"
13 #include "components/metrics/proto/omnibox_input_type.pb.h" 14 #include "components/metrics/proto/omnibox_input_type.pb.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 #include "url/url_parse.h" 16 #include "url/url_parse.h"
16 17
17 // The user input for an autocomplete query. Allows copying. 18 // The user input for an autocomplete query. Allows copying.
18 class AutocompleteInput { 19 class AutocompleteInput {
19 public: 20 public:
20 typedef metrics::OmniboxInputType::Type Type;
21
22 // The type of page currently displayed.
23 // Warning: when adding an element to this enum, please add it at the end
24 // and update omnibox_event.proto::PageClassification and
25 // omnibox_edit_model.cc::ClassifyPage() too.
26 enum PageClassification {
27 // An invalid URL; shouldn't happen.
28 INVALID_SPEC = 0,
29
30 // chrome://newtab/. This can be either the built-in version or a
31 // replacement new tab page from an extension. Note that when Instant
32 // Extended is enabled, the new tab page will be reported as either
33 // INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS or
34 // INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS below,
35 // unless an extension is replacing the new tab page, in which case
36 // it will still be reported as NTP.
37 NTP = 1,
38
39 // about:blank.
40 BLANK = 2,
41
42 // The user's home page. Note that if the home page is set to any
43 // of the new tab page versions or to about:blank, then we'll
44 // classify the page into those categories, not HOME_PAGE.
45 HOME_PAGE = 3,
46
47 // The catch-all entry of everything not included somewhere else
48 // on this list.
49 OTHER = 4,
50
51 // The user is on a search result page that's doing search term
52 // replacement, meaning the search terms should've appeared in the omnibox
53 // before the user started editing it, not the URL of the page.
54 SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT = 6,
55
56 // The new tab page in which this omnibox interaction first started
57 // with the user having focus in the omnibox.
58 INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS = 7,
59
60 // The new tab page in which this omnibox interaction first started
61 // with the user having focus in the fakebox.
62 INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS = 8,
63
64 // The user is on a search result page that's not doing search term
65 // replacement, meaning the URL of the page should've appeared in the
66 // omnibox before the user started editing it, not the search terms.
67 SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT = 9
68 };
69
70 AutocompleteInput(); 21 AutocompleteInput();
71 // |text| and |cursor_position| represent the input query and location of 22 // |text| and |cursor_position| represent the input query and location of
72 // the cursor with the query respectively. |cursor_position| may be set to 23 // the cursor with the query respectively. |cursor_position| may be set to
73 // base::string16::npos if the input |text| doesn't come directly from the 24 // base::string16::npos if the input |text| doesn't come directly from the
74 // user's typing. 25 // user's typing.
75 // 26 //
76 // |desired_tld| is the user's desired TLD, if one is not already present in 27 // |desired_tld| is the user's desired TLD, if one is not already present in
77 // the text to autocomplete. When this is non-empty, it also implies that 28 // the text to autocomplete. When this is non-empty, it also implies that
78 // "www." should be prepended to the domain where possible. The |desired_tld| 29 // "www." should be prepended to the domain where possible. The |desired_tld|
79 // should not contain a leading '.' (use "com" instead of ".com"). 30 // should not contain a leading '.' (use "com" instead of ".com").
(...skipping 24 matching lines...) Expand all
104 // in a page and telling the browser to search for it or navigate to it. This 55 // in a page and telling the browser to search for it or navigate to it. This
105 // parameter only applies to substituting keywords. 56 // parameter only applies to substituting keywords.
106 // 57 //
107 // If |matches_requested| is BEST_MATCH or SYNCHRONOUS_MATCHES the controller 58 // If |matches_requested| is BEST_MATCH or SYNCHRONOUS_MATCHES the controller
108 // asks the providers to only return matches which are synchronously 59 // asks the providers to only return matches which are synchronously
109 // available, which should mean that all providers will be done immediately. 60 // available, which should mean that all providers will be done immediately.
110 AutocompleteInput(const base::string16& text, 61 AutocompleteInput(const base::string16& text,
111 size_t cursor_position, 62 size_t cursor_position,
112 const base::string16& desired_tld, 63 const base::string16& desired_tld,
113 const GURL& current_url, 64 const GURL& current_url,
114 PageClassification current_page_classification, 65 metrics::OmniboxEventProto::PageClassification
66 current_page_classification,
115 bool prevent_inline_autocomplete, 67 bool prevent_inline_autocomplete,
116 bool prefer_keyword, 68 bool prefer_keyword,
117 bool allow_exact_keyword_match, 69 bool allow_exact_keyword_match,
118 bool want_asynchronous_matches); 70 bool want_asynchronous_matches);
119 ~AutocompleteInput(); 71 ~AutocompleteInput();
120 72
121 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed. 73 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed.
122 // Returns number of leading characters removed. 74 // Returns number of leading characters removed.
123 static size_t RemoveForcedQueryStringIfNecessary(Type type, 75 static size_t RemoveForcedQueryStringIfNecessary(
124 base::string16* text); 76 metrics::OmniboxInputType::Type type,
77 base::string16* text);
125 78
126 // Converts |type| to a string representation. Used in logging. 79 // Converts |type| to a string representation. Used in logging.
127 static std::string TypeToString(Type type); 80 static std::string TypeToString(metrics::OmniboxInputType::Type type);
128 81
129 // Parses |text| and returns the type of input this will be interpreted as. 82 // Parses |text| and returns the type of input this will be interpreted as.
130 // The components of the input are stored in the output parameter |parts|, if 83 // The components of the input are stored in the output parameter |parts|, if
131 // it is non-NULL. The scheme is stored in |scheme| if it is non-NULL. The 84 // it is non-NULL. The scheme is stored in |scheme| if it is non-NULL. The
132 // canonicalized URL is stored in |canonicalized_url|; however, this URL is 85 // canonicalized URL is stored in |canonicalized_url|; however, this URL is
133 // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY. 86 // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY.
134 static Type Parse(const base::string16& text, 87 static metrics::OmniboxInputType::Type Parse(
135 const base::string16& desired_tld, 88 const base::string16& text,
136 url::Parsed* parts, 89 const base::string16& desired_tld,
137 base::string16* scheme, 90 url::Parsed* parts,
138 GURL* canonicalized_url); 91 base::string16* scheme,
92 GURL* canonicalized_url);
139 93
140 // Parses |text| and fill |scheme| and |host| by the positions of them. 94 // Parses |text| and fill |scheme| and |host| by the positions of them.
141 // The results are almost as same as the result of Parse(), but if the scheme 95 // The results are almost as same as the result of Parse(), but if the scheme
142 // is view-source, this function returns the positions of scheme and host 96 // is view-source, this function returns the positions of scheme and host
143 // in the URL qualified by "view-source:" prefix. 97 // in the URL qualified by "view-source:" prefix.
144 static void ParseForEmphasizeComponents(const base::string16& text, 98 static void ParseForEmphasizeComponents(const base::string16& text,
145 url::Component* scheme, 99 url::Component* scheme,
146 url::Component* host); 100 url::Component* host);
147 101
148 // Code that wants to format URLs with a format flag including 102 // Code that wants to format URLs with a format flag including
(...skipping 24 matching lines...) Expand all
173 // that they're not changing the type/scheme/etc. should use this. 127 // that they're not changing the type/scheme/etc. should use this.
174 void UpdateText(const base::string16& text, 128 void UpdateText(const base::string16& text,
175 size_t cursor_position, 129 size_t cursor_position,
176 const url::Parsed& parts); 130 const url::Parsed& parts);
177 131
178 // The current URL, or an invalid GURL if query refinement is not desired. 132 // The current URL, or an invalid GURL if query refinement is not desired.
179 const GURL& current_url() const { return current_url_; } 133 const GURL& current_url() const { return current_url_; }
180 134
181 // The type of page that is currently behind displayed and how it is 135 // The type of page that is currently behind displayed and how it is
182 // displayed (e.g., with search term replacement or without). 136 // displayed (e.g., with search term replacement or without).
183 AutocompleteInput::PageClassification current_page_classification() const { 137 metrics::OmniboxEventProto::PageClassification current_page_classification()
138 const {
184 return current_page_classification_; 139 return current_page_classification_;
185 } 140 }
186 141
187 // The type of input supplied. 142 // The type of input supplied.
188 Type type() const { return type_; } 143 metrics::OmniboxInputType::Type type() const { return type_; }
189 144
190 // Returns parsed URL components. 145 // Returns parsed URL components.
191 const url::Parsed& parts() const { return parts_; } 146 const url::Parsed& parts() const { return parts_; }
192 147
193 // The scheme parsed from the provided text; only meaningful when type_ is 148 // The scheme parsed from the provided text; only meaningful when type_ is
194 // URL. 149 // URL.
195 const base::string16& scheme() const { return scheme_; } 150 const base::string16& scheme() const { return scheme_; }
196 151
197 // The input as an URL to navigate to, if possible. 152 // The input as an URL to navigate to, if possible.
198 const GURL& canonicalized_url() const { return canonicalized_url_; } 153 const GURL& canonicalized_url() const { return canonicalized_url_; }
(...skipping 20 matching lines...) Expand all
219 void Clear(); 174 void Clear();
220 175
221 private: 176 private:
222 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); 177 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL);
223 178
224 // NOTE: Whenever adding a new field here, please make sure to update Clear() 179 // NOTE: Whenever adding a new field here, please make sure to update Clear()
225 // method. 180 // method.
226 base::string16 text_; 181 base::string16 text_;
227 size_t cursor_position_; 182 size_t cursor_position_;
228 GURL current_url_; 183 GURL current_url_;
229 AutocompleteInput::PageClassification current_page_classification_; 184 metrics::OmniboxEventProto::PageClassification current_page_classification_;
230 Type type_; 185 metrics::OmniboxInputType::Type type_;
231 url::Parsed parts_; 186 url::Parsed parts_;
232 base::string16 scheme_; 187 base::string16 scheme_;
233 GURL canonicalized_url_; 188 GURL canonicalized_url_;
234 bool prevent_inline_autocomplete_; 189 bool prevent_inline_autocomplete_;
235 bool prefer_keyword_; 190 bool prefer_keyword_;
236 bool allow_exact_keyword_match_; 191 bool allow_exact_keyword_match_;
237 bool want_asynchronous_matches_; 192 bool want_asynchronous_matches_;
238 }; 193 };
239 194
240 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ 195 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_classifier.cc ('k') | chrome/browser/autocomplete/autocomplete_input.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698