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

Side by Side Diff: chromeos/login/auth/user_context.cc

Issue 1412813003: This CL replaces user_manager::UserID with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@468875--Chrome-OS-handles-deletion-of-Gmail-account-poorly--Create-AccountID-structure-part2--user_names
Patch Set: Update after review. Created 5 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chromeos/login/auth/user_context.h" 5 #include "chromeos/login/auth/user_context.h"
6 #include "chromeos/login/user_names.h" 6 #include "chromeos/login/user_names.h"
7 7
8 namespace chromeos { 8 namespace chromeos {
9 9
10 UserContext::UserContext() 10 UserContext::UserContext()
11 : is_using_oauth_(true), 11 : account_id_(EmptyAccountId()),
achuithb 2015/10/28 23:11:46 I think you can still use in-class member initiali
Alexander Alekseev 2015/10/29 02:00:42 I mean that adding a new constructor here without
12 is_using_oauth_(true),
12 auth_flow_(AUTH_FLOW_OFFLINE), 13 auth_flow_(AUTH_FLOW_OFFLINE),
13 user_type_(user_manager::USER_TYPE_REGULAR) { 14 user_type_(user_manager::USER_TYPE_REGULAR) {}
14 }
15 15
16 UserContext::UserContext(const UserContext& other) 16 UserContext::UserContext(const UserContext& other)
17 : user_id_(other.user_id_), 17 : account_id_(other.account_id_),
18 gaia_id_(other.gaia_id_), 18 gaia_id_(other.gaia_id_),
19 key_(other.key_), 19 key_(other.key_),
20 auth_code_(other.auth_code_), 20 auth_code_(other.auth_code_),
21 refresh_token_(other.refresh_token_), 21 refresh_token_(other.refresh_token_),
22 access_token_(other.access_token_), 22 access_token_(other.access_token_),
23 user_id_hash_(other.user_id_hash_), 23 user_id_hash_(other.user_id_hash_),
24 is_using_oauth_(other.is_using_oauth_), 24 is_using_oauth_(other.is_using_oauth_),
25 auth_flow_(other.auth_flow_), 25 auth_flow_(other.auth_flow_),
26 user_type_(other.user_type_), 26 user_type_(other.user_type_),
27 public_session_locale_(other.public_session_locale_), 27 public_session_locale_(other.public_session_locale_),
28 public_session_input_method_(other.public_session_input_method_), 28 public_session_input_method_(other.public_session_input_method_),
29 device_id_(other.device_id_), 29 device_id_(other.device_id_),
30 gaps_cookie_(other.gaps_cookie_) { 30 gaps_cookie_(other.gaps_cookie_) {}
31 }
32 31
33 UserContext::UserContext(const std::string& user_id) 32 UserContext::UserContext(const AccountId& account_id)
34 : user_id_(login::CanonicalizeUserID(user_id)), 33 : account_id_(account_id),
35 is_using_oauth_(true), 34 is_using_oauth_(true),
36 auth_flow_(AUTH_FLOW_OFFLINE), 35 auth_flow_(AUTH_FLOW_OFFLINE),
37 user_type_(user_manager::USER_TYPE_REGULAR) { 36 user_type_(user_manager::USER_TYPE_REGULAR) {
37 account_id_.SetUserEmail(
38 login::CanonicalizeUserID(account_id.GetUserEmail()));
38 } 39 }
39 40
40 UserContext::UserContext(user_manager::UserType user_type, 41 UserContext::UserContext(user_manager::UserType user_type,
41 const std::string& user_id) 42 const std::string& user_id)
42 : is_using_oauth_(true), 43 : account_id_(EmptyAccountId()),
44 is_using_oauth_(true),
43 auth_flow_(AUTH_FLOW_OFFLINE), 45 auth_flow_(AUTH_FLOW_OFFLINE),
44 user_type_(user_type) { 46 user_type_(user_type) {
45 if (user_type_ == user_manager::USER_TYPE_REGULAR) 47 if (user_type_ == user_manager::USER_TYPE_REGULAR)
46 user_id_ = login::CanonicalizeUserID(user_id); 48 account_id_ = AccountId::FromUserEmail(login::CanonicalizeUserID(user_id));
47 else 49 else
48 user_id_ = user_id; 50 account_id_ = AccountId::FromUserEmail(user_id);
49 } 51 }
50 52
51 UserContext::~UserContext() { 53 UserContext::~UserContext() {
52 } 54 }
53 55
54 bool UserContext::operator==(const UserContext& context) const { 56 bool UserContext::operator==(const UserContext& context) const {
55 return context.user_id_ == user_id_ && context.gaia_id_ == gaia_id_ && 57 return context.account_id_ == account_id_ && context.gaia_id_ == gaia_id_ &&
56 context.key_ == key_ && context.auth_code_ == auth_code_ && 58 context.key_ == key_ && context.auth_code_ == auth_code_ &&
57 context.refresh_token_ == refresh_token_ && 59 context.refresh_token_ == refresh_token_ &&
58 context.access_token_ == access_token_ && 60 context.access_token_ == access_token_ &&
59 context.user_id_hash_ == user_id_hash_ && 61 context.user_id_hash_ == user_id_hash_ &&
60 context.is_using_oauth_ == is_using_oauth_ && 62 context.is_using_oauth_ == is_using_oauth_ &&
61 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_ && 63 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_ &&
62 context.public_session_locale_ == public_session_locale_ && 64 context.public_session_locale_ == public_session_locale_ &&
63 context.public_session_input_method_ == public_session_input_method_; 65 context.public_session_input_method_ == public_session_input_method_;
64 } 66 }
65 67
66 bool UserContext::operator!=(const UserContext& context) const { 68 bool UserContext::operator!=(const UserContext& context) const {
67 return !(*this == context); 69 return !(*this == context);
68 } 70 }
69 71
70 const std::string& UserContext::GetUserID() const { 72 const AccountId& UserContext::GetAccountId() const {
71 return user_id_; 73 return account_id_;
72 } 74 }
73 75
74 const std::string& UserContext::GetGaiaID() const { 76 const std::string& UserContext::GetGaiaID() const {
75 return gaia_id_; 77 return gaia_id_;
76 } 78 }
77 79
78 const Key* UserContext::GetKey() const { 80 const Key* UserContext::GetKey() const {
79 return &key_; 81 return &key_;
80 } 82 }
81 83
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 123
122 const std::string& UserContext::GetDeviceId() const { 124 const std::string& UserContext::GetDeviceId() const {
123 return device_id_; 125 return device_id_;
124 } 126 }
125 127
126 const std::string& UserContext::GetGAPSCookie() const { 128 const std::string& UserContext::GetGAPSCookie() const {
127 return gaps_cookie_; 129 return gaps_cookie_;
128 } 130 }
129 131
130 bool UserContext::HasCredentials() const { 132 bool UserContext::HasCredentials() const {
131 return (!user_id_.empty() && !key_.GetSecret().empty()) || 133 return (account_id_.is_valid() && !key_.GetSecret().empty()) ||
132 !auth_code_.empty(); 134 !auth_code_.empty();
133 } 135 }
134 136
135 void UserContext::SetUserID(const std::string& user_id) { 137 void UserContext::SetUserID(const std::string& user_id) {
achuithb 2015/10/28 23:11:46 Why not SetAccountId instead?
Alexander Alekseev 2015/10/29 02:00:42 Because this CL is limited to UserManager API.
136 user_id_ = login::CanonicalizeUserID(user_id); 138 account_id_ = AccountId::FromUserEmail(login::CanonicalizeUserID(user_id));
137 } 139 }
138 140
139 void UserContext::SetGaiaID(const std::string& gaia_id) { 141 void UserContext::SetGaiaID(const std::string& gaia_id) {
140 gaia_id_ = gaia_id; 142 gaia_id_ = gaia_id;
141 } 143 }
142 144
143 void UserContext::SetKey(const Key& key) { 145 void UserContext::SetKey(const Key& key) {
144 key_ = key; 146 key_ = key;
145 } 147 }
146 148
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 gaps_cookie_ = gaps_cookie; 190 gaps_cookie_ = gaps_cookie;
189 } 191 }
190 192
191 void UserContext::ClearSecrets() { 193 void UserContext::ClearSecrets() {
192 key_.ClearSecret(); 194 key_.ClearSecret();
193 auth_code_.clear(); 195 auth_code_.clear();
194 refresh_token_.clear(); 196 refresh_token_.clear();
195 } 197 }
196 198
197 } // namespace chromeos 199 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698