Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: chrome/browser/chromeos/login/existing_user_controller.cc

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

Powered by Google App Engine
This is Rietveld 408576698