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/helper.h" |
12 #include "chrome/browser/chromeos/login/users/avatar/default_user_images.h" | 12 #include "chrome/browser/chromeos/login/users/avatar/default_user_images.h" |
13 #include "chrome/browser/chromeos/login/users/user_manager.h" | 13 #include "chrome/browser/chromeos/login/users/user_manager.h" |
14 #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" | |
16 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
17 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
18 | 17 |
19 namespace chromeos { | 18 namespace chromeos { |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 // Returns account name portion of an email. | 22 // Returns account name portion of an email. |
24 std::string GetUserName(const std::string& email) { | 23 std::string GetUserName(const std::string& email) { |
25 std::string::size_type i = email.find('@'); | 24 std::string::size_type i = email.find('@'); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 explicit PublicAccountUser(const std::string& email); | 101 explicit PublicAccountUser(const std::string& email); |
103 virtual ~PublicAccountUser(); | 102 virtual ~PublicAccountUser(); |
104 | 103 |
105 // Overridden from User: | 104 // Overridden from User: |
106 virtual UserType GetType() const OVERRIDE; | 105 virtual UserType GetType() const OVERRIDE; |
107 | 106 |
108 private: | 107 private: |
109 DISALLOW_COPY_AND_ASSIGN(PublicAccountUser); | 108 DISALLOW_COPY_AND_ASSIGN(PublicAccountUser); |
110 }; | 109 }; |
111 | 110 |
112 UserContext::UserContext() : does_need_password_hashing_(true), | |
113 is_using_oauth_(true), | |
114 auth_flow_(AUTH_FLOW_OFFLINE) { | |
115 } | |
116 | |
117 UserContext::UserContext(const UserContext& other) | |
118 : user_id_(other.user_id_), | |
119 password_(other.password_), | |
120 does_need_password_hashing_(other.does_need_password_hashing_), | |
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)), | |
130 does_need_password_hashing_(true), | |
131 is_using_oauth_(true), | |
132 auth_flow_(AUTH_FLOW_OFFLINE) { | |
133 } | |
134 | |
135 UserContext::~UserContext() { | |
136 } | |
137 | |
138 bool UserContext::operator==(const UserContext& context) const { | |
139 return context.user_id_ == user_id_ && | |
140 context.password_ == password_ && | |
141 context.does_need_password_hashing_ == does_need_password_hashing_ && | |
142 context.key_label_ == key_label_ && | |
143 context.auth_code_ == auth_code_ && | |
144 context.user_id_hash_ == user_id_hash_ && | |
145 context.is_using_oauth_ == is_using_oauth_ && | |
146 context.auth_flow_ == auth_flow_; | |
147 } | |
148 | |
149 const std::string& UserContext::GetUserID() const { | |
150 return user_id_; | |
151 } | |
152 | |
153 const std::string& UserContext::GetPassword() const { | |
154 return password_; | |
155 } | |
156 | |
157 bool UserContext::DoesNeedPasswordHashing() const { | |
158 return does_need_password_hashing_; | |
159 } | |
160 | |
161 const std::string& UserContext::GetKeyLabel() const { | |
162 return key_label_; | |
163 } | |
164 | |
165 const std::string& UserContext::GetAuthCode() const { | |
166 return auth_code_; | |
167 } | |
168 | |
169 const std::string& UserContext::GetUserIDHash() const { | |
170 return user_id_hash_; | |
171 } | |
172 | |
173 bool UserContext::IsUsingOAuth() const { | |
174 return is_using_oauth_; | |
175 } | |
176 | |
177 UserContext::AuthFlow UserContext::GetAuthFlow() const { | |
178 return auth_flow_; | |
179 } | |
180 | |
181 bool UserContext::HasCredentials() const { | |
182 return (!user_id_.empty() && !password_.empty()) || !auth_code_.empty(); | |
183 } | |
184 | |
185 void UserContext::SetUserID(const std::string& user_id) { | |
186 user_id_ = login::CanonicalizeUserID(user_id); | |
187 } | |
188 | |
189 void UserContext::SetPassword(const std::string& password) { | |
190 password_ = password; | |
191 } | |
192 | |
193 void UserContext::SetDoesNeedPasswordHashing(bool does_need_password_hashing) { | |
194 does_need_password_hashing_ = does_need_password_hashing; | |
195 } | |
196 | |
197 void UserContext::SetKeyLabel(const std::string& key_label) { | |
198 key_label_ = key_label; | |
199 } | |
200 | |
201 void UserContext::SetAuthCode(const std::string& auth_code) { | |
202 auth_code_ = auth_code; | |
203 } | |
204 | |
205 void UserContext::SetUserIDHash(const std::string& user_id_hash) { | |
206 user_id_hash_ = user_id_hash; | |
207 } | |
208 | |
209 void UserContext::SetIsUsingOAuth(bool is_using_oauth) { | |
210 is_using_oauth_ = is_using_oauth; | |
211 } | |
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 | |
222 std::string User::GetEmail() const { | 111 std::string User::GetEmail() const { |
223 return display_email(); | 112 return display_email(); |
224 } | 113 } |
225 | 114 |
226 base::string16 User::GetDisplayName() const { | 115 base::string16 User::GetDisplayName() const { |
227 // Fallback to the email account name in case display name haven't been set. | 116 // Fallback to the email account name in case display name haven't been set. |
228 return display_name_.empty() ? | 117 return display_name_.empty() ? |
229 base::UTF8ToUTF16(GetAccountName(true)) : | 118 base::UTF8ToUTF16(GetAccountName(true)) : |
230 display_name_; | 119 display_name_; |
231 } | 120 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 case USER_TYPE_LOCALLY_MANAGED: | 311 case USER_TYPE_LOCALLY_MANAGED: |
423 case USER_TYPE_KIOSK_APP: | 312 case USER_TYPE_KIOSK_APP: |
424 return false; | 313 return false; |
425 default: | 314 default: |
426 NOTREACHED(); | 315 NOTREACHED(); |
427 } | 316 } |
428 return false; | 317 return false; |
429 } | 318 } |
430 | 319 |
431 } // namespace chromeos | 320 } // namespace chromeos |
OLD | NEW |