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