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

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

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

Powered by Google App Engine
This is Rietveld 408576698