Skip to content

Commit

Permalink
ash: Add QS tile for shelf party mode
Browse files Browse the repository at this point in the history
Bug: 1262374
Test: ash_unittests ShelfPartyQsTileTest.*
Test: ash_unittests ShelfControllerShelfPartyTest.*
Change-Id: Ifc8f7948f85feb8f6664ad5b5648227331d40837
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3290495
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Avery Musbach <amusbach@chromium.org>
Cr-Commit-Position: refs/heads/main@{#943338}
  • Loading branch information
Avery Musbach authored and Chromium LUCI CQ committed Nov 19, 2021
1 parent e6c392d commit 2041a09
Show file tree
Hide file tree
Showing 30 changed files with 367 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,8 @@ component("ash") {
"shelf/shelf_navigation_widget.cc",
"shelf/shelf_navigation_widget.h",
"shelf/shelf_observer.h",
"shelf/shelf_party_feature_pod_controller.cc",
"shelf/shelf_party_feature_pod_controller.h",
"shelf/shelf_test_api.cc",
"shelf/shelf_tooltip_bubble.cc",
"shelf/shelf_tooltip_bubble.h",
Expand Down
20 changes: 20 additions & 0 deletions ash/ash_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -4309,6 +4309,26 @@ Here are some things you can try to get started.
<message name="IDS_ENTER_PIP_A11Y_NOTIFICATION" is_accessibility_with_no_ui="true" desc="Accessibility text read by chromevox when a window starts picture-in-picture mode.">
Picture-in-picture started, Alt+Shift+V to focus
</message>

<!-- Shelf Party -->
<message name="IDS_ASH_STATUS_TRAY_SHELF_PARTY_LABEL" desc="The text shown in the tray menu button that toggles Shelf Party mode.">
Shelf Party
</message>
<message name="IDS_ASH_STATUS_TRAY_SHELF_PARTY_TOGGLE_TOOLTIP" desc="The tooltip text used for the tray menu button that toggles Shelf Party mode.">
Toggle Shelf Party. <ph name="STATE_TEXT">$1<ex>Shelf Party is on.</ex></ph>
</message>
<message name="IDS_ASH_STATUS_TRAY_SHELF_PARTY_ENABLED_STATE_TOOLTIP" desc="The tooltip text indicating that Shelf Party mode is on.">
Shelf Party is on.
</message>
<message name="IDS_ASH_STATUS_TRAY_SHELF_PARTY_DISABLED_STATE_TOOLTIP" desc="The tooltip text indicating that Shelf Party mode is off.">
Shelf Party is off.
</message>
<message name="IDS_ASH_STATUS_TRAY_SHELF_PARTY_ON_SUBLABEL" desc="The sub label text shown under the tray menu button when Shelf Party mode is on.">
On
</message>
<message name="IDS_ASH_STATUS_TRAY_SHELF_PARTY_OFF_SUBLABEL" desc="The sub label text shown under the tray menu button when Shelf Party mode is off.">
Off
</message>
</messages>
</release>
</grit>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d54188f8bff1ce8b7373f98a92b92bfd0fee092e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a0a1d8bbf3bda871177fda7df20f198e883e3634
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
07e87468238a9ee999d954266cc29c6cb81c9e6a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9b14f0cdbecc32ed7a4de8de4da1424ca136513b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
07e87468238a9ee999d954266cc29c6cb81c9e6a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a0a1d8bbf3bda871177fda7df20f198e883e3634
4 changes: 4 additions & 0 deletions ash/constants/ash_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,10 @@ const base::Feature kSettingsAppNotificationSettings{
const base::Feature kShelfLauncherNudge{"ShelfLauncherNudge",
base::FEATURE_DISABLED_BY_DEFAULT};

// Enables the shelf party.
const base::Feature kShelfParty{"ShelfParty",
base::FEATURE_DISABLED_BY_DEFAULT};

// Enables or disables the new shimless rma flow.
const base::Feature kShimlessRMAFlow{"ShimlessRMAFlow",
base::FEATURE_DISABLED_BY_DEFAULT};
Expand Down
1 change: 1 addition & 0 deletions ash/constants/ash_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ extern const base::Feature kSessionManagerLivenessCheck;
COMPONENT_EXPORT(ASH_CONSTANTS)
extern const base::Feature kSettingsAppNotificationSettings;
COMPONENT_EXPORT(ASH_CONSTANTS) extern const base::Feature kShelfLauncherNudge;
COMPONENT_EXPORT(ASH_CONSTANTS) extern const base::Feature kShelfParty;
COMPONENT_EXPORT(ASH_CONSTANTS) extern const base::Feature kShimlessRMAFlow;
COMPONENT_EXPORT(ASH_CONSTANTS)
extern const base::Feature kShowBluetoothDebugLogToggle;
Expand Down
3 changes: 3 additions & 0 deletions ash/public/cpp/session/session_controller_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class ASH_PUBLIC_EXPORT SessionControllerClient {
// Returns the pref service for the given user if available.
virtual PrefService* GetUserPrefService(const AccountId& account_id) = 0;

// Returns true if the device is enterprise managed.
virtual bool IsEnterpriseManaged() const = 0;

protected:
virtual ~SessionControllerClient() = default;
};
Expand Down
6 changes: 6 additions & 0 deletions ash/public/cpp/shelf_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ void ShelfModel::OnItemReturnedFromRipOff(int index) {
observer.ShelfItemReturnedFromRipOff(index);
}

void ShelfModel::ToggleShelfParty() {
in_shelf_party_ = !in_shelf_party_;
for (auto& observer : observers_)
observer.ShelfPartyToggled(in_shelf_party_);
}

int ShelfModel::ItemIndexByID(const ShelfID& shelf_id) const {
for (size_t i = 0; i < items_.size(); ++i) {
if (items_[i].id == shelf_id)
Expand Down
6 changes: 6 additions & 0 deletions ash/public/cpp/shelf_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class ASH_PUBLIC_EXPORT ShelfModel {
return current_mutation_is_user_triggered_ > 0;
}

bool in_shelf_party() const { return in_shelf_party_; }

// Sets |shelf_id| to be the newly active shelf item.
void SetActiveShelfID(const ShelfID& shelf_id);

Expand All @@ -179,6 +181,8 @@ class ASH_PUBLIC_EXPORT ShelfModel {
// dragged back onto the shelf (it is still being dragged).
void OnItemReturnedFromRipOff(int index);

void ToggleShelfParty();

// Update the ShelfItem with |app_id| to set whether the item currently has a
// notification.
void UpdateItemNotification(const std::string& app_id, bool has_badge);
Expand Down Expand Up @@ -246,6 +250,8 @@ class ASH_PUBLIC_EXPORT ShelfModel {
// user interaction.
int current_mutation_is_user_triggered_ = 0;

bool in_shelf_party_ = false;

base::ObserverList<ShelfModelObserver>::Unchecked observers_;

std::map<ShelfID, std::unique_ptr<ShelfItemDelegate>>
Expand Down
3 changes: 3 additions & 0 deletions ash/public/cpp/shelf_model_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class ASH_PUBLIC_EXPORT ShelfModelObserver {
// onto the shelf (it is still being dragged).
virtual void ShelfItemReturnedFromRipOff(int index) {}

// Invoked when shelf party mode is toggled.
virtual void ShelfPartyToggled(bool in_shelf_party) {}

protected:
virtual ~ShelfModelObserver() {}
};
Expand Down
1 change: 1 addition & 0 deletions ash/resources/vector_icons/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ aggregate_vector_icons("ash_vector_icons") {
"shelf_overflow.icon",
"shelf_overflow_horizontal_dots.icon",
"shelf_overview.icon",
"shelf_party.icon",
"shelf_position.icon",
"shelf_shutdown_button.icon",
"shelf_sign_out_button.icon",
Expand Down
43 changes: 43 additions & 0 deletions ash/resources/vector_icons/shelf_party.icon
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

CANVAS_DIMENSIONS, 24,
MOVE_TO, 13.16f, 8.8f,
R_CUBIC_TO, -1.69f, 4.61f, -7.68f, 7.64f, -9.53f, 6.96f,
CUBIC_TO, 1.79f, 15.09f, -0.82f, 8.9f, 0.87f, 4.29f,
R_ARC_TO, 6.55f, 6.55f, 0, 1, 1, 12.29f, 4.51f,
CLOSE,
NEW_PATH,
MOVE_TO, 4.2f, 14.23f,
LINE_TO, 0, 16.17f,
R_LINE_TO, 6.15f, 2.25f,
CLOSE,
NEW_PATH,
MOVE_TO, 20.5f, 15.39f,
R_CUBIC_TO, -0.99f, -0.03f, -2.02f, 0.18f, -3.01f, 0.54f,
R_CUBIC_TO, -1.99f, 0.72f, -3.99f, 1.99f, -5.94f, 3.2f,
R_CUBIC_TO, -1.95f, 1.21f, -3.84f, 2.35f, -5.41f, 2.84f,
R_CUBIC_TO, -0.79f, 0.25f, -1.48f, 0.34f, -2.06f, 0.25f,
R_CUBIC_TO, -0.58f, -0.09f, -1.07f, -0.32f, -1.56f, -0.85f,
R_CUBIC_TO, -0.05f, -0.05f, -0.12f, -0.22f, -0.04f, -0.63f,
R_CUBIC_TO, 0.07f, -0.41f, 0.28f, -0.96f, 0.54f, -1.48f,
R_CUBIC_TO, 0.52f, -1.04f, 1.19f, -1.97f, 1.19f, -1.97f,
LINE_TO, 2.8f, 16.25f,
R_CUBIC_TO, 0, 0, -0.75f, 1.01f, -1.35f, 2.23f,
R_CUBIC_TO, -0.3f, 0.61f, -0.57f, 1.27f, -0.69f, 1.96f,
R_CUBIC_TO, -0.12f, 0.69f, -0.08f, 1.51f, 0.49f, 2.12f,
R_CUBIC_TO, 0.73f, 0.78f, 1.63f, 1.24f, 2.57f, 1.39f,
R_CUBIC_TO, 0.94f, 0.14f, 1.89f, 0, 2.85f, -0.3f,
R_CUBIC_TO, 1.91f, -0.6f, 3.86f, -1.82f, 5.81f, -3.03f,
R_CUBIC_TO, 1.95f, -1.21f, 3.9f, -2.41f, 5.61f, -3.04f,
R_CUBIC_TO, 1.71f, -0.62f, 3.04f, -0.68f, 4.19f, 0.18f,
R_CUBIC_TO, -0.11f, -0.08f, -0.07f, -0.1f, -0.05f, 0.02f,
R_CUBIC_TO, 0.02f, 0.13f, 0.03f, 0.35f, 0.01f, 0.57f,
R_CUBIC_TO, -0.04f, 0.44f, -0.14f, 0.86f, -0.14f, 0.86f,
R_LINE_TO, 1.7f, 0.43f,
R_CUBIC_TO, 0, 0, 0.14f, -0.53f, 0.19f, -1.16f,
R_ARC_TO, 3.93f, 3.93f, 0, 0, 0, -0.04f, -1.02f,
R_CUBIC_TO, -0.06f, -0.36f, -0.2f, -0.8f, -0.63f, -1.12f,
R_CUBIC_TO, -0.86f, -0.64f, -1.82f, -0.93f, -2.82f, -0.96f,
CLOSE
4 changes: 4 additions & 0 deletions ash/session/session_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ bool SessionControllerImpl::IsUserFirstLogin() const {
return GetUserSession(0)->user_info.is_new_profile;
}

bool SessionControllerImpl::IsEnterpriseManaged() const {
return client_ && client_->IsEnterpriseManaged();
}

bool SessionControllerImpl::ShouldDisplayManagedUI() const {
if (!IsActiveUserSessionStarted())
return false;
Expand Down
3 changes: 3 additions & 0 deletions ash/session/session_controller_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class ASH_EXPORT SessionControllerImpl : public SessionController {
// device (i.e. first time login on the device).
bool IsUserFirstLogin() const;

// Returns true if the device is enterprise managed.
bool IsEnterpriseManaged() const;

// Returns true if should display managed icon for current session,
// and false otherwise.
bool ShouldDisplayManagedUI() const;
Expand Down
4 changes: 4 additions & 0 deletions ash/session/test_session_controller_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ PrefService* TestSessionControllerClient::GetUserPrefService(
return prefs_provider_ ? prefs_provider_->GetUserPrefs(account_id) : nullptr;
}

bool TestSessionControllerClient::IsEnterpriseManaged() const {
return is_enterprise_managed_;
}

void TestSessionControllerClient::DoSwitchUser(const AccountId& account_id,
bool switch_user) {
if (!switch_user)
Expand Down
7 changes: 7 additions & 0 deletions ash/session/test_session_controller_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class TestSessionControllerClient : public SessionControllerClient {
void EmitAshInitialized() override;
PrefService* GetSigninScreenPrefService() override;
PrefService* GetUserPrefService(const AccountId& account_id) override;
bool IsEnterpriseManaged() const override;

// By default `LockScreen()` only changes the session state but no UI views
// will be created. If your tests requires the lock screen to be created,
Expand All @@ -143,6 +144,10 @@ class TestSessionControllerClient : public SessionControllerClient {
should_show_lock_screen_ = should_show;
}

void set_is_enterprise_managed(bool is_enterprise_managed) {
is_enterprise_managed_ = is_enterprise_managed;
}

private:
void DoSwitchUser(const AccountId& account_id, bool switch_user);

Expand All @@ -158,6 +163,8 @@ class TestSessionControllerClient : public SessionControllerClient {

bool should_show_lock_screen_ = false;

bool is_enterprise_managed_ = false;

std::unique_ptr<views::Widget> multi_profile_login_widget_;

base::WeakPtrFactory<TestSessionControllerClient> weak_ptr_factory_{this};
Expand Down
11 changes: 11 additions & 0 deletions ash/shelf/shelf_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ void ShelfController::RegisterProfilePrefs(PrefRegistrySimple* registry) {
LauncherNudgeController::RegisterProfilePrefs(registry);
}

void ShelfController::OnActiveUserSessionChanged(const AccountId& account_id) {
if (model_.in_shelf_party())
model_.ToggleShelfParty();
}

void ShelfController::OnSessionStateChanged(
session_manager::SessionState state) {
if (model_.in_shelf_party())
model_.ToggleShelfParty();
}

void ShelfController::OnActiveUserPrefServiceChanged(
PrefService* pref_service) {
SetShelfBehaviorsFromPrefs();
Expand Down
2 changes: 2 additions & 0 deletions ash/shelf/shelf_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class ASH_EXPORT ShelfController : public SessionObserver,

private:
// SessionObserver:
void OnActiveUserSessionChanged(const AccountId& account_id) override;
void OnSessionStateChanged(session_manager::SessionState state) override;
void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;

// TabletModeObserver:
Expand Down
28 changes: 28 additions & 0 deletions ash/shelf/shelf_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ash/wm/window_util.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "components/account_id/account_id.h"
#include "components/prefs/pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/image/image_unittest_util.h"
Expand Down Expand Up @@ -383,4 +384,31 @@ TEST_F(ShelfControllerAppModeTest, AutoHideBehavior) {
EXPECT_EQ(ShelfAutoHideBehavior::kAlwaysHidden, shelf->auto_hide_behavior());
}

using ShelfControllerShelfPartyTest = NoSessionAshTestBase;

TEST_F(ShelfControllerShelfPartyTest, ShelfPartyEndedOnLockScreen) {
auto* session_controller = GetSessionControllerClient();
session_controller->SetSessionState(session_manager::SessionState::ACTIVE);
ShelfModel* model = Shell::Get()->shelf_controller()->model();
model->ToggleShelfParty();
EXPECT_TRUE(model->in_shelf_party());
session_controller->SetSessionState(session_manager::SessionState::LOCKED);
EXPECT_FALSE(model->in_shelf_party());
}

TEST_F(ShelfControllerShelfPartyTest, ShelfPartyEndedOnSwitchUsers) {
auto* session_controller = GetSessionControllerClient();
constexpr char kEmail1[] = "user1@gmail.com";
session_controller->AddUserSession(kEmail1);
constexpr char kEmail2[] = "user2@gmail.com";
session_controller->AddUserSession(kEmail2);
session_controller->SwitchActiveUser(AccountId::FromUserEmail(kEmail1));
session_controller->SetSessionState(session_manager::SessionState::ACTIVE);
ShelfModel* model = Shell::Get()->shelf_controller()->model();
model->ToggleShelfParty();
EXPECT_TRUE(model->in_shelf_party());
session_controller->SwitchActiveUser(AccountId::FromUserEmail(kEmail2));
EXPECT_FALSE(model->in_shelf_party());
}

} // namespace ash
76 changes: 76 additions & 0 deletions ash/shelf/shelf_party_feature_pod_controller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/shelf/shelf_party_feature_pod_controller.h"

#include "ash/public/cpp/shelf_model.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/shelf_controller.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/unified/feature_pod_button.h"
#include "components/session_manager/session_manager_types.h"
#include "ui/base/l10n/l10n_util.h"

namespace ash {

ShelfPartyFeaturePodController::ShelfPartyFeaturePodController() = default;

ShelfPartyFeaturePodController::~ShelfPartyFeaturePodController() {
Shell::Get()->session_controller()->RemoveObserver(this);
Shell::Get()->shelf_controller()->model()->RemoveObserver(this);
}

FeaturePodButton* ShelfPartyFeaturePodController::CreateButton() {
DCHECK(!button_);
button_ = new FeaturePodButton(this);
button_->DisableLabelButtonFocus();
button_->SetVectorIcon(kShelfPartyIcon);
button_->SetLabel(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHELF_PARTY_LABEL));
UpdateButton();
Shell::Get()->session_controller()->AddObserver(this);
Shell::Get()->shelf_controller()->model()->AddObserver(this);
return button_;
}

void ShelfPartyFeaturePodController::OnIconPressed() {
Shell::Get()->shelf_controller()->model()->ToggleShelfParty();
}

SystemTrayItemUmaType ShelfPartyFeaturePodController::GetUmaType() const {
return SystemTrayItemUmaType::UMA_SHELF_PARTY;
}

void ShelfPartyFeaturePodController::OnSessionStateChanged(
session_manager::SessionState state) {
UpdateButton();
}

void ShelfPartyFeaturePodController::ShelfPartyToggled(bool in_shelf_party) {
UpdateButton();
}

void ShelfPartyFeaturePodController::UpdateButton() {
DCHECK(button_);
const SessionControllerImpl* session_controller =
Shell::Get()->session_controller();
button_->SetVisible(session_controller->GetSessionState() ==
session_manager::SessionState::ACTIVE &&
!session_controller->IsEnterpriseManaged());
const bool toggled =
Shell::Get()->shelf_controller()->model()->in_shelf_party();
button_->SetToggled(toggled);
button_->SetSubLabel(l10n_util::GetStringUTF16(
toggled ? IDS_ASH_STATUS_TRAY_SHELF_PARTY_ON_SUBLABEL
: IDS_ASH_STATUS_TRAY_SHELF_PARTY_OFF_SUBLABEL));
button_->SetIconAndLabelTooltips(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_SHELF_PARTY_TOGGLE_TOOLTIP,
l10n_util::GetStringUTF16(
toggled ? IDS_ASH_STATUS_TRAY_SHELF_PARTY_ENABLED_STATE_TOOLTIP
: IDS_ASH_STATUS_TRAY_SHELF_PARTY_DISABLED_STATE_TOOLTIP)));
}

} // namespace ash
Loading

0 comments on commit 2041a09

Please sign in to comment.