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

Side by Side Diff: components/omnibox/autocomplete_match.cc

Issue 1215233003: Reland - Omnibox - Mark As Duplicates URLs that only differ by a trailing slash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move const Created 5 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/omnibox/autocomplete_match.h" 5 #include "components/omnibox/autocomplete_match.h"
6 6
7 #include "base/i18n/time_formatting.h" 7 #include "base/i18n/time_formatting.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 424
425 // Remove the www. prefix from the host. 425 // Remove the www. prefix from the host.
426 static const char prefix[] = "www."; 426 static const char prefix[] = "www.";
427 static const size_t prefix_len = arraysize(prefix) - 1; 427 static const size_t prefix_len = arraysize(prefix) - 1;
428 std::string host = stripped_destination_url.host(); 428 std::string host = stripped_destination_url.host();
429 if (host.compare(0, prefix_len, prefix) == 0) { 429 if (host.compare(0, prefix_len, prefix) == 0) {
430 replacements.SetHostStr(base::StringPiece(host).substr(prefix_len)); 430 replacements.SetHostStr(base::StringPiece(host).substr(prefix_len));
431 needs_replacement = true; 431 needs_replacement = true;
432 } 432 }
433 433
434 // Remove any trailing slash (if it's not a lone slash), or add a slash (to
435 // make a lone slash) if the path is empty. (We can't unconditionally
436 // remove even lone slashes because for some schemes the path must consist
437 // of at least a slash.)
438 const std::string& path = stripped_destination_url.path();
439 if ((path.length() > 1) && (path[path.length() - 1] == '/')) {
440 replacements.SetPathStr(
441 base::StringPiece(path).substr(0, path.length() - 1));
442 needs_replacement = true;
443 } else if (path.empty()) {
444 static const char slash[] = "/";
445 replacements.SetPathStr(base::StringPiece(slash));
446 needs_replacement = true;
447 }
448
434 // Replace https protocol with http protocol. 449 // Replace https protocol with http protocol.
435 if (stripped_destination_url.SchemeIs(url::kHttpsScheme)) { 450 if (stripped_destination_url.SchemeIs(url::kHttpsScheme)) {
436 replacements.SetScheme(url::kHttpScheme, 451 replacements.SetScheme(url::kHttpScheme,
437 url::Component(0, strlen(url::kHttpScheme))); 452 url::Component(0, strlen(url::kHttpScheme)));
438 needs_replacement = true; 453 needs_replacement = true;
439 } 454 }
440 455
441 if (needs_replacement) 456 if (needs_replacement)
442 stripped_destination_url = stripped_destination_url.ReplaceComponents( 457 stripped_destination_url = stripped_destination_url.ReplaceComponents(
443 replacements); 458 replacements);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 return false; 557 return false;
543 } 558 }
544 559
545 void AutocompleteMatch::PossiblySwapContentsAndDescriptionForDisplay() { 560 void AutocompleteMatch::PossiblySwapContentsAndDescriptionForDisplay() {
546 if (swap_contents_and_description) { 561 if (swap_contents_and_description) {
547 std::swap(contents, description); 562 std::swap(contents, description);
548 std::swap(contents_class, description_class); 563 std::swap(contents_class, description_class);
549 } 564 }
550 } 565 }
551 566
567 void AutocompleteMatch::StripLoneSlashOnInlineAutocompletion() {
568 DCHECK(!IsSearchType(type));
569 static const base::char16 slash_utf8 = 0x002F;
Peter Kasting 2015/07/01 22:01:36 Why declare a variable for this? And use 0x002f i
570 if ((inline_autocompletion.length() == 1) &&
Mark P 2015/06/30 23:47:30 I know you may argue that we should simply remove
571 (inline_autocompletion[0] == slash_utf8)) {
Peter Kasting 2015/07/01 22:01:36 Nit: No {}
572 inline_autocompletion.clear();
573 }
574 }
575
552 #ifndef NDEBUG 576 #ifndef NDEBUG
553 void AutocompleteMatch::Validate() const { 577 void AutocompleteMatch::Validate() const {
554 ValidateClassifications(contents, contents_class); 578 ValidateClassifications(contents, contents_class);
555 ValidateClassifications(description, description_class); 579 ValidateClassifications(description, description_class);
556 } 580 }
557 581
558 void AutocompleteMatch::ValidateClassifications( 582 void AutocompleteMatch::ValidateClassifications(
559 const base::string16& text, 583 const base::string16& text,
560 const ACMatchClassifications& classifications) const { 584 const ACMatchClassifications& classifications) const {
561 if (text.empty()) { 585 if (text.empty()) {
(...skipping 18 matching lines...) Expand all
580 << " is unsorted in relation to last offset of " << last_offset 604 << " is unsorted in relation to last offset of " << last_offset
581 << ". Provider: " << provider_name << "."; 605 << ". Provider: " << provider_name << ".";
582 DCHECK_LT(i->offset, text.length()) 606 DCHECK_LT(i->offset, text.length())
583 << " Classification of [" << i->offset << "," << text.length() 607 << " Classification of [" << i->offset << "," << text.length()
584 << "] is out of bounds for \"" << text << "\". Provider: " 608 << "] is out of bounds for \"" << text << "\". Provider: "
585 << provider_name << "."; 609 << provider_name << ".";
586 last_offset = i->offset; 610 last_offset = i->offset;
587 } 611 }
588 } 612 }
589 #endif 613 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698