| 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 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "google_apis/gaia/gaia_auth_util.h" | 15 #include "google_apis/gaia/gaia_auth_util.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Known account types. | 19 // Known account types. |
| 20 const char kGoogle[] = "google"; | 20 const char kGoogle[] = "google"; |
| 21 | 21 |
| 22 // Serialization keys | 22 // Serialization keys |
| 23 const char kGaiaIdKey[] = "gaia_id"; | 23 const char kGaiaIdKey[] = "gaia_id"; |
| 24 const char kEmailKey[] = "email"; | 24 const char kEmailKey[] = "email"; |
| 25 | 25 |
| 26 // Prefix for GetGaiaIdKey(). | 26 // Prefix for GetAccountIdKey(). |
| 27 const char kKeyGaiaIdPrefix[] = "g-"; | 27 const char kKeyGaiaIdPrefix[] = "g-"; |
| 28 | 28 |
| 29 struct GoogleStringSingleton { | 29 struct GoogleStringSingleton { |
| 30 GoogleStringSingleton() : google(kGoogle) {} | 30 GoogleStringSingleton() : google(kGoogle) {} |
| 31 | 31 |
| 32 static GoogleStringSingleton* GetInstance() { | 32 static GoogleStringSingleton* GetInstance() { |
| 33 return base::Singleton<GoogleStringSingleton>::get(); | 33 return base::Singleton<GoogleStringSingleton>::get(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 const std::string google; | 36 const std::string google; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 98 } |
| 99 | 99 |
| 100 const std::string& AccountId::GetGaiaId() const { | 100 const std::string& AccountId::GetGaiaId() const { |
| 101 return gaia_id_; | 101 return gaia_id_; |
| 102 } | 102 } |
| 103 | 103 |
| 104 const std::string& AccountId::GetUserEmail() const { | 104 const std::string& AccountId::GetUserEmail() const { |
| 105 return user_email_; | 105 return user_email_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 const std::string AccountId::GetGaiaIdKey() const { | 108 const std::string AccountId::GetAccountIdKey() const { |
| 109 #ifdef NDEBUG | 109 #ifdef NDEBUG |
| 110 if (gaia_id_.empty()) | 110 if (gaia_id_.empty()) |
| 111 LOG(FATAL) << "GetGaiaIdKey(): no gaia id for " << Serialize(); | 111 LOG(FATAL) << "GetAccountIdKey(): no gaia id for " << Serialize(); |
| 112 | 112 |
| 113 #else | 113 #else |
| 114 CHECK(!gaia_id_.empty()); | 114 CHECK(!gaia_id_.empty()); |
| 115 #endif | 115 #endif |
| 116 | 116 |
| 117 return std::string(kKeyGaiaIdPrefix) + gaia_id_; | 117 return std::string(kKeyGaiaIdPrefix) + gaia_id_; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void AccountId::SetGaiaId(const std::string& gaia_id) { | 120 void AccountId::SetGaiaId(const std::string& gaia_id) { |
| 121 DCHECK(!gaia_id.empty()); | 121 DCHECK(!gaia_id.empty()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 return AccountId::EmptyAccountId::GetInstance()->user_id; | 190 return AccountId::EmptyAccountId::GetInstance()->user_id; |
| 191 } | 191 } |
| 192 | 192 |
| 193 namespace BASE_HASH_NAMESPACE { | 193 namespace BASE_HASH_NAMESPACE { |
| 194 | 194 |
| 195 std::size_t hash<AccountId>::operator()(const AccountId& user_id) const { | 195 std::size_t hash<AccountId>::operator()(const AccountId& user_id) const { |
| 196 return hash<std::string>()(user_id.GetUserEmail()); | 196 return hash<std::string>()(user_id.GetUserEmail()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 } // namespace BASE_HASH_NAMESPACE | 199 } // namespace BASE_HASH_NAMESPACE |
| OLD | NEW |