Commit 4d8627b5 authored by Tim Song's avatar Tim Song Committed by Commit Bot

Ash Tray: Move existing functionality to UserChooserDetailedViewController.

This is a follow-up refactoring CL to
https://chromium.googlesource.com/chromium/src/+/e3b4260ee889203e9d9ec9852412f7a767018417

TEST=unit tests pass
BUG=953658

Change-Id: I4f024f5f550225c7ae68ccf5b56ac0d704e6932b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1580141
Commit-Queue: Tim Song <tengs@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653452}
parent 2bc167e4
......@@ -19,6 +19,7 @@
#include "ash/system/unified/sign_out_button.h"
#include "ash/system/unified/top_shortcut_button.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/system/unified/user_chooser_detailed_view_controller.h"
#include "ash/system/unified/user_chooser_view.h"
#include "base/numerics/ranges.h"
#include "ui/gfx/paint_vector_icon.h"
......@@ -163,7 +164,8 @@ TopShortcutsView::TopShortcutsView(UnifiedSystemTrayController* controller)
if (Shell::Get()->session_controller()->login_status() !=
LoginStatus::NOT_LOGGED_IN) {
user_avatar_button_ = new UserAvatarButton(this);
user_avatar_button_->SetEnabled(controller->IsUserChooserEnabled());
user_avatar_button_->SetEnabled(
UserChooserDetailedViewController::IsUserChooserEnabled());
container_->AddUserAvatarButton(user_avatar_button_);
}
......
......@@ -6,7 +6,6 @@
#include "ash/metrics/user_metrics_action.h"
#include "ash/metrics/user_metrics_recorder.h"
#include "ash/multi_profile_uma.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/system/accessibility/accessibility_feature_pod_controller.h"
......@@ -92,31 +91,6 @@ UnifiedSystemTrayView* UnifiedSystemTrayController::CreateView() {
return unified_view_;
}
void UnifiedSystemTrayController::HandleUserSwitch(int user_index) {
// Do not switch users when the log screen is presented.
SessionController* controller = Shell::Get()->session_controller();
if (controller->IsUserSessionBlocked())
return;
// |user_index| must be in range (0, number_of_user). Note 0 is excluded
// because it represents the active user and SwitchUser should not be called
// for such case.
DCHECK_GT(user_index, 0);
DCHECK_LT(user_index, controller->NumberOfLoggedInUsers());
MultiProfileUMA::RecordSwitchActiveUser(
MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY);
controller->SwitchActiveUser(
controller->GetUserSession(user_index)->user_info->account_id);
CloseBubble();
}
void UnifiedSystemTrayController::HandleAddUserAction() {
MultiProfileUMA::RecordSigninUser(MultiProfileUMA::SIGNIN_USER_BY_TRAY);
Shell::Get()->session_controller()->ShowMultiProfileLogin();
CloseBubble();
}
void UnifiedSystemTrayController::HandleSignOutAction() {
Shell::Get()->metrics()->RecordUserMetricsAction(UMA_STATUS_AREA_SIGN_OUT);
if (Shell::Get()->session_controller()->IsDemoSession())
......@@ -231,7 +205,7 @@ void UnifiedSystemTrayController::Fling(int velocity) {
}
void UnifiedSystemTrayController::ShowUserChooserView() {
if (!IsUserChooserEnabled())
if (!UserChooserDetailedViewController::IsUserChooserEnabled())
return;
animation_->Reset(1.0);
UpdateExpandedAmount();
......@@ -315,24 +289,6 @@ void UnifiedSystemTrayController::EnsureExpanded() {
animation_->Show();
}
bool UnifiedSystemTrayController::IsUserChooserEnabled() const {
// Don't allow user add or switch when CancelCastingDialog is open.
// See http://crrev.com/291276 and http://crbug.com/353170.
if (Shell::IsSystemModalWindowOpen())
return false;
// Don't allow at login, lock or when adding a multi-profile user.
SessionController* session = Shell::Get()->session_controller();
if (session->IsUserSessionBlocked())
return false;
// Don't show if we cannot add or switch users.
if (session->GetAddUserPolicy() != AddUserSessionPolicy::ALLOWED &&
session->NumberOfLoggedInUsers() <= 1)
return false;
return true;
}
void UnifiedSystemTrayController::AnimationEnded(
const gfx::Animation* animation) {
UpdateExpandedAmount();
......
......@@ -41,10 +41,6 @@ class ASH_EXPORT UnifiedSystemTrayController
// Create the view. The created view is unowned.
UnifiedSystemTrayView* CreateView();
// Switch the active user to |user_index|. Called from the view.
void HandleUserSwitch(int user_index);
// Show multi profile login UI. Called from the view.
void HandleAddUserAction();
// Sign out from the current user. Called from the view.
void HandleSignOutAction();
// Show lock screen which asks the user password. Called from the view.
......@@ -105,9 +101,6 @@ class ASH_EXPORT UnifiedSystemTrayController
// Ensure the main view is expanded. Called from the slider bubble controller.
void EnsureExpanded();
// Return true if user chooser is enabled. Called from the view.
bool IsUserChooserEnabled() const;
// gfx::AnimationDelegate:
void AnimationEnded(const gfx::Animation* animation) override;
void AnimationProgressed(const gfx::Animation* animation) override;
......
......@@ -4,6 +4,10 @@
#include "ash/system/unified/user_chooser_detailed_view_controller.h"
#include "ash/multi_profile_uma.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/system/unified/user_chooser_view.h"
namespace ash {
......@@ -15,8 +19,56 @@ UserChooserDetailedViewController::UserChooserDetailedViewController(
UserChooserDetailedViewController::~UserChooserDetailedViewController() =
default;
// static
bool UserChooserDetailedViewController::IsUserChooserEnabled() {
// Don't allow user add or switch when CancelCastingDialog is open.
// See http://crrev.com/291276 and http://crbug.com/353170.
if (Shell::IsSystemModalWindowOpen())
return false;
// Don't allow at login, lock or when adding a multi-profile user.
SessionController* session = Shell::Get()->session_controller();
if (session->IsUserSessionBlocked())
return false;
// Don't show if we cannot add or switch users.
if (session->GetAddUserPolicy() != AddUserSessionPolicy::ALLOWED &&
session->NumberOfLoggedInUsers() <= 1)
return false;
return true;
}
void UserChooserDetailedViewController::TransitionToMainView() {
tray_controller_->TransitionToMainView(true /* restore_focus */);
}
void UserChooserDetailedViewController::HandleUserSwitch(int user_index) {
// Do not switch users when the log screen is presented.
SessionController* controller = Shell::Get()->session_controller();
if (controller->IsUserSessionBlocked())
return;
// |user_index| must be in range (0, number_of_user). Note 0 is excluded
// because it represents the active user and SwitchUser should not be called
// for such case.
DCHECK_GT(user_index, 0);
DCHECK_LT(user_index, controller->NumberOfLoggedInUsers());
MultiProfileUMA::RecordSwitchActiveUser(
MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY);
controller->SwitchActiveUser(
controller->GetUserSession(user_index)->user_info->account_id);
tray_controller_->CloseBubble();
}
void UserChooserDetailedViewController::HandleAddUserAction() {
MultiProfileUMA::RecordSigninUser(MultiProfileUMA::SIGNIN_USER_BY_TRAY);
Shell::Get()->session_controller()->ShowMultiProfileLogin();
tray_controller_->CloseBubble();
}
views::View* UserChooserDetailedViewController::CreateView() {
return new UserChooserView(tray_controller_);
return new UserChooserView(this);
}
} // namespace ash
......@@ -20,6 +20,18 @@ class UserChooserDetailedViewController : public DetailedViewController {
UnifiedSystemTrayController* tray_controller);
~UserChooserDetailedViewController() override;
// Return true if user chooser is enabled. Called from the view.
static bool IsUserChooserEnabled();
// Transitions back from the detailed view to the main view.
void TransitionToMainView();
// Switch the active user to |user_index|. Called from the view.
void HandleUserSwitch(int user_index);
// Show multi profile login UI. Called from the view.
void HandleAddUserAction();
// DetailedViewController:
views::View* CreateView() override;
......
......@@ -19,7 +19,7 @@
#include "ash/system/tray/tri_view.h"
#include "ash/system/unified/top_shortcut_button.h"
#include "ash/system/unified/top_shortcuts_view.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/system/unified/user_chooser_detailed_view_controller.h"
#include "ash/system/user/rounded_image_view.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -39,41 +39,41 @@ namespace {
class CloseButton : public TopShortcutButton, public views::ButtonListener {
public:
explicit CloseButton(UnifiedSystemTrayController* controller);
explicit CloseButton(UserChooserDetailedViewController* controller);
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private:
UnifiedSystemTrayController* const controller_;
UserChooserDetailedViewController* const controller_;
DISALLOW_COPY_AND_ASSIGN(CloseButton);
};
CloseButton::CloseButton(UnifiedSystemTrayController* controller)
CloseButton::CloseButton(UserChooserDetailedViewController* controller)
: TopShortcutButton(this, views::kIcCloseIcon, IDS_APP_ACCNAME_CLOSE),
controller_(controller) {}
void CloseButton::ButtonPressed(views::Button* sender, const ui::Event& event) {
controller_->TransitionToMainView(true /* restore_focus */);
controller_->TransitionToMainView();
}
// A button that will transition to multi profile login UI.
class AddUserButton : public views::Button, public views::ButtonListener {
public:
explicit AddUserButton(UnifiedSystemTrayController* controller);
explicit AddUserButton(UserChooserDetailedViewController* controller);
~AddUserButton() override = default;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private:
UnifiedSystemTrayController* const controller_;
UserChooserDetailedViewController* const controller_;
DISALLOW_COPY_AND_ASSIGN(AddUserButton);
};
AddUserButton::AddUserButton(UnifiedSystemTrayController* controller)
AddUserButton::AddUserButton(UserChooserDetailedViewController* controller)
: Button(this), controller_(controller) {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::kHorizontal, gfx::Insets(kUnifiedTopShortcutSpacing),
......@@ -186,7 +186,7 @@ base::string16 GetUserItemAccessibleString(int user_index) {
}
UserItemButton::UserItemButton(int user_index,
UnifiedSystemTrayController* controller,
UserChooserDetailedViewController* controller,
bool has_close_button)
: Button(this),
user_index_(user_index),
......@@ -283,7 +283,8 @@ void UserItemButton::ButtonPressed(views::Button* sender,
controller_->HandleUserSwitch(user_index_);
}
UserChooserView::UserChooserView(UnifiedSystemTrayController* controller) {
UserChooserView::UserChooserView(
UserChooserDetailedViewController* controller) {
SetLayoutManager(
std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical));
const int num_users =
......
......@@ -16,7 +16,7 @@ class Label;
namespace ash {
class UnifiedSystemTrayController;
class UserChooserDetailedViewController;
// Circular image view with user's icon of |user_index|.
views::View* CreateUserAvatarView(int user_index);
......@@ -28,7 +28,7 @@ base::string16 GetUserItemAccessibleString(int user_index);
class UserItemButton : public views::Button, public views::ButtonListener {
public:
UserItemButton(int user_index,
UnifiedSystemTrayController* controller,
UserChooserDetailedViewController* controller,
bool has_close_button);
~UserItemButton() override = default;
......@@ -42,7 +42,7 @@ class UserItemButton : public views::Button, public views::ButtonListener {
private:
const int user_index_;
UnifiedSystemTrayController* const controller_;
UserChooserDetailedViewController* const controller_;
views::ImageView* const capture_icon_;
views::Label* const name_;
views::Label* const email_;
......@@ -53,7 +53,7 @@ class UserItemButton : public views::Button, public views::ButtonListener {
// A detailed view of user chooser.
class UserChooserView : public views::View, public MediaCaptureObserver {
public:
UserChooserView(UnifiedSystemTrayController* controller);
explicit UserChooserView(UserChooserDetailedViewController* controller);
~UserChooserView() override;
// MediaCaptureObserver:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment