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

Side by Side Diff: ash/common/system/user/user_view.cc

Issue 2512693003: ash: Replace SessionStateDelegate::CanAddUserToMultiProfile (Closed)
Patch Set: Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ash/common/system/user/user_view.h" 5 #include "ash/common/system/user/user_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
(...skipping 11 matching lines...) Expand all
22 #include "ash/common/system/user/button_from_view.h" 22 #include "ash/common/system/user/button_from_view.h"
23 #include "ash/common/system/user/login_status.h" 23 #include "ash/common/system/user/login_status.h"
24 #include "ash/common/system/user/rounded_image_view.h" 24 #include "ash/common/system/user/rounded_image_view.h"
25 #include "ash/common/system/user/user_card_view.h" 25 #include "ash/common/system/user/user_card_view.h"
26 #include "ash/common/wm_lookup.h" 26 #include "ash/common/wm_lookup.h"
27 #include "ash/common/wm_root_window_controller.h" 27 #include "ash/common/wm_root_window_controller.h"
28 #include "ash/common/wm_shell.h" 28 #include "ash/common/wm_shell.h"
29 #include "ash/common/wm_window.h" 29 #include "ash/common/wm_window.h"
30 #include "ash/public/cpp/shell_window_ids.h" 30 #include "ash/public/cpp/shell_window_ids.h"
31 #include "ash/resources/vector_icons/vector_icons.h" 31 #include "ash/resources/vector_icons/vector_icons.h"
32 #include "base/optional.h"
33 #include "components/signin/core/account_id/account_id.h" 32 #include "components/signin/core/account_id/account_id.h"
34 #include "components/user_manager/user_info.h" 33 #include "components/user_manager/user_info.h"
35 #include "grit/ash_resources.h" 34 #include "grit/ash_resources.h"
36 #include "grit/ash_strings.h" 35 #include "grit/ash_strings.h"
37 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/resource/resource_bundle.h" 37 #include "ui/base/resource/resource_bundle.h"
39 #include "ui/gfx/canvas.h" 38 #include "ui/gfx/canvas.h"
40 #include "ui/gfx/geometry/insets.h" 39 #include "ui/gfx/geometry/insets.h"
41 #include "ui/gfx/paint_vector_icon.h" 40 #include "ui/gfx/paint_vector_icon.h"
42 #include "ui/views/controls/button/label_button.h" 41 #include "ui/views/controls/button/label_button.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); 97 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY);
99 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId()); 98 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId());
100 } 99 }
101 100
102 bool IsMultiProfileSupportedAndUserActive() { 101 bool IsMultiProfileSupportedAndUserActive() {
103 return WmShell::Get()->delegate()->IsMultiProfilesEnabled() && 102 return WmShell::Get()->delegate()->IsMultiProfilesEnabled() &&
104 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked(); 103 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked();
105 } 104 }
106 105
107 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). 106 // Creates the view shown in the user switcher popup ("AddUserMenuOption").
108 views::View* CreateAddUserView( 107 views::View* CreateAddUserView(AddUserSessionPolicy policy) {
109 base::Optional<SessionStateDelegate::AddUserError> error) {
110 DCHECK(UseMd()); 108 DCHECK(UseMd());
111 auto view = new views::View; 109 auto view = new views::View;
112 auto layout = new views::BoxLayout( 110 auto layout = new views::BoxLayout(
113 views::BoxLayout::kHorizontal, (kMenuButtonSize - kMenuIconSize) / 2, 111 views::BoxLayout::kHorizontal, (kMenuButtonSize - kMenuIconSize) / 2,
114 kMenuSeparatorVerticalPadding, kTrayPopupPaddingBetweenItems); 112 kMenuSeparatorVerticalPadding, kTrayPopupPaddingBetweenItems);
115 layout->set_minimum_cross_axis_size( 113 layout->set_minimum_cross_axis_size(
116 error ? 56 : GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT)); 114 policy != AddUserSessionPolicy::ALLOWED
115 ? 56
116 : GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT));
117 view->SetLayoutManager(layout); 117 view->SetLayoutManager(layout);
118 view->set_background( 118 view->set_background(
119 views::Background::CreateSolidBackground(kBackgroundColor)); 119 views::Background::CreateSolidBackground(kBackgroundColor));
120 120
121 if (!error) {
122 auto icon = new views::ImageView();
123 icon->SetImage(
124 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor));
125 view->AddChildView(icon);
126 }
127
128 int message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT; 121 int message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT;
Evan Stade 2016/11/17 23:18:13 nit: could you make this = 0 and assign this IDS t
xiyuan 2016/11/17 23:57:46 Done.
129 if (error) { 122 switch (policy) {
130 switch (*error) { 123 case AddUserSessionPolicy::ALLOWED: {
131 case SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER: 124 auto icon = new views::ImageView();
132 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER; 125 icon->SetImage(
133 break; 126 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor));
134 case SessionStateDelegate::ADD_USER_ERROR_MAXIMUM_USERS_REACHED: 127 view->AddChildView(icon);
135 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER; 128 break;
136 break;
137 case SessionStateDelegate::ADD_USER_ERROR_OUT_OF_USERS:
138 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS;
139 break;
140 } 129 }
130 case AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER:
131 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER;
132 break;
133 case AddUserSessionPolicy::ERROR_MAXIMUM_USERS_REACHED:
134 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER;
135 break;
136 case AddUserSessionPolicy::ERROR_OUT_OF_USERS:
137 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS;
138 break;
141 } 139 }
142 140
143 auto command_label = new views::Label(l10n_util::GetStringUTF16(message_id)); 141 auto command_label = new views::Label(l10n_util::GetStringUTF16(message_id));
144 command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 142 command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
145 command_label->SetMultiLine(true); 143 command_label->SetMultiLine(true);
146 view->AddChildView(command_label); 144 view->AddChildView(command_label);
147 return view; 145 return view;
148 } 146 }
149 147
150 class UserViewMouseWatcherHost : public views::MouseWatcherHost { 148 class UserViewMouseWatcherHost : public views::MouseWatcherHost {
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 WmLookup::Get() 595 WmLookup::Get()
598 ->GetWindowForWidget(GetWidget()) 596 ->GetWindowForWidget(GetWidget())
599 ->GetRootWindowController() 597 ->GetRootWindowController()
600 ->ConfigureWidgetInitParamsForContainer( 598 ->ConfigureWidgetInitParamsForContainer(
601 add_menu_option_.get(), kShellWindowId_DragImageAndTooltipContainer, 599 add_menu_option_.get(), kShellWindowId_DragImageAndTooltipContainer,
602 &params); 600 &params);
603 add_menu_option_->Init(params); 601 add_menu_option_->Init(params);
604 602
605 const SessionStateDelegate* delegate = 603 const SessionStateDelegate* delegate =
606 WmShell::Get()->GetSessionStateDelegate(); 604 WmShell::Get()->GetSessionStateDelegate();
607 SessionStateDelegate::AddUserError add_user_error; 605 const AddUserSessionPolicy add_user_policy =
608 add_user_enabled_ = delegate->CanAddUserToMultiProfile(&add_user_error); 606 delegate->GetAddUserSessionPolicy();
607 add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED;
609 608
610 if (UseMd()) { 609 if (UseMd()) {
611 base::Optional<SessionStateDelegate::AddUserError> error;
612 if (!add_user_enabled_)
613 error = add_user_error;
614 ButtonFromView* button = new ButtonFromView( 610 ButtonFromView* button = new ButtonFromView(
615 CreateAddUserView(error), add_user_enabled_ ? this : nullptr, 611 CreateAddUserView(add_user_policy), add_user_enabled_ ? this : nullptr,
616 IsActiveUser() ? TrayPopupInkDropStyle::INSET_BOUNDS 612 IsActiveUser() ? TrayPopupInkDropStyle::INSET_BOUNDS
617 : TrayPopupInkDropStyle::FILL_BOUNDS, 613 : TrayPopupInkDropStyle::FILL_BOUNDS,
618 false, gfx::Insets()); 614 false, gfx::Insets());
619 button->SetAccessibleName( 615 button->SetAccessibleName(
620 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); 616 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
621 button->ForceBorderVisible(true); 617 button->ForceBorderVisible(true);
622 618
623 // Position the widget on top of the user card view (which is still in the 619 // Position the widget on top of the user card view (which is still in the
624 // system menu). The top half of the widget will be transparent to allow 620 // system menu). The top half of the widget will be transparent to allow
625 // the active user to show through. 621 // the active user to show through.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 669
674 if (add_user_enabled_) { 670 if (add_user_enabled_) {
675 // We activate the entry automatically if invoked with focus. 671 // We activate the entry automatically if invoked with focus.
676 if (user_card_view_->HasFocus()) { 672 if (user_card_view_->HasFocus()) {
677 button->GetFocusManager()->SetFocusedView(button); 673 button->GetFocusManager()->SetFocusedView(button);
678 user_card_view_->GetFocusManager()->SetFocusedView(button); 674 user_card_view_->GetFocusManager()->SetFocusedView(button);
679 } 675 }
680 } else { 676 } else {
681 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 677 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
682 int message_id = 0; 678 int message_id = 0;
683 switch (add_user_error) { 679 switch (add_user_policy) {
684 case SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER: 680 case AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER:
685 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER; 681 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER;
686 break; 682 break;
687 case SessionStateDelegate::ADD_USER_ERROR_MAXIMUM_USERS_REACHED: 683 case AddUserSessionPolicy::ERROR_MAXIMUM_USERS_REACHED:
688 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER; 684 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER;
689 break; 685 break;
690 case SessionStateDelegate::ADD_USER_ERROR_OUT_OF_USERS: 686 case AddUserSessionPolicy::ERROR_OUT_OF_USERS:
691 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS; 687 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS;
692 break; 688 break;
693 default: 689 default:
694 NOTREACHED() << "Unknown adding user error " << add_user_error; 690 NOTREACHED() << "Unknown adding user policy "
691 << static_cast<int>(add_user_policy);
695 } 692 }
696 693
697 popup_message_.reset(new PopupMessage( 694 popup_message_.reset(new PopupMessage(
698 bundle.GetLocalizedString( 695 bundle.GetLocalizedString(
699 IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER), 696 IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER),
700 bundle.GetLocalizedString(message_id), PopupMessage::ICON_WARNING, 697 bundle.GetLocalizedString(message_id), PopupMessage::ICON_WARNING,
701 add_user_view->anchor(), views::BubbleBorder::TOP_LEFT, 698 add_user_view->anchor(), views::BubbleBorder::TOP_LEFT,
702 gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0), 699 gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0),
703 2 * kPopupMessageOffset)); 700 2 * kPopupMessageOffset));
704 } 701 }
(...skipping 19 matching lines...) Expand all
724 focus_manager_ = nullptr; 721 focus_manager_ = nullptr;
725 if (user_card_view_->GetFocusManager()) 722 if (user_card_view_->GetFocusManager())
726 user_card_view_->GetFocusManager()->ClearFocus(); 723 user_card_view_->GetFocusManager()->ClearFocus();
727 popup_message_.reset(); 724 popup_message_.reset();
728 mouse_watcher_.reset(); 725 mouse_watcher_.reset();
729 add_menu_option_.reset(); 726 add_menu_option_.reset();
730 } 727 }
731 728
732 } // namespace tray 729 } // namespace tray
733 } // namespace ash 730 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/session/session_types.h ('k') | chrome/browser/ui/ash/session_state_delegate_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698