| Index: url_util.cc
 | 
| diff --git a/url_util.cc b/url_util.cc
 | 
| index 008a5e48b687dddb0d14f62743ba201763f3d97d..279ab7e24b1f5203c4b63f812fa3d395d7371c2a 100644
 | 
| --- a/url_util.cc
 | 
| +++ b/url_util.cc
 | 
| @@ -9,6 +9,7 @@
 | 
|  
 | 
|  #include "base/debug/leak_annotations.h"
 | 
|  #include "base/logging.h"
 | 
| +#include "base/strings/string_util.h"
 | 
|  #include "url/url_canon_internal.h"
 | 
|  #include "url/url_file.h"
 | 
|  #include "url/url_util_internal.h"
 | 
| @@ -17,28 +18,11 @@ namespace url {
 | 
|  
 | 
|  namespace {
 | 
|  
 | 
| -// ASCII-specific tolower.  The standard library's tolower is locale sensitive,
 | 
| -// so we don't want to use it here.
 | 
| -template<class Char>
 | 
| -inline Char ToLowerASCII(Char c) {
 | 
| -  return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c;
 | 
| -}
 | 
| -
 | 
| -// Backend for LowerCaseEqualsASCII.
 | 
| -template<typename Iter>
 | 
| -inline bool DoLowerCaseEqualsASCII(Iter a_begin, Iter a_end, const char* b) {
 | 
| -  for (Iter it = a_begin; it != a_end; ++it, ++b) {
 | 
| -    if (!*b || ToLowerASCII(*it) != *b)
 | 
| -      return false;
 | 
| -  }
 | 
| -  return *b == 0;
 | 
| -}
 | 
| -
 | 
|  const int kNumStandardURLSchemes = 8;
 | 
|  const char* kStandardURLSchemes[kNumStandardURLSchemes] = {
 | 
|    kHttpScheme,
 | 
|    kHttpsScheme,
 | 
| -  kFileScheme,  // Yes, file urls can have a hostname!
 | 
| +  kFileScheme,  // Yes, file URLs can have a hostname!
 | 
|    kFtpScheme,
 | 
|    kGopherScheme,
 | 
|    kWsScheme,    // WebSocket.
 | 
| @@ -54,6 +38,17 @@ std::vector<const char*>* standard_schemes = NULL;
 | 
|  // See the LockStandardSchemes declaration in the header.
 | 
|  bool standard_schemes_locked = false;
 | 
|  
 | 
| +// This template converts a given character type to the corresponding
 | 
| +// StringPiece type.
 | 
| +template<typename CHAR> struct CharToStringPiece {
 | 
| +};
 | 
| +template<> struct CharToStringPiece<char> {
 | 
| +  typedef base::StringPiece Piece;
 | 
| +};
 | 
| +template<> struct CharToStringPiece<base::char16> {
 | 
| +  typedef base::StringPiece16 Piece;
 | 
| +};
 | 
| +
 | 
|  // Ensures that the standard_schemes list is initialized, does nothing if it
 | 
|  // already has values.
 | 
|  void InitStandardSchemes() {
 | 
| @@ -72,9 +67,10 @@ inline bool DoCompareSchemeComponent(const CHAR* spec,
 | 
|                                       const char* compare_to) {
 | 
|    if (!component.is_nonempty())
 | 
|      return compare_to[0] == 0;  // When component is empty, match empty scheme.
 | 
| -  return LowerCaseEqualsASCII(&spec[component.begin],
 | 
| -                              &spec[component.end()],
 | 
| -                              compare_to);
 | 
| +  return base::LowerCaseEqualsASCII(
 | 
| +      typename CharToStringPiece<CHAR>::Piece(
 | 
| +          &spec[component.begin], component.len),
 | 
| +      compare_to);
 | 
|  }
 | 
|  
 | 
|  // Returns true if the given scheme identified by |scheme| within |spec| is one
 | 
| @@ -86,8 +82,10 @@ bool DoIsStandard(const CHAR* spec, const Component& scheme) {
 | 
|  
 | 
|    InitStandardSchemes();
 | 
|    for (size_t i = 0; i < standard_schemes->size(); i++) {
 | 
| -    if (LowerCaseEqualsASCII(&spec[scheme.begin], &spec[scheme.end()],
 | 
| -                             standard_schemes->at(i)))
 | 
| +    if (base::LowerCaseEqualsASCII(
 | 
| +            typename CharToStringPiece<CHAR>::Piece(
 | 
| +                &spec[scheme.begin], scheme.len),
 | 
| +            standard_schemes->at(i)))
 | 
|        return true;
 | 
|    }
 | 
|    return false;
 | 
| @@ -134,7 +132,7 @@ bool DoCanonicalize(const CHAR* in_spec,
 | 
|    Parsed parsed_input;
 | 
|  #ifdef WIN32
 | 
|    // For Windows, we allow things that look like absolute Windows paths to be
 | 
| -  // fixed up magically to file URLs. This is done for IE compatability. For
 | 
| +  // fixed up magically to file URLs. This is done for IE compatibility. For
 | 
|    // example, this will change "c:/foo" into a file URL rather than treating
 | 
|    // it as a URL with the protocol "c". It also works for UNC ("\\foo\bar.txt").
 | 
|    // There is similar logic in url_canon_relative.cc for
 | 
| @@ -177,13 +175,14 @@ bool DoCanonicalize(const CHAR* in_spec,
 | 
|                                        charset_converter, output, output_parsed);
 | 
|  
 | 
|    } else if (DoCompareSchemeComponent(spec, scheme, url::kMailToScheme)) {
 | 
| -    // Mailto are treated like a standard url with only a scheme, path, query
 | 
| +    // Mailto URLs are treated like standard URLs, with only a scheme, path,
 | 
| +    // and query.
 | 
|      ParseMailtoURL(spec, spec_len, &parsed_input);
 | 
|      success = CanonicalizeMailtoURL(spec, spec_len, parsed_input, output,
 | 
|                                      output_parsed);
 | 
|  
 | 
|    } else {
 | 
| -    // "Weird" URLs like data: and javascript:
 | 
| +    // "Weird" URLs like data: and javascript:.
 | 
|      ParsePathURL(spec, spec_len, trim_path_end, &parsed_input);
 | 
|      success = CanonicalizePathURL(spec, spec_len, parsed_input, output,
 | 
|                                    output_parsed);
 | 
| @@ -273,7 +272,7 @@ bool DoReplaceComponents(const char* spec,
 | 
|                           CanonOutput* output,
 | 
|                           Parsed* out_parsed) {
 | 
|    // If the scheme is overridden, just do a simple string substitution and
 | 
| -  // reparse the whole thing. There are lots of edge cases that we really don't
 | 
| +  // re-parse the whole thing. There are lots of edge cases that we really don't
 | 
|    // want to deal with. Like what happens if I replace "http://e:8080/foo"
 | 
|    // with a file. Does it become "file:///E:/8080/foo" where the port number
 | 
|    // becomes part of the path? Parsing that string as a file URL says "yes"
 | 
| @@ -320,7 +319,7 @@ bool DoReplaceComponents(const char* spec,
 | 
|      // getting replaced here. If ReplaceComponents didn't re-check everything,
 | 
|      // we wouldn't know if something *not* getting replaced is a problem.
 | 
|      // If the scheme-specific replacers are made more intelligent so they don't
 | 
| -    // re-check everything, we should instead recanonicalize the whole thing
 | 
| +    // re-check everything, we should instead re-canonicalize the whole thing
 | 
|      // after this call to check validity (this assumes replacing the scheme is
 | 
|      // much much less common than other types of replacements, like clearing the
 | 
|      // ref).
 | 
| @@ -373,7 +372,7 @@ void AddStandardScheme(const char* new_scheme) {
 | 
|    //
 | 
|    // This normally means you're trying to set up a new standard scheme too late
 | 
|    // in your application's init process. Locate where your app does this
 | 
| -  // initialization and calls LockStandardScheme, and add your new standard
 | 
| +  // initialization and calls LockStandardSchemes, and add your new standard
 | 
|    // scheme there.
 | 
|    DCHECK(!standard_schemes_locked) <<
 | 
|        "Trying to add a standard scheme after the list has been locked.";
 | 
| @@ -382,7 +381,7 @@ void AddStandardScheme(const char* new_scheme) {
 | 
|    if (scheme_len == 0)
 | 
|      return;
 | 
|  
 | 
| -  // Dulicate the scheme into a new buffer and add it to the list of standard
 | 
| +  // Duplicate the scheme into a new buffer and add it to the list of standard
 | 
|    // schemes. This pointer will be leaked on shutdown.
 | 
|    char* dup_scheme = new char[scheme_len + 1];
 | 
|    ANNOTATE_LEAKING_OBJECT_PTR(dup_scheme);
 | 
| @@ -486,31 +485,6 @@ bool ReplaceComponents(const char* spec,
 | 
|                               charset_converter, output, out_parsed);
 | 
|  }
 | 
|  
 | 
| -// Front-ends for LowerCaseEqualsASCII.
 | 
| -bool LowerCaseEqualsASCII(const char* a_begin,
 | 
| -                          const char* a_end,
 | 
| -                          const char* b) {
 | 
| -  return DoLowerCaseEqualsASCII(a_begin, a_end, b);
 | 
| -}
 | 
| -
 | 
| -bool LowerCaseEqualsASCII(const char* a_begin,
 | 
| -                          const char* a_end,
 | 
| -                          const char* b_begin,
 | 
| -                          const char* b_end) {
 | 
| -  while (a_begin != a_end && b_begin != b_end &&
 | 
| -         ToLowerASCII(*a_begin) == *b_begin) {
 | 
| -    a_begin++;
 | 
| -    b_begin++;
 | 
| -  }
 | 
| -  return a_begin == a_end && b_begin == b_end;
 | 
| -}
 | 
| -
 | 
| -bool LowerCaseEqualsASCII(const base::char16* a_begin,
 | 
| -                          const base::char16* a_end,
 | 
| -                          const char* b) {
 | 
| -  return DoLowerCaseEqualsASCII(a_begin, a_end, b);
 | 
| -}
 | 
| -
 | 
|  void DecodeURLEscapeSequences(const char* input,
 | 
|                                int length,
 | 
|                                CanonOutputW* output) {
 | 
| 
 |