| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/signin/core/account_id/account_id.h" | 5 #include "components/signin/core/account_id/account_id.h" |
| 6 | 6 |
| 7 #include <functional> | 7 #include <functional> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/strings/string_util.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "google_apis/gaia/gaia_auth_util.h" | 14 #include "google_apis/gaia/gaia_auth_util.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 // Known account types. | 18 // Known account types. |
| 18 const char kGoogle[] = "google"; | 19 const char kGoogle[] = "google"; |
| 19 | 20 |
| 20 // Serialization keys | 21 // Serialization keys |
| 21 const char kGaiaIdKey[] = "gaia_id"; | 22 const char kGaiaIdKey[] = "gaia_id"; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 42 | 43 |
| 43 static EmptyAccountId* GetInstance() { | 44 static EmptyAccountId* GetInstance() { |
| 44 return base::Singleton<EmptyAccountId>::get(); | 45 return base::Singleton<EmptyAccountId>::get(); |
| 45 } | 46 } |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 AccountId::AccountId() {} | 49 AccountId::AccountId() {} |
| 49 | 50 |
| 50 AccountId::AccountId(const std::string& gaia_id, const std::string& user_email) | 51 AccountId::AccountId(const std::string& gaia_id, const std::string& user_email) |
| 51 : gaia_id_(gaia_id), user_email_(user_email) { | 52 : gaia_id_(gaia_id), user_email_(user_email) { |
| 53 LOG_ASSERT(!base::StartsWith(user_email, "g:", base::CompareCase::SENSITIVE)) |
| 54 << "Bad e-mail: '" << user_email << "' with gaia_id='" << gaia_id << "'"; |
| 55 |
| 52 // TODO(alemate): DCHECK(!email.empty()); | 56 // TODO(alemate): DCHECK(!email.empty()); |
| 53 // TODO(alemate): check gaia_id is not empty once it is required. | 57 // TODO(alemate): check gaia_id is not empty once it is required. |
| 54 } | 58 } |
| 55 | 59 |
| 56 AccountId::AccountId(const AccountId& other) | 60 AccountId::AccountId(const AccountId& other) |
| 57 : gaia_id_(other.gaia_id_), user_email_(other.user_email_) {} | 61 : gaia_id_(other.gaia_id_), user_email_(other.user_email_) {} |
| 58 | 62 |
| 59 bool AccountId::operator==(const AccountId& other) const { | 63 bool AccountId::operator==(const AccountId& other) const { |
| 60 return (this == &other) || | 64 return (this == &other) || |
| 61 (gaia_id_ == other.gaia_id_ && user_email_ == other.user_email_) || | 65 (gaia_id_ == other.gaia_id_ && user_email_ == other.user_email_) || |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 return AccountId::EmptyAccountId::GetInstance()->user_id; | 179 return AccountId::EmptyAccountId::GetInstance()->user_id; |
| 176 } | 180 } |
| 177 | 181 |
| 178 namespace BASE_HASH_NAMESPACE { | 182 namespace BASE_HASH_NAMESPACE { |
| 179 | 183 |
| 180 std::size_t hash<AccountId>::operator()(const AccountId& user_id) const { | 184 std::size_t hash<AccountId>::operator()(const AccountId& user_id) const { |
| 181 return hash<std::string>()(user_id.GetUserEmail()); | 185 return hash<std::string>()(user_id.GetUserEmail()); |
| 182 } | 186 } |
| 183 | 187 |
| 184 } // namespace BASE_HASH_NAMESPACE | 188 } // namespace BASE_HASH_NAMESPACE |
| OLD | NEW |