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