Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/existing_user_controller.h" | 5 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 ShowEnrollmentScreen(true, username); | 328 ShowEnrollmentScreen(true, username); |
| 329 } else { | 329 } else { |
| 330 CompleteLoginInternal(username, password); | 330 CompleteLoginInternal(username, password); |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 void ExistingUserController::CompleteLoginInternal(std::string username, | 334 void ExistingUserController::CompleteLoginInternal(std::string username, |
| 335 std::string password) { | 335 std::string password) { |
| 336 resume_login_callback_.Reset(); | 336 resume_login_callback_.Reset(); |
| 337 | 337 |
| 338 if (!login_performer_.get()) { | 338 DeviceSettingsService::Get()->GetOwnershipStatusAsync( |
| 339 LoginPerformer::Delegate* delegate = this; | 339 base::Bind(&ExistingUserController::PerformLogin, |
| 340 if (login_performer_delegate_.get()) | 340 weak_factory_.GetWeakPtr(), username, password, |
| 341 delegate = login_performer_delegate_.get(); | 341 LoginPerformer::AUTH_MODE_EXTENSION)); |
| 342 // Only one instance of LoginPerformer should exist at a time. | |
| 343 login_performer_.reset(new LoginPerformer(delegate)); | |
| 344 } | |
| 345 | |
| 346 // If the device is not owned yet, successfully logged in user will be owner. | |
| 347 is_owner_login_ = OwnershipService::GetSharedInstance()->GetStatus(true) == | |
| 348 OwnershipService::OWNERSHIP_NONE; | |
| 349 | |
| 350 is_login_in_progress_ = true; | |
| 351 login_performer_->CompleteLogin(username, password); | |
| 352 accessibility::MaybeSpeak( | |
| 353 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNING_IN)); | |
| 354 } | 342 } |
| 355 | 343 |
| 356 void ExistingUserController::Login(const std::string& username, | 344 void ExistingUserController::Login(const std::string& username, |
| 357 const std::string& password) { | 345 const std::string& password) { |
| 358 if (username.empty() || password.empty()) | 346 if (username.empty() || password.empty()) |
| 359 return; | 347 return; |
| 360 // Disable clicking on other windows. | 348 // Disable clicking on other windows. |
| 361 login_display_->SetUIEnabled(false); | 349 login_display_->SetUIEnabled(false); |
| 362 | 350 |
| 363 // If the device is not owned yet, successfully logged in user will be owner. | |
| 364 is_owner_login_ = OwnershipService::GetSharedInstance()->GetStatus(true) == | |
| 365 OwnershipService::OWNERSHIP_NONE; | |
| 366 | |
| 367 BootTimesLoader::Get()->RecordLoginAttempted(); | 351 BootTimesLoader::Get()->RecordLoginAttempted(); |
| 368 | 352 |
| 369 if (last_login_attempt_username_ != username) { | 353 if (last_login_attempt_username_ != username) { |
| 370 last_login_attempt_username_ = username; | 354 last_login_attempt_username_ = username; |
| 371 num_login_attempts_ = 0; | 355 num_login_attempts_ = 0; |
| 372 // Also reset state variables, which are used to determine password change. | 356 // Also reset state variables, which are used to determine password change. |
| 373 offline_failed_ = false; | 357 offline_failed_ = false; |
| 374 online_succeeded_for_.clear(); | 358 online_succeeded_for_.clear(); |
| 375 } | 359 } |
| 376 num_login_attempts_++; | 360 num_login_attempts_++; |
| 377 | 361 |
| 362 DeviceSettingsService::Get()->GetOwnershipStatusAsync( | |
| 363 base::Bind(&ExistingUserController::PerformLogin, | |
| 364 weak_factory_.GetWeakPtr(), username, password, | |
| 365 LoginPerformer::AUTH_MODE_INTERNAL)); | |
| 366 } | |
| 367 | |
| 368 void ExistingUserController::PerformLogin( | |
| 369 const std::string& username, | |
| 370 const std::string& password, | |
| 371 LoginPerformer::AuthorizationMode auth_mode, | |
| 372 DeviceSettingsService::OwnershipStatus ownership_status, | |
| 373 bool is_owner) { | |
| 374 // If the device is not owned yet, successfully logged in user will be owner. | |
| 375 is_owner_login_ = ownership_status == DeviceSettingsService::OWNERSHIP_NONE; | |
| 376 | |
| 378 // Use the same LoginPerformer for subsequent login as it has state | 377 // Use the same LoginPerformer for subsequent login as it has state |
| 379 // such as Authenticator instance. | 378 // such as Authenticator instance. |
| 380 if (!login_performer_.get() || num_login_attempts_ <= 1) { | 379 if (!login_performer_.get() || num_login_attempts_ <= 1) { |
|
Mattias Nissler (ping if slow)
2012/08/06 21:38:00
Nikita, are you OK with folding the common parts o
Nikita (slow)
2012/08/08 10:50:02
num_login_attempts_ is reset to 0 when new user st
| |
| 381 LoginPerformer::Delegate* delegate = this; | 380 LoginPerformer::Delegate* delegate = this; |
| 382 if (login_performer_delegate_.get()) | 381 if (login_performer_delegate_.get()) |
| 383 delegate = login_performer_delegate_.get(); | 382 delegate = login_performer_delegate_.get(); |
| 384 // Only one instance of LoginPerformer should exist at a time. | 383 // Only one instance of LoginPerformer should exist at a time. |
| 385 login_performer_.reset(NULL); | 384 login_performer_.reset(NULL); |
| 386 login_performer_.reset(new LoginPerformer(delegate)); | 385 login_performer_.reset(new LoginPerformer(delegate)); |
| 387 } | 386 } |
| 387 | |
| 388 is_login_in_progress_ = true; | 388 is_login_in_progress_ = true; |
| 389 login_performer_->Login(username, password); | 389 login_performer_->PerformLogin(username, password, auth_mode); |
| 390 accessibility::MaybeSpeak( | 390 accessibility::MaybeSpeak( |
| 391 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNING_IN)); | 391 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNING_IN)); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void ExistingUserController::LoginAsDemoUser() { | 394 void ExistingUserController::LoginAsDemoUser() { |
| 395 // Disable clicking on other windows. | 395 // Disable clicking on other windows. |
| 396 login_display_->SetUIEnabled(false); | 396 login_display_->SetUIEnabled(false); |
| 397 // TODO(rkc): Add a CHECK to make sure demo logins are allowed once | 397 // TODO(rkc): Add a CHECK to make sure demo logins are allowed once |
| 398 // the enterprise policy wiring is done for kiosk mode. | 398 // the enterprise policy wiring is done for kiosk mode. |
| 399 | 399 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 } | 456 } |
| 457 | 457 |
| 458 void ExistingUserController::OnUserSelected(const std::string& username) { | 458 void ExistingUserController::OnUserSelected(const std::string& username) { |
| 459 login_performer_.reset(NULL); | 459 login_performer_.reset(NULL); |
| 460 num_login_attempts_ = 0; | 460 num_login_attempts_ = 0; |
| 461 } | 461 } |
| 462 | 462 |
| 463 void ExistingUserController::OnStartEnterpriseEnrollment() { | 463 void ExistingUserController::OnStartEnterpriseEnrollment() { |
| 464 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 464 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 465 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) { | 465 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) { |
| 466 OwnershipService::GetSharedInstance()->GetStatusAsync( | 466 DeviceSettingsService::Get()->GetOwnershipStatusAsync( |
| 467 base::Bind(&ExistingUserController::OnEnrollmentOwnershipCheckCompleted, | 467 base::Bind(&ExistingUserController::OnEnrollmentOwnershipCheckCompleted, |
| 468 weak_factory_.GetWeakPtr())); | 468 weak_factory_.GetWeakPtr())); |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 | 471 |
| 472 void ExistingUserController::OnEnrollmentOwnershipCheckCompleted( | 472 void ExistingUserController::OnEnrollmentOwnershipCheckCompleted( |
| 473 OwnershipService::Status status, | 473 DeviceSettingsService::OwnershipStatus status, |
| 474 bool current_user_is_owner) { | 474 bool current_user_is_owner) { |
| 475 if (status == OwnershipService::OWNERSHIP_NONE) { | 475 if (status == DeviceSettingsService::OWNERSHIP_NONE) { |
| 476 ShowEnrollmentScreen(false, std::string()); | 476 ShowEnrollmentScreen(false, std::string()); |
| 477 } else if (status == OwnershipService::OWNERSHIP_TAKEN) { | 477 } else if (status == DeviceSettingsService::OWNERSHIP_TAKEN) { |
| 478 // On a device that is already owned we might want to allow users to | 478 // On a device that is already owned we might want to allow users to |
| 479 // re-enroll if the policy information is invalid. | 479 // re-enroll if the policy information is invalid. |
| 480 CrosSettingsProvider::TrustedStatus trusted_status = | 480 CrosSettingsProvider::TrustedStatus trusted_status = |
| 481 CrosSettings::Get()->PrepareTrustedValues( | 481 CrosSettings::Get()->PrepareTrustedValues( |
| 482 base::Bind( | 482 base::Bind( |
| 483 &ExistingUserController::OnEnrollmentOwnershipCheckCompleted, | 483 &ExistingUserController::OnEnrollmentOwnershipCheckCompleted, |
| 484 weak_factory_.GetWeakPtr(), status, current_user_is_owner)); | 484 weak_factory_.GetWeakPtr(), status, current_user_is_owner)); |
| 485 if (trusted_status == CrosSettingsProvider::PERMANENTLY_UNTRUSTED) | 485 if (trusted_status == CrosSettingsProvider::PERMANENTLY_UNTRUSTED) |
| 486 ShowEnrollmentScreen(false, std::string()); | 486 ShowEnrollmentScreen(false, std::string()); |
| 487 } else { | 487 } else { |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 920 // Invalidate OAuth token, since it can't be correct after password is | 920 // Invalidate OAuth token, since it can't be correct after password is |
| 921 // changed. | 921 // changed. |
| 922 UserManager::Get()->SaveUserOAuthStatus(username, | 922 UserManager::Get()->SaveUserOAuthStatus(username, |
| 923 User::OAUTH_TOKEN_STATUS_INVALID); | 923 User::OAUTH_TOKEN_STATUS_INVALID); |
| 924 | 924 |
| 925 login_display_->SetUIEnabled(true); | 925 login_display_->SetUIEnabled(true); |
| 926 login_display_->ShowGaiaPasswordChanged(username); | 926 login_display_->ShowGaiaPasswordChanged(username); |
| 927 } | 927 } |
| 928 | 928 |
| 929 } // namespace chromeos | 929 } // namespace chromeos |
| OLD | NEW |