| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/bind.h" |
| 11 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "google_apis/gaia/gaia_urls.h" | 17 #include "google_apis/gaia/gaia_urls.h" |
| 18 #include "net/url_request/url_fetcher.h" |
| 19 #include "net/url_request/url_request.h" |
| 17 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 18 | 21 |
| 19 namespace gaia { | 22 namespace gaia { |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 const char kGmailDomain[] = "gmail.com"; | 26 const char kGmailDomain[] = "gmail.com"; |
| 24 const char kGooglemailDomain[] = "googlemail.com"; | 27 const char kGooglemailDomain[] = "googlemail.com"; |
| 25 | 28 |
| 29 const void* kURLRequestUserDataKey = |
| 30 static_cast<const void*>(&kURLRequestUserDataKey); |
| 31 |
| 26 std::string CanonicalizeEmailImpl(const std::string& email_address, | 32 std::string CanonicalizeEmailImpl(const std::string& email_address, |
| 27 bool change_googlemail_to_gmail) { | 33 bool change_googlemail_to_gmail) { |
| 28 std::vector<std::string> parts = base::SplitString( | 34 std::vector<std::string> parts = base::SplitString( |
| 29 email_address, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 35 email_address, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 30 if (parts.size() != 2U) { | 36 if (parts.size() != 2U) { |
| 31 NOTREACHED() << "expecting exactly one @, but got " | 37 NOTREACHED() << "expecting exactly one @, but got " |
| 32 << (parts.empty() ? 0 : parts.size() - 1) | 38 << (parts.empty() ? 0 : parts.size() - 1) |
| 33 << " : " << email_address; | 39 << " : " << email_address; |
| 34 } else { | 40 } else { |
| 35 if (change_googlemail_to_gmail && parts[1] == kGooglemailDomain) | 41 if (change_googlemail_to_gmail && parts[1] == kGooglemailDomain) |
| 36 parts[1] = kGmailDomain; | 42 parts[1] = kGmailDomain; |
| 37 | 43 |
| 38 if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts. | 44 if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts. |
| 39 base::RemoveChars(parts[0], ".", &parts[0]); | 45 base::RemoveChars(parts[0], ".", &parts[0]); |
| 40 } | 46 } |
| 41 | 47 |
| 42 std::string new_email = base::ToLowerASCII(base::JoinString(parts, "@")); | 48 std::string new_email = base::ToLowerASCII(base::JoinString(parts, "@")); |
| 43 VLOG(1) << "Canonicalized " << email_address << " to " << new_email; | 49 VLOG(1) << "Canonicalized " << email_address << " to " << new_email; |
| 44 return new_email; | 50 return new_email; |
| 45 } | 51 } |
| 46 | 52 |
| 53 class GaiaURLRequestUserData : public base::SupportsUserData::Data { |
| 54 public: |
| 55 static base::SupportsUserData::Data* Create() { |
| 56 return new GaiaURLRequestUserData(); |
| 57 } |
| 58 }; |
| 59 |
| 47 } // namespace | 60 } // namespace |
| 48 | 61 |
| 49 | 62 |
| 50 ListedAccount::ListedAccount() {} | 63 ListedAccount::ListedAccount() {} |
| 51 | 64 |
| 52 ListedAccount::ListedAccount(const ListedAccount& other) = default; | 65 ListedAccount::ListedAccount(const ListedAccount& other) = default; |
| 53 | 66 |
| 54 ListedAccount::~ListedAccount() {} | 67 ListedAccount::~ListedAccount() {} |
| 55 | 68 |
| 56 bool ListedAccount::operator==(const ListedAccount& other) const { | 69 bool ListedAccount::operator==(const ListedAccount& other) const { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 if (list) | 186 if (list) |
| 174 list->push_back(listed_account); | 187 list->push_back(listed_account); |
| 175 } | 188 } |
| 176 } | 189 } |
| 177 } | 190 } |
| 178 } | 191 } |
| 179 | 192 |
| 180 return true; | 193 return true; |
| 181 } | 194 } |
| 182 | 195 |
| 196 bool RequestOriginatedFromGaia(const net::URLRequest& request) { |
| 197 return request.GetUserData(kURLRequestUserDataKey) != nullptr; |
| 198 } |
| 199 |
| 200 void MarkURLFetcherAsGaia(net::URLFetcher* fetcher) { |
| 201 DCHECK(fetcher); |
| 202 fetcher->SetURLRequestUserData(kURLRequestUserDataKey, |
| 203 base::Bind(&GaiaURLRequestUserData::Create)); |
| 204 } |
| 205 |
| 183 } // namespace gaia | 206 } // namespace gaia |
| OLD | NEW |