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

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

Issue 2529103002: Add account_type into AccountId (Closed)
Patch Set: Fix MultiUserWindowManagerChromeOSTest.* Created 4 years 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 #ifndef COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ 5 #ifndef COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_
6 #define COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ 6 #define COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 12
13 enum class AccountType { UNKNOWN, GOOGLE, ACTIVE_DIRECTORY };
14
13 // Type that contains enough information to identify user. 15 // Type that contains enough information to identify user.
14 // 16 //
15 // TODO(alemate): we are in the process of moving away from std::string as a 17 // TODO(alemate): we are in the process of moving away from std::string as a
16 // type for storing user identifier to AccountId. At this time GaiaId is mostly 18 // type for storing user identifier to AccountId. At this time GaiaId is mostly
17 // empty, so this type is used as a replacement for e-mail string. 19 // empty, so this type is used as a replacement for e-mail string.
18 // But in near future AccountId will become full feature user identifier. 20 // But in near future AccountId will become full feature user identifier.
19 class AccountId { 21 class AccountId {
20 public: 22 public:
21 struct EmptyAccountId; 23 struct EmptyAccountId;
22 24
23 AccountId(const AccountId& other); 25 AccountId(const AccountId& other);
24 26
25 bool operator==(const AccountId& other) const; 27 bool operator==(const AccountId& other) const;
26 bool operator!=(const AccountId& other) const; 28 bool operator!=(const AccountId& other) const;
27 bool operator<(const AccountId& right) const; 29 bool operator<(const AccountId& right) const;
28 30
29 // empty() is deprecated. Use !is_valid() instead. 31 // empty() is deprecated. Use !is_valid() instead.
30 bool empty() const; 32 bool empty() const;
31 bool is_valid() const; 33 bool is_valid() const;
32 void clear(); 34 void clear();
33 35
34 const std::string& GetAccountType() const; 36 const AccountType& GetAccountType() const;
Roger Tawa OOO till Jul 10th 2016/12/05 16:34:31 Is there reason to keep this as a const &? I woul
Alexander Alekseev 2016/12/06 02:21:14 The reason was "it's better to return a reference
Roger Tawa OOO till Jul 10th 2016/12/07 22:09:37 My 2 cents: given C++11 move semantics and return
Roman Sorokin (ftl) 2016/12/13 13:45:59 Done.
Roman Sorokin (ftl) 2016/12/13 13:45:59 Done.
35 const std::string& GetGaiaId() const; 37 const std::string& GetGaiaId() const;
36 // Users of AccountId should make no assumptions on the format of email. 38 // Users of AccountId should make no assumptions on the format of email.
37 // I.e. it cannot be used as account identifier, because it is (in general) 39 // I.e. it cannot be used as account identifier, because it is (in general)
38 // non-comparable. 40 // non-comparable.
39 const std::string& GetUserEmail() const; 41 const std::string& GetUserEmail() const;
40 42
41 // This returns prefixed some string that can be used as a storage key. 43 // This returns prefixed some string that can be used as a storage key.
42 // You should make no assumptions on the format of this string. 44 // You should make no assumptions on the format of this string.
43 const std::string GetAccountIdKey() const; 45 const std::string GetAccountIdKey() const;
44 46
45 void SetGaiaId(const std::string& gaia_id); 47 void SetGaiaId(const std::string& gaia_id);
46 void SetUserEmail(const std::string& email); 48 void SetUserEmail(const std::string& email);
49 void SetAccountType(const AccountType& account_type);
47 50
48 // This method is to be used during transition period only. 51 // This method is to be used during transition period only.
49 static AccountId FromUserEmail(const std::string& user_email); 52 static AccountId FromUserEmail(const std::string& user_email);
50 // This method is to be used during transition period only. 53 // This method is to be used during transition period only.
51 static AccountId FromGaiaId(const std::string& gaia_id); 54 static AccountId FromGaiaId(const std::string& gaia_id);
52 // This method is the preferred way to construct AccountId if you have 55 // This method is the preferred way to construct AccountId if you have
53 // full account information. 56 // full account information.
54 static AccountId FromUserEmailGaiaId(const std::string& user_email, 57 static AccountId FromUserEmailGaiaId(const std::string& user_email,
55 const std::string& gaia_id); 58 const std::string& gaia_id);
59 // This method is used to construct AccountId with specific types.
60 static AccountId FromUserEmailGaiaIdAccountType(
61 const std::string& email,
62 const std::string& gaia_id,
63 const AccountType& account_type);
64 static AccountId FromGaiaIdAccountType(const std::string& gaia_id,
65 const AccountType& account_type);
66
67 // Translation functions between AccountType and std::string. Used for
68 // serialization.
69 static AccountType StringToAccountType(
70 const std::string& account_type_string);
71 static std::string AccountTypeToString(const AccountType& account_type);
56 72
57 // These are (for now) unstable and cannot be used to store serialized data to 73 // These are (for now) unstable and cannot be used to store serialized data to
58 // persistent storage. Only in-memory storage is safe. 74 // persistent storage. Only in-memory storage is safe.
59 // Serialize() returns JSON dictionary, 75 // Serialize() returns JSON dictionary,
60 // Deserialize() restores AccountId after serialization. 76 // Deserialize() restores AccountId after serialization.
61 std::string Serialize() const; 77 std::string Serialize() const;
62 static bool Deserialize(const std::string& serialized, 78 static bool Deserialize(const std::string& serialized,
63 AccountId* out_account_id); 79 AccountId* out_account_id);
64 80
65 private: 81 private:
66 AccountId(); 82 AccountId();
67 AccountId(const std::string& gaia_id, const std::string& user_email); 83 AccountId(const std::string& gaia_id, const std::string& user_email);
84 AccountId(const std::string& gaia_id,
85 const std::string& user_email,
86 const AccountType& account_type);
68 87
69 std::string gaia_id_; 88 std::string gaia_id_;
70 std::string user_email_; 89 std::string user_email_;
90 AccountType account_type_ = AccountType::GOOGLE;
71 }; 91 };
72 92
73 // Returns a reference to a singleton. 93 // Returns a reference to a singleton.
74 const AccountId& EmptyAccountId(); 94 const AccountId& EmptyAccountId();
75 95
76 namespace BASE_HASH_NAMESPACE { 96 namespace BASE_HASH_NAMESPACE {
77 97
78 // Implement hashing of AccountId, so it can be used as a key in STL containers. 98 // Implement hashing of AccountId, so it can be used as a key in STL containers.
79 template <> 99 template <>
80 struct hash<AccountId> { 100 struct hash<AccountId> {
81 std::size_t operator()(const AccountId& user_id) const; 101 std::size_t operator()(const AccountId& user_id) const;
82 }; 102 };
83 103
84 } // namespace BASE_HASH_NAMESPACE 104 } // namespace BASE_HASH_NAMESPACE
85 105
86 #endif // COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ 106 #endif // COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698