| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/common/net/gaia/gaia_auth_util.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/string_split.h" | |
| 11 #include "base/string_util.h" | |
| 12 | |
| 13 namespace gaia { | |
| 14 | |
| 15 namespace { | |
| 16 const char kGmailDomain[] = "gmail.com"; | |
| 17 } | |
| 18 | |
| 19 std::string CanonicalizeEmail(const std::string& email_address) { | |
| 20 std::vector<std::string> parts; | |
| 21 char at = '@'; | |
| 22 base::SplitString(email_address, at, &parts); | |
| 23 if (parts.size() != 2U) | |
| 24 NOTREACHED() << "expecting exactly one @, but got " << parts.size(); | |
| 25 else if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts. | |
| 26 RemoveChars(parts[0], ".", &parts[0]); | |
| 27 std::string new_email = StringToLowerASCII(JoinString(parts, at)); | |
| 28 VLOG(1) << "Canonicalized " << email_address << " to " << new_email; | |
| 29 return new_email; | |
| 30 } | |
| 31 | |
| 32 std::string CanonicalizeDomain(const std::string& domain) { | |
| 33 // Canonicalization of domain names means lower-casing them. Make sure to | |
| 34 // update this function in sync with Canonicalize if this ever changes. | |
| 35 return StringToLowerASCII(domain); | |
| 36 } | |
| 37 | |
| 38 std::string SanitizeEmail(const std::string& email_address) { | |
| 39 std::string sanitized(email_address); | |
| 40 | |
| 41 // Apply a default domain if necessary. | |
| 42 if (sanitized.find('@') == std::string::npos) { | |
| 43 sanitized += '@'; | |
| 44 sanitized += kGmailDomain; | |
| 45 } | |
| 46 | |
| 47 return sanitized; | |
| 48 } | |
| 49 | |
| 50 std::string ExtractDomainName(const std::string& email_address) { | |
| 51 // First canonicalize which will also verify we have proper domain part. | |
| 52 std::string email = CanonicalizeEmail(email_address); | |
| 53 size_t separator_pos = email.find('@'); | |
| 54 if (separator_pos != email.npos && separator_pos < email.length() - 1) | |
| 55 return email.substr(separator_pos + 1); | |
| 56 else | |
| 57 NOTREACHED() << "Not a proper email address: " << email; | |
| 58 return std::string(); | |
| 59 } | |
| 60 | |
| 61 } // namespace gaia | |
| OLD | NEW |