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 "google_apis/gaia/gaia_auth_util.h" | 5 #include "google_apis/gaia/gaia_auth_util.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "google_apis/gaia/gaia_urls.h" | 12 #include "google_apis/gaia/gaia_urls.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 namespace gaia { | 15 namespace gaia { |
16 | 16 |
17 namespace { | 17 namespace { |
18 const char kGmailDomain[] = "gmail.com"; | 18 const char kGmailDomain[] = "gmail.com"; |
19 } | 19 } |
20 | 20 |
21 std::string CanonicalizeEmail(const std::string& email_address) { | 21 std::string CanonicalizeEmail(const std::string& email_address) { |
22 std::vector<std::string> parts; | 22 std::vector<std::string> parts; |
23 char at = '@'; | 23 char at = '@'; |
24 base::SplitString(email_address, at, &parts); | 24 base::SplitString(email_address, at, &parts); |
25 if (parts.size() != 2U) | 25 if (parts.size() != 2U) { |
26 NOTREACHED() << "expecting exactly one @, but got " << parts.size(); | 26 NOTREACHED() << "expecting exactly one @, but got " << parts.size()-1 << |
27 else if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts. | 27 " : " << email_address; |
| 28 } else if (parts[1] == kGmailDomain) { // only strip '.' for gmail accounts. |
28 base::RemoveChars(parts[0], ".", &parts[0]); | 29 base::RemoveChars(parts[0], ".", &parts[0]); |
| 30 } |
29 std::string new_email = StringToLowerASCII(JoinString(parts, at)); | 31 std::string new_email = StringToLowerASCII(JoinString(parts, at)); |
30 VLOG(1) << "Canonicalized " << email_address << " to " << new_email; | 32 VLOG(1) << "Canonicalized " << email_address << " to " << new_email; |
31 return new_email; | 33 return new_email; |
32 } | 34 } |
33 | 35 |
34 std::string CanonicalizeDomain(const std::string& domain) { | 36 std::string CanonicalizeDomain(const std::string& domain) { |
35 // Canonicalization of domain names means lower-casing them. Make sure to | 37 // Canonicalization of domain names means lower-casing them. Make sure to |
36 // update this function in sync with Canonicalize if this ever changes. | 38 // update this function in sync with Canonicalize if this ever changes. |
37 return StringToLowerASCII(domain); | 39 return StringToLowerASCII(domain); |
38 } | 40 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Canonicalize the email since ListAccounts returns "display email". | 101 // Canonicalize the email since ListAccounts returns "display email". |
100 if (account->GetString(3, &email) && !email.empty()) | 102 if (account->GetString(3, &email) && !email.empty()) |
101 account_ids.push_back(CanonicalizeEmail(email)); | 103 account_ids.push_back(CanonicalizeEmail(email)); |
102 } | 104 } |
103 } | 105 } |
104 | 106 |
105 return account_ids; | 107 return account_ids; |
106 } | 108 } |
107 | 109 |
108 } // namespace gaia | 110 } // namespace gaia |
OLD | NEW |