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

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

Issue 6258015: Remove wstring from autocomplete.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_H_ 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_
6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
14 #include "base/string16.h"
14 #include "base/timer.h" 15 #include "base/timer.h"
15 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
16 #include "googleurl/src/url_parse.h" 17 #include "googleurl/src/url_parse.h"
17 18
18 // The AutocompleteController is the center of the autocomplete system. A 19 // The AutocompleteController is the center of the autocomplete system. A
19 // class creates an instance of the controller, which in turn creates a set of 20 // class creates an instance of the controller, which in turn creates a set of
20 // AutocompleteProviders to serve it. The owning class can ask the controller 21 // AutocompleteProviders to serve it. The owning class can ask the controller
21 // to Start() a query; the controller in turn passes this call down to the 22 // to Start() a query; the controller in turn passes this call down to the
22 // providers, each of which keeps track of its own matches and whether it has 23 // providers, each of which keeps track of its own matches and whether it has
23 // finished processing the query. When a provider gets more matches or finishes 24 // finished processing the query. When a provider gets more matches or finishes
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 INVALID, // Empty input 174 INVALID, // Empty input
174 UNKNOWN, // Valid input whose type cannot be determined 175 UNKNOWN, // Valid input whose type cannot be determined
175 REQUESTED_URL, // Input autodetected as UNKNOWN, which the user wants to 176 REQUESTED_URL, // Input autodetected as UNKNOWN, which the user wants to
176 // treat as an URL by specifying a desired_tld 177 // treat as an URL by specifying a desired_tld
177 URL, // Input autodetected as a URL 178 URL, // Input autodetected as a URL
178 QUERY, // Input autodetected as a query 179 QUERY, // Input autodetected as a query
179 FORCED_QUERY, // Input forced to be a query by an initial '?' 180 FORCED_QUERY, // Input forced to be a query by an initial '?'
180 }; 181 };
181 182
182 AutocompleteInput(); 183 AutocompleteInput();
183 AutocompleteInput(const std::wstring& text, 184 AutocompleteInput(const string16& text,
184 const std::wstring& desired_tld, 185 const string16& desired_tld,
185 bool prevent_inline_autocomplete, 186 bool prevent_inline_autocomplete,
186 bool prefer_keyword, 187 bool prefer_keyword,
187 bool allow_exact_keyword_match, 188 bool allow_exact_keyword_match,
188 bool synchronous_only); 189 bool synchronous_only);
189 ~AutocompleteInput(); 190 ~AutocompleteInput();
190 191
191 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed. 192 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed.
192 static void RemoveForcedQueryStringIfNecessary(Type type, std::wstring* text); 193 static void RemoveForcedQueryStringIfNecessary(Type type, string16* text);
193 194
194 // Converts |type| to a string representation. Used in logging. 195 // Converts |type| to a string representation. Used in logging.
195 static std::string TypeToString(Type type); 196 static std::string TypeToString(Type type);
196 197
197 // Parses |text| and returns the type of input this will be interpreted as. 198 // Parses |text| and returns the type of input this will be interpreted as.
198 // The components of the input are stored in the output parameter |parts|, if 199 // The components of the input are stored in the output parameter |parts|, if
199 // it is non-NULL. The scheme is stored in |scheme| if it is non-NULL. The 200 // it is non-NULL. The scheme is stored in |scheme| if it is non-NULL. The
200 // canonicalized URL is stored in |canonicalized_url|; however, this URL is 201 // canonicalized URL is stored in |canonicalized_url|; however, this URL is
201 // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY. 202 // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY.
202 static Type Parse(const std::wstring& text, 203 static Type Parse(const string16& text,
203 const std::wstring& desired_tld, 204 const string16& desired_tld,
204 url_parse::Parsed* parts, 205 url_parse::Parsed* parts,
205 std::wstring* scheme, 206 string16* scheme,
206 GURL* canonicalized_url); 207 GURL* canonicalized_url);
207 208
208 // Parses |text| and fill |scheme| and |host| by the positions of them. 209 // Parses |text| and fill |scheme| and |host| by the positions of them.
209 // The results are almost as same as the result of Parse(), but if the scheme 210 // The results are almost as same as the result of Parse(), but if the scheme
210 // is view-source, this function returns the positions of scheme and host 211 // is view-source, this function returns the positions of scheme and host
211 // in the URL qualified by "view-source:" prefix. 212 // in the URL qualified by "view-source:" prefix.
212 static void ParseForEmphasizeComponents(const std::wstring& text, 213 static void ParseForEmphasizeComponents(const string16& text,
213 const std::wstring& desired_tld, 214 const string16& desired_tld,
214 url_parse::Component* scheme, 215 url_parse::Component* scheme,
215 url_parse::Component* host); 216 url_parse::Component* host);
216 217
217 // Code that wants to format URLs with a format flag including 218 // Code that wants to format URLs with a format flag including
218 // net::kFormatUrlOmitTrailingSlashOnBareHostname risk changing the meaning if 219 // net::kFormatUrlOmitTrailingSlashOnBareHostname risk changing the meaning if
219 // the result is then parsed as AutocompleteInput. Such code can call this 220 // the result is then parsed as AutocompleteInput. Such code can call this
220 // function with the URL and its formatted string, and it will return a 221 // function with the URL and its formatted string, and it will return a
221 // formatted string with the same meaning as the original URL (i.e. it will 222 // formatted string with the same meaning as the original URL (i.e. it will
222 // re-append a slash if necessary). 223 // re-append a slash if necessary).
223 static std::wstring FormattedStringWithEquivalentMeaning( 224 static string16 FormattedStringWithEquivalentMeaning(
224 const GURL& url, 225 const GURL& url,
225 const std::wstring& formatted_url); 226 const string16& formatted_url);
226 227
227 // User-provided text to be completed. 228 // User-provided text to be completed.
228 const std::wstring& text() const { return text_; } 229 const string16& text() const { return text_; }
229 230
230 // Use of this setter is risky, since no other internal state is updated 231 // Use of this setter is risky, since no other internal state is updated
231 // besides |text_|. Only callers who know that they're not changing the 232 // besides |text_|. Only callers who know that they're not changing the
232 // type/scheme/etc. should use this. 233 // type/scheme/etc. should use this.
233 void set_text(const std::wstring& text) { text_ = text; } 234 void set_text(const string16& text) { text_ = text; }
234 235
235 // User's desired TLD, if one is not already present in the text to 236 // User's desired TLD, if one is not already present in the text to
236 // autocomplete. When this is non-empty, it also implies that "www." should 237 // autocomplete. When this is non-empty, it also implies that "www." should
237 // be prepended to the domain where possible. This should not have a leading 238 // be prepended to the domain where possible. This should not have a leading
238 // '.' (use "com" instead of ".com"). 239 // '.' (use "com" instead of ".com").
239 const std::wstring& desired_tld() const { return desired_tld_; } 240 const string16& desired_tld() const { return desired_tld_; }
240 241
241 // The type of input supplied. 242 // The type of input supplied.
242 Type type() const { return type_; } 243 Type type() const { return type_; }
243 244
244 // Returns parsed URL components. 245 // Returns parsed URL components.
245 const url_parse::Parsed& parts() const { return parts_; } 246 const url_parse::Parsed& parts() const { return parts_; }
246 247
247 // The scheme parsed from the provided text; only meaningful when type_ is 248 // The scheme parsed from the provided text; only meaningful when type_ is
248 // URL. 249 // URL.
249 const std::wstring& scheme() const { return scheme_; } 250 const string16& scheme() const { return scheme_; }
250 251
251 // The input as an URL to navigate to, if possible. 252 // The input as an URL to navigate to, if possible.
252 const GURL& canonicalized_url() const { return canonicalized_url_; } 253 const GURL& canonicalized_url() const { return canonicalized_url_; }
253 254
254 // Returns whether inline autocompletion should be prevented. 255 // Returns whether inline autocompletion should be prevented.
255 bool prevent_inline_autocomplete() const { 256 bool prevent_inline_autocomplete() const {
256 return prevent_inline_autocomplete_; 257 return prevent_inline_autocomplete_;
257 } 258 }
258 259
259 // Returns the value of |prevent_inline_autocomplete| supplied to the 260 // Returns the value of |prevent_inline_autocomplete| supplied to the
(...skipping 18 matching lines...) Expand all
278 // asynchronous work should be canceled, so no later callbacks are fired. 279 // asynchronous work should be canceled, so no later callbacks are fired.
279 bool synchronous_only() const { return synchronous_only_; } 280 bool synchronous_only() const { return synchronous_only_; }
280 281
281 // operator==() by another name. 282 // operator==() by another name.
282 bool Equals(const AutocompleteInput& other) const; 283 bool Equals(const AutocompleteInput& other) const;
283 284
284 // Resets all internal variables to the null-constructed state. 285 // Resets all internal variables to the null-constructed state.
285 void Clear(); 286 void Clear();
286 287
287 private: 288 private:
288 std::wstring text_; 289 string16 text_;
289 std::wstring desired_tld_; 290 string16 desired_tld_;
290 Type type_; 291 Type type_;
291 url_parse::Parsed parts_; 292 url_parse::Parsed parts_;
292 std::wstring scheme_; 293 string16 scheme_;
293 GURL canonicalized_url_; 294 GURL canonicalized_url_;
294 bool initial_prevent_inline_autocomplete_; 295 bool initial_prevent_inline_autocomplete_;
295 bool prevent_inline_autocomplete_; 296 bool prevent_inline_autocomplete_;
296 bool prefer_keyword_; 297 bool prefer_keyword_;
297 bool allow_exact_keyword_match_; 298 bool allow_exact_keyword_match_;
298 bool synchronous_only_; 299 bool synchronous_only_;
299 }; 300 };
300 301
301 // AutocompleteProvider ------------------------------------------------------- 302 // AutocompleteProvider -------------------------------------------------------
302 303
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // we have good relevance heuristics; the controller should handle all 383 // we have good relevance heuristics; the controller should handle all
383 // culling. 384 // culling.
384 static const size_t kMaxMatches; 385 static const size_t kMaxMatches;
385 386
386 protected: 387 protected:
387 friend class base::RefCountedThreadSafe<AutocompleteProvider>; 388 friend class base::RefCountedThreadSafe<AutocompleteProvider>;
388 389
389 virtual ~AutocompleteProvider(); 390 virtual ~AutocompleteProvider();
390 391
391 // Returns whether |input| begins "http:" or "view-source:http:". 392 // Returns whether |input| begins "http:" or "view-source:http:".
392 static bool HasHTTPScheme(const std::wstring& input); 393 static bool HasHTTPScheme(const string16& input);
393 394
394 // Updates the starred state of each of the matches in matches_ from the 395 // Updates the starred state of each of the matches in matches_ from the
395 // profile's bookmark bar model. 396 // profile's bookmark bar model.
396 void UpdateStarredStateOfMatches(); 397 void UpdateStarredStateOfMatches();
397 398
398 // A convenience function to call net::FormatUrl() with the current set of 399 // A convenience function to call net::FormatUrl() with the current set of
399 // "Accept Languages" when check_accept_lang is true. Otherwise, it's called 400 // "Accept Languages" when check_accept_lang is true. Otherwise, it's called
400 // with an empty list. 401 // with an empty list.
401 std::wstring StringForURLDisplay(const GURL& url, 402 string16 StringForURLDisplay(const GURL& url,
402 bool check_accept_lang, 403 bool check_accept_lang,
403 bool trim_http) const; 404 bool trim_http) const;
404 405
405 // The profile associated with the AutocompleteProvider. Reference is not 406 // The profile associated with the AutocompleteProvider. Reference is not
406 // owned by us. 407 // owned by us.
407 Profile* profile_; 408 Profile* profile_;
408 409
409 ACProviderListener* listener_; 410 ACProviderListener* listener_;
410 ACMatches matches_; 411 ACMatches matches_;
411 bool done_; 412 bool done_;
412 413
413 // The name of this provider. Used for logging. 414 // The name of this provider. Used for logging.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 // return matches which are synchronously available, which should mean that 579 // return matches which are synchronously available, which should mean that
579 // all providers will be done immediately. 580 // all providers will be done immediately.
580 // 581 //
581 // The controller will fire 582 // The controller will fire
582 // AUTOCOMPLETE_CONTROLLER_SYNCHRONOUS_MATCHES_AVAILABLE from inside this 583 // AUTOCOMPLETE_CONTROLLER_SYNCHRONOUS_MATCHES_AVAILABLE from inside this
583 // call, and unless the query is stopped, will fire at least one (and perhaps 584 // call, and unless the query is stopped, will fire at least one (and perhaps
584 // more) AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED later as more matches come in 585 // more) AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED later as more matches come in
585 // (even if the query completes synchronously). Listeners should use the 586 // (even if the query completes synchronously). Listeners should use the
586 // result set provided in the accompanying Details object to update 587 // result set provided in the accompanying Details object to update
587 // themselves. 588 // themselves.
588 void Start(const std::wstring& text, 589 void Start(const string16& text,
589 const std::wstring& desired_tld, 590 const string16& desired_tld,
590 bool prevent_inline_autocomplete, 591 bool prevent_inline_autocomplete,
591 bool prefer_keyword, 592 bool prefer_keyword,
592 bool allow_exact_keyword_match, 593 bool allow_exact_keyword_match,
593 bool synchronous_only); 594 bool synchronous_only);
594 595
595 // Cancels the current query, ensuring there will be no future notifications 596 // Cancels the current query, ensuring there will be no future notifications
596 // fired. If new matches have come in since the most recent notification was 597 // fired. If new matches have come in since the most recent notification was
597 // fired, they will be discarded. 598 // fired, they will be discarded.
598 // 599 //
599 // If |clear_result| is true, the controller will also erase the result set. 600 // If |clear_result| is true, the controller will also erase the result set.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 base::RepeatingTimer<AutocompleteController> update_delay_timer_; 693 base::RepeatingTimer<AutocompleteController> update_delay_timer_;
693 694
694 DISALLOW_COPY_AND_ASSIGN(AutocompleteController); 695 DISALLOW_COPY_AND_ASSIGN(AutocompleteController);
695 }; 696 };
696 697
697 // AutocompleteLog ------------------------------------------------------------ 698 // AutocompleteLog ------------------------------------------------------------
698 699
699 // The data to log (via the metrics service) when the user selects an item 700 // The data to log (via the metrics service) when the user selects an item
700 // from the omnibox popup. 701 // from the omnibox popup.
701 struct AutocompleteLog { 702 struct AutocompleteLog {
702 AutocompleteLog(std::wstring text, 703 AutocompleteLog(string16 text,
703 AutocompleteInput::Type input_type, 704 AutocompleteInput::Type input_type,
704 size_t selected_index, 705 size_t selected_index,
705 size_t inline_autocompleted_length, 706 size_t inline_autocompleted_length,
706 const AutocompleteResult& result) 707 const AutocompleteResult& result)
707 : text(text), 708 : text(text),
708 input_type(input_type), 709 input_type(input_type),
709 selected_index(selected_index), 710 selected_index(selected_index),
710 inline_autocompleted_length(inline_autocompleted_length), 711 inline_autocompleted_length(inline_autocompleted_length),
711 result(result) { 712 result(result) {
712 } 713 }
713 // The user's input text in the omnibox. 714 // The user's input text in the omnibox.
714 std::wstring text; 715 string16 text;
715 // The detected type of the user's input. 716 // The detected type of the user's input.
716 AutocompleteInput::Type input_type; 717 AutocompleteInput::Type input_type;
717 // Selected index (if selected) or -1 (AutocompletePopupModel::kNoMatch). 718 // Selected index (if selected) or -1 (AutocompletePopupModel::kNoMatch).
718 size_t selected_index; 719 size_t selected_index;
719 // Inline autocompleted length (if displayed). 720 // Inline autocompleted length (if displayed).
720 size_t inline_autocompleted_length; 721 size_t inline_autocompleted_length;
721 // Result set. 722 // Result set.
722 const AutocompleteResult& result; 723 const AutocompleteResult& result;
723 }; 724 };
724 725
725 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ 726 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete.cc » ('j') | chrome/browser/autocomplete/autocomplete.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698