OLD | NEW |
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 "chrome/browser/chromeos/login/users/user.h" | 5 #include "chrome/browser/chromeos/login/users/user.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| 11 #include "chrome/browser/chromeos/login/helper.h" |
11 #include "chrome/browser/chromeos/login/users/avatar/default_user_images.h" | 12 #include "chrome/browser/chromeos/login/users/avatar/default_user_images.h" |
12 #include "chrome/browser/chromeos/login/users/user_manager.h" | 13 #include "chrome/browser/chromeos/login/users/user_manager.h" |
13 #include "google_apis/gaia/gaia_auth_util.h" | 14 #include "google_apis/gaia/gaia_auth_util.h" |
| 15 #include "google_apis/gaia/gaia_auth_util.h" |
14 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
15 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
16 | 18 |
17 namespace chromeos { | 19 namespace chromeos { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 // Returns account name portion of an email. | 23 // Returns account name portion of an email. |
22 std::string GetUserName(const std::string& email) { | 24 std::string GetUserName(const std::string& email) { |
23 std::string::size_type i = email.find('@'); | 25 std::string::size_type i = email.find('@'); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 explicit PublicAccountUser(const std::string& email); | 102 explicit PublicAccountUser(const std::string& email); |
101 virtual ~PublicAccountUser(); | 103 virtual ~PublicAccountUser(); |
102 | 104 |
103 // Overridden from User: | 105 // Overridden from User: |
104 virtual UserType GetType() const OVERRIDE; | 106 virtual UserType GetType() const OVERRIDE; |
105 | 107 |
106 private: | 108 private: |
107 DISALLOW_COPY_AND_ASSIGN(PublicAccountUser); | 109 DISALLOW_COPY_AND_ASSIGN(PublicAccountUser); |
108 }; | 110 }; |
109 | 111 |
110 UserContext::UserContext() : is_using_oauth_(true), | 112 UserContext::UserContext() : does_need_password_hashing_(true), |
| 113 is_using_oauth_(true), |
111 auth_flow_(AUTH_FLOW_OFFLINE) { | 114 auth_flow_(AUTH_FLOW_OFFLINE) { |
112 } | 115 } |
113 | 116 |
114 UserContext::UserContext(const std::string& user_id, | 117 UserContext::UserContext(const UserContext& other) |
115 const std::string& password, | 118 : user_id_(other.user_id_), |
116 const std::string& auth_code) | 119 password_(other.password_), |
117 : user_id_(user_id), | 120 does_need_password_hashing_(other.does_need_password_hashing_), |
118 password_(password), | 121 key_label_(other.key_label_), |
| 122 auth_code_(other.auth_code_), |
| 123 user_id_hash_(other.user_id_hash_), |
| 124 is_using_oauth_(other.is_using_oauth_), |
| 125 auth_flow_(other.auth_flow_) { |
| 126 } |
| 127 |
| 128 UserContext::UserContext(const std::string& user_id) |
| 129 : user_id_(login::CanonicalizeUserID(user_id)), |
119 does_need_password_hashing_(true), | 130 does_need_password_hashing_(true), |
120 auth_code_(auth_code), | |
121 is_using_oauth_(true), | 131 is_using_oauth_(true), |
122 auth_flow_(AUTH_FLOW_OFFLINE) { | 132 auth_flow_(AUTH_FLOW_OFFLINE) { |
123 } | 133 } |
124 | 134 |
125 UserContext::UserContext(const std::string& user_id, | |
126 const std::string& password, | |
127 const std::string& auth_code, | |
128 const std::string& user_id_hash) | |
129 : user_id_(user_id), | |
130 password_(password), | |
131 does_need_password_hashing_(true), | |
132 auth_code_(auth_code), | |
133 user_id_hash_(user_id_hash), | |
134 is_using_oauth_(true), | |
135 auth_flow_(AUTH_FLOW_OFFLINE) { | |
136 } | |
137 | |
138 UserContext::UserContext(const std::string& user_id, | |
139 const std::string& password, | |
140 const std::string& auth_code, | |
141 const std::string& user_id_hash, | |
142 bool is_using_oauth, | |
143 AuthFlow auth_flow) | |
144 : user_id_(user_id), | |
145 password_(password), | |
146 does_need_password_hashing_(true), | |
147 auth_code_(auth_code), | |
148 user_id_hash_(user_id_hash), | |
149 is_using_oauth_(is_using_oauth), | |
150 auth_flow_(auth_flow) { | |
151 } | |
152 | |
153 UserContext::~UserContext() { | 135 UserContext::~UserContext() { |
154 } | 136 } |
155 | 137 |
156 bool UserContext::operator==(const UserContext& context) const { | 138 bool UserContext::operator==(const UserContext& context) const { |
157 return context.user_id_ == user_id_ && | 139 return context.user_id_ == user_id_ && |
158 context.password_ == password_ && | 140 context.password_ == password_ && |
159 context.does_need_password_hashing_ == does_need_password_hashing_ && | 141 context.does_need_password_hashing_ == does_need_password_hashing_ && |
160 context.key_label_ == key_label_ && | 142 context.key_label_ == key_label_ && |
161 context.auth_code_ == auth_code_ && | 143 context.auth_code_ == auth_code_ && |
162 context.user_id_hash_ == user_id_hash_ && | 144 context.user_id_hash_ == user_id_hash_ && |
163 context.is_using_oauth_ == is_using_oauth_ && | 145 context.is_using_oauth_ == is_using_oauth_ && |
164 context.auth_flow_ == auth_flow_; | 146 context.auth_flow_ == auth_flow_; |
165 } | 147 } |
166 | 148 |
167 void UserContext::CopyFrom(const UserContext& other) { | |
168 user_id_ = other.user_id_; | |
169 password_ = other.password_; | |
170 does_need_password_hashing_ = other.does_need_password_hashing_; | |
171 key_label_ = other.key_label_; | |
172 auth_code_ = other.auth_code_; | |
173 user_id_hash_ = other.user_id_hash_; | |
174 is_using_oauth_ = other.is_using_oauth_; | |
175 auth_flow_ = other.auth_flow_; | |
176 } | |
177 | |
178 const std::string& UserContext::GetUserID() const { | 149 const std::string& UserContext::GetUserID() const { |
179 return user_id_; | 150 return user_id_; |
180 } | 151 } |
181 | 152 |
182 const std::string& UserContext::GetPassword() const { | 153 const std::string& UserContext::GetPassword() const { |
183 return password_; | 154 return password_; |
184 } | 155 } |
185 | 156 |
186 bool UserContext::DoesNeedPasswordHashing() const { | 157 bool UserContext::DoesNeedPasswordHashing() const { |
187 return does_need_password_hashing_; | 158 return does_need_password_hashing_; |
(...skipping 17 matching lines...) Expand all Loading... |
205 | 176 |
206 UserContext::AuthFlow UserContext::GetAuthFlow() const { | 177 UserContext::AuthFlow UserContext::GetAuthFlow() const { |
207 return auth_flow_; | 178 return auth_flow_; |
208 } | 179 } |
209 | 180 |
210 bool UserContext::HasCredentials() const { | 181 bool UserContext::HasCredentials() const { |
211 return (!user_id_.empty() && !password_.empty()) || !auth_code_.empty(); | 182 return (!user_id_.empty() && !password_.empty()) || !auth_code_.empty(); |
212 } | 183 } |
213 | 184 |
214 void UserContext::SetUserID(const std::string& user_id) { | 185 void UserContext::SetUserID(const std::string& user_id) { |
215 user_id_ = user_id; | 186 user_id_ = login::CanonicalizeUserID(user_id); |
216 } | 187 } |
217 | 188 |
218 void UserContext::SetPassword(const std::string& password) { | 189 void UserContext::SetPassword(const std::string& password) { |
219 password_ = password; | 190 password_ = password; |
220 } | 191 } |
221 | 192 |
222 void UserContext::SetDoesNeedPasswordHashing(bool does_need_password_hashing) { | 193 void UserContext::SetDoesNeedPasswordHashing(bool does_need_password_hashing) { |
223 does_need_password_hashing_ = does_need_password_hashing; | 194 does_need_password_hashing_ = does_need_password_hashing; |
224 } | 195 } |
225 | 196 |
226 void UserContext::SetKeyLabel(const std::string& key_label) { | 197 void UserContext::SetKeyLabel(const std::string& key_label) { |
227 key_label_ = key_label; | 198 key_label_ = key_label; |
228 } | 199 } |
229 | 200 |
230 void UserContext::SetAuthCode(const std::string& auth_code) { | 201 void UserContext::SetAuthCode(const std::string& auth_code) { |
231 auth_code_ = auth_code; | 202 auth_code_ = auth_code; |
232 } | 203 } |
233 | 204 |
234 void UserContext::SetUserIDHash(const std::string& user_id_hash) { | 205 void UserContext::SetUserIDHash(const std::string& user_id_hash) { |
235 user_id_hash_ = user_id_hash; | 206 user_id_hash_ = user_id_hash; |
236 } | 207 } |
237 | 208 |
238 void UserContext::SetIsUsingOAuth(bool is_using_oauth) { | 209 void UserContext::SetIsUsingOAuth(bool is_using_oauth) { |
239 is_using_oauth_ = is_using_oauth; | 210 is_using_oauth_ = is_using_oauth; |
240 } | 211 } |
241 | 212 |
| 213 void UserContext::SetAuthFlow(AuthFlow auth_flow) { |
| 214 auth_flow_ = auth_flow; |
| 215 } |
| 216 |
| 217 void UserContext::ClearSecrets() { |
| 218 password_.clear(); |
| 219 auth_code_.clear(); |
| 220 } |
| 221 |
242 std::string User::GetEmail() const { | 222 std::string User::GetEmail() const { |
243 return display_email(); | 223 return display_email(); |
244 } | 224 } |
245 | 225 |
246 base::string16 User::GetDisplayName() const { | 226 base::string16 User::GetDisplayName() const { |
247 // Fallback to the email account name in case display name haven't been set. | 227 // Fallback to the email account name in case display name haven't been set. |
248 return display_name_.empty() ? | 228 return display_name_.empty() ? |
249 base::UTF8ToUTF16(GetAccountName(true)) : | 229 base::UTF8ToUTF16(GetAccountName(true)) : |
250 display_name_; | 230 display_name_; |
251 } | 231 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 case USER_TYPE_LOCALLY_MANAGED: | 422 case USER_TYPE_LOCALLY_MANAGED: |
443 case USER_TYPE_KIOSK_APP: | 423 case USER_TYPE_KIOSK_APP: |
444 return false; | 424 return false; |
445 default: | 425 default: |
446 NOTREACHED(); | 426 NOTREACHED(); |
447 } | 427 } |
448 return false; | 428 return false; |
449 } | 429 } |
450 | 430 |
451 } // namespace chromeos | 431 } // namespace chromeos |
OLD | NEW |