Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 #include "views/screen.h" | 41 #include "views/screen.h" |
| 42 #include "views/widget/widget_gtk.h" | 42 #include "views/widget/widget_gtk.h" |
| 43 #include "views/window/window.h" | 43 #include "views/window/window.h" |
| 44 | 44 |
| 45 namespace chromeos { | 45 namespace chromeos { |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 // Max number of users we'll show. The true max is the min of this and the | 49 // Max number of users we'll show. The true max is the min of this and the |
| 50 // number of windows that fit on the screen. | 50 // number of windows that fit on the screen. |
| 51 const size_t kMaxUsers = 5; | 51 const size_t kMaxUsers = 6; |
| 52 | 52 |
| 53 // Used to indicate no user has been selected. | 53 // Used to indicate no user has been selected. |
| 54 const size_t kNotSelected = -1; | 54 const size_t kNotSelected = -1; |
| 55 | 55 |
| 56 // Offset of cursor in first position from edit left side. It's used to position | 56 // Offset of cursor in first position from edit left side. It's used to position |
| 57 // info bubble arrow to cursor. | 57 // info bubble arrow to cursor. |
| 58 const int kCursorOffset = 5; | 58 const int kCursorOffset = 5; |
| 59 | 59 |
| 60 // Url for setting up sync authentication. | 60 // Url for setting up sync authentication. |
| 61 const char kSettingsSyncLoginUrl[] = "chrome://settings/personal"; | 61 const char kSettingsSyncLoginUrl[] = "chrome://settings/personal"; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 background_window_(NULL), | 124 background_window_(NULL), |
| 125 background_view_(NULL), | 125 background_view_(NULL), |
| 126 selected_view_index_(kNotSelected), | 126 selected_view_index_(kNotSelected), |
| 127 num_login_attempts_(0), | 127 num_login_attempts_(0), |
| 128 bubble_(NULL), | 128 bubble_(NULL), |
| 129 user_settings_(new UserCrosSettingsProvider), | 129 user_settings_(new UserCrosSettingsProvider), |
| 130 method_factory_(this) { | 130 method_factory_(this) { |
| 131 if (delete_scheduled_instance_) | 131 if (delete_scheduled_instance_) |
| 132 delete_scheduled_instance_->Delete(); | 132 delete_scheduled_instance_->Delete(); |
| 133 | 133 |
| 134 // Caclulate the max number of users from available screen size. | 134 // Calculate the max number of users from available screen size. |
| 135 bool show_guest = UserCrosSettingsProvider::cached_allow_guest(); | |
| 136 bool show_new_user = true; | |
| 135 if (UserCrosSettingsProvider::cached_show_users_on_signin()) { | 137 if (UserCrosSettingsProvider::cached_show_users_on_signin()) { |
| 136 size_t max_users = kMaxUsers; | 138 size_t max_users = kMaxUsers; |
| 137 int screen_width = background_bounds.width(); | 139 int screen_width = background_bounds.width(); |
| 138 if (screen_width > 0) { | 140 if (screen_width > 0) { |
| 139 max_users = std::max(static_cast<size_t>(2), std::min(kMaxUsers, | 141 max_users = std::max(static_cast<size_t>(3), std::min(kMaxUsers, |
|
whywhat
2010/12/27 14:28:13
Magic constant?
Dmitry Polukhin
2010/12/27 15:09:36
Done.
| |
| 140 static_cast<size_t>((screen_width - login::kUserImageSize) | 142 static_cast<size_t>((screen_width - login::kUserImageSize) |
|
whywhat
2010/12/27 14:28:13
Could you assign this formula to a separate variab
Dmitry Polukhin
2010/12/27 15:09:36
Done.
| |
| 141 / (UserController::kUnselectedSize + | 143 / (UserController::kUnselectedSize + |
| 142 UserController::kPadding)))); | 144 UserController::kPadding)))); |
| 143 } | 145 } |
| 144 | 146 |
| 145 size_t visible_users_count = std::min(users.size(), max_users - 1); | 147 size_t visible_users_count = std::min(users.size(), max_users - |
| 148 static_cast<int>(show_guest) - static_cast<int>(show_new_user)); | |
| 146 for (size_t i = 0; i < users.size(); ++i) { | 149 for (size_t i = 0; i < users.size(); ++i) { |
| 147 if (controllers_.size() == visible_users_count) | |
| 148 break; | |
| 149 | |
| 150 // TODO(xiyuan): Clean user profile whose email is not in whitelist. | 150 // TODO(xiyuan): Clean user profile whose email is not in whitelist. |
| 151 if (UserCrosSettingsProvider::cached_allow_new_user() || | 151 if (UserCrosSettingsProvider::cached_allow_new_user() || |
| 152 UserCrosSettingsProvider::IsEmailInCachedWhitelist( | 152 UserCrosSettingsProvider::IsEmailInCachedWhitelist( |
| 153 users[i].email())) { | 153 users[i].email())) { |
| 154 controllers_.push_back(new UserController(this, users[i])); | 154 UserController* user_controller = new UserController(this, users[i]); |
| 155 if (controllers_.size() < visible_users_count) | |
| 156 controllers_.push_back(user_controller); | |
| 157 else | |
| 158 invisible_controllers_.push_back(user_controller); | |
| 155 } | 159 } |
| 156 } | 160 } |
| 157 } | 161 } |
| 158 | 162 |
| 159 if (!controllers_.empty() && UserCrosSettingsProvider::cached_allow_guest()) | 163 if (!controllers_.empty() && show_guest) |
| 160 controllers_.push_back(new UserController(this, true)); | 164 controllers_.push_back(new UserController(this, true)); |
| 161 | 165 |
| 162 // Add the view representing the new user. | 166 if (show_new_user) |
| 163 controllers_.push_back(new UserController(this, false)); | 167 controllers_.push_back(new UserController(this, false)); |
| 164 } | 168 } |
| 165 | 169 |
| 166 void ExistingUserController::Init() { | 170 void ExistingUserController::Init() { |
| 167 if (!background_window_) { | 171 if (!background_window_) { |
| 168 std::string url_string = | 172 std::string url_string = |
| 169 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 173 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 170 switches::kScreenSaverUrl); | 174 switches::kScreenSaverUrl); |
| 171 | 175 |
| 172 background_window_ = BackgroundView::CreateWindowContainingView( | 176 background_window_ = BackgroundView::CreateWindowContainingView( |
| 173 background_bounds_, | 177 background_bounds_, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 | 237 |
| 234 ExistingUserController::~ExistingUserController() { | 238 ExistingUserController::~ExistingUserController() { |
| 235 ClearErrors(); | 239 ClearErrors(); |
| 236 | 240 |
| 237 if (background_window_) | 241 if (background_window_) |
| 238 background_window_->Close(); | 242 background_window_->Close(); |
| 239 | 243 |
| 240 WmMessageListener::GetInstance()->RemoveObserver(this); | 244 WmMessageListener::GetInstance()->RemoveObserver(this); |
| 241 | 245 |
| 242 STLDeleteElements(&controllers_); | 246 STLDeleteElements(&controllers_); |
| 247 STLDeleteElements(&invisible_controllers_); | |
| 243 } | 248 } |
| 244 | 249 |
| 245 void ExistingUserController::Delete() { | 250 void ExistingUserController::Delete() { |
| 246 delete_scheduled_instance_ = NULL; | 251 delete_scheduled_instance_ = NULL; |
| 247 delete this; | 252 delete this; |
| 248 } | 253 } |
| 249 | 254 |
| 250 void ExistingUserController::ProcessWmMessage(const WmIpc::Message& message, | 255 void ExistingUserController::ProcessWmMessage(const WmIpc::Message& message, |
| 251 GdkWindow* window) { | 256 GdkWindow* window) { |
| 252 if (message.type() != WM_IPC_MESSAGE_CHROME_CREATE_GUEST_WINDOW) | 257 if (message.type() != WM_IPC_MESSAGE_CHROME_CREATE_GUEST_WINDOW) |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 void ExistingUserController::RemoveUser(UserController* source) { | 371 void ExistingUserController::RemoveUser(UserController* source) { |
| 367 ClearErrors(); | 372 ClearErrors(); |
| 368 | 373 |
| 369 // Owner is not allowed to be removed from the device. | 374 // Owner is not allowed to be removed from the device. |
| 370 // It must be enforced at upper levels. | 375 // It must be enforced at upper levels. |
| 371 DCHECK(user_settings_->RequestTrustedOwner(NULL)); | 376 DCHECK(user_settings_->RequestTrustedOwner(NULL)); |
| 372 DCHECK(source->user().email() != UserCrosSettingsProvider::cached_owner()); | 377 DCHECK(source->user().email() != UserCrosSettingsProvider::cached_owner()); |
| 373 | 378 |
| 374 UserManager::Get()->RemoveUser(source->user().email()); | 379 UserManager::Get()->RemoveUser(source->user().email()); |
| 375 | 380 |
| 381 int removed_user_position = source->user_index(); | |
| 376 controllers_.erase(controllers_.begin() + source->user_index()); | 382 controllers_.erase(controllers_.begin() + source->user_index()); |
| 377 | 383 |
| 378 EnableTooltipsIfNeeded(controllers_); | 384 EnableTooltipsIfNeeded(controllers_); |
| 379 | 385 |
| 380 // Update user count before unmapping windows, otherwise window manager won't | 386 // Update user count before unmapping windows, otherwise window manager won't |
| 381 // be in the right state. | 387 // be in the right state. |
| 382 int new_size = static_cast<int>(controllers_.size()); | 388 int new_size = static_cast<int>(controllers_.size()); |
| 383 for (int i = 0; i < new_size; ++i) | 389 for (int i = 0; i < new_size; ++i) |
| 384 controllers_[i]->UpdateUserCount(i, new_size); | 390 controllers_[i]->UpdateUserCount(i, new_size); |
| 385 | 391 |
| 386 // Delete the encrypted user directory. | 392 // Delete the encrypted user directory. |
| 387 new RemoveAttempt(source->user().email()); | 393 new RemoveAttempt(source->user().email()); |
| 388 // We need to unmap entry windows, the windows will be unmapped in destructor. | 394 // We need to unmap entry windows, the windows will be unmapped in destructor. |
| 389 delete source; | 395 delete source; |
| 396 | |
| 397 // Nothing to insert. | |
| 398 if (invisible_controllers_.empty()) | |
| 399 return; | |
| 400 | |
| 401 // Insert just before guest or add new user pods if any. | |
| 402 int insert_position = new_size; | |
| 403 while (insert_position > 0 && | |
| 404 (controllers_[insert_position - 1]->is_new_user() || | |
| 405 controllers_[insert_position - 1]->is_guest())) | |
| 406 --insert_position; | |
| 407 | |
| 408 controllers_.insert(controllers_.begin() + insert_position, | |
| 409 invisible_controllers_[0]); | |
| 410 invisible_controllers_.erase(invisible_controllers_.begin()); | |
| 411 | |
| 412 // Update counts for exiting pods. | |
| 413 new_size = static_cast<int>(controllers_.size()); | |
| 414 for (int i = 0; i < new_size; ++i) { | |
| 415 if (i != insert_position) | |
| 416 controllers_[i]->UpdateUserCount(i, new_size); | |
| 417 } | |
| 418 | |
| 419 // And initialize new one that was invisible. | |
| 420 controllers_[insert_position]->Init(insert_position, new_size, false); | |
| 421 | |
| 422 EnableTooltipsIfNeeded(controllers_); | |
| 423 | |
| 424 SelectUser(removed_user_position); | |
| 390 } | 425 } |
| 391 | 426 |
| 392 void ExistingUserController::SelectUser(int index) { | 427 void ExistingUserController::SelectUser(int index) { |
| 393 if (index >= 0 && index < static_cast<int>(controllers_.size()) && | 428 if (index >= 0 && index < static_cast<int>(controllers_.size()) && |
| 394 index != static_cast<int>(selected_view_index_)) { | 429 index != static_cast<int>(selected_view_index_)) { |
| 395 WmIpc::Message message(WM_IPC_MESSAGE_WM_SELECT_LOGIN_USER); | 430 WmIpc::Message message(WM_IPC_MESSAGE_WM_SELECT_LOGIN_USER); |
| 396 message.set_param(0, index); | 431 message.set_param(0, index); |
| 397 WmIpc::instance()->SendMessage(message); | 432 WmIpc::instance()->SendMessage(message); |
| 398 } | 433 } |
| 399 } | 434 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 login_performer_->RecoverEncryptedData(old_password); | 659 login_performer_->RecoverEncryptedData(old_password); |
| 625 } | 660 } |
| 626 | 661 |
| 627 void ExistingUserController::ResyncEncryptedData() { | 662 void ExistingUserController::ResyncEncryptedData() { |
| 628 // LoginPerformer instance has state of the user so it should exist. | 663 // LoginPerformer instance has state of the user so it should exist. |
| 629 if (login_performer_.get()) | 664 if (login_performer_.get()) |
| 630 login_performer_->ResyncEncryptedData(); | 665 login_performer_->ResyncEncryptedData(); |
| 631 } | 666 } |
| 632 | 667 |
| 633 } // namespace chromeos | 668 } // namespace chromeos |
| OLD | NEW |