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

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

Issue 1169173005: 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: peter's optimizations Created 5 years, 6 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 408
409 // Remove the www. prefix from the host. 409 // Remove the www. prefix from the host.
410 static const char prefix[] = "www."; 410 static const char prefix[] = "www.";
411 static const size_t prefix_len = arraysize(prefix) - 1; 411 static const size_t prefix_len = arraysize(prefix) - 1;
412 std::string host = stripped_destination_url.host(); 412 std::string host = stripped_destination_url.host();
413 if (host.compare(0, prefix_len, prefix) == 0) { 413 if (host.compare(0, prefix_len, prefix) == 0) {
414 replacements.SetHostStr(base::StringPiece(host).substr(prefix_len)); 414 replacements.SetHostStr(base::StringPiece(host).substr(prefix_len));
415 needs_replacement = true; 415 needs_replacement = true;
416 } 416 }
417 417
418 // Remove the trailing slash if any (if it's not a lone slash), and
Peter Kasting 2015/06/12 19:30:36 Nit: "Remove any trailing slash ..."; and -> or
Mark P 2015/06/12 19:57:57 Done. (removed "if any", replaced "the" with "any
419 // add a slash (to make a lone slash) if the path is empty.
Peter Kasting 2015/06/12 19:30:36 Nit: Maybe add: "(We can't unconditionally remove
Mark P 2015/06/12 19:57:57 Okay. Done.
420 const std::string& path = stripped_destination_url.path();
421 // |slash| lives at this scope rather than inside the if
422 // statement because it has to live until the ReplaceComponents() call below.
423 std::string slash("/");
Peter Kasting 2015/06/12 19:30:36 Can we do: static const char slash[] = "/"; ?
Mark P 2015/06/12 19:57:57 Apparently we can. Done.
424 if ((path.length() > 1) && (path[path.length() - 1] == '/')) {
425 replacements.SetPathStr(
426 base::StringPiece(path).substr(0, path.length() - 1));
427 needs_replacement = true;
428 } else if (path.empty()) {
429 replacements.SetPathStr(base::StringPiece(slash));
430 needs_replacement = true;
431 }
432
418 // Replace https protocol with http protocol. 433 // Replace https protocol with http protocol.
419 if (stripped_destination_url.SchemeIs(url::kHttpsScheme)) { 434 if (stripped_destination_url.SchemeIs(url::kHttpsScheme)) {
420 replacements.SetScheme(url::kHttpScheme, 435 replacements.SetScheme(url::kHttpScheme,
421 url::Component(0, strlen(url::kHttpScheme))); 436 url::Component(0, strlen(url::kHttpScheme)));
422 needs_replacement = true; 437 needs_replacement = true;
423 } 438 }
424 439
425 if (needs_replacement) 440 if (needs_replacement)
426 stripped_destination_url = stripped_destination_url.ReplaceComponents( 441 stripped_destination_url = stripped_destination_url.ReplaceComponents(
427 replacements); 442 replacements);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 << " is unsorted in relation to last offset of " << last_offset 572 << " is unsorted in relation to last offset of " << last_offset
558 << ". Provider: " << provider_name << "."; 573 << ". Provider: " << provider_name << ".";
559 DCHECK_LT(i->offset, text.length()) 574 DCHECK_LT(i->offset, text.length())
560 << " Classification of [" << i->offset << "," << text.length() 575 << " Classification of [" << i->offset << "," << text.length()
561 << "] is out of bounds for \"" << text << "\". Provider: " 576 << "] is out of bounds for \"" << text << "\". Provider: "
562 << provider_name << "."; 577 << provider_name << ".";
563 last_offset = i->offset; 578 last_offset = i->offset;
564 } 579 }
565 } 580 }
566 #endif 581 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698