Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/login_performer.h" | 5 #include "chrome/browser/chromeos/login/login_performer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/boot_times_loader.h" | 16 #include "chrome/browser/chromeos/boot_times_loader.h" |
| 16 #include "chrome/browser/chromeos/cros/cros_library.h" | 17 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 18 #include "chrome/browser/chromeos/cros_settings.h" | |
|
Denis Lagno
2011/09/20 14:05:22
nit: / precedes _ in ASCII order.
pastarmovj
2011/09/20 17:11:52
Done.
| |
| 17 #include "chrome/browser/chromeos/cros/screen_lock_library.h" | 19 #include "chrome/browser/chromeos/cros/screen_lock_library.h" |
| 18 #include "chrome/browser/chromeos/cros_settings_names.h" | 20 #include "chrome/browser/chromeos/cros_settings_names.h" |
| 19 #include "chrome/browser/chromeos/login/login_utils.h" | 21 #include "chrome/browser/chromeos/login/login_utils.h" |
| 20 #include "chrome/browser/chromeos/login/screen_locker.h" | 22 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 21 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | |
| 22 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 28 #include "content/browser/browser_thread.h" | 29 #include "content/browser/browser_thread.h" |
| 29 #include "content/browser/user_metrics.h" | 30 #include "content/browser/user_metrics.h" |
| 30 #include "content/common/content_notification_types.h" | 31 #include "content/common/content_notification_types.h" |
| 31 #include "content/common/notification_service.h" | 32 #include "content/common/notification_service.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 last_login_failure_ = | 220 last_login_failure_ = |
| 220 LoginFailure::FromNetworkAuthFailure(GoogleServiceAuthError( | 221 LoginFailure::FromNetworkAuthFailure(GoogleServiceAuthError( |
| 221 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); | 222 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); |
| 222 password_changed_ = true; | 223 password_changed_ = true; |
| 223 DVLOG(1) << "Password change detected - locking screen."; | 224 DVLOG(1) << "Password change detected - locking screen."; |
| 224 RequestScreenLock(); | 225 RequestScreenLock(); |
| 225 } | 226 } |
| 226 } | 227 } |
| 227 | 228 |
| 228 //////////////////////////////////////////////////////////////////////////////// | 229 //////////////////////////////////////////////////////////////////////////////// |
| 229 // LoginPerformer, SignedSettingsHelper::Callback implementation: | |
| 230 | |
| 231 void LoginPerformer::OnCheckWhitelistCompleted(SignedSettings::ReturnCode code, | |
| 232 const std::string& email) { | |
| 233 if (code == SignedSettings::SUCCESS) { | |
| 234 // Whitelist check passed, continue with authentication. | |
| 235 if (auth_mode_ == AUTH_MODE_EXTENSION) { | |
| 236 StartLoginCompletion(); | |
| 237 } else { | |
| 238 StartAuthentication(); | |
| 239 } | |
| 240 } else { | |
| 241 if (delegate_) | |
| 242 delegate_->WhiteListCheckFailed(email); | |
| 243 else | |
| 244 NOTREACHED(); | |
| 245 } | |
| 246 } | |
| 247 | |
| 248 //////////////////////////////////////////////////////////////////////////////// | |
| 249 // LoginPerformer, NotificationObserver implementation: | 230 // LoginPerformer, NotificationObserver implementation: |
| 250 // | 231 // |
| 251 | 232 |
| 252 void LoginPerformer::Observe(int type, | 233 void LoginPerformer::Observe(int type, |
| 253 const NotificationSource& source, | 234 const NotificationSource& source, |
| 254 const NotificationDetails& details) { | 235 const NotificationDetails& details) { |
| 255 if (type != chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED) | 236 if (type != chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED) |
| 256 return; | 237 return; |
| 257 | 238 |
| 258 bool is_screen_locked = *Details<bool>(details).ptr(); | 239 bool is_screen_locked = *Details<bool>(details).ptr(); |
| 259 if (is_screen_locked) { | 240 if (is_screen_locked) { |
| 260 if (screen_lock_requested_) { | 241 if (screen_lock_requested_) { |
| 261 screen_lock_requested_ = false; | 242 screen_lock_requested_ = false; |
| 262 ResolveScreenLocked(); | 243 ResolveScreenLocked(); |
| 263 } | 244 } |
| 264 } else { | 245 } else { |
| 265 ResolveScreenUnlocked(); | 246 ResolveScreenUnlocked(); |
| 266 } | 247 } |
| 267 } | 248 } |
| 268 | 249 |
| 269 //////////////////////////////////////////////////////////////////////////////// | 250 //////////////////////////////////////////////////////////////////////////////// |
| 270 // LoginPerformer, public: | 251 // LoginPerformer, public: |
| 271 void LoginPerformer::CompleteLogin(const std::string& username, | 252 void LoginPerformer::CompleteLogin(const std::string& username, |
| 272 const std::string& password) { | 253 const std::string& password) { |
| 273 auth_mode_ = AUTH_MODE_EXTENSION; | 254 auth_mode_ = AUTH_MODE_EXTENSION; |
| 274 username_ = username; | 255 username_ = username; |
| 275 password_ = password; | 256 password_ = password; |
| 257 | |
| 258 CrosSettings* cros_settings = CrosSettings::Get(); | |
| 259 | |
| 276 // Whitelist check is always performed during initial login and | 260 // Whitelist check is always performed during initial login and |
| 277 // should not be performed when ScreenLock is active (pending online auth). | 261 // should not be performed when ScreenLock is active (pending online auth). |
| 278 if (!ScreenLocker::default_screen_locker()) { | 262 if (!ScreenLocker::default_screen_locker()) { |
| 279 // Must not proceed without signature verification. | 263 // Must not proceed without signature verification or valid user list. |
| 280 UserCrosSettingsProvider user_settings; | 264 bool trusted_settings_available = |
| 281 bool trusted_setting_available = user_settings.RequestTrustedAllowNewUser( | 265 cros_settings->GetTrusted( |
| 282 method_factory_.NewRunnableMethod(&LoginPerformer::CompleteLogin, | 266 kAccountsPrefAllowNewUser, |
| 283 username, | 267 base::Bind(&LoginPerformer::CompleteLogin, base::Unretained(this), |
|
pastarmovj
2011/09/20 17:11:52
Fixed those too.
| |
| 284 password)); | 268 username, password)) || |
| 285 if (!trusted_setting_available) { | 269 cros_settings->GetTrusted( |
| 270 kAccountsPrefAllowNewUser, | |
| 271 base::Bind(&LoginPerformer::CompleteLogin, base::Unretained(this), | |
| 272 username, password)); | |
| 273 if (!trusted_settings_available) { | |
| 286 // Value of AllowNewUser setting is still not verified. | 274 // Value of AllowNewUser setting is still not verified. |
| 287 // Another attempt will be invoked after verification completion. | 275 // Another attempt will be invoked after verification completion. |
| 288 return; | 276 return; |
| 289 } | 277 } |
| 290 } | 278 } |
| 291 | 279 |
| 292 if (ScreenLocker::default_screen_locker() || | 280 bool allow_new_user = false; |
| 293 UserCrosSettingsProvider::cached_allow_new_user()) { | 281 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 282 if (ScreenLocker::default_screen_locker() || allow_new_user) { | |
| 294 // Starts authentication if guest login is allowed or online auth pending. | 283 // Starts authentication if guest login is allowed or online auth pending. |
| 295 StartLoginCompletion(); | 284 StartLoginCompletion(); |
| 296 } else { | 285 } else { |
| 297 // Otherwise, do whitelist check first. | 286 const ListValue *user_list; |
| 298 PrefService* local_state = g_browser_process->local_state(); | 287 if (cros_settings->GetList(kAccountsPrefUsers, &user_list) && |
| 299 CHECK(local_state); | 288 user_list->Find(StringValue(username)) != user_list->end()) { |
| 300 if (local_state->IsManagedPreference(kAccountsPrefUsers)) { | 289 StartLoginCompletion(); |
| 301 if (UserCrosSettingsProvider::IsEmailInCachedWhitelist(username)) { | |
| 302 StartLoginCompletion(); | |
| 303 } else { | |
| 304 if (delegate_) | |
| 305 delegate_->WhiteListCheckFailed(username); | |
| 306 else | |
| 307 NOTREACHED(); | |
| 308 } | |
| 309 } else { | 290 } else { |
| 310 // In case of signed settings: with current implementation we do not | 291 if (delegate_) |
| 311 // trust whitelist returned by PrefService. So make separate check. | 292 delegate_->WhiteListCheckFailed(username); |
| 312 SignedSettingsHelper::Get()->StartCheckWhitelistOp( | 293 else |
| 313 username, this); | 294 NOTREACHED(); |
| 314 } | 295 } |
| 315 } | 296 } |
| 316 } | 297 } |
| 317 | 298 |
| 318 void LoginPerformer::Login(const std::string& username, | 299 void LoginPerformer::Login(const std::string& username, |
| 319 const std::string& password) { | 300 const std::string& password) { |
| 320 auth_mode_ = AUTH_MODE_INTERNAL; | 301 auth_mode_ = AUTH_MODE_INTERNAL; |
| 321 username_ = username; | 302 username_ = username; |
| 322 password_ = password; | 303 password_ = password; |
| 323 | 304 |
| 305 CrosSettings* cros_settings = CrosSettings::Get(); | |
| 306 | |
| 324 // Whitelist check is always performed during initial login and | 307 // Whitelist check is always performed during initial login and |
| 325 // should not be performed when ScreenLock is active (pending online auth). | 308 // should not be performed when ScreenLock is active (pending online auth). |
| 326 if (!ScreenLocker::default_screen_locker()) { | 309 if (!ScreenLocker::default_screen_locker()) { |
| 327 // Must not proceed without signature verification. | 310 // Must not proceed without signature verification. |
| 328 UserCrosSettingsProvider user_settings; | 311 bool trusted_settings_available = |
| 329 bool trusted_setting_available = user_settings.RequestTrustedAllowNewUser( | 312 cros_settings->GetTrusted( |
| 330 method_factory_.NewRunnableMethod(&LoginPerformer::Login, | 313 kAccountsPrefAllowNewUser, |
| 331 username, | 314 base::Bind(&LoginPerformer::CompleteLogin, base::Unretained(this), |
| 332 password)); | 315 username, password)) || |
| 333 if (!trusted_setting_available) { | 316 cros_settings->GetTrusted( |
| 317 kAccountsPrefAllowNewUser, | |
| 318 base::Bind(&LoginPerformer::CompleteLogin, base::Unretained(this), | |
| 319 username, password)); | |
| 320 if (!trusted_settings_available) { | |
| 334 // Value of AllowNewUser setting is still not verified. | 321 // Value of AllowNewUser setting is still not verified. |
| 335 // Another attempt will be invoked after verification completion. | 322 // Another attempt will be invoked after verification completion. |
| 336 return; | 323 return; |
| 337 } | 324 } |
| 338 } | 325 } |
| 339 | 326 |
| 340 if (ScreenLocker::default_screen_locker() || | 327 bool allow_new_user = false; |
| 341 UserCrosSettingsProvider::cached_allow_new_user()) { | 328 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 329 if (ScreenLocker::default_screen_locker() || allow_new_user) { | |
| 342 // Starts authentication if guest login is allowed or online auth pending. | 330 // Starts authentication if guest login is allowed or online auth pending. |
| 343 StartAuthentication(); | 331 StartAuthentication(); |
| 344 } else { | 332 } else { |
| 345 // Otherwise, do whitelist check first. | 333 const ListValue *user_list; |
| 346 PrefService* local_state = g_browser_process->local_state(); | 334 if (cros_settings->GetList(kAccountsPrefUsers, &user_list) && |
| 347 CHECK(local_state); | 335 user_list->Find(StringValue(username)) != user_list->end()) { |
| 348 if (local_state->IsManagedPreference(kAccountsPrefUsers)) { | 336 StartAuthentication(); |
| 349 if (UserCrosSettingsProvider::IsEmailInCachedWhitelist(username)) { | |
| 350 StartAuthentication(); | |
| 351 } else { | |
| 352 if (delegate_) | |
| 353 delegate_->WhiteListCheckFailed(username); | |
| 354 else | |
| 355 NOTREACHED(); | |
| 356 } | |
| 357 } else { | 337 } else { |
| 358 // In case of signed settings: with current implementation we do not | 338 if (delegate_) |
| 359 // trust whitelist returned by PrefService. So make separate check. | 339 delegate_->WhiteListCheckFailed(username); |
| 360 SignedSettingsHelper::Get()->StartCheckWhitelistOp( | 340 else |
| 361 username, this); | 341 NOTREACHED(); |
| 362 } | 342 } |
| 363 } | 343 } |
| 364 } | 344 } |
| 365 | 345 |
| 366 void LoginPerformer::LoginOffTheRecord() { | 346 void LoginPerformer::LoginOffTheRecord() { |
| 367 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); | 347 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); |
| 368 BrowserThread::PostTask( | 348 BrowserThread::PostTask( |
| 369 BrowserThread::UI, FROM_HERE, | 349 BrowserThread::UI, FROM_HERE, |
| 370 NewRunnableMethod(authenticator_.get(), | 350 NewRunnableMethod(authenticator_.get(), |
| 371 &Authenticator::LoginOffTheRecord)); | 351 &Authenticator::LoginOffTheRecord)); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 profile, | 567 profile, |
| 588 username_, | 568 username_, |
| 589 password_, | 569 password_, |
| 590 captcha_token_, | 570 captcha_token_, |
| 591 captcha_)); | 571 captcha_)); |
| 592 } | 572 } |
| 593 password_.clear(); | 573 password_.clear(); |
| 594 } | 574 } |
| 595 | 575 |
| 596 } // namespace chromeos | 576 } // namespace chromeos |
| OLD | NEW |