OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/user_manager/user_id.h" | |
6 | |
7 #include "base/memory/singleton.h" | |
8 #include "google_apis/gaia/gaia_auth_util.h" | |
9 | |
10 namespace { | |
11 | |
12 struct EmptyUserID { | |
13 EmptyUserID() : user_id(std::string(), std::string()) {} | |
14 const user_manager::UserID user_id; | |
15 | |
16 static EmptyUserID* GetInstance() { | |
17 return Singleton<EmptyUserID>::get(); | |
18 } | |
19 }; | |
20 | |
21 } // anonymous namespace | |
22 | |
23 namespace user_manager { | |
24 | |
25 UserID::UserID(const std::string& gaia_id, const std::string& user_email) : gaia _id_(gaia_id), user_email_(user_email) {} | |
26 | |
27 UserID::UserID(const UserID& other) : gaia_id_(other.gaia_id_), user_email_(othe r.user_email_) {} | |
28 | |
29 bool UserID::operator==(const UserID& other) const { | |
30 return (!gaia_id_.empty() && gaia_id_ == other.gaia_id_) || (!user_email_.empt y() && user_email_ == other.user_email_); | |
Denis Kuznetsov (DE-MUC)
2015/06/10 16:50:44
what if our gaia_id_ is not empty, but other.gaia_
| |
31 } | |
32 | |
33 bool UserID::operator!=(const UserID& other) const { | |
34 return (!gaia_id_.empty() && gaia_id_ == other.gaia_id_) || (!user_email_.empt y() && user_email_ == other.user_email_); | |
35 } | |
36 | |
37 bool UserID::operator<(const UserID& right) const { | |
38 return user_email_ < right.user_email_; | |
Denis Kuznetsov (DE-MUC)
2015/06/10 16:50:44
What if e-mails are both empty, but GaiaIDs are di
| |
39 } | |
40 | |
41 bool UserID::empty() const { | |
42 return gaia_id_.empty() && user_email_.empty(); | |
43 } | |
44 | |
45 void UserID::clear() { | |
46 gaia_id_.clear(); | |
47 user_email_.clear(); | |
48 } | |
49 | |
50 const std::string& UserID::GetGaiaId() const { | |
51 return gaia_id_; | |
52 } | |
53 | |
54 const std::string& UserID::GetUserEmail() const { | |
55 return user_email_; | |
56 } | |
57 | |
58 void UserID::SetGaiaId(const std::string& gaia_id) { | |
59 gaia_id_ = gaia_id; | |
60 } | |
61 | |
62 void UserID::SetUserEmail(const std::string& email) { | |
63 user_email_ = email; | |
64 } | |
65 | |
66 // static | |
67 UserID UserID::FromUserEmail(const std::string& email) { | |
68 return UserID(std::string() /* gaia_id */, email); | |
69 } | |
70 | |
71 // static | |
72 UserID UserID::Deserialize(const std::string& serialized) { | |
73 // If the account_id is an email address, then canonicalize it. | |
74 if (serialized.find('@') != std::string::npos) | |
75 return UserID(std::string() /* gaia_id */, gaia::CanonicalizeEmail(serialize d)); | |
76 | |
77 #ifdef OS_CHROME | |
78 if (serialized == chromeos::login::kLegacyGuestUserName) | |
79 return UserID(std::string() /* gaia_id */, gaia::CanonicalizeEmail(serialize d)); | |
80 #endif | |
81 | |
82 // This will change once UserID will change. | |
83 return UserID(std::string() /* gaia_id */, serialized); | |
84 } | |
85 | |
86 std::string UserID::Serialize() const { | |
87 return user_email_; | |
88 } | |
89 | |
90 const UserID& EmptyUserID() { | |
91 return EmptyUserID::GetInstance()->user_id; | |
92 } | |
93 | |
94 } // namespace user_manager | |
95 | |
96 namespace BASE_HASH_NAMESPACE { | |
97 | |
98 std::size_t | |
99 hash<user_manager::UserID>::operator()(const user_manager::UserID& user_id) cons t { | |
100 return std::hash<std::string>()(user_id.GetUserEmail()); | |
101 } | |
102 | |
103 } // namespace BASE_HASH_NAMESPACE | |
OLD | NEW |