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/lock/screen_locker.h" | 5 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } // namespace | 129 } // namespace |
130 | 130 |
131 // static | 131 // static |
132 ScreenLocker* ScreenLocker::screen_locker_ = NULL; | 132 ScreenLocker* ScreenLocker::screen_locker_ = NULL; |
133 | 133 |
134 ////////////////////////////////////////////////////////////////////////////// | 134 ////////////////////////////////////////////////////////////////////////////// |
135 // ScreenLocker, public: | 135 // ScreenLocker, public: |
136 | 136 |
137 ScreenLocker::ScreenLocker(const user_manager::UserList& users) | 137 ScreenLocker::ScreenLocker(const user_manager::UserList& users) |
138 : users_(users), | 138 : users_(users), |
139 locked_(false), | |
140 start_time_(base::Time::Now()), | |
141 auth_status_consumer_(NULL), | |
142 incorrect_passwords_count_(0), | |
143 weak_factory_(this) { | 139 weak_factory_(this) { |
144 DCHECK(!screen_locker_); | 140 DCHECK(!screen_locker_); |
145 screen_locker_ = this; | 141 screen_locker_ = this; |
146 | 142 |
147 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 143 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
148 media::SoundsManager* manager = media::SoundsManager::Get(); | 144 media::SoundsManager* manager = media::SoundsManager::Get(); |
149 manager->Initialize(SOUND_LOCK, | 145 manager->Initialize(SOUND_LOCK, |
150 bundle.GetRawDataResource(IDR_SOUND_LOCK_WAV)); | 146 bundle.GetRawDataResource(IDR_SOUND_LOCK_WAV)); |
151 manager->Initialize(SOUND_UNLOCK, | 147 manager->Initialize(SOUND_UNLOCK, |
152 bundle.GetRawDataResource(IDR_SOUND_UNLOCK_WAV)); | 148 bundle.GetRawDataResource(IDR_SOUND_UNLOCK_WAV)); |
(...skipping 29 matching lines...) Expand all Loading... |
182 void ScreenLocker::OnAuthFailure(const AuthFailure& error) { | 178 void ScreenLocker::OnAuthFailure(const AuthFailure& error) { |
183 content::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); | 179 content::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); |
184 if (authentication_start_time_.is_null()) { | 180 if (authentication_start_time_.is_null()) { |
185 LOG(ERROR) << "Start time is not set at authentication failure"; | 181 LOG(ERROR) << "Start time is not set at authentication failure"; |
186 } else { | 182 } else { |
187 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; | 183 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; |
188 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)"; | 184 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)"; |
189 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); | 185 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); |
190 } | 186 } |
191 | 187 |
| 188 UMA_HISTOGRAM_ENUMERATION( |
| 189 "ScreenLocker.AuthenticationFailure", |
| 190 is_pin_attempt_ ? UnlockType::AUTH_PIN : UnlockType::AUTH_PASSWORD, |
| 191 UnlockType::AUTH_COUNT); |
| 192 |
192 EnableInput(); | 193 EnableInput(); |
193 // Don't enable signout button here as we're showing | 194 // Don't enable signout button here as we're showing |
194 // MessageBubble. | 195 // MessageBubble. |
195 | 196 |
196 delegate_->ShowErrorMessage(incorrect_passwords_count_++ ? | 197 delegate_->ShowErrorMessage(incorrect_passwords_count_++ ? |
197 IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME : | 198 IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME : |
198 IDS_LOGIN_ERROR_AUTHENTICATING, | 199 IDS_LOGIN_ERROR_AUTHENTICATING, |
199 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); | 200 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); |
200 | 201 |
201 if (auth_status_consumer_) | 202 if (auth_status_consumer_) |
202 auth_status_consumer_->OnAuthFailure(error); | 203 auth_status_consumer_->OnAuthFailure(error); |
203 } | 204 } |
204 | 205 |
205 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { | 206 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { |
206 incorrect_passwords_count_ = 0; | 207 incorrect_passwords_count_ = 0; |
207 if (authentication_start_time_.is_null()) { | 208 if (authentication_start_time_.is_null()) { |
208 if (user_context.GetAccountId().is_valid()) | 209 if (user_context.GetAccountId().is_valid()) |
209 LOG(ERROR) << "Start time is not set at authentication success"; | 210 LOG(ERROR) << "Start time is not set at authentication success"; |
210 } else { | 211 } else { |
211 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; | 212 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; |
212 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; | 213 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; |
213 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationSuccessTime", delta); | 214 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationSuccessTime", delta); |
214 } | 215 } |
215 | 216 |
| 217 UMA_HISTOGRAM_ENUMERATION( |
| 218 "ScreenLocker.AuthenticationSuccess", |
| 219 is_pin_attempt_ ? UnlockType::AUTH_PIN : UnlockType::AUTH_PASSWORD, |
| 220 UnlockType::AUTH_COUNT); |
| 221 |
216 const user_manager::User* user = | 222 const user_manager::User* user = |
217 user_manager::UserManager::Get()->FindUser(user_context.GetAccountId()); | 223 user_manager::UserManager::Get()->FindUser(user_context.GetAccountId()); |
218 if (user) { | 224 if (user) { |
219 if (!user->is_active()) { | 225 if (!user->is_active()) { |
220 saved_ime_state_ = NULL; | 226 saved_ime_state_ = NULL; |
221 user_manager::UserManager::Get()->SwitchActiveUser( | 227 user_manager::UserManager::Get()->SwitchActiveUser( |
222 user_context.GetAccountId()); | 228 user_context.GetAccountId()); |
223 } | 229 } |
224 | 230 |
225 // Reset the number of PIN attempts available to the user. We always do this | 231 // Reset the number of PIN attempts available to the user. We always do this |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 chromeos::ScreenLocker::Hide(); | 282 chromeos::ScreenLocker::Hide(); |
277 } | 283 } |
278 | 284 |
279 void ScreenLocker::Authenticate(const UserContext& user_context) { | 285 void ScreenLocker::Authenticate(const UserContext& user_context) { |
280 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId())) | 286 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId())) |
281 << "Invalid user trying to unlock."; | 287 << "Invalid user trying to unlock."; |
282 | 288 |
283 authentication_start_time_ = base::Time::Now(); | 289 authentication_start_time_ = base::Time::Now(); |
284 delegate_->SetInputEnabled(false); | 290 delegate_->SetInputEnabled(false); |
285 delegate_->OnAuthenticate(); | 291 delegate_->OnAuthenticate(); |
| 292 is_pin_attempt_ = user_context.IsUsingPin(); |
286 | 293 |
287 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId()); | 294 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId()); |
288 if (user) { | 295 if (user) { |
289 // Check to see if the user submitted a PIN and it is valid. | 296 // Check to see if the user submitted a PIN and it is valid. |
290 const std::string pin = user_context.GetKey()->GetSecret(); | 297 const std::string pin = user_context.GetKey()->GetSecret(); |
291 | 298 |
292 // We only want to try authenticating the pin if it is a number, | 299 // We only want to try authenticating the pin if it is a number, |
293 // otherwise we will timeout PIN if the user enters their account password | 300 // otherwise we will timeout PIN if the user enters their account password |
294 // incorrectly more than a few times. | 301 // incorrectly more than a few times. |
295 int dummy_value; | 302 int dummy_value; |
296 if (base::StringToInt(pin, &dummy_value)) { | 303 if (is_pin_attempt_ && base::StringToInt(pin, &dummy_value)) { |
297 chromeos::PinStorage* pin_storage = | 304 chromeos::PinStorage* pin_storage = |
298 chromeos::PinStorageFactory::GetForUser(user); | 305 chromeos::PinStorageFactory::GetForUser(user); |
299 if (pin_storage && pin_storage->TryAuthenticatePin(pin)) { | 306 if (pin_storage && pin_storage->TryAuthenticatePin(pin)) { |
300 OnAuthSuccess(user_context); | 307 OnAuthSuccess(user_context); |
301 return; | 308 return; |
302 } | 309 } |
303 } | 310 } |
304 | 311 |
305 // Special case: supervised users. Use special authenticator. | 312 // Special case: supervised users. Use special authenticator. |
306 if (user->GetType() == user_manager::USER_TYPE_SUPERVISED) { | 313 if (user->GetType() == user_manager::USER_TYPE_SUPERVISED) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 547 |
541 bool ScreenLocker::IsUserLoggedIn(const AccountId& account_id) const { | 548 bool ScreenLocker::IsUserLoggedIn(const AccountId& account_id) const { |
542 for (user_manager::User* user : users_) { | 549 for (user_manager::User* user : users_) { |
543 if (user->GetAccountId() == account_id) | 550 if (user->GetAccountId() == account_id) |
544 return true; | 551 return true; |
545 } | 552 } |
546 return false; | 553 return false; |
547 } | 554 } |
548 | 555 |
549 } // namespace chromeos | 556 } // namespace chromeos |
OLD | NEW |