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 |
| 53 // Minimum number of users we'll show (including Guest and New User pods). |
| 54 const size_t kMinUsers = 3; |
52 | 55 |
53 // Used to indicate no user has been selected. | 56 // Used to indicate no user has been selected. |
54 const size_t kNotSelected = -1; | 57 const size_t kNotSelected = -1; |
55 | 58 |
56 // Offset of cursor in first position from edit left side. It's used to position | 59 // Offset of cursor in first position from edit left side. It's used to position |
57 // info bubble arrow to cursor. | 60 // info bubble arrow to cursor. |
58 const int kCursorOffset = 5; | 61 const int kCursorOffset = 5; |
59 | 62 |
60 // Url for setting up sync authentication. | 63 // Url for setting up sync authentication. |
61 const char kSettingsSyncLoginUrl[] = "chrome://settings/personal"; | 64 const char kSettingsSyncLoginUrl[] = "chrome://settings/personal"; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 background_window_(NULL), | 127 background_window_(NULL), |
125 background_view_(NULL), | 128 background_view_(NULL), |
126 selected_view_index_(kNotSelected), | 129 selected_view_index_(kNotSelected), |
127 num_login_attempts_(0), | 130 num_login_attempts_(0), |
128 bubble_(NULL), | 131 bubble_(NULL), |
129 user_settings_(new UserCrosSettingsProvider), | 132 user_settings_(new UserCrosSettingsProvider), |
130 method_factory_(this) { | 133 method_factory_(this) { |
131 if (delete_scheduled_instance_) | 134 if (delete_scheduled_instance_) |
132 delete_scheduled_instance_->Delete(); | 135 delete_scheduled_instance_->Delete(); |
133 | 136 |
134 // Caclulate the max number of users from available screen size. | 137 // Calculate the max number of users from available screen size. |
| 138 bool show_guest = UserCrosSettingsProvider::cached_allow_guest(); |
| 139 bool show_new_user = true; |
135 if (UserCrosSettingsProvider::cached_show_users_on_signin()) { | 140 if (UserCrosSettingsProvider::cached_show_users_on_signin()) { |
136 size_t max_users = kMaxUsers; | 141 size_t max_users = kMaxUsers; |
137 int screen_width = background_bounds.width(); | 142 int screen_width = background_bounds.width(); |
138 if (screen_width > 0) { | 143 if (screen_width > 0) { |
139 max_users = std::max(static_cast<size_t>(2), std::min(kMaxUsers, | 144 size_t users_per_screen = (screen_width - login::kUserImageSize) |
140 static_cast<size_t>((screen_width - login::kUserImageSize) | 145 / (UserController::kUnselectedSize + UserController::kPadding); |
141 / (UserController::kUnselectedSize + | 146 max_users = std::max(kMinUsers, std::min(kMaxUsers, users_per_screen)); |
142 UserController::kPadding)))); | |
143 } | 147 } |
144 | 148 |
145 size_t visible_users_count = std::min(users.size(), max_users - 1); | 149 size_t visible_users_count = std::min(users.size(), max_users - |
| 150 static_cast<int>(show_guest) - static_cast<int>(show_new_user)); |
146 for (size_t i = 0; i < users.size(); ++i) { | 151 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. | 152 // TODO(xiyuan): Clean user profile whose email is not in whitelist. |
151 if (UserCrosSettingsProvider::cached_allow_new_user() || | 153 if (UserCrosSettingsProvider::cached_allow_new_user() || |
152 UserCrosSettingsProvider::IsEmailInCachedWhitelist( | 154 UserCrosSettingsProvider::IsEmailInCachedWhitelist( |
153 users[i].email())) { | 155 users[i].email())) { |
154 controllers_.push_back(new UserController(this, users[i])); | 156 UserController* user_controller = new UserController(this, users[i]); |
| 157 if (controllers_.size() < visible_users_count) |
| 158 controllers_.push_back(user_controller); |
| 159 else |
| 160 invisible_controllers_.push_back(user_controller); |
155 } | 161 } |
156 } | 162 } |
157 } | 163 } |
158 | 164 |
159 if (!controllers_.empty() && UserCrosSettingsProvider::cached_allow_guest()) | 165 if (!controllers_.empty() && show_guest) |
160 controllers_.push_back(new UserController(this, true)); | 166 controllers_.push_back(new UserController(this, true)); |
161 | 167 |
162 // Add the view representing the new user. | 168 if (show_new_user) |
163 controllers_.push_back(new UserController(this, false)); | 169 controllers_.push_back(new UserController(this, false)); |
164 } | 170 } |
165 | 171 |
166 void ExistingUserController::Init() { | 172 void ExistingUserController::Init() { |
167 if (!background_window_) { | 173 if (!background_window_) { |
168 std::string url_string = | 174 std::string url_string = |
169 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 175 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
170 switches::kScreenSaverUrl); | 176 switches::kScreenSaverUrl); |
171 | 177 |
172 background_window_ = BackgroundView::CreateWindowContainingView( | 178 background_window_ = BackgroundView::CreateWindowContainingView( |
173 background_bounds_, | 179 background_bounds_, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 239 |
234 ExistingUserController::~ExistingUserController() { | 240 ExistingUserController::~ExistingUserController() { |
235 ClearErrors(); | 241 ClearErrors(); |
236 | 242 |
237 if (background_window_) | 243 if (background_window_) |
238 background_window_->Close(); | 244 background_window_->Close(); |
239 | 245 |
240 WmMessageListener::GetInstance()->RemoveObserver(this); | 246 WmMessageListener::GetInstance()->RemoveObserver(this); |
241 | 247 |
242 STLDeleteElements(&controllers_); | 248 STLDeleteElements(&controllers_); |
| 249 STLDeleteElements(&invisible_controllers_); |
243 } | 250 } |
244 | 251 |
245 void ExistingUserController::Delete() { | 252 void ExistingUserController::Delete() { |
246 delete_scheduled_instance_ = NULL; | 253 delete_scheduled_instance_ = NULL; |
247 delete this; | 254 delete this; |
248 } | 255 } |
249 | 256 |
250 void ExistingUserController::ProcessWmMessage(const WmIpc::Message& message, | 257 void ExistingUserController::ProcessWmMessage(const WmIpc::Message& message, |
251 GdkWindow* window) { | 258 GdkWindow* window) { |
252 if (message.type() != WM_IPC_MESSAGE_CHROME_CREATE_GUEST_WINDOW) | 259 if (message.type() != WM_IPC_MESSAGE_CHROME_CREATE_GUEST_WINDOW) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 // Update user count before unmapping windows, otherwise window manager won't | 387 // Update user count before unmapping windows, otherwise window manager won't |
381 // be in the right state. | 388 // be in the right state. |
382 int new_size = static_cast<int>(controllers_.size()); | 389 int new_size = static_cast<int>(controllers_.size()); |
383 for (int i = 0; i < new_size; ++i) | 390 for (int i = 0; i < new_size; ++i) |
384 controllers_[i]->UpdateUserCount(i, new_size); | 391 controllers_[i]->UpdateUserCount(i, new_size); |
385 | 392 |
386 // Delete the encrypted user directory. | 393 // Delete the encrypted user directory. |
387 new RemoveAttempt(source->user().email()); | 394 new RemoveAttempt(source->user().email()); |
388 // We need to unmap entry windows, the windows will be unmapped in destructor. | 395 // We need to unmap entry windows, the windows will be unmapped in destructor. |
389 delete source; | 396 delete source; |
| 397 |
| 398 // Nothing to insert. |
| 399 if (invisible_controllers_.empty()) |
| 400 return; |
| 401 |
| 402 // Insert just before guest or add new user pods if any. |
| 403 int insert_position = new_size; |
| 404 while (insert_position > 0 && |
| 405 (controllers_[insert_position - 1]->is_new_user() || |
| 406 controllers_[insert_position - 1]->is_guest())) |
| 407 --insert_position; |
| 408 |
| 409 controllers_.insert(controllers_.begin() + insert_position, |
| 410 invisible_controllers_[0]); |
| 411 invisible_controllers_.erase(invisible_controllers_.begin()); |
| 412 |
| 413 // Update counts for exiting pods. |
| 414 new_size = static_cast<int>(controllers_.size()); |
| 415 for (int i = 0; i < new_size; ++i) { |
| 416 if (i != insert_position) |
| 417 controllers_[i]->UpdateUserCount(i, new_size); |
| 418 } |
| 419 |
| 420 // And initialize new one that was invisible. |
| 421 controllers_[insert_position]->Init(insert_position, new_size, false); |
| 422 |
| 423 EnableTooltipsIfNeeded(controllers_); |
390 } | 424 } |
391 | 425 |
392 void ExistingUserController::SelectUser(int index) { | 426 void ExistingUserController::SelectUser(int index) { |
393 if (index >= 0 && index < static_cast<int>(controllers_.size()) && | 427 if (index >= 0 && index < static_cast<int>(controllers_.size()) && |
394 index != static_cast<int>(selected_view_index_)) { | 428 index != static_cast<int>(selected_view_index_)) { |
395 WmIpc::Message message(WM_IPC_MESSAGE_WM_SELECT_LOGIN_USER); | 429 WmIpc::Message message(WM_IPC_MESSAGE_WM_SELECT_LOGIN_USER); |
396 message.set_param(0, index); | 430 message.set_param(0, index); |
397 WmIpc::instance()->SendMessage(message); | 431 WmIpc::instance()->SendMessage(message); |
398 } | 432 } |
399 } | 433 } |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 login_performer_->RecoverEncryptedData(old_password); | 658 login_performer_->RecoverEncryptedData(old_password); |
625 } | 659 } |
626 | 660 |
627 void ExistingUserController::ResyncEncryptedData() { | 661 void ExistingUserController::ResyncEncryptedData() { |
628 // LoginPerformer instance has state of the user so it should exist. | 662 // LoginPerformer instance has state of the user so it should exist. |
629 if (login_performer_.get()) | 663 if (login_performer_.get()) |
630 login_performer_->ResyncEncryptedData(); | 664 login_performer_->ResyncEncryptedData(); |
631 } | 665 } |
632 | 666 |
633 } // namespace chromeos | 667 } // namespace chromeos |
OLD | NEW |