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/existing_user_controller.h" | 5 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
9 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/chromeos/boot_times_loader.h" | 15 #include "chrome/browser/chromeos/boot_times_loader.h" |
| 16 #include "chrome/browser/chromeos/cros_settings.h" |
15 #include "chrome/browser/chromeos/cros/cros_library.h" | 17 #include "chrome/browser/chromeos/cros/cros_library.h" |
16 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 18 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
17 #include "chrome/browser/chromeos/cros/login_library.h" | 19 #include "chrome/browser/chromeos/cros/login_library.h" |
18 #include "chrome/browser/chromeos/cros/network_library.h" | 20 #include "chrome/browser/chromeos/cros/network_library.h" |
19 #include "chrome/browser/chromeos/customization_document.h" | 21 #include "chrome/browser/chromeos/customization_document.h" |
20 #include "chrome/browser/chromeos/login/helper.h" | 22 #include "chrome/browser/chromeos/login/helper.h" |
21 #include "chrome/browser/chromeos/login/login_display_host.h" | 23 #include "chrome/browser/chromeos/login/login_display_host.h" |
22 #include "chrome/browser/chromeos/login/views_login_display.h" | 24 #include "chrome/browser/chromeos/login/views_login_display.h" |
23 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" | 25 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" |
24 #include "chrome/browser/chromeos/login/wizard_controller.h" | 26 #include "chrome/browser/chromeos/login/wizard_controller.h" |
25 #include "chrome/browser/chromeos/status/status_area_view.h" | 27 #include "chrome/browser/chromeos/status/status_area_view.h" |
26 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | |
27 #include "chrome/browser/google/google_util.h" | 28 #include "chrome/browser/google/google_util.h" |
28 #include "chrome/browser/prefs/pref_service.h" | 29 #include "chrome/browser/prefs/pref_service.h" |
29 #include "chrome/browser/profiles/profile_manager.h" | 30 #include "chrome/browser/profiles/profile_manager.h" |
30 #include "chrome/browser/ui/views/window.h" | 31 #include "chrome/browser/ui/views/window.h" |
31 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/common/net/gaia/google_service_auth_error.h" | 34 #include "chrome/common/net/gaia/google_service_auth_error.h" |
34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
35 #include "content/common/content_notification_types.h" | 36 #include "content/common/content_notification_types.h" |
36 #include "content/common/notification_service.h" | 37 #include "content/common/notification_service.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // static | 71 // static |
71 ExistingUserController* ExistingUserController::current_controller_ = NULL; | 72 ExistingUserController* ExistingUserController::current_controller_ = NULL; |
72 | 73 |
73 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
74 // ExistingUserController, public: | 75 // ExistingUserController, public: |
75 | 76 |
76 ExistingUserController::ExistingUserController(LoginDisplayHost* host) | 77 ExistingUserController::ExistingUserController(LoginDisplayHost* host) |
77 : login_status_consumer_(NULL), | 78 : login_status_consumer_(NULL), |
78 host_(host), | 79 host_(host), |
79 num_login_attempts_(0), | 80 num_login_attempts_(0), |
80 user_settings_(new UserCrosSettingsProvider), | 81 user_settings_(CrosSettings::Get()), |
81 method_factory_(this), | 82 pointer_factory_(this), |
82 is_owner_login_(false) { | 83 is_owner_login_(false) { |
83 DCHECK(current_controller_ == NULL); | 84 DCHECK(current_controller_ == NULL); |
84 current_controller_ = this; | 85 current_controller_ = this; |
85 | 86 |
86 login_display_ = host_->CreateLoginDisplay(this); | 87 login_display_ = host_->CreateLoginDisplay(this); |
87 | 88 |
88 registrar_.Add(this, | 89 registrar_.Add(this, |
89 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 90 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
90 NotificationService::AllSources()); | 91 NotificationService::AllSources()); |
91 } | 92 } |
92 | 93 |
93 void ExistingUserController::Init(const UserVector& users) { | 94 void ExistingUserController::Init(const UserVector& users) { |
94 UserVector filtered_users; | 95 UserVector filtered_users; |
95 if (UserCrosSettingsProvider::cached_show_users_on_signin()) { | 96 bool show_users_on_signin; |
96 for (size_t i = 0; i < users.size(); ++i) | 97 |
| 98 // TODO(pastarmovj): Make this class an observer of the CrosSettings to be |
| 99 // able to update the UI whenever policy is loaded. |
| 100 user_settings_->GetBoolean(kAccountsPrefShowUserNamesOnSignIn, |
| 101 &show_users_on_signin); |
| 102 if (show_users_on_signin) { |
| 103 bool allow_new_user = false; |
| 104 const ListValue *user_list; |
| 105 user_settings_->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 106 user_settings_->GetList(kAccountsPrefUsers, &user_list); |
| 107 for (size_t i = 0; i < users.size(); ++i) { |
97 // TODO(xiyuan): Clean user profile whose email is not in whitelist. | 108 // TODO(xiyuan): Clean user profile whose email is not in whitelist. |
98 if (UserCrosSettingsProvider::cached_allow_new_user() || | 109 if (allow_new_user || |
99 UserCrosSettingsProvider::IsEmailInCachedWhitelist( | 110 user_list->Find(StringValue(users[i].email())) != user_list->end()) { |
100 users[i].email())) { | |
101 filtered_users.push_back(users[i]); | 111 filtered_users.push_back(users[i]); |
102 } | 112 } |
| 113 } |
103 } | 114 } |
104 | 115 |
105 // If no user pods are visible, fallback to single new user pod which will | 116 // If no user pods are visible, fallback to single new user pod which will |
106 // have guest session link. | 117 // have guest session link. |
107 bool show_guest = UserCrosSettingsProvider::cached_allow_guest() && | 118 bool show_guest; |
108 !filtered_users.empty(); | 119 user_settings_->GetBoolean(kAccountsPrefAllowGuest, &show_guest); |
| 120 show_guest &= !filtered_users.empty(); |
109 bool show_new_user = true; | 121 bool show_new_user = true; |
110 login_display_->set_parent_window(GetNativeWindow()); | 122 login_display_->set_parent_window(GetNativeWindow()); |
111 login_display_->Init(filtered_users, show_guest, show_new_user); | 123 login_display_->Init(filtered_users, show_guest, show_new_user); |
112 | 124 |
113 LoginUtils::Get()->PrewarmAuthentication(); | 125 LoginUtils::Get()->PrewarmAuthentication(); |
114 if (CrosLibrary::Get()->EnsureLoaded()) | 126 if (CrosLibrary::Get()->EnsureLoaded()) |
115 CrosLibrary::Get()->GetLoginLibrary()->EmitLoginPromptReady(); | 127 CrosLibrary::Get()->GetLoginLibrary()->EmitLoginPromptReady(); |
116 StartAutomaticFreeDiskSpaceControl(); | 128 StartAutomaticFreeDiskSpaceControl(); |
117 } | 129 } |
118 | 130 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 false, true); | 234 false, true); |
223 } | 235 } |
224 | 236 |
225 void ExistingUserController::LoginAsGuest() { | 237 void ExistingUserController::LoginAsGuest() { |
226 SetStatusAreaEnabled(false); | 238 SetStatusAreaEnabled(false); |
227 // Disable clicking on other windows. | 239 // Disable clicking on other windows. |
228 login_display_->SetUIEnabled(false); | 240 login_display_->SetUIEnabled(false); |
229 | 241 |
230 // Check allow_guest in case this call is fired from key accelerator. | 242 // Check allow_guest in case this call is fired from key accelerator. |
231 // Must not proceed without signature verification. | 243 // Must not proceed without signature verification. |
232 bool trusted_setting_available = user_settings_->RequestTrustedAllowGuest( | 244 bool trusted_setting_available = user_settings_->GetTrusted( |
233 method_factory_.NewRunnableMethod( | 245 kAccountsPrefAllowGuest, |
234 &ExistingUserController::LoginAsGuest)); | 246 base::Bind(&ExistingUserController::LoginAsGuest, |
| 247 pointer_factory_.GetWeakPtr())); |
235 if (!trusted_setting_available) { | 248 if (!trusted_setting_available) { |
236 // Value of AllowGuest setting is still not verified. | 249 // Value of AllowGuest setting is still not verified. |
237 // Another attempt will be invoked again after verification completion. | 250 // Another attempt will be invoked again after verification completion. |
238 return; | 251 return; |
239 } | 252 } |
240 if (!UserCrosSettingsProvider::cached_allow_guest()) { | 253 bool allow_guest; |
| 254 user_settings_->GetBoolean(kAccountsPrefAllowGuest, &allow_guest); |
| 255 if (!allow_guest) { |
241 // Disallowed. | 256 // Disallowed. |
242 return; | 257 return; |
243 } | 258 } |
244 | 259 |
245 // Only one instance of LoginPerformer should exist at a time. | 260 // Only one instance of LoginPerformer should exist at a time. |
246 login_performer_.reset(NULL); | 261 login_performer_.reset(NULL); |
247 login_performer_.reset(new LoginPerformer(this)); | 262 login_performer_.reset(new LoginPerformer(this)); |
248 login_performer_->LoginOffTheRecord(); | 263 login_performer_->LoginOffTheRecord(); |
249 WizardAccessibilityHelper::GetInstance()->MaybeSpeak( | 264 WizardAccessibilityHelper::GetInstance()->MaybeSpeak( |
250 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNIN_OFFRECORD).c_str(), | 265 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNIN_OFFRECORD).c_str(), |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED, error); | 334 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED, error); |
320 } else if ((active_network && active_network->restricted_pool()) || | 335 } else if ((active_network && active_network->restricted_pool()) || |
321 (failure.reason() == LoginFailure::NETWORK_AUTH_FAILED && | 336 (failure.reason() == LoginFailure::NETWORK_AUTH_FAILED && |
322 failure.error().state() == | 337 failure.error().state() == |
323 GoogleServiceAuthError::SERVICE_UNAVAILABLE)) { | 338 GoogleServiceAuthError::SERVICE_UNAVAILABLE)) { |
324 // Use explicit captive portal state (restricted_pool()) or implicit one. | 339 // Use explicit captive portal state (restricted_pool()) or implicit one. |
325 // SERVICE_UNAVAILABLE is generated in 2 cases: | 340 // SERVICE_UNAVAILABLE is generated in 2 cases: |
326 // 1. ClientLogin returns ServiceUnavailable code. | 341 // 1. ClientLogin returns ServiceUnavailable code. |
327 // 2. Internet connectivity may be behind the captive portal. | 342 // 2. Internet connectivity may be behind the captive portal. |
328 // Suggesting user to try sign in to a portal in Guest mode. | 343 // Suggesting user to try sign in to a portal in Guest mode. |
329 if (UserCrosSettingsProvider::cached_allow_guest()) | 344 bool allow_guest; |
| 345 user_settings_->GetBoolean(kAccountsPrefAllowGuest, &allow_guest); |
| 346 if (allow_guest) |
330 ShowError(IDS_LOGIN_ERROR_CAPTIVE_PORTAL, error); | 347 ShowError(IDS_LOGIN_ERROR_CAPTIVE_PORTAL, error); |
331 else | 348 else |
332 ShowError(IDS_LOGIN_ERROR_CAPTIVE_PORTAL_NO_GUEST_MODE, error); | 349 ShowError(IDS_LOGIN_ERROR_CAPTIVE_PORTAL_NO_GUEST_MODE, error); |
333 } else { | 350 } else { |
334 if (!is_known_user) | 351 if (!is_known_user) |
335 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_NEW, error); | 352 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_NEW, error); |
336 else | 353 else |
337 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING, error); | 354 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING, error); |
338 } | 355 } |
339 } | 356 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 ActivateWizard(WizardController::kRegistrationScreenName); | 474 ActivateWizard(WizardController::kRegistrationScreenName); |
458 } | 475 } |
459 | 476 |
460 if (login_status_consumer_) | 477 if (login_status_consumer_) |
461 login_status_consumer_->OnOffTheRecordLoginSuccess(); | 478 login_status_consumer_->OnOffTheRecordLoginSuccess(); |
462 } | 479 } |
463 | 480 |
464 void ExistingUserController::OnPasswordChangeDetected( | 481 void ExistingUserController::OnPasswordChangeDetected( |
465 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 482 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
466 // Must not proceed without signature verification. | 483 // Must not proceed without signature verification. |
467 bool trusted_setting_available = user_settings_->RequestTrustedOwner( | 484 bool trusted_setting_available = user_settings_->GetTrusted( |
468 method_factory_.NewRunnableMethod( | 485 kDeviceOwner, |
469 &ExistingUserController::OnPasswordChangeDetected, | 486 base::Bind(&ExistingUserController::OnPasswordChangeDetected, |
470 credentials)); | 487 pointer_factory_.GetWeakPtr(), |
| 488 credentials)); |
471 if (!trusted_setting_available) { | 489 if (!trusted_setting_available) { |
472 // Value of owner email is still not verified. | 490 // Value of owner email is still not verified. |
473 // Another attempt will be invoked after verification completion. | 491 // Another attempt will be invoked after verification completion. |
474 return; | 492 return; |
475 } | 493 } |
476 | 494 |
477 // Passing 'false' here enables "full sync" mode in the dialog, | 495 // Passing 'false' here enables "full sync" mode in the dialog, |
478 // which disables the requirement for the old owner password, | 496 // which disables the requirement for the old owner password, |
479 // allowing us to recover from a lost owner password/homedir. | 497 // allowing us to recover from a lost owner password/homedir. |
480 // TODO(gspencer): We shouldn't have to erase stateful data when | 498 // TODO(gspencer): We shouldn't have to erase stateful data when |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 help_topic_id = login_performer_->login_timed_out() ? | 581 help_topic_id = login_performer_->login_timed_out() ? |
564 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT_OFFLINE : | 582 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT_OFFLINE : |
565 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT; | 583 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT; |
566 break; | 584 break; |
567 } | 585 } |
568 | 586 |
569 login_display_->ShowError(error_id, num_login_attempts_, help_topic_id); | 587 login_display_->ShowError(error_id, num_login_attempts_, help_topic_id); |
570 } | 588 } |
571 | 589 |
572 void ExistingUserController::StartAutomaticFreeDiskSpaceControl() { | 590 void ExistingUserController::StartAutomaticFreeDiskSpaceControl() { |
573 bool trusted_owner_available = user_settings_->RequestTrustedOwner( | 591 bool trusted_owner_available = user_settings_->GetTrusted( |
574 method_factory_.NewRunnableMethod( | 592 kDeviceOwner, |
575 &ExistingUserController::StartAutomaticFreeDiskSpaceControl)); | 593 base::Bind(&ExistingUserController::StartAutomaticFreeDiskSpaceControl, |
| 594 pointer_factory_.GetWeakPtr())); |
576 if (!trusted_owner_available) { | 595 if (!trusted_owner_available) { |
577 // Value of owner email is still not verified. | 596 // Value of owner email is still not verified. |
578 // Another attempt will be invoked after verification completion. | 597 // Another attempt will be invoked after verification completion. |
579 return; | 598 return; |
580 } | 599 } |
581 if (CrosLibrary::Get()->EnsureLoaded()) { | 600 if (CrosLibrary::Get()->EnsureLoaded()) { |
582 CryptohomeLibrary* cryptohomed = CrosLibrary::Get()->GetCryptohomeLibrary(); | 601 CryptohomeLibrary* cryptohomed = CrosLibrary::Get()->GetCryptohomeLibrary(); |
583 cryptohomed->AsyncSetOwnerUser( | 602 std::string owner; |
584 UserCrosSettingsProvider::cached_owner(), NULL); | 603 user_settings_->GetString(kDeviceOwner, &owner); |
| 604 cryptohomed->AsyncSetOwnerUser(owner, NULL); |
585 cryptohomed->AsyncDoAutomaticFreeDiskSpaceControl(NULL); | 605 cryptohomed->AsyncDoAutomaticFreeDiskSpaceControl(NULL); |
586 } | 606 } |
587 } | 607 } |
588 | 608 |
589 } // namespace chromeos | 609 } // namespace chromeos |
OLD | NEW |