user_chooser_detailed_view_controller.cc 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/system/unified/user_chooser_detailed_view_controller.h"
  5. #include "ash/multi_profile_uma.h"
  6. #include "ash/session/session_controller_impl.h"
  7. #include "ash/shell.h"
  8. #include "ash/strings/grit/ash_strings.h"
  9. #include "ash/system/unified/unified_system_tray_controller.h"
  10. #include "ash/system/unified/user_chooser_view.h"
  11. #include "components/user_manager/user_type.h"
  12. #include "ui/base/l10n/l10n_util.h"
  13. namespace ash {
  14. UserChooserDetailedViewController::UserChooserDetailedViewController(
  15. UnifiedSystemTrayController* tray_controller)
  16. : tray_controller_(tray_controller) {}
  17. UserChooserDetailedViewController::~UserChooserDetailedViewController() =
  18. default;
  19. // static
  20. bool UserChooserDetailedViewController::IsUserChooserEnabled() {
  21. // Don't allow user add or switch when CancelCastingDialog is open.
  22. // See http://crrev.com/291276 and http://crbug.com/353170.
  23. if (Shell::IsSystemModalWindowOpen())
  24. return false;
  25. // Don't allow at login, lock or when adding a multi-profile user.
  26. SessionControllerImpl* session = Shell::Get()->session_controller();
  27. if (session->IsUserSessionBlocked())
  28. return false;
  29. // Only allow for regular user session.
  30. if (session->GetPrimaryUserSession()->user_info.type !=
  31. user_manager::USER_TYPE_REGULAR) {
  32. return false;
  33. }
  34. return true;
  35. }
  36. void UserChooserDetailedViewController::TransitionToMainView() {
  37. tray_controller_->TransitionToMainView(true /* restore_focus */);
  38. }
  39. void UserChooserDetailedViewController::HandleUserSwitch(int user_index) {
  40. // Do not switch users when the log screen is presented.
  41. SessionControllerImpl* controller = Shell::Get()->session_controller();
  42. if (controller->IsUserSessionBlocked())
  43. return;
  44. // |user_index| must be in range (0, number_of_user). Note 0 is excluded
  45. // because it represents the active user and SwitchUser should not be called
  46. // for such case.
  47. DCHECK_GT(user_index, 0);
  48. DCHECK_LT(user_index, controller->NumberOfLoggedInUsers());
  49. MultiProfileUMA::RecordSwitchActiveUser(
  50. MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY);
  51. tray_controller_->CloseBubble();
  52. controller->SwitchActiveUser(
  53. controller->GetUserSession(user_index)->user_info.account_id);
  54. // SwitchActiveUser may delete us.
  55. }
  56. void UserChooserDetailedViewController::HandleAddUserAction() {
  57. tray_controller_->CloseBubble();
  58. Shell::Get()->session_controller()->ShowMultiProfileLogin();
  59. // ShowMultiProfileLogin may delete us.
  60. }
  61. views::View* UserChooserDetailedViewController::CreateView() {
  62. return new UserChooserView(this);
  63. }
  64. std::u16string UserChooserDetailedViewController::GetAccessibleName() const {
  65. return l10n_util::GetStringUTF16(
  66. IDS_ASH_QUICK_SETTINGS_BUBBLE_USER_SETTINGS_ACCESSIBLE_DESCRIPTION);
  67. }
  68. } // namespace ash