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

Side by Side Diff: chrome/browser/autocomplete/history_url_provider.cc

Issue 6306011: 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 #include "chrome/browser/autocomplete/history_url_provider.h" 5 #include "chrome/browser/autocomplete/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (a.url_info.visit_count() != b.url_info.visit_count()) 71 if (a.url_info.visit_count() != b.url_info.visit_count())
72 return a.url_info.visit_count() > b.url_info.visit_count(); 72 return a.url_info.visit_count() > b.url_info.visit_count();
73 73
74 // URLs that have been visited more recently are better. 74 // URLs that have been visited more recently are better.
75 return a.url_info.last_visit() > b.url_info.last_visit(); 75 return a.url_info.last_visit() > b.url_info.last_visit();
76 } 76 }
77 77
78 // Given the user's |input| and a |match| created from it, reduce the 78 // Given the user's |input| and a |match| created from it, reduce the
79 // match's URL to just a host. If this host still matches the user input, 79 // match's URL to just a host. If this host still matches the user input,
80 // return it. Returns the empty string on failure. 80 // return it. Returns the empty string on failure.
81 GURL ConvertToHostOnly(const HistoryMatch& match, const std::wstring& input) { 81 GURL ConvertToHostOnly(const HistoryMatch& match, const string16& input) {
82 // See if we should try to do host-only suggestions for this URL. Nonstandard 82 // See if we should try to do host-only suggestions for this URL. Nonstandard
83 // schemes means there's no authority section, so suggesting the host name 83 // schemes means there's no authority section, so suggesting the host name
84 // is useless. File URLs are standard, but host suggestion is not useful for 84 // is useless. File URLs are standard, but host suggestion is not useful for
85 // them either. 85 // them either.
86 const GURL& url = match.url_info.url(); 86 const GURL& url = match.url_info.url();
87 if (!url.is_valid() || !url.IsStandard() || url.SchemeIsFile()) 87 if (!url.is_valid() || !url.IsStandard() || url.SchemeIsFile())
88 return GURL(); 88 return GURL();
89 89
90 // Transform to a host-only match. Bail if the host no longer matches the 90 // Transform to a host-only match. Bail if the host no longer matches the
91 // user input (e.g. because the user typed more than just a host). 91 // user input (e.g. because the user typed more than just a host).
92 GURL host = url.GetWithEmptyPath(); 92 GURL host = url.GetWithEmptyPath();
93 if ((host.spec().length() < (match.input_location + input.length()))) 93 if ((host.spec().length() < (match.input_location + input.length())))
94 return GURL(); // User typing is longer than this host suggestion. 94 return GURL(); // User typing is longer than this host suggestion.
95 95
96 const std::wstring spec = UTF8ToWide(host.spec()); 96 const string16 spec = UTF8ToUTF16(host.spec());
97 if (spec.compare(match.input_location, input.length(), input)) 97 if (spec.compare(match.input_location, input.length(), input))
98 return GURL(); // User typing is no longer a prefix. 98 return GURL(); // User typing is no longer a prefix.
99 99
100 return host; 100 return host;
101 } 101 }
102 102
103 } // namespace history 103 } // namespace history
104 104
105 HistoryURLProviderParams::HistoryURLProviderParams( 105 HistoryURLProviderParams::HistoryURLProviderParams(
106 const AutocompleteInput& input, 106 const AutocompleteInput& input,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // * Their input can be opened as a URL, and 181 // * Their input can be opened as a URL, and
182 // * They hit ctrl-enter, or we parsed the input as a URL, or it starts with 182 // * They hit ctrl-enter, or we parsed the input as a URL, or it starts with
183 // an explicit "http:" or "https:". 183 // an explicit "http:" or "https:".
184 // Otherwise, this is just low-quality noise. In the cases where we've parsed 184 // Otherwise, this is just low-quality noise. In the cases where we've parsed
185 // as UNKNOWN, we'll still show an accidental search infobar if need be. 185 // as UNKNOWN, we'll still show an accidental search infobar if need be.
186 bool have_what_you_typed_match = 186 bool have_what_you_typed_match =
187 params->input.canonicalized_url().is_valid() && 187 params->input.canonicalized_url().is_valid() &&
188 (params->input.type() != AutocompleteInput::QUERY) && 188 (params->input.type() != AutocompleteInput::QUERY) &&
189 ((params->input.type() != AutocompleteInput::UNKNOWN) || 189 ((params->input.type() != AutocompleteInput::UNKNOWN) ||
190 !params->trim_http || 190 !params->trim_http ||
191 url_util::FindAndCompareScheme(WideToUTF8(params->input.text()), 191 url_util::FindAndCompareScheme(UTF16ToUTF8(params->input.text()),
192 chrome::kHttpsScheme, NULL)); 192 chrome::kHttpsScheme, NULL));
193 AutocompleteMatch what_you_typed_match(SuggestExactInput(params->input, 193 AutocompleteMatch what_you_typed_match(SuggestExactInput(params->input,
194 params->trim_http)); 194 params->trim_http));
195 195
196 // Get the matching URLs from the DB 196 // Get the matching URLs from the DB
197 typedef std::vector<history::URLRow> URLRowVector; 197 typedef std::vector<history::URLRow> URLRowVector;
198 URLRowVector url_matches; 198 URLRowVector url_matches;
199 HistoryMatches history_matches; 199 HistoryMatches history_matches;
200 200
201 for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end(); 201 for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end();
202 ++i) { 202 ++i) {
203 if (params->cancel) 203 if (params->cancel)
204 return; // Canceled in the middle of a query, give up. 204 return; // Canceled in the middle of a query, give up.
205 // We only need kMaxMatches results in the end, but before we get there we 205 // We only need kMaxMatches results in the end, but before we get there we
206 // need to promote lower-quality matches that are prefixes of 206 // need to promote lower-quality matches that are prefixes of
207 // higher-quality matches, and remove lower-quality redirects. So we ask 207 // higher-quality matches, and remove lower-quality redirects. So we ask
208 // for more results than we need, of every prefix type, in hopes this will 208 // for more results than we need, of every prefix type, in hopes this will
209 // give us far more than enough to work with. CullRedirects() will then 209 // give us far more than enough to work with. CullRedirects() will then
210 // reduce the list to the best kMaxMatches results. 210 // reduce the list to the best kMaxMatches results.
211 db->AutocompleteForPrefix(WideToUTF16(i->prefix + params->input.text()), 211 db->AutocompleteForPrefix(i->prefix + params->input.text(),
212 kMaxMatches * 2, (backend == NULL), &url_matches); 212 kMaxMatches * 2, (backend == NULL), &url_matches);
213 for (URLRowVector::const_iterator j(url_matches.begin()); 213 for (URLRowVector::const_iterator j(url_matches.begin());
214 j != url_matches.end(); ++j) { 214 j != url_matches.end(); ++j) {
215 const Prefix* best_prefix = BestPrefix(j->url(), std::wstring()); 215 const Prefix* best_prefix = BestPrefix(j->url(), string16());
216 DCHECK(best_prefix != NULL); 216 DCHECK(best_prefix != NULL);
217 history_matches.push_back(HistoryMatch(*j, i->prefix.length(), 217 history_matches.push_back(HistoryMatch(*j, i->prefix.length(),
218 !i->num_components, 218 !i->num_components,
219 i->num_components >= best_prefix->num_components)); 219 i->num_components >= best_prefix->num_components));
220 } 220 }
221 } 221 }
222 222
223 // Create sorted list of suggestions. 223 // Create sorted list of suggestions.
224 CullPoorMatches(&history_matches); 224 CullPoorMatches(&history_matches);
225 SortMatches(&history_matches); 225 SortMatches(&history_matches);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 const GURL& url = input.canonicalized_url(); 306 const GURL& url = input.canonicalized_url();
307 if (url.is_valid()) { 307 if (url.is_valid()) {
308 match.destination_url = url; 308 match.destination_url = url;
309 309
310 // Trim off "http://" if the user didn't type it. 310 // Trim off "http://" if the user didn't type it.
311 // NOTE: We use TrimHttpPrefix() here rather than StringForURLDisplay() to 311 // NOTE: We use TrimHttpPrefix() here rather than StringForURLDisplay() to
312 // strip the scheme as we need to know the offset so we can adjust the 312 // strip the scheme as we need to know the offset so we can adjust the
313 // |match_location| below. StringForURLDisplay() and TrimHttpPrefix() have 313 // |match_location| below. StringForURLDisplay() and TrimHttpPrefix() have
314 // slightly different behavior as well (the latter will strip even without 314 // slightly different behavior as well (the latter will strip even without
315 // two slashes after the scheme). 315 // two slashes after the scheme).
316 std::wstring display_string(StringForURLDisplay(url, false, false)); 316 string16 display_string(StringForURLDisplay(url, false, false));
317 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; 317 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0;
318 match.fill_into_edit = 318 match.fill_into_edit =
319 AutocompleteInput::FormattedStringWithEquivalentMeaning(url, 319 AutocompleteInput::FormattedStringWithEquivalentMeaning(url,
320 display_string); 320 display_string);
321 // NOTE: Don't set match.input_location (to allow inline autocompletion) 321 // NOTE: Don't set match.input_location (to allow inline autocompletion)
322 // here, it's surprising and annoying. 322 // here, it's surprising and annoying.
323 323
324 // Try to highlight "innermost" match location. If we fix up "w" into 324 // Try to highlight "innermost" match location. If we fix up "w" into
325 // "www.w.com", we want to highlight the fifth character, not the first. 325 // "www.w.com", we want to highlight the fifth character, not the first.
326 // This relies on match.destination_url being the non-prefix-trimmed version 326 // This relies on match.destination_url being the non-prefix-trimmed version
327 // of match.contents. 327 // of match.contents.
328 match.contents = display_string; 328 match.contents = display_string;
329 const Prefix* best_prefix = BestPrefix(match.destination_url, input.text()); 329 const Prefix* best_prefix = BestPrefix(match.destination_url, input.text());
330 // Because of the vagaries of GURL, it's possible for match.destination_url 330 // Because of the vagaries of GURL, it's possible for match.destination_url
331 // to not contain the user's input at all. In this case don't mark anything 331 // to not contain the user's input at all. In this case don't mark anything
332 // as a match. 332 // as a match.
333 const size_t match_location = (best_prefix == NULL) ? 333 const size_t match_location = (best_prefix == NULL) ?
334 std::wstring::npos : best_prefix->prefix.length() - offset; 334 string16::npos : best_prefix->prefix.length() - offset;
335 AutocompleteMatch::ClassifyLocationInString(match_location, 335 AutocompleteMatch::ClassifyLocationInString(match_location,
336 input.text().length(), 336 input.text().length(),
337 match.contents.length(), 337 match.contents.length(),
338 ACMatchClassification::URL, 338 ACMatchClassification::URL,
339 &match.contents_class); 339 &match.contents_class);
340 340
341 match.is_history_what_you_typed_match = true; 341 match.is_history_what_you_typed_match = true;
342 } 342 }
343 343
344 return match; 344 return match;
(...skipping 19 matching lines...) Expand all
364 // * If the what-you-typed match is not in the history DB, 364 // * If the what-you-typed match is not in the history DB,
365 // * and the user has specified a TLD, 365 // * and the user has specified a TLD,
366 // * and the input _without_ the TLD _is_ in the history DB, 366 // * and the input _without_ the TLD _is_ in the history DB,
367 // * ...then just before pressing "ctrl" the best match we supplied was the 367 // * ...then just before pressing "ctrl" the best match we supplied was the
368 // what-you-typed match, so stick with it by promoting this. 368 // what-you-typed match, so stick with it by promoting this.
369 history::URLRow info; 369 history::URLRow info;
370 MatchType type = INLINE_AUTOCOMPLETE; 370 MatchType type = INLINE_AUTOCOMPLETE;
371 if (!db->GetRowForURL(match->destination_url, &info)) { 371 if (!db->GetRowForURL(match->destination_url, &info)) {
372 if (input.desired_tld().empty()) 372 if (input.desired_tld().empty())
373 return false; 373 return false;
374 GURL destination_url(URLFixerUpper::FixupURL(WideToUTF8(input.text()), 374 GURL destination_url(URLFixerUpper::FixupURL(UTF16ToUTF8(input.text()),
375 std::string())); 375 std::string()));
376 if (!db->GetRowForURL(destination_url, NULL)) 376 if (!db->GetRowForURL(destination_url, NULL))
377 return false; 377 return false;
378 378
379 // If we got here, then we hit the tricky corner case. Make sure that 379 // If we got here, then we hit the tricky corner case. Make sure that
380 // |info| corresponds to the right URL. 380 // |info| corresponds to the right URL.
381 info = history::URLRow(match->destination_url); 381 info = history::URLRow(match->destination_url);
382 } else { 382 } else {
383 // We have data for this match, use it. 383 // We have data for this match, use it.
384 match->deletable = true; 384 match->deletable = true;
385 match->description = UTF16ToWide(info.title()); 385 match->description = info.title();
386 AutocompleteMatch::ClassifyMatchInString(input.text(), 386 AutocompleteMatch::ClassifyMatchInString(input.text(),
387 UTF16ToWide(info.title()), 387 info.title(),
388 ACMatchClassification::NONE, &match->description_class); 388 ACMatchClassification::NONE, &match->description_class);
389 if (!info.typed_count()) { 389 if (!info.typed_count()) {
390 // If we reach here, we must be in the second pass, and we must not have 390 // If we reach here, we must be in the second pass, and we must not have
391 // promoted this match as an exact match during the first pass. That 391 // promoted this match as an exact match during the first pass. That
392 // means it will have been outscored by the "search what you typed match". 392 // means it will have been outscored by the "search what you typed match".
393 // We need to maintain that ordering in order to not make the destination 393 // We need to maintain that ordering in order to not make the destination
394 // for the user's typing change depending on when they hit enter. So 394 // for the user's typing change depending on when they hit enter. So
395 // lower the score here enough to let the search provider continue to 395 // lower the score here enough to let the search provider continue to
396 // outscore this match. 396 // outscore this match.
397 type = WHAT_YOU_TYPED; 397 type = WHAT_YOU_TYPED;
398 } 398 }
399 } 399 }
400 400
401 // Promote as an exact match. 401 // Promote as an exact match.
402 match->relevance = CalculateRelevance(input.type(), type, 0); 402 match->relevance = CalculateRelevance(input.type(), type, 0);
403 403
404 // Put it on the front of the HistoryMatches for redirect culling. 404 // Put it on the front of the HistoryMatches for redirect culling.
405 EnsureMatchPresent(info, std::wstring::npos, false, matches, true); 405 EnsureMatchPresent(info, string16::npos, false, matches, true);
406 return true; 406 return true;
407 } 407 }
408 408
409 bool HistoryURLProvider::PromoteMatchForInlineAutocomplete( 409 bool HistoryURLProvider::PromoteMatchForInlineAutocomplete(
410 HistoryURLProviderParams* params, 410 HistoryURLProviderParams* params,
411 const HistoryMatch& match) { 411 const HistoryMatch& match) {
412 // Promote the first match if it's been typed at least n times, where n == 1 412 // Promote the first match if it's been typed at least n times, where n == 1
413 // for "simple" (host-only) URLs and n == 2 for others. We set a higher bar 413 // for "simple" (host-only) URLs and n == 2 for others. We set a higher bar
414 // for these long URLs because it's less likely that users will want to visit 414 // for these long URLs because it's less likely that users will want to visit
415 // them again. Even though we don't increment the typed_count for pasted-in 415 // them again. Even though we don't increment the typed_count for pasted-in
416 // URLs, if the user manually edits the URL or types some long thing in by 416 // URLs, if the user manually edits the URL or types some long thing in by
417 // hand, we wouldn't want to immediately start autocompleting it. 417 // hand, we wouldn't want to immediately start autocompleting it.
418 if (!match.url_info.typed_count() || 418 if (!match.url_info.typed_count() ||
419 ((match.url_info.typed_count() == 1) && 419 ((match.url_info.typed_count() == 1) &&
420 !history::IsHostOnly(match.url_info.url()))) 420 !history::IsHostOnly(match.url_info.url())))
421 return false; 421 return false;
422 422
423 params->matches.push_back(HistoryMatchToACMatch(params, match, 423 params->matches.push_back(HistoryMatchToACMatch(params, match,
424 INLINE_AUTOCOMPLETE, 0)); 424 INLINE_AUTOCOMPLETE, 0));
425 return true; 425 return true;
426 } 426 }
427 427
428 // static 428 // static
429 history::Prefixes HistoryURLProvider::GetPrefixes() { 429 history::Prefixes HistoryURLProvider::GetPrefixes() {
430 // We'll complete text following these prefixes. 430 // We'll complete text following these prefixes.
431 // NOTE: There's no requirement that these be in any particular order. 431 // NOTE: There's no requirement that these be in any particular order.
432 Prefixes prefixes; 432 Prefixes prefixes;
433 prefixes.push_back(Prefix(L"https://www.", 2)); 433 prefixes.push_back(Prefix(ASCIIToUTF16("https://www."), 2));
434 prefixes.push_back(Prefix(L"http://www.", 2)); 434 prefixes.push_back(Prefix(ASCIIToUTF16("http://www."), 2));
435 prefixes.push_back(Prefix(L"ftp://ftp.", 2)); 435 prefixes.push_back(Prefix(ASCIIToUTF16("ftp://ftp."), 2));
436 prefixes.push_back(Prefix(L"ftp://www.", 2)); 436 prefixes.push_back(Prefix(ASCIIToUTF16("ftp://www."), 2));
437 prefixes.push_back(Prefix(L"https://", 1)); 437 prefixes.push_back(Prefix(ASCIIToUTF16("https://"), 1));
438 prefixes.push_back(Prefix(L"http://", 1)); 438 prefixes.push_back(Prefix(ASCIIToUTF16("http://"), 1));
439 prefixes.push_back(Prefix(L"ftp://", 1)); 439 prefixes.push_back(Prefix(ASCIIToUTF16("ftp://"), 1));
440 prefixes.push_back(Prefix(L"", 0)); // Catches within-scheme matches as well 440 // Empty string catches within-scheme matches as well.
441 prefixes.push_back(Prefix(string16(), 0));
441 return prefixes; 442 return prefixes;
442 } 443 }
443 444
444 // static 445 // static
445 int HistoryURLProvider::CalculateRelevance(AutocompleteInput::Type input_type, 446 int HistoryURLProvider::CalculateRelevance(AutocompleteInput::Type input_type,
446 MatchType match_type, 447 MatchType match_type,
447 size_t match_number) { 448 size_t match_number) {
448 switch (match_type) { 449 switch (match_type) {
449 case INLINE_AUTOCOMPLETE: 450 case INLINE_AUTOCOMPLETE:
450 return 1400; 451 return 1400;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 523 }
523 524
524 // Promote or add the desired URL to the list of matches. 525 // Promote or add the desired URL to the list of matches.
525 EnsureMatchPresent(info, match.input_location, match.match_in_scheme, 526 EnsureMatchPresent(info, match.input_location, match.match_in_scheme,
526 matches, promote); 527 matches, promote);
527 } 528 }
528 529
529 // static 530 // static
530 void HistoryURLProvider::EnsureMatchPresent( 531 void HistoryURLProvider::EnsureMatchPresent(
531 const history::URLRow& info, 532 const history::URLRow& info,
532 std::wstring::size_type input_location, 533 string16::size_type input_location,
533 bool match_in_scheme, 534 bool match_in_scheme,
534 HistoryMatches* matches, 535 HistoryMatches* matches,
535 bool promote) { 536 bool promote) {
536 // |matches| may already have an entry for this. 537 // |matches| may already have an entry for this.
537 for (HistoryMatches::iterator i(matches->begin()); i != matches->end(); 538 for (HistoryMatches::iterator i(matches->begin()); i != matches->end();
538 ++i) { 539 ++i) {
539 if (i->url_info.url() == info.url()) { 540 if (i->url_info.url() == info.url()) {
540 // Rotate it to the front if the caller wishes. 541 // Rotate it to the front if the caller wishes.
541 if (promote) 542 if (promote)
542 std::rotate(matches->begin(), i, i + 1); 543 std::rotate(matches->begin(), i, i + 1);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 } 588 }
588 scoped_ptr<HistoryURLProviderParams> params( 589 scoped_ptr<HistoryURLProviderParams> params(
589 new HistoryURLProviderParams(input, trim_http, languages)); 590 new HistoryURLProviderParams(input, trim_http, languages));
590 591
591 if (fixup_input_and_run_pass_1) { 592 if (fixup_input_and_run_pass_1) {
592 // Do some fixup on the user input before matching against it, so we provide 593 // Do some fixup on the user input before matching against it, so we provide
593 // good results for local file paths, input with spaces, etc. 594 // good results for local file paths, input with spaces, etc.
594 // NOTE: This purposefully doesn't take input.desired_tld() into account; if 595 // NOTE: This purposefully doesn't take input.desired_tld() into account; if
595 // it did, then holding "ctrl" would change all the results from the 596 // it did, then holding "ctrl" would change all the results from the
596 // HistoryURLProvider provider, not just the What You Typed Result. 597 // HistoryURLProvider provider, not just the What You Typed Result.
597 const std::wstring fixed_text(FixupUserInput(input)); 598 const string16 fixed_text(FixupUserInput(input));
598 if (fixed_text.empty()) { 599 if (fixed_text.empty()) {
599 // Conceivably fixup could result in an empty string (although I don't 600 // Conceivably fixup could result in an empty string (although I don't
600 // have cases where this happens offhand). We can't do anything with 601 // have cases where this happens offhand). We can't do anything with
601 // empty input, so just bail; otherwise we'd crash later. 602 // empty input, so just bail; otherwise we'd crash later.
602 return; 603 return;
603 } 604 }
604 params->input.set_text(fixed_text); 605 params->input.set_text(fixed_text);
605 606
606 // Pass 1: Get the in-memory URL database, and use it to find and promote 607 // Pass 1: Get the in-memory URL database, and use it to find and promote
607 // the inline autocomplete match, if any. 608 // the inline autocomplete match, if any.
(...skipping 20 matching lines...) Expand all
628 if (!input.synchronous_only()) { 629 if (!input.synchronous_only()) {
629 done_ = false; 630 done_ = false;
630 params_ = params.release(); // This object will be destroyed in 631 params_ = params.release(); // This object will be destroyed in
631 // QueryComplete() once we're done with it. 632 // QueryComplete() once we're done with it.
632 history_service->ScheduleAutocomplete(this, params_); 633 history_service->ScheduleAutocomplete(this, params_);
633 } 634 }
634 } 635 }
635 636
636 const history::Prefix* HistoryURLProvider::BestPrefix( 637 const history::Prefix* HistoryURLProvider::BestPrefix(
637 const GURL& url, 638 const GURL& url,
638 const std::wstring& prefix_suffix) const { 639 const string16& prefix_suffix) const {
639 const Prefix* best_prefix = NULL; 640 const Prefix* best_prefix = NULL;
640 const std::wstring text(UTF8ToWide(url.spec())); 641 const string16 text(UTF8ToUTF16(url.spec()));
641 for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end(); 642 for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end();
642 ++i) { 643 ++i) {
643 if ((best_prefix == NULL) || 644 if ((best_prefix == NULL) ||
644 (i->num_components > best_prefix->num_components)) { 645 (i->num_components > best_prefix->num_components)) {
645 std::wstring prefix_with_suffix(i->prefix + prefix_suffix); 646 string16 prefix_with_suffix(i->prefix + prefix_suffix);
646 if ((text.length() >= prefix_with_suffix.length()) && 647 if ((text.length() >= prefix_with_suffix.length()) &&
647 !text.compare(0, prefix_with_suffix.length(), prefix_with_suffix)) 648 !text.compare(0, prefix_with_suffix.length(), prefix_with_suffix))
648 best_prefix = &(*i); 649 best_prefix = &(*i);
649 } 650 }
650 } 651 }
651 return best_prefix; 652 return best_prefix;
652 } 653 }
653 654
654 void HistoryURLProvider::SortMatches(HistoryMatches* matches) const { 655 void HistoryURLProvider::SortMatches(HistoryMatches* matches) const {
655 // Sort by quality, best first. 656 // Sort by quality, best first.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 DCHECK(match.destination_url.is_valid()); 772 DCHECK(match.destination_url.is_valid());
772 size_t inline_autocomplete_offset = 773 size_t inline_autocomplete_offset =
773 history_match.input_location + params->input.text().length(); 774 history_match.input_location + params->input.text().length();
774 std::string languages = (match_type == WHAT_YOU_TYPED) ? 775 std::string languages = (match_type == WHAT_YOU_TYPED) ?
775 std::string() : params->languages; 776 std::string() : params->languages;
776 const net::FormatUrlTypes format_types = net::kFormatUrlOmitAll & 777 const net::FormatUrlTypes format_types = net::kFormatUrlOmitAll &
777 ~((params->trim_http && !history_match.match_in_scheme) ? 778 ~((params->trim_http && !history_match.match_in_scheme) ?
778 0 : net::kFormatUrlOmitHTTP); 779 0 : net::kFormatUrlOmitHTTP);
779 match.fill_into_edit = 780 match.fill_into_edit =
780 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), 781 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(),
781 UTF16ToWideHack(net::FormatUrl(info.url(), languages, format_types, 782 net::FormatUrl(info.url(), languages, format_types,
782 UnescapeRule::SPACES, NULL, NULL, 783 UnescapeRule::SPACES, NULL, NULL,
783 &inline_autocomplete_offset))); 784 &inline_autocomplete_offset));
784 if (!params->input.prevent_inline_autocomplete()) 785 if (!params->input.prevent_inline_autocomplete())
785 match.inline_autocomplete_offset = inline_autocomplete_offset; 786 match.inline_autocomplete_offset = inline_autocomplete_offset;
786 DCHECK((match.inline_autocomplete_offset == std::wstring::npos) || 787 DCHECK((match.inline_autocomplete_offset == string16::npos) ||
787 (match.inline_autocomplete_offset <= match.fill_into_edit.length())); 788 (match.inline_autocomplete_offset <= match.fill_into_edit.length()));
788 789
789 size_t match_start = history_match.input_location; 790 size_t match_start = history_match.input_location;
790 match.contents = UTF16ToWideHack(net::FormatUrl(info.url(), languages, 791 match.contents = net::FormatUrl(info.url(), languages,
791 format_types, UnescapeRule::SPACES, NULL, NULL, &match_start)); 792 format_types, UnescapeRule::SPACES, NULL, NULL, &match_start);
792 if ((match_start != std::wstring::npos) && 793 if ((match_start != string16::npos) &&
793 (inline_autocomplete_offset != std::wstring::npos) && 794 (inline_autocomplete_offset != string16::npos) &&
794 (inline_autocomplete_offset != match_start)) { 795 (inline_autocomplete_offset != match_start)) {
795 DCHECK(inline_autocomplete_offset > match_start); 796 DCHECK(inline_autocomplete_offset > match_start);
796 AutocompleteMatch::ClassifyLocationInString(match_start, 797 AutocompleteMatch::ClassifyLocationInString(match_start,
797 inline_autocomplete_offset - match_start, match.contents.length(), 798 inline_autocomplete_offset - match_start, match.contents.length(),
798 ACMatchClassification::URL, &match.contents_class); 799 ACMatchClassification::URL, &match.contents_class);
799 } else { 800 } else {
800 AutocompleteMatch::ClassifyLocationInString(std::wstring::npos, 0, 801 AutocompleteMatch::ClassifyLocationInString(string16::npos, 0,
801 match.contents.length(), ACMatchClassification::URL, 802 match.contents.length(), ACMatchClassification::URL,
802 &match.contents_class); 803 &match.contents_class);
803 } 804 }
804 match.description = UTF16ToWide(info.title()); 805 match.description = info.title();
805 AutocompleteMatch::ClassifyMatchInString(params->input.text(), 806 AutocompleteMatch::ClassifyMatchInString(params->input.text(),
806 UTF16ToWide(info.title()), 807 info.title(),
807 ACMatchClassification::NONE, 808 ACMatchClassification::NONE,
808 &match.description_class); 809 &match.description_class);
809 810
810 return match; 811 return match;
811 } 812 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698