Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: components/signin/core/account_id/account_id.cc

Issue 1693383003: ChromeOS cryptohome should be able to use gaia id as user identifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/tpm/tpm_token_info_getter_unittest.cc ('k') | components/user_manager/known_user.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Fail if e-mail looks similar to GaiaIdKey.
54 LOG_ASSERT(!base::StartsWith(user_email, kKeyGaiaIdPrefix,
55 base::CompareCase::SENSITIVE) ||
56 user_email.find('@') != std::string::npos)
57 << "Bad e-mail: '" << user_email << "' with gaia_id='" << gaia_id << "'";
58
52 // TODO(alemate): DCHECK(!email.empty()); 59 // TODO(alemate): DCHECK(!email.empty());
53 // TODO(alemate): check gaia_id is not empty once it is required. 60 // TODO(alemate): check gaia_id is not empty once it is required.
54 } 61 }
55 62
56 AccountId::AccountId(const AccountId& other) 63 AccountId::AccountId(const AccountId& other)
57 : gaia_id_(other.gaia_id_), user_email_(other.user_email_) {} 64 : gaia_id_(other.gaia_id_), user_email_(other.user_email_) {}
58 65
59 bool AccountId::operator==(const AccountId& other) const { 66 bool AccountId::operator==(const AccountId& other) const {
60 return (this == &other) || 67 return (this == &other) ||
61 (gaia_id_ == other.gaia_id_ && user_email_ == other.user_email_) || 68 (gaia_id_ == other.gaia_id_ && user_email_ == other.user_email_) ||
(...skipping 29 matching lines...) Expand all
91 98
92 const std::string& AccountId::GetGaiaId() const { 99 const std::string& AccountId::GetGaiaId() const {
93 return gaia_id_; 100 return gaia_id_;
94 } 101 }
95 102
96 const std::string& AccountId::GetUserEmail() const { 103 const std::string& AccountId::GetUserEmail() const {
97 return user_email_; 104 return user_email_;
98 } 105 }
99 106
100 const std::string AccountId::GetGaiaIdKey() const { 107 const std::string AccountId::GetGaiaIdKey() const {
108 #ifdef NDEBUG
109 if (gaia_id_.empty())
110 LOG(FATAL) << "GetGaiaIdKey(): no gaia id for " << Serialize();
111
112 #else
101 CHECK(!gaia_id_.empty()); 113 CHECK(!gaia_id_.empty());
114 #endif
115
102 return std::string(kKeyGaiaIdPrefix) + gaia_id_; 116 return std::string(kKeyGaiaIdPrefix) + gaia_id_;
103 } 117 }
104 118
105 void AccountId::SetGaiaId(const std::string& gaia_id) { 119 void AccountId::SetGaiaId(const std::string& gaia_id) {
106 DCHECK(!gaia_id.empty()); 120 DCHECK(!gaia_id.empty());
107 gaia_id_ = gaia_id; 121 gaia_id_ = gaia_id;
108 } 122 }
109 123
110 void AccountId::SetUserEmail(const std::string& email) { 124 void AccountId::SetUserEmail(const std::string& email) {
111 DCHECK(!email.empty()); 125 DCHECK(!email.empty());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return AccountId::EmptyAccountId::GetInstance()->user_id; 189 return AccountId::EmptyAccountId::GetInstance()->user_id;
176 } 190 }
177 191
178 namespace BASE_HASH_NAMESPACE { 192 namespace BASE_HASH_NAMESPACE {
179 193
180 std::size_t hash<AccountId>::operator()(const AccountId& user_id) const { 194 std::size_t hash<AccountId>::operator()(const AccountId& user_id) const {
181 return hash<std::string>()(user_id.GetUserEmail()); 195 return hash<std::string>()(user_id.GetUserEmail());
182 } 196 }
183 197
184 } // namespace BASE_HASH_NAMESPACE 198 } // namespace BASE_HASH_NAMESPACE
OLDNEW
« no previous file with comments | « chromeos/tpm/tpm_token_info_getter_unittest.cc ('k') | components/user_manager/known_user.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698