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

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

Issue 109013006: Update some uses of UTF conversions in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 12 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 #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/bind.h" 10 #include "base/bind.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 const GURL& url = match.url_info.url(); 94 const GURL& url = match.url_info.url();
95 if (!url.is_valid() || !url.IsStandard() || url.SchemeIsFile()) 95 if (!url.is_valid() || !url.IsStandard() || url.SchemeIsFile())
96 return GURL(); 96 return GURL();
97 97
98 // Transform to a host-only match. Bail if the host no longer matches the 98 // Transform to a host-only match. Bail if the host no longer matches the
99 // user input (e.g. because the user typed more than just a host). 99 // user input (e.g. because the user typed more than just a host).
100 GURL host = url.GetWithEmptyPath(); 100 GURL host = url.GetWithEmptyPath();
101 if ((host.spec().length() < (match.input_location + input.length()))) 101 if ((host.spec().length() < (match.input_location + input.length())))
102 return GURL(); // User typing is longer than this host suggestion. 102 return GURL(); // User typing is longer than this host suggestion.
103 103
104 const base::string16 spec = UTF8ToUTF16(host.spec()); 104 const base::string16 spec = base::UTF8ToUTF16(host.spec());
105 if (spec.compare(match.input_location, input.length(), input)) 105 if (spec.compare(match.input_location, input.length(), input))
106 return GURL(); // User typing is no longer a prefix. 106 return GURL(); // User typing is no longer a prefix.
107 107
108 return host; 108 return host;
109 } 109 }
110 110
111 // Acts like the > operator for URLInfo classes. 111 // Acts like the > operator for URLInfo classes.
112 bool CompareHistoryMatch(const history::HistoryMatch& a, 112 bool CompareHistoryMatch(const history::HistoryMatch& a,
113 const history::HistoryMatch& b) { 113 const history::HistoryMatch& b) {
114 // A promoted match is better than non-promoted. 114 // A promoted match is better than non-promoted.
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 display_string); 423 display_string);
424 match.allowed_to_be_default_match = true; 424 match.allowed_to_be_default_match = true;
425 // NOTE: Don't set match.inline_autocompletion to something non-empty here; 425 // NOTE: Don't set match.inline_autocompletion to something non-empty here;
426 // it's surprising and annoying. 426 // it's surprising and annoying.
427 427
428 // Try to highlight "innermost" match location. If we fix up "w" into 428 // Try to highlight "innermost" match location. If we fix up "w" into
429 // "www.w.com", we want to highlight the fifth character, not the first. 429 // "www.w.com", we want to highlight the fifth character, not the first.
430 // This relies on match.destination_url being the non-prefix-trimmed version 430 // This relies on match.destination_url being the non-prefix-trimmed version
431 // of match.contents. 431 // of match.contents.
432 match.contents = display_string; 432 match.contents = display_string;
433 const URLPrefix* best_prefix = 433 const URLPrefix* best_prefix = URLPrefix::BestURLPrefix(
434 URLPrefix::BestURLPrefix(UTF8ToUTF16(destination_url.spec()), text); 434 base::UTF8ToUTF16(destination_url.spec()), text);
435 // It's possible for match.destination_url to not contain the user's input 435 // It's possible for match.destination_url to not contain the user's input
436 // at all (so |best_prefix| is NULL), for example if the input is 436 // at all (so |best_prefix| is NULL), for example if the input is
437 // "view-source:x" and |destination_url| has an inserted "http://" in the 437 // "view-source:x" and |destination_url| has an inserted "http://" in the
438 // middle. 438 // middle.
439 if (best_prefix == NULL) { 439 if (best_prefix == NULL) {
440 AutocompleteMatch::ClassifyMatchInString(text, match.contents, 440 AutocompleteMatch::ClassifyMatchInString(text, match.contents,
441 ACMatchClassification::URL, 441 ACMatchClassification::URL,
442 &match.contents_class); 442 &match.contents_class);
443 } else { 443 } else {
444 AutocompleteMatch::ClassifyLocationInString( 444 AutocompleteMatch::ClassifyLocationInString(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 if (params->cancel_flag.IsSet()) 514 if (params->cancel_flag.IsSet())
515 return; // Canceled in the middle of a query, give up. 515 return; // Canceled in the middle of a query, give up.
516 // We only need kMaxMatches results in the end, but before we 516 // We only need kMaxMatches results in the end, but before we
517 // get there we need to promote lower-quality matches that are 517 // get there we need to promote lower-quality matches that are
518 // prefixes of higher-quality matches, and remove lower-quality 518 // prefixes of higher-quality matches, and remove lower-quality
519 // redirects. So we ask for more results than we need, of every 519 // redirects. So we ask for more results than we need, of every
520 // prefix type, in hopes this will give us far more than enough 520 // prefix type, in hopes this will give us far more than enough
521 // to work with. CullRedirects() will then reduce the list to 521 // to work with. CullRedirects() will then reduce the list to
522 // the best kMaxMatches results. 522 // the best kMaxMatches results.
523 db->AutocompleteForPrefix( 523 db->AutocompleteForPrefix(
524 UTF16ToUTF8(i->prefix + params->input.text()), 524 base::UTF16ToUTF8(i->prefix + params->input.text()),
525 kMaxMatches * 2, 525 kMaxMatches * 2,
526 (backend == NULL), 526 (backend == NULL),
527 &url_matches); 527 &url_matches);
528 for (history::URLRows::const_iterator j(url_matches.begin()); 528 for (history::URLRows::const_iterator j(url_matches.begin());
529 j != url_matches.end(); ++j) { 529 j != url_matches.end(); ++j) {
530 const URLPrefix* best_prefix = 530 const URLPrefix* best_prefix =
531 URLPrefix::BestURLPrefix(UTF8ToUTF16(j->url().spec()), 531 URLPrefix::BestURLPrefix(base::UTF8ToUTF16(j->url().spec()),
532 base::string16()); 532 base::string16());
533 DCHECK(best_prefix != NULL); 533 DCHECK(best_prefix != NULL);
534 history_matches.push_back(history::HistoryMatch(*j, i->prefix.length(), 534 history_matches.push_back(history::HistoryMatch(*j, i->prefix.length(),
535 i->num_components == 0, 535 i->num_components == 0,
536 i->num_components >= best_prefix->num_components)); 536 i->num_components >= best_prefix->num_components));
537 } 537 }
538 } 538 }
539 } 539 }
540 540
541 // Create sorted list of suggestions. 541 // Create sorted list of suggestions.
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 history::URLDatabase* db, 836 history::URLDatabase* db,
837 const AutocompleteInput& input) const { 837 const AutocompleteInput& input) const {
838 // Normally passing the first two conditions below ought to guarantee the 838 // Normally passing the first two conditions below ought to guarantee the
839 // third condition, but because FixupUserInput() can run and modify the 839 // third condition, but because FixupUserInput() can run and modify the
840 // input's text and parts between Parse() and here, it seems better to be 840 // input's text and parts between Parse() and here, it seems better to be
841 // paranoid and check. 841 // paranoid and check.
842 if ((input.type() != AutocompleteInput::UNKNOWN) || 842 if ((input.type() != AutocompleteInput::UNKNOWN) ||
843 !LowerCaseEqualsASCII(input.scheme(), content::kHttpScheme) || 843 !LowerCaseEqualsASCII(input.scheme(), content::kHttpScheme) ||
844 !input.parts().host.is_nonempty()) 844 !input.parts().host.is_nonempty())
845 return false; 845 return false;
846 const std::string host(UTF16ToUTF8( 846 const std::string host(base::UTF16ToUTF8(
847 input.text().substr(input.parts().host.begin, input.parts().host.len))); 847 input.text().substr(input.parts().host.begin, input.parts().host.len)));
848 const size_t registry_length = 848 const size_t registry_length =
849 net::registry_controlled_domains::GetRegistryLength( 849 net::registry_controlled_domains::GetRegistryLength(
850 host, 850 host,
851 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, 851 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
852 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); 852 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
853 return registry_length == 0 && db->IsTypedHost(host); 853 return registry_length == 0 && db->IsTypedHost(host);
854 } 854 }
855 855
856 bool HistoryURLProvider::PromoteMatchForInlineAutocomplete( 856 bool HistoryURLProvider::PromoteMatchForInlineAutocomplete(
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 history::MatchTermInString(input_text, clean_description, 0))); 1104 history::MatchTermInString(input_text, clean_description, 0)));
1105 history::WordStarts description_word_starts; 1105 history::WordStarts description_word_starts;
1106 history::String16VectorFromString16( 1106 history::String16VectorFromString16(
1107 clean_description, false, &description_word_starts); 1107 clean_description, false, &description_word_starts);
1108 description_matches = 1108 description_matches =
1109 history::ScoredHistoryMatch::FilterTermMatchesByWordStarts( 1109 history::ScoredHistoryMatch::FilterTermMatchesByWordStarts(
1110 description_matches, description_word_starts, 0, std::string::npos); 1110 description_matches, description_word_starts, 0, std::string::npos);
1111 return SpansFromTermMatch( 1111 return SpansFromTermMatch(
1112 description_matches, clean_description.length(), false); 1112 description_matches, clean_description.length(), false);
1113 } 1113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698