| OLD | NEW |
| 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/chromeos/login/authenticator.h" | 5 #include "chrome/browser/chromeos/login/authenticator.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 if (parts.size() != 2U) | 33 if (parts.size() != 2U) |
| 34 NOTREACHED() << "expecting exactly one @, but got " << parts.size(); | 34 NOTREACHED() << "expecting exactly one @, but got " << parts.size(); |
| 35 else if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts. | 35 else if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts. |
| 36 RemoveChars(parts[0], ".", &parts[0]); | 36 RemoveChars(parts[0], ".", &parts[0]); |
| 37 std::string new_email = StringToLowerASCII(JoinString(parts, at)); | 37 std::string new_email = StringToLowerASCII(JoinString(parts, at)); |
| 38 VLOG(1) << "Canonicalized " << email_address << " to " << new_email; | 38 VLOG(1) << "Canonicalized " << email_address << " to " << new_email; |
| 39 return new_email; | 39 return new_email; |
| 40 } | 40 } |
| 41 | 41 |
| 42 // static | 42 // static |
| 43 std::string Authenticator::CanonicalizeDomain(const std::string& domain) { |
| 44 // Canonicalization of domain names means lower-casing them. Make sure to |
| 45 // update this function in sync with Canonicalize if this ever changes. |
| 46 return StringToLowerASCII(domain); |
| 47 } |
| 48 |
| 49 // static |
| 43 std::string Authenticator::Sanitize(const std::string& email_address) { | 50 std::string Authenticator::Sanitize(const std::string& email_address) { |
| 44 std::string sanitized(email_address); | 51 std::string sanitized(email_address); |
| 45 | 52 |
| 46 // Apply a default domain if necessary. | 53 // Apply a default domain if necessary. |
| 47 if (sanitized.find('@') == std::string::npos) { | 54 if (sanitized.find('@') == std::string::npos) { |
| 48 sanitized += '@'; | 55 sanitized += '@'; |
| 49 sanitized += kGmailDomain; | 56 sanitized += kGmailDomain; |
| 50 } | 57 } |
| 51 | 58 |
| 52 return sanitized; | 59 return sanitized; |
| 53 } | 60 } |
| 54 | 61 |
| 62 // static |
| 63 std::string Authenticator::ExtractDomainName(const std::string& email_address) { |
| 64 // First canonicalize which will also verify we have proper domain part. |
| 65 std::string email = Canonicalize(email_address); |
| 66 size_t separator_pos = email.find('@'); |
| 67 if (separator_pos != email.npos && separator_pos < email.length() - 1) |
| 68 return email.substr(separator_pos + 1); |
| 69 else |
| 70 NOTREACHED() << "Not a proper email address: " << email; |
| 71 return std::string(); |
| 72 } |
| 73 |
| 55 } // namespace chromeos | 74 } // namespace chromeos |
| OLD | NEW |