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

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: Better condition in LOG_ASSERT in AccountId. Created 4 years, 10 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
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return AccountId::EmptyAccountId::GetInstance()->user_id; 182 return AccountId::EmptyAccountId::GetInstance()->user_id;
176 } 183 }
177 184
178 namespace BASE_HASH_NAMESPACE { 185 namespace BASE_HASH_NAMESPACE {
179 186
180 std::size_t hash<AccountId>::operator()(const AccountId& user_id) const { 187 std::size_t hash<AccountId>::operator()(const AccountId& user_id) const {
181 return hash<std::string>()(user_id.GetUserEmail()); 188 return hash<std::string>()(user_id.GetUserEmail());
182 } 189 }
183 190
184 } // namespace BASE_HASH_NAMESPACE 191 } // namespace BASE_HASH_NAMESPACE
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698